DeepCover Embedded Security in IoT: Public-key Secured Data Paths

Dependencies:   MaximInterface

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SensorNode.hpp Source File

SensorNode.hpp

00001 /*******************************************************************************
00002 * Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved.
00003 *
00004 * Permission is hereby granted, free of charge, to any person obtaining a
00005 * copy of this software and associated documentation files (the "Software"),
00006 * to deal in the Software without restriction, including without limitation
00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008 * and/or sell copies of the Software, and to permit persons to whom the
00009 * Software is furnished to do so, subject to the following conditions:
00010 *
00011 * The above copyright notice and this permission notice shall be included
00012 * in all copies or substantial portions of the Software.
00013 *
00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020 * OTHER DEALINGS IN THE SOFTWARE.
00021 *
00022 * Except as contained in this notice, the name of Maxim Integrated
00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated
00024 * Products, Inc. Branding Policy.
00025 *
00026 * The mere transfer of this software does not imply any licenses
00027 * of trade secrets, proprietary technology, copyrights, patents,
00028 * trademarks, maskwork rights, or any other form of intellectual
00029 * property whatsoever. Maxim Integrated Products, Inc. retains all
00030 * ownership rights.
00031 *******************************************************************************/
00032 
00033 #ifndef SENSORNODE_HPP
00034 #define SENSORNODE_HPP
00035 
00036 #include <stdint.h>
00037 #include <MaximInterfaceCore/Function.hpp>
00038 #include <MaximInterfaceCore/ManId.hpp>
00039 #include <MaximInterfaceCore/Result.hpp>
00040 #include <MaximInterfaceCore/RomId.hpp>
00041 #include <MaximInterfaceDevices/DS28C36_DS2476.hpp>
00042 
00043 namespace MaximInterfaceCore {
00044 
00045 class I2CMaster;
00046 class Sleep;
00047 
00048 } // namespace MaximInterfaceCore
00049 namespace MaximInterfaceDevices {
00050 
00051 class DS2476;
00052 
00053 } // namespace MaximInterfaceDevices
00054 
00055 /// Interface to the authenticated sensor node peripheral board.
00056 class SensorNode {
00057 public:
00058   /// Prints a null-terminated char string.
00059   typedef MaximInterfaceCore::Function<void(const char *)> PrintHandler;
00060 
00061   /// Style of temperature to measure.
00062   enum TempStyle { AmbientTemp, ObjectTemp };
00063 
00064   enum State  {
00065     Disconnected,       ///< No sensor node is connected.
00066     Invalid,            ///< Sensor node is not valid.
00067     ValidLaserDisabled, ///< Sensor node is valid, and laser is disabled.
00068     ValidLaserEnabled,  ///< Sensor node is valid, and laser is enabled.
00069   };
00070 
00071   /// @param i2c
00072   /// I2C bus connected to the sensor node that communicates with DS28C36 and
00073   /// MLX90614.
00074   /// @param ds2476 Coprocessor used for authentication computations.
00075   SensorNode (MaximInterfaceCore::Sleep & sleep,
00076              MaximInterfaceCore::I2CMaster & i2c,
00077              MaximInterfaceDevices::DS2476 & ds2476);
00078 
00079   /// Detects if a potential sensor node is connected.
00080   State  detect();
00081 
00082   /// @brief Enable or disable the laser.
00083   /// @param enabled True to enable the laser or false to disable.
00084   /// @param print
00085   /// Optional callback for displaying informational messages to the user.
00086   /// @returns True if the operation was successful.
00087   MaximInterfaceCore::Result<void>
00088   setLaserEnabled(bool enabled, const PrintHandler & print = PrintHandler());
00089 
00090   /// @brief Get a temperature measurement from the MLX90614.
00091   /// @param style Temperature style to read.
00092   /// @returns Temperature in Celsius.
00093   MaximInterfaceCore::Result<double> readTemp(TempStyle style);
00094 
00095 private:
00096   /// Checks if the sensor node is authentic.
00097   MaximInterfaceCore::Result<void> authenticate();
00098 
00099   /// @brief Checks if the laser is enabled.
00100   /// @returns True if the laser is enabled.
00101   MaximInterfaceCore::Result<bool> getLaserEnabled();
00102 
00103   MaximInterfaceCore::I2CMaster * i2c;
00104   MaximInterfaceDevices::DS28C36 ds28c36;
00105   MaximInterfaceDevices::DS2476 * ds2476;
00106   MaximInterfaceCore::RomId::array romId;
00107   MaximInterfaceCore::ManId::array manId;
00108 
00109   friend class HardwareTestWindow;
00110 };
00111 
00112 #endif