Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FXAS21002 FXOS8700Q
m2mdevice.h
00001 /* 00002 * Copyright (c) 2015 ARM Limited. All rights reserved. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * Licensed under the Apache License, Version 2.0 (the License); you may 00005 * not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #ifndef M2M_DEVICE_H 00017 #define M2M_DEVICE_H 00018 00019 #include "mbed-client/m2mobject.h" 00020 00021 // FORWARD DECLARATION 00022 class M2MResource; 00023 class M2MResourceInstance; 00024 00025 /*! \file m2mdevice.h 00026 * \brief M2MDevice. 00027 * This class represents the Device Object model of the LwM2M framework. 00028 * 00029 * It provides an interface for handling the device object 00030 * and all its corresponding resources. There can be only one instance 00031 * of a Device Object. 00032 */ 00033 00034 /*! \class M2MDevice 00035 * \brief A class representin the Device Object model of the LwM2M framework. 00036 * \note There can be only one instance of a Device Object. 00037 */ 00038 class M2MDevice : public M2MObject { 00039 00040 friend class M2MInterfaceFactory; 00041 00042 public: 00043 00044 /** 00045 * \brief An enum defining all the resources associated with the 00046 * Device Object in the LWM2M framework. 00047 */ 00048 typedef enum { 00049 Manufacturer, 00050 DeviceType, 00051 ModelNumber, 00052 SerialNumber, 00053 HardwareVersion, 00054 FirmwareVersion, 00055 SoftwareVersion, 00056 Reboot, 00057 FactoryReset, 00058 AvailablePowerSources, 00059 PowerSourceVoltage, 00060 PowerSourceCurrent, 00061 BatteryLevel, 00062 BatteryStatus, 00063 MemoryFree, 00064 MemoryTotal, 00065 ErrorCode, 00066 ResetErrorCode, 00067 CurrentTime, 00068 UTCOffset, 00069 Timezone, 00070 SupportedBindingMode 00071 }DeviceResource; 00072 00073 private: 00074 00075 /** 00076 * \brief Constructor 00077 */ 00078 M2MDevice(char *path); 00079 00080 // Prevents the use of assignment operator. 00081 M2MDevice& operator=( const M2MDevice& /*other*/ ); 00082 00083 // Prevents the use of copy constructor 00084 M2MDevice( const M2MDevice& /*other*/ ); 00085 00086 /** 00087 * \brief Destructor 00088 */ 00089 virtual ~M2MDevice(); 00090 00091 static M2MDevice* get_instance(); 00092 00093 public: 00094 00095 /** 00096 * \brief Deletes an M2MDevice instance. 00097 */ 00098 static void delete_instance(); 00099 00100 /** 00101 * \brief Creates a new resource for the given resource enum. 00102 * \param resource With this function, the following resources can be created: 00103 * 'Manufacturer', 'DeviceType','ModelNumber','SerialNumber', 00104 * 'HardwareVersion', 'FirmwareVersion', 'SoftwareVersion', 00105 * 'UTCOffset', 'Timezone', 'SupportedBindingMode'. 00106 * \param value The value to be set on the resource, in string format. 00107 * \return M2MResource if created successfully, else NULL. 00108 */ 00109 M2MResource* create_resource(DeviceResource resource, const String &value); 00110 00111 /** 00112 * \brief Creates a new resource for the given resource enum. 00113 * \param resource With this function, the following resources can be created: 00114 * 'AvailablePowerSources','PowerSourceVoltage','PowerSourceCurrent', 00115 * 'BatteryLevel', 'BatteryStatus', 'MemoryFree', 'MemoryTotal', 00116 * 'ErrorCode', 'CurrentTime'. For 'CurrentTime', pass the time value in EPOCH format, for example 00117 * 1438944683. 00118 * \param value The value to be set on the resource, in integer format. 00119 * \return M2MResource if created successfully, else NULL. 00120 */ 00121 M2MResource* create_resource(DeviceResource resource, int64_t value); 00122 00123 /** 00124 * \brief Creates a new resource instance for the given resource enum. 00125 * \param resource With this function, the following resources can be created: 00126 * 'AvailablePowerSources','PowerSourceVoltage','PowerSourceCurrent', 00127 * 'ErrorCode'. 00128 * \param value The value to be set on the resource, in integer format. 00129 * \return M2MResourceInstance if created successfully, else NULL. 00130 */ 00131 M2MResourceInstance* create_resource_instance(DeviceResource resource, int64_t value, 00132 uint16_t instance_id); 00133 00134 /** 00135 * \brief Creates a new resource for the given resource name. 00136 * \param resource With this function, the following resources can be created: 00137 * 'ResetErrorCode','FactoryReset'. 00138 * \return M2MResource if created successfully, else NULL. 00139 */ 00140 M2MResource* create_resource(DeviceResource resource); 00141 00142 /** 00143 * \brief Deletes the resource with the given resource enum. 00144 * Mandatory resources cannot be deleted. 00145 * \param resource The name of the resource to be deleted. 00146 * \return True if deleted, else false. 00147 */ 00148 bool delete_resource(DeviceResource resource); 00149 00150 /** 00151 * \brief Deletes the resource with the given resource enum. 00152 * Mandatory resources cannot be deleted. 00153 * \param resource The name of the resource to be deleted. 00154 * \param instance_id The instance ID of the resource. 00155 * \return True if deleted, else false. 00156 */ 00157 bool delete_resource_instance(DeviceResource resource, 00158 uint16_t instance_id); 00159 00160 /** 00161 * \brief Sets the value of the given resource enum. 00162 * \param resource With this function, a value can be set for the following resources: 00163 * 'Manufacturer', 'DeviceType','ModelNumber','SerialNumber', 00164 * 'HardwareVersion', 'FirmwareVersion', 'SoftwareVersion', 00165 * 'UTCOffset', 'Timezone', 'SupportedBindingMode'. 00166 * \param value The value to be set on the resource, in string format. 00167 * \param instance_id The instance ID of the resource, default is 0. 00168 * \return True if successfully set, else false. 00169 */ 00170 bool set_resource_value(DeviceResource resource, 00171 const String &value, 00172 uint16_t instance_id = 0); 00173 00174 /** 00175 * \brief Sets the value of the given resource enum. 00176 * \param resource With this function, a value can be set for the following resources: 00177 * 'AvailablePowerSources','PowerSourceVoltage','PowerSourceCurrent', 00178 * 'BatteryLevel', 'BatteryStatus', 'MemoryFree', 'MemoryTotal', 00179 * 'ErrorCode', 'CurrentTime'. 00180 * \param value The value to be set on the resource, in integer format. 00181 * \param instance_id The instance ID of the resource, default is 0. 00182 * \return True if successfully set, else false. 00183 */ 00184 bool set_resource_value(DeviceResource resource, 00185 int64_t value, 00186 uint16_t instance_id = 0); 00187 00188 /** 00189 * \brief Returns the value of the given resource enum, in string format. 00190 * \param resource With this function, the following resources can return a value: 00191 * 'Manufacturer', 'DeviceType','ModelNumber','SerialNumber', 00192 * 'HardwareVersion', 'FirmwareVersion', 'SoftwareVersion', 00193 * 'UTCOffset', 'Timezone', 'SupportedBindingMode'. 00194 * \param instance_id The instance ID of the resource, default is 0. 00195 * \return The value associated with that resource. If the resource is not valid NULL is returned. 00196 */ 00197 String resource_value_string(DeviceResource resource, 00198 uint16_t instance_id = 0) const; 00199 00200 /** 00201 * \brief Returns the value of the given resource key name, in integer format. 00202 * \param resource With this function, the following resources can return a value: 00203 * 'AvailablePowerSources','PowerSourceVoltage','PowerSourceCurrent', 00204 * 'BatteryLevel', 'BatteryStatus', 'MemoryFree', 'MemoryTotal', 00205 * 'ErrorCode', 'CurrentTime'. 00206 * \param instance_id The instance ID of the resource, default is 0 00207 * \return The value associated with that resource. If the resource is not valid -1 is returned. 00208 */ 00209 int64_t resource_value_int(DeviceResource resource, 00210 uint16_t instance_id = 0) const; 00211 00212 /** 00213 * \brief Indicates whether the resource instance with the given resource enum exists or not. 00214 * \param resource The resource enum. 00215 * \return True if at least one instance exists, else false. 00216 */ 00217 bool is_resource_present(DeviceResource resource)const; 00218 00219 /** 00220 * \brief Returns the number of resources for the whole device object. 00221 * \return Total number of resources belonging to the device object. 00222 */ 00223 uint16_t total_resource_count()const; 00224 00225 /** 00226 * \brief Returns the number of resources for a given resource enum. 00227 * \param resource The resource enum. 00228 * \return The number of resources for a given resource enum. Returns 1 for the 00229 * mandatory resources. Can be 0 as well if no instances exist for an 00230 * optional resource. 00231 */ 00232 uint16_t per_resource_count(DeviceResource resource)const; 00233 00234 private: 00235 00236 M2MResourceBase* get_resource_instance(DeviceResource dev_res, 00237 uint16_t instance_id) const; 00238 00239 static const char* resource_name(DeviceResource resource); 00240 00241 static bool check_value_range(DeviceResource resource, const int64_t value); 00242 00243 private : 00244 00245 M2MObjectInstance* _device_instance; //Not owned 00246 00247 protected: 00248 00249 static M2MDevice* _instance; 00250 00251 friend class Test_M2MDevice; 00252 friend class Test_M2MInterfaceFactory; 00253 }; 00254 00255 #endif // M2M_DEVICE_H
Generated on Tue Jul 12 2022 20:21:00 by
