mbed client on ethernet with LWIP
Dependencies: mbed Socket lwip-eth lwip-sys lwip
Fork of mbed-client-classic-example-lwip by
mbed-client/mbed-client/m2mdevice.h@11:cada08fc8a70, 2016-06-09 (annotated)
- Committer:
- mbedAustin
- Date:
- Thu Jun 09 17:08:36 2016 +0000
- Revision:
- 11:cada08fc8a70
Commit for public Consumption
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedAustin | 11:cada08fc8a70 | 1 | /* |
mbedAustin | 11:cada08fc8a70 | 2 | * Copyright (c) 2015 ARM Limited. All rights reserved. |
mbedAustin | 11:cada08fc8a70 | 3 | * SPDX-License-Identifier: Apache-2.0 |
mbedAustin | 11:cada08fc8a70 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
mbedAustin | 11:cada08fc8a70 | 5 | * not use this file except in compliance with the License. |
mbedAustin | 11:cada08fc8a70 | 6 | * You may obtain a copy of the License at |
mbedAustin | 11:cada08fc8a70 | 7 | * |
mbedAustin | 11:cada08fc8a70 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbedAustin | 11:cada08fc8a70 | 9 | * |
mbedAustin | 11:cada08fc8a70 | 10 | * Unless required by applicable law or agreed to in writing, software |
mbedAustin | 11:cada08fc8a70 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
mbedAustin | 11:cada08fc8a70 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbedAustin | 11:cada08fc8a70 | 13 | * See the License for the specific language governing permissions and |
mbedAustin | 11:cada08fc8a70 | 14 | * limitations under the License. |
mbedAustin | 11:cada08fc8a70 | 15 | */ |
mbedAustin | 11:cada08fc8a70 | 16 | #ifndef M2M_DEVICE_H |
mbedAustin | 11:cada08fc8a70 | 17 | #define M2M_DEVICE_H |
mbedAustin | 11:cada08fc8a70 | 18 | |
mbedAustin | 11:cada08fc8a70 | 19 | #include "mbed-client/m2mobject.h" |
mbedAustin | 11:cada08fc8a70 | 20 | |
mbedAustin | 11:cada08fc8a70 | 21 | // FORWARD DECLARATION |
mbedAustin | 11:cada08fc8a70 | 22 | class M2MResource; |
mbedAustin | 11:cada08fc8a70 | 23 | class M2MResourceInstance; |
mbedAustin | 11:cada08fc8a70 | 24 | |
mbedAustin | 11:cada08fc8a70 | 25 | /** |
mbedAustin | 11:cada08fc8a70 | 26 | * @brief M2MDevice. |
mbedAustin | 11:cada08fc8a70 | 27 | * This class represents the Device Object model of the LWM2M framework. |
mbedAustin | 11:cada08fc8a70 | 28 | * It provides an interface for handling the device object |
mbedAustin | 11:cada08fc8a70 | 29 | * and all its corresponding resources. There can be only one instance |
mbedAustin | 11:cada08fc8a70 | 30 | * of a Device Object. |
mbedAustin | 11:cada08fc8a70 | 31 | */ |
mbedAustin | 11:cada08fc8a70 | 32 | class M2MDevice : public M2MObject { |
mbedAustin | 11:cada08fc8a70 | 33 | |
mbedAustin | 11:cada08fc8a70 | 34 | friend class M2MInterfaceFactory; |
mbedAustin | 11:cada08fc8a70 | 35 | |
mbedAustin | 11:cada08fc8a70 | 36 | public: |
mbedAustin | 11:cada08fc8a70 | 37 | |
mbedAustin | 11:cada08fc8a70 | 38 | /** |
mbedAustin | 11:cada08fc8a70 | 39 | * @brief Enum defining all the resources associated with the |
mbedAustin | 11:cada08fc8a70 | 40 | * Device Object in the LWM2M framework. |
mbedAustin | 11:cada08fc8a70 | 41 | */ |
mbedAustin | 11:cada08fc8a70 | 42 | typedef enum { |
mbedAustin | 11:cada08fc8a70 | 43 | Manufacturer, |
mbedAustin | 11:cada08fc8a70 | 44 | DeviceType, |
mbedAustin | 11:cada08fc8a70 | 45 | ModelNumber, |
mbedAustin | 11:cada08fc8a70 | 46 | SerialNumber, |
mbedAustin | 11:cada08fc8a70 | 47 | HardwareVersion, |
mbedAustin | 11:cada08fc8a70 | 48 | FirmwareVersion, |
mbedAustin | 11:cada08fc8a70 | 49 | SoftwareVersion, |
mbedAustin | 11:cada08fc8a70 | 50 | Reboot, |
mbedAustin | 11:cada08fc8a70 | 51 | FactoryReset, |
mbedAustin | 11:cada08fc8a70 | 52 | AvailablePowerSources, |
mbedAustin | 11:cada08fc8a70 | 53 | PowerSourceVoltage, |
mbedAustin | 11:cada08fc8a70 | 54 | PowerSourceCurrent, |
mbedAustin | 11:cada08fc8a70 | 55 | BatteryLevel, |
mbedAustin | 11:cada08fc8a70 | 56 | BatteryStatus, |
mbedAustin | 11:cada08fc8a70 | 57 | MemoryFree, |
mbedAustin | 11:cada08fc8a70 | 58 | MemoryTotal, |
mbedAustin | 11:cada08fc8a70 | 59 | ErrorCode, |
mbedAustin | 11:cada08fc8a70 | 60 | ResetErrorCode, |
mbedAustin | 11:cada08fc8a70 | 61 | CurrentTime, |
mbedAustin | 11:cada08fc8a70 | 62 | UTCOffset, |
mbedAustin | 11:cada08fc8a70 | 63 | Timezone, |
mbedAustin | 11:cada08fc8a70 | 64 | SupportedBindingMode |
mbedAustin | 11:cada08fc8a70 | 65 | }DeviceResource; |
mbedAustin | 11:cada08fc8a70 | 66 | |
mbedAustin | 11:cada08fc8a70 | 67 | private: |
mbedAustin | 11:cada08fc8a70 | 68 | |
mbedAustin | 11:cada08fc8a70 | 69 | /** |
mbedAustin | 11:cada08fc8a70 | 70 | * Constructor |
mbedAustin | 11:cada08fc8a70 | 71 | */ |
mbedAustin | 11:cada08fc8a70 | 72 | M2MDevice(); |
mbedAustin | 11:cada08fc8a70 | 73 | |
mbedAustin | 11:cada08fc8a70 | 74 | // Prevents the use of assignment operator. |
mbedAustin | 11:cada08fc8a70 | 75 | M2MDevice& operator=( const M2MDevice& /*other*/ ); |
mbedAustin | 11:cada08fc8a70 | 76 | |
mbedAustin | 11:cada08fc8a70 | 77 | // Prevents the use of copy constructor |
mbedAustin | 11:cada08fc8a70 | 78 | M2MDevice( const M2MDevice& /*other*/ ); |
mbedAustin | 11:cada08fc8a70 | 79 | |
mbedAustin | 11:cada08fc8a70 | 80 | /** |
mbedAustin | 11:cada08fc8a70 | 81 | * Destructor |
mbedAustin | 11:cada08fc8a70 | 82 | */ |
mbedAustin | 11:cada08fc8a70 | 83 | virtual ~M2MDevice(); |
mbedAustin | 11:cada08fc8a70 | 84 | |
mbedAustin | 11:cada08fc8a70 | 85 | static M2MDevice* get_instance(); |
mbedAustin | 11:cada08fc8a70 | 86 | |
mbedAustin | 11:cada08fc8a70 | 87 | public: |
mbedAustin | 11:cada08fc8a70 | 88 | |
mbedAustin | 11:cada08fc8a70 | 89 | /** |
mbedAustin | 11:cada08fc8a70 | 90 | * @brief Deletes the M2MDevice instance. |
mbedAustin | 11:cada08fc8a70 | 91 | */ |
mbedAustin | 11:cada08fc8a70 | 92 | static void delete_instance(); |
mbedAustin | 11:cada08fc8a70 | 93 | |
mbedAustin | 11:cada08fc8a70 | 94 | /** |
mbedAustin | 11:cada08fc8a70 | 95 | * @brief Creates a new resource for the given resource enum. |
mbedAustin | 11:cada08fc8a70 | 96 | * @param resource, With this function, the following resources can be created: |
mbedAustin | 11:cada08fc8a70 | 97 | * 'Manufacturer', 'DeviceType','ModelNumber','SerialNumber', |
mbedAustin | 11:cada08fc8a70 | 98 | * 'HardwareVersion', 'FirmwareVersion', 'SoftwareVersion', |
mbedAustin | 11:cada08fc8a70 | 99 | * 'UTCOffset', 'Timezone', 'SupportedBindingMode'. |
mbedAustin | 11:cada08fc8a70 | 100 | * @param value, Value to be set on the resource, in String format. |
mbedAustin | 11:cada08fc8a70 | 101 | * @return M2MResource if created successfully, else NULL. |
mbedAustin | 11:cada08fc8a70 | 102 | */ |
mbedAustin | 11:cada08fc8a70 | 103 | M2MResource* create_resource(DeviceResource resource, const String &value); |
mbedAustin | 11:cada08fc8a70 | 104 | |
mbedAustin | 11:cada08fc8a70 | 105 | /** |
mbedAustin | 11:cada08fc8a70 | 106 | * @brief Creates a new resource for given resource enum. |
mbedAustin | 11:cada08fc8a70 | 107 | * @param resource, With this function, the following resources can be created: |
mbedAustin | 11:cada08fc8a70 | 108 | * 'AvailablePowerSources','PowerSourceVoltage','PowerSourceCurrent', |
mbedAustin | 11:cada08fc8a70 | 109 | * 'BatteryLevel', 'BatteryStatus', 'MemoryFree', 'MemoryTotal', |
mbedAustin | 11:cada08fc8a70 | 110 | * 'ErrorCode', 'CurrentTime'. For 'CurrentTime', pass the time value in EPOCH format, for example |
mbedAustin | 11:cada08fc8a70 | 111 | * 1438944683. |
mbedAustin | 11:cada08fc8a70 | 112 | * @param value, Value to be set on the resource, in Integer format. |
mbedAustin | 11:cada08fc8a70 | 113 | * @return M2MResource if created successfully, else NULL. |
mbedAustin | 11:cada08fc8a70 | 114 | */ |
mbedAustin | 11:cada08fc8a70 | 115 | M2MResource* create_resource(DeviceResource resource, int64_t value); |
mbedAustin | 11:cada08fc8a70 | 116 | |
mbedAustin | 11:cada08fc8a70 | 117 | /** |
mbedAustin | 11:cada08fc8a70 | 118 | * @brief Creates a new resource instance for given resource enum. |
mbedAustin | 11:cada08fc8a70 | 119 | * @param resource, With this function, the following resources can be created: |
mbedAustin | 11:cada08fc8a70 | 120 | * 'AvailablePowerSources','PowerSourceVoltage','PowerSourceCurrent', |
mbedAustin | 11:cada08fc8a70 | 121 | * 'ErrorCode'. |
mbedAustin | 11:cada08fc8a70 | 122 | * @param value, Value to be set on the resource, in Integer format. |
mbedAustin | 11:cada08fc8a70 | 123 | * @return M2MResourceInstance if created successfully, else NULL. |
mbedAustin | 11:cada08fc8a70 | 124 | */ |
mbedAustin | 11:cada08fc8a70 | 125 | M2MResourceInstance* create_resource_instance(DeviceResource resource, int64_t value, |
mbedAustin | 11:cada08fc8a70 | 126 | uint16_t instance_id); |
mbedAustin | 11:cada08fc8a70 | 127 | |
mbedAustin | 11:cada08fc8a70 | 128 | /** |
mbedAustin | 11:cada08fc8a70 | 129 | * @brief Creates a new resource for given resource name. |
mbedAustin | 11:cada08fc8a70 | 130 | * @param resource, With this function, the following resources can be created: |
mbedAustin | 11:cada08fc8a70 | 131 | * 'ResetErrorCode','FactoryReset'. |
mbedAustin | 11:cada08fc8a70 | 132 | * @return M2MResource if created successfully, else NULL. |
mbedAustin | 11:cada08fc8a70 | 133 | */ |
mbedAustin | 11:cada08fc8a70 | 134 | M2MResource* create_resource(DeviceResource resource); |
mbedAustin | 11:cada08fc8a70 | 135 | |
mbedAustin | 11:cada08fc8a70 | 136 | /** |
mbedAustin | 11:cada08fc8a70 | 137 | * @brief Deletes the resource with the given resource enum. |
mbedAustin | 11:cada08fc8a70 | 138 | * Mandatory resources cannot be deleted. |
mbedAustin | 11:cada08fc8a70 | 139 | * @param resource, Name of the resource to be deleted. |
mbedAustin | 11:cada08fc8a70 | 140 | * @return True if deleted, else false. |
mbedAustin | 11:cada08fc8a70 | 141 | */ |
mbedAustin | 11:cada08fc8a70 | 142 | bool delete_resource(DeviceResource resource); |
mbedAustin | 11:cada08fc8a70 | 143 | |
mbedAustin | 11:cada08fc8a70 | 144 | /** |
mbedAustin | 11:cada08fc8a70 | 145 | * @brief Deletes the resource with the given resource enum. |
mbedAustin | 11:cada08fc8a70 | 146 | * Mandatory resources cannot be deleted. |
mbedAustin | 11:cada08fc8a70 | 147 | * @param resource, Name of the resource to be deleted. |
mbedAustin | 11:cada08fc8a70 | 148 | * @param instance_id, Instance Id of the resource. |
mbedAustin | 11:cada08fc8a70 | 149 | * @return True if deleted, else false. |
mbedAustin | 11:cada08fc8a70 | 150 | */ |
mbedAustin | 11:cada08fc8a70 | 151 | bool delete_resource_instance(DeviceResource resource, |
mbedAustin | 11:cada08fc8a70 | 152 | uint16_t instance_id); |
mbedAustin | 11:cada08fc8a70 | 153 | |
mbedAustin | 11:cada08fc8a70 | 154 | /** |
mbedAustin | 11:cada08fc8a70 | 155 | * @brief Sets the value of the given resource enum. |
mbedAustin | 11:cada08fc8a70 | 156 | * @param resource, With this function, a value can be set for the following resources: |
mbedAustin | 11:cada08fc8a70 | 157 | * 'Manufacturer', 'DeviceType','ModelNumber','SerialNumber', |
mbedAustin | 11:cada08fc8a70 | 158 | * 'HardwareVersion', 'FirmwareVersion', 'SoftwareVersion', |
mbedAustin | 11:cada08fc8a70 | 159 | * 'UTCOffset', 'Timezone', 'SupportedBindingMode'. |
mbedAustin | 11:cada08fc8a70 | 160 | * @param value, Value to be set on the resource, in String format. |
mbedAustin | 11:cada08fc8a70 | 161 | * @param instance_id, Instance Id of the resource, default is 0. |
mbedAustin | 11:cada08fc8a70 | 162 | * @return True if successfully set, else false. |
mbedAustin | 11:cada08fc8a70 | 163 | */ |
mbedAustin | 11:cada08fc8a70 | 164 | bool set_resource_value(DeviceResource resource, |
mbedAustin | 11:cada08fc8a70 | 165 | const String &value, |
mbedAustin | 11:cada08fc8a70 | 166 | uint16_t instance_id = 0); |
mbedAustin | 11:cada08fc8a70 | 167 | |
mbedAustin | 11:cada08fc8a70 | 168 | /** |
mbedAustin | 11:cada08fc8a70 | 169 | * @brief Sets the value of the given resource enum. |
mbedAustin | 11:cada08fc8a70 | 170 | * @param resource, With this function, a value can be set for the following resources: |
mbedAustin | 11:cada08fc8a70 | 171 | * 'AvailablePowerSources','PowerSourceVoltage','PowerSourceCurrent', |
mbedAustin | 11:cada08fc8a70 | 172 | * 'BatteryLevel', 'BatteryStatus', 'MemoryFree', 'MemoryTotal', |
mbedAustin | 11:cada08fc8a70 | 173 | * 'ErrorCode', 'CurrentTime'. |
mbedAustin | 11:cada08fc8a70 | 174 | * @param value, Value to be set on the resource, in Integer format. |
mbedAustin | 11:cada08fc8a70 | 175 | * @param instance_id, Instance Id of the resource, default is 0. |
mbedAustin | 11:cada08fc8a70 | 176 | * @return True if successfully set, else false. |
mbedAustin | 11:cada08fc8a70 | 177 | */ |
mbedAustin | 11:cada08fc8a70 | 178 | bool set_resource_value(DeviceResource resource, |
mbedAustin | 11:cada08fc8a70 | 179 | int64_t value, |
mbedAustin | 11:cada08fc8a70 | 180 | uint16_t instance_id = 0); |
mbedAustin | 11:cada08fc8a70 | 181 | |
mbedAustin | 11:cada08fc8a70 | 182 | /** |
mbedAustin | 11:cada08fc8a70 | 183 | * @brief Returns the value of the given resource enum, in String. |
mbedAustin | 11:cada08fc8a70 | 184 | * @param resource, With this function, the following resources can return a value: |
mbedAustin | 11:cada08fc8a70 | 185 | * 'Manufacturer', 'DeviceType','ModelNumber','SerialNumber', |
mbedAustin | 11:cada08fc8a70 | 186 | * 'HardwareVersion', 'FirmwareVersion', 'SoftwareVersion', |
mbedAustin | 11:cada08fc8a70 | 187 | * 'UTCOffset', 'Timezone', 'SupportedBindingMode'. |
mbedAustin | 11:cada08fc8a70 | 188 | * @param instance_id, Instance Id of the resource, default is 0. |
mbedAustin | 11:cada08fc8a70 | 189 | * @return Value associated with that resource. If the resource is not valid NULL is returned. |
mbedAustin | 11:cada08fc8a70 | 190 | */ |
mbedAustin | 11:cada08fc8a70 | 191 | String resource_value_string(DeviceResource resource, |
mbedAustin | 11:cada08fc8a70 | 192 | uint16_t instance_id = 0) const; |
mbedAustin | 11:cada08fc8a70 | 193 | |
mbedAustin | 11:cada08fc8a70 | 194 | /** |
mbedAustin | 11:cada08fc8a70 | 195 | * @brief Returns the value of the given resource key name, in Integer. |
mbedAustin | 11:cada08fc8a70 | 196 | * @param resource, With this function, the following resources can return a value: |
mbedAustin | 11:cada08fc8a70 | 197 | * 'AvailablePowerSources','PowerSourceVoltage','PowerSourceCurrent', |
mbedAustin | 11:cada08fc8a70 | 198 | * 'BatteryLevel', 'BatteryStatus', 'MemoryFree', 'MemoryTotal', |
mbedAustin | 11:cada08fc8a70 | 199 | * 'ErrorCode', 'CurrentTime'. |
mbedAustin | 11:cada08fc8a70 | 200 | * @param instance_id, Instance Id of the resource, default is 0 |
mbedAustin | 11:cada08fc8a70 | 201 | * @return Value associated with that resource. If the resource is not valid -1 is returned. |
mbedAustin | 11:cada08fc8a70 | 202 | */ |
mbedAustin | 11:cada08fc8a70 | 203 | int64_t resource_value_int(DeviceResource resource, |
mbedAustin | 11:cada08fc8a70 | 204 | uint16_t instance_id = 0) const; |
mbedAustin | 11:cada08fc8a70 | 205 | |
mbedAustin | 11:cada08fc8a70 | 206 | /** |
mbedAustin | 11:cada08fc8a70 | 207 | * @brief Indicates whether the resource instance with given resource enum exists or not. |
mbedAustin | 11:cada08fc8a70 | 208 | * @param resource, Resource enum. |
mbedAustin | 11:cada08fc8a70 | 209 | * @return True if at least one instance exists, else false. |
mbedAustin | 11:cada08fc8a70 | 210 | */ |
mbedAustin | 11:cada08fc8a70 | 211 | bool is_resource_present(DeviceResource resource)const; |
mbedAustin | 11:cada08fc8a70 | 212 | |
mbedAustin | 11:cada08fc8a70 | 213 | /** |
mbedAustin | 11:cada08fc8a70 | 214 | * @brief Returns the number of resources for the whole device object. |
mbedAustin | 11:cada08fc8a70 | 215 | * @return Total number of resources belonging to the device object. |
mbedAustin | 11:cada08fc8a70 | 216 | */ |
mbedAustin | 11:cada08fc8a70 | 217 | uint16_t total_resource_count()const; |
mbedAustin | 11:cada08fc8a70 | 218 | |
mbedAustin | 11:cada08fc8a70 | 219 | /** |
mbedAustin | 11:cada08fc8a70 | 220 | * @brief Returns the number of resources for a given resource enum. |
mbedAustin | 11:cada08fc8a70 | 221 | * @param resource, Resource enum. |
mbedAustin | 11:cada08fc8a70 | 222 | * @return Number of resources for a given resource enum. Returns 1 for the |
mbedAustin | 11:cada08fc8a70 | 223 | * mandatory resources. Can be 0 as well if no instances exist for an |
mbedAustin | 11:cada08fc8a70 | 224 | * optional resource. |
mbedAustin | 11:cada08fc8a70 | 225 | */ |
mbedAustin | 11:cada08fc8a70 | 226 | uint16_t per_resource_count(DeviceResource resource)const; |
mbedAustin | 11:cada08fc8a70 | 227 | |
mbedAustin | 11:cada08fc8a70 | 228 | private: |
mbedAustin | 11:cada08fc8a70 | 229 | |
mbedAustin | 11:cada08fc8a70 | 230 | M2MResourceInstance* get_resource_instance(DeviceResource dev_res, |
mbedAustin | 11:cada08fc8a70 | 231 | uint16_t instance_id) const; |
mbedAustin | 11:cada08fc8a70 | 232 | |
mbedAustin | 11:cada08fc8a70 | 233 | String resource_name(DeviceResource resource) const; |
mbedAustin | 11:cada08fc8a70 | 234 | |
mbedAustin | 11:cada08fc8a70 | 235 | bool check_value_range(DeviceResource resource, const int64_t value) const; |
mbedAustin | 11:cada08fc8a70 | 236 | |
mbedAustin | 11:cada08fc8a70 | 237 | private : |
mbedAustin | 11:cada08fc8a70 | 238 | |
mbedAustin | 11:cada08fc8a70 | 239 | M2MObjectInstance* _device_instance; //Not owned |
mbedAustin | 11:cada08fc8a70 | 240 | |
mbedAustin | 11:cada08fc8a70 | 241 | protected: |
mbedAustin | 11:cada08fc8a70 | 242 | |
mbedAustin | 11:cada08fc8a70 | 243 | static M2MDevice* _instance; |
mbedAustin | 11:cada08fc8a70 | 244 | |
mbedAustin | 11:cada08fc8a70 | 245 | friend class Test_M2MDevice; |
mbedAustin | 11:cada08fc8a70 | 246 | friend class Test_M2MInterfaceFactory; |
mbedAustin | 11:cada08fc8a70 | 247 | }; |
mbedAustin | 11:cada08fc8a70 | 248 | |
mbedAustin | 11:cada08fc8a70 | 249 | #endif // M2M_DEVICE_H |
mbedAustin | 11:cada08fc8a70 | 250 |