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: mbed Socket lwip-eth lwip-sys lwip
Fork of 6_songs-from-the-cloud by
m2mfirmware.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 M2MFIRMWARE_H 00017 #define M2MFIRMWARE_H 00018 00019 #include "mbed-client/m2mobject.h" 00020 00021 // FORWARD DECLARATION 00022 class M2MResource; 00023 class M2MResourceInstance; 00024 00025 /** 00026 * @brief M2MFirmware. 00027 * This class represents the Firmware Object model of the LWM2M framework. 00028 * It provides an interface for handling the firmware object 00029 * and all its corresponding resources. There can be only one instance 00030 * of a Firmware Object. 00031 */ 00032 class M2MFirmware : public M2MObject { 00033 00034 friend class M2MInterfaceFactory; 00035 00036 public: 00037 00038 /** 00039 * @brief Enum defining all the resources associated with a 00040 * Firmware Object in the LWM2M framework. 00041 */ 00042 typedef enum { 00043 Package, 00044 PackageUri, 00045 Update, 00046 State, 00047 UpdateSupportedObjects, 00048 UpdateResult, 00049 PackageName, 00050 PackageVersion 00051 } FirmwareResource; 00052 00053 /** 00054 * @brief Enum defining the state of the firmware update. 00055 */ 00056 typedef enum { 00057 Idle = 0, 00058 Downloading, 00059 Downloaded 00060 } UpdateState; 00061 00062 /** 00063 * @brief Enum defining the result of the firmware update. 00064 */ 00065 typedef enum { 00066 Default = 0, 00067 SuccessfullyUpdated, 00068 NotEnoughSpace, 00069 OutOfMemory, 00070 ConnectionLost, 00071 CRCCheckFailure, 00072 UnsupportedPackageType, 00073 InvalidURI 00074 } ResultOfUpdate; 00075 00076 private: 00077 00078 /** 00079 * Constructor 00080 */ 00081 M2MFirmware(); 00082 00083 // Prevents the use of assignment operator. 00084 M2MFirmware& operator=( const M2MFirmware& /*other*/ ); 00085 00086 // Prevents the use of copy constructor. 00087 M2MFirmware( const M2MFirmware& /*other*/ ); 00088 00089 /** 00090 * Destructor 00091 */ 00092 virtual ~M2MFirmware(); 00093 00094 static M2MFirmware* get_instance(); 00095 00096 public: 00097 00098 /** 00099 * @brief Deletes the M2MFirmware instance. 00100 */ 00101 static void delete_instance(); 00102 00103 /** 00104 * @brief Creates a new resource for given resource enum. 00105 * @param resource, With this function, the following resources can be created: 00106 * 'PackageUri', 'PackageName','PackageVersion'. 00107 * @param value, Value to be set on the resource, in String format. 00108 * @return M2MResource if created successfully, else NULL. 00109 */ 00110 M2MResource* create_resource(FirmwareResource resource, const String &value); 00111 00112 /** 00113 * @brief Creates a new resource for given resource enum. 00114 * @param resource, With this function, the following resources can be created: 00115 * 'State','UpdateSupportedObjects','UpdateResult'. 00116 * @param value, Value to be set on the resource, in Integer format. 00117 * @return M2MResource if created successfully, else NULL. 00118 */ 00119 M2MResource* create_resource(FirmwareResource resource, int64_t value); 00120 00121 /** 00122 * @brief Deletes the resource with the given resource enum. 00123 * Mandatory resources cannot be deleted. 00124 * @param resource, Name of the resource to be deleted. 00125 * @return True if deleted, else false. 00126 */ 00127 bool delete_resource(FirmwareResource resource); 00128 00129 /** 00130 * @brief Sets the value of the given resource enum. 00131 * @param resource, With this function, a value can be set on the following resources: 00132 * 'Package', 'PackageUri', 'PackageName','PackageVersion'. 00133 * @param value, Value to be set on the resource, in String format. 00134 * @return True if successfully set, else false. 00135 */ 00136 bool set_resource_value(FirmwareResource resource, 00137 const String &value); 00138 00139 /** 00140 * @brief Sets the value of the given resource enum. 00141 * @param resource, With this function, a value can be set for the following resources: 00142 * 'State','UpdateSupportedObjects','UpdateResult'. 00143 * @param value, Value to be set on the resource, in Integer format. 00144 * @return True if successfully set, else false. 00145 */ 00146 bool set_resource_value(FirmwareResource resource, 00147 int64_t value); 00148 00149 /** 00150 * @brief Sets the value of the given resource enum. 00151 * @param resource, With this function, a value can be set for the following resources: 00152 * 'Package'. 00153 * @param value, Value to be set on the resource, in uint8_t format. 00154 * @param size, Size of the buffer value to be set on the resource. 00155 * @return True if successfully set, else false. 00156 */ 00157 bool set_resource_value(FirmwareResource resource, 00158 const uint8_t *value, 00159 const uint32_t length); 00160 00161 /** 00162 * @brief Returns the value of the given resource enum, in String. 00163 * @param resource, With this function, the following resources can return value: 00164 * 'PackageUri', 'PackageName','PackageVersion'. 00165 * @return Value associated with that resource, if key is not valid it returns NULL. 00166 */ 00167 String resource_value_string(FirmwareResource resource) const; 00168 00169 /** 00170 * @brief Returns the value of the given resource key name, in Integer. 00171 * @param resource, With this function, the following resources can return a value: 00172 * 'State','UpdateSupportedObjects','UpdateResult'. 00173 * @return Value associated with that resource. If the resource is not valid -1 is returned. 00174 */ 00175 int64_t resource_value_int(FirmwareResource resource) const; 00176 00177 /** 00178 * @brief Populates the data buffer and returns the size of the buffer. 00179 * @param resource, With this function, the following resources can return a value: 00180 * 'Package'. 00181 * @param [OUT] data, Data buffer containing the value. 00182 * @return Size of the buffer populated. 00183 */ 00184 uint32_t resource_value_buffer(FirmwareResource resource, 00185 uint8_t *&data) const; 00186 00187 /** 00188 * @brief Returns whether the resource instance with given resource enum exists or not. 00189 * @param resource, Resource enum. 00190 * @return True if at least one instance exists, else false. 00191 */ 00192 bool is_resource_present(FirmwareResource resource) const; 00193 00194 /** 00195 * @brief Returns number of resources for the whole firmware object. 00196 * @return Total number of resources belonging to the firmware object. 00197 */ 00198 uint16_t total_resource_count() const; 00199 00200 /** 00201 * @brief Returns the number of resources for a given resource enum. 00202 * @param resource, Resource enum. 00203 * @return Number of resources for a given resource enum. Returns 1 for the 00204 * mandatory resources. Can be 0 as well if no instance exists for an 00205 * optional resource. 00206 */ 00207 uint16_t per_resource_count(FirmwareResource resource) const; 00208 00209 00210 private: 00211 00212 M2MResource* get_resource(FirmwareResource resource) const; 00213 00214 String resource_name(FirmwareResource resource) const; 00215 00216 void create_mandatory_resources(); 00217 00218 bool check_value_range(FirmwareResource resource, const int64_t value) const; 00219 00220 private : 00221 00222 M2MObjectInstance* _firmware_instance; //Not owned 00223 00224 protected: 00225 00226 static M2MFirmware* _instance; 00227 00228 friend class Test_M2MFirmware; 00229 friend class Test_M2MInterfaceFactory; 00230 }; 00231 00232 00233 #endif // M2MFIRMWARE_H
Generated on Tue Jul 12 2022 12:47:47 by
