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.
DeviceManager.cpp
00001 /** 00002 * @file DeviceManager.cpp 00003 * @brief mbed CoAP Endpoint Device Management class 00004 * @author Doug Anson 00005 * @version 1.0 00006 * @see 00007 * 00008 * Copyright (c) 2016 00009 * 00010 * Licensed under the Apache License, Version 2.0 (the "License"); 00011 * you may not use this file except in compliance with the License. 00012 * You may obtain a copy of the License at 00013 * 00014 * http://www.apache.org/licenses/LICENSE-2.0 00015 * 00016 * Unless required by applicable law or agreed to in writing, software 00017 * distributed under the License is distributed on an "AS IS" BASIS, 00018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00019 * See the License for the specific language governing permissions and 00020 * limitations under the License. 00021 */ 00022 00023 // configuration 00024 #include "mbed-connector-interface/mbedConnectorInterface.h" 00025 00026 // BaseClass 00027 #include "mbed-connector-interface/DeviceManager.h" 00028 00029 // Endpoint Class 00030 #include "mbed-connector-interface/ConnectorEndpoint.h" 00031 00032 // Options Builder 00033 #include "mbed-connector-interface/OptionsBuilder.h" 00034 00035 // Device Management Responder 00036 #include "mbed-connector-interface/DeviceManagementResponder.h" 00037 00038 // Constructor 00039 DeviceManager::DeviceManager(const Logger *logger,const void *dm_responder,const char *mfg,const char *dev_type,const char *model,const char *serial,const char *fw_vers,const char *hw_vers,const char *sw_vers) { 00040 // record the data management responder if we have one 00041 this->m_dm_responder = (void *)dm_responder; 00042 00043 // establish the default base LWM2M device info resource values 00044 this->m_dev[0] = new DeviceResource(logger,M2MDevice::Manufacturer,mfg); // Manufacturer 00045 this->m_dev[1] = new DeviceResource(logger,M2MDevice::DeviceType,dev_type); // Device Type 00046 this->m_dev[2] = new DeviceResource(logger,M2MDevice::ModelNumber,model); // Device Model 00047 this->m_dev[3] = new DeviceResource(logger,M2MDevice::SerialNumber,serial); // Device Serial 00048 this->m_dev[4] = new DeviceResource(logger,M2MDevice::FirmwareVersion,fw_vers); // Firmware Version 00049 this->m_dev[5] = new DeviceResource(logger,M2MDevice::HardwareVersion,hw_vers); // Hardware Version 00050 this->m_dev[6] = new DeviceResource(logger,M2MDevice::SoftwareVersion,sw_vers); // Software Version 00051 00052 // record the dev type and logger for later... 00053 this->m_dev_type = (char *)dev_type; 00054 this->m_logger = (Logger *)logger; 00055 00056 // Device DeRegistration Resource 00057 this->m_deregister_resource = new DeviceDeRegisterResource(logger,LWM2M_DEVICE_OBJ_ID,LWM2M_DEV_DEREGISTER_ID,dm_responder); 00058 00059 // Device Reboot Resource 00060 this->m_reboot_resource = new DeviceRebootResource(logger,LWM2M_DEVICE_OBJ_ID,this->createResName(M2MDevice::Reboot).c_str(),dm_responder); 00061 00062 // Device Reset Resource 00063 this->m_reset_resource = new DeviceResetResource(logger,LWM2M_DEVICE_OBJ_ID,this->createResName(M2MDevice::FactoryReset).c_str(),dm_responder); 00064 00065 // Device Firmware Composite Resource 00066 this->m_firmware_composite_resource = new DeviceFirmwareCompositeResource(logger,LWM2M_FIRMWARE_OBJ_ID,dm_responder); 00067 this->m_firmware_composite_resource->buildResources(); 00068 } 00069 00070 // create a string form of our device resource value 00071 string DeviceManager::createResName(M2MDevice::DeviceResource res) { 00072 char buf[10]; 00073 memset(buf,0,10); 00074 sprintf(buf,"%d",res); 00075 return string(buf); 00076 } 00077 00078 // Copy constructor 00079 DeviceManager::DeviceManager(const DeviceManager &manager) { 00080 for(int i=0;i<NUM_DEVICE_RESOURCES;++i) { 00081 this->m_dev[i] = new DeviceResource(*manager.m_dev[i]); 00082 } 00083 this->m_dev_type = manager.m_dev_type; 00084 this->m_logger = manager.m_logger; 00085 this->m_endpoint = manager.m_endpoint; 00086 00087 // copy the additional resources 00088 } 00089 00090 // Destructor 00091 DeviceManager::~DeviceManager() { 00092 for(int i=0;i<NUM_DEVICE_RESOURCES;++i) { 00093 delete this->m_dev[i]; 00094 } 00095 } 00096 00097 // Install the device manager into the Connector Endpoint 00098 void DeviceManager::install(const void *endpoint,const void *config) { 00099 // record the configuration 00100 this->m_config = (void *)config; 00101 00102 // record the endpoint 00103 this->m_endpoint = (void *)endpoint; 00104 00105 // our Endpoint 00106 Connector::Endpoint *ep = (Connector::Endpoint *)this->m_endpoint; 00107 00108 // our Endpoint configuration 00109 Connector::OptionsBuilder *cfg = (Connector::OptionsBuilder *)this->m_config; 00110 00111 // add the base device resources 00112 for(int i=0;i<NUM_DEVICE_RESOURCES;++i) { 00113 // DEBUG 00114 this->m_logger->log("Adding Base Device Resource: %s = %s...",this->m_dev[i]->getFullName().c_str(),this->m_dev[i]->getValue().c_str()); 00115 00116 // add the resource 00117 cfg->addResource(this->m_dev[i]); 00118 } 00119 00120 // set our device type 00121 cfg->setEndpointType(this->m_dev_type); 00122 00123 // establish connection to our responder 00124 if (this->m_dm_responder != NULL) { 00125 ((DeviceManagementResponder *)this->m_dm_responder)->setEndpoint((const void *)ep); 00126 } 00127 00128 // add the device action resources 00129 cfg->addResource(this->m_deregister_resource); // de-registration action 00130 cfg->addResource(this->m_reboot_resource); // reboot action 00131 cfg->addResource(this->m_reset_resource); // reset action 00132 this->m_firmware_composite_resource->addResources(cfg); // Firmware Composite Resource adds internally... 00133 } 00134 00135 // get our device management responder 00136 void *DeviceManager::getResponder() { return this->m_dm_responder; }
Generated on Wed Jul 13 2022 21:59:32 by
1.7.2