mbedConnectorInterface back port from mbedOS v3 using mbed-client C++ call interface
Diff: source/DeviceFirmwareCompositeResource.cpp
- Revision:
- 14:d9ce4e56684e
- Parent:
- 13:9edad7677211
- Child:
- 15:c11dbe4d354c
--- a/source/DeviceFirmwareCompositeResource.cpp Wed Jun 08 22:32:08 2016 +0000 +++ b/source/DeviceFirmwareCompositeResource.cpp Thu Jun 09 19:05:18 2016 +0000 @@ -49,7 +49,7 @@ this->m_logger = (Logger *)logger; this->m_dm_responder = (void *)dm_responder; this->m_obj_name = (char *)obj_name; - for(int i=0;i<NUM_FIRMWARE_RESOURCES;++i) { + for(int i=0;i<NUM_FIRMWARE_RESOURCE_IDS;++i) { this->m_firmware_resource[i] = NULL; } } @@ -59,7 +59,7 @@ this->m_logger = res.m_logger; this->m_dm_responder = res.m_dm_responder; this->m_obj_name = res.m_obj_name; - for(int i=0;i<NUM_FIRMWARE_RESOURCES;++i) { + for(int i=0;i<NUM_FIRMWARE_RESOURCE_IDS;++i) { this->m_firmware_resource[i] = res.m_firmware_resource[i]; } } @@ -70,35 +70,34 @@ // Build out our Firmware Resources void DeviceFirmwareCompositeResource::buildResources() { - // LWM2M_DEV_FIRMWARE_PACKAGE_ID == 0 (TODO: Needs to be OPAQUE and full firmware blob...) - this->m_firmware_resource[0] = new DeviceStringResource(this->m_logger,this->m_obj_name,LWM2M_DEV_FIRMWARE_PACKAGE_ID,"fw_package",this->m_dm_responder,false); + // LWM2M_PAYLOAD_ID (TODO: Needs to be OPAQUE and full firmware blob...) + this->m_firmware_resource[LWM2M_PAYLOAD_ID] = new DeviceStringResource(this->m_logger,this->m_obj_name,LWM2M_DEV_FIRMWARE_PACKAGE_ID,"fw_package",this->m_dm_responder,false); - // LWM2M_DEV_FIRMWARE_PACKAGE_URI_ID == 1 - this->m_firmware_resource[1] = new DeviceFirmwareManifestResource(this->m_logger,this->m_obj_name,LWM2M_DEV_FIRMWARE_PACKAGE_URI_ID,this->m_dm_responder,false); + // LWM2M_MANIFEST_ID + this->m_firmware_resource[LWM2M_MANIFEST_ID] = new DeviceFirmwareManifestResource(this->m_logger,this->m_obj_name,LWM2M_DEV_FIRMWARE_PACKAGE_URI_ID,this->m_dm_responder,false); - // LWM2M_DEV_FIRMWARE_UPDATE_ID == 2 - this->m_firmware_resource[2] = new DeviceFirmwareUpdateResource(this->m_logger,this->m_obj_name,LWM2M_DEV_FIRMWARE_UPDATE_ID,this->m_dm_responder,false); + // LWM2M_UPDATE_ID + this->m_firmware_resource[LWM2M_UPDATE_ID] = new DeviceFirmwareUpdateResource(this->m_logger,this->m_obj_name,LWM2M_DEV_FIRMWARE_UPDATE_ID,this->m_dm_responder,false); - // LWM2M_DEV_FIRMWARE_STATE_ID == 3 - this->m_firmware_resource[3] = new DeviceIntegerResource(this->m_logger,this->m_obj_name,LWM2M_DEV_FIRMWARE_STATE_ID,"fw_state",this->m_dm_responder,false); + // LWM2M_STATE_ID + this->m_firmware_resource[LWM2M_STATE_ID] = new DeviceIntegerResource(this->m_logger,this->m_obj_name,LWM2M_DEV_FIRMWARE_STATE_ID,"fw_state",this->m_dm_responder,false); - // LWM2M_DEV_FIRMWARE_RESULT_ID == 5 - this->m_firmware_resource[5] = new DeviceIntegerResource(this->m_logger,this->m_obj_name,LWM2M_DEV_FIRMWARE_RESULT_ID,"fw_result",this->m_dm_responder,false); + // LWM2M_RESULT_ID + this->m_firmware_resource[LWM2M_RESULT_ID] = new DeviceIntegerResource(this->m_logger,this->m_obj_name,LWM2M_DEV_FIRMWARE_RESULT_ID,"fw_result",this->m_dm_responder,true); - // LWM2M_DEV_FIRMWARE_PKG_NAME_ID = 6 - this->m_firmware_resource[6] = new DeviceStringResource(this->m_logger,this->m_obj_name,LWM2M_DEV_FIRMWARE_PKG_NAME_ID,"fw_pkg_name",this->m_dm_responder,false); + // LWM2M_PKGNAME_ID + this->m_firmware_resource[LWM2M_PKGNAME_ID] = new DeviceStringResource(this->m_logger,this->m_obj_name,LWM2M_DEV_FIRMWARE_PKG_NAME_ID,"fw_pkg_name",this->m_dm_responder,false); - // LWM2M_DEV_FIRMWARE_PKG_VERSION_ID = 7 - this->m_firmware_resource[7] = new DeviceStringResource(this->m_logger,this->m_obj_name,LWM2M_DEV_FIRMWARE_PKG_VERSION_ID,"fw_pkg_version",this->m_dm_responder,false); + // LWM2M_PKGVERSION_ID + this->m_firmware_resource[LWM2M_PKGVERSION_ID] = new DeviceStringResource(this->m_logger,this->m_obj_name,LWM2M_DEV_FIRMWARE_PKG_VERSION_ID,"fw_pkg_version",this->m_dm_responder,false); // Establish default values for State and Result - this->m_firmware_resource[3]->put("1"); // idle == 1 - this->m_firmware_resource[5]->put("0"); // default result + this->m_firmware_resource[LWM2M_STATE_ID]->put("1"); // idle == 1 + this->m_firmware_resource[LWM2M_RESULT_ID]->put("0"); // default result == 0 - // Tie State and Result resources for future updating by the dm_responder functions + // Tie firmare composite resource for future updating by the dm_responder functions DeviceManagementResponder *dmr = (DeviceManagementResponder *)this->m_dm_responder; - dmr->setStateResource(this->m_firmware_resource[3]); - dmr->setResultResource(this->m_firmware_resource[5]); + dmr->setFirmwareCompositeResource(this); } // add resources @@ -107,12 +106,21 @@ Connector::OptionsBuilder *configure_options = (Connector::OptionsBuilder *)cfg; // loop through the internal resources and add them... - for(int i=0;i<NUM_FIRMWARE_RESOURCES;++i) { + for(int i=0;i<NUM_FIRMWARE_RESOURCE_IDS;++i) { if (this->m_firmware_resource[i] != NULL) { configure_options->addResource(this->m_firmware_resource[i]); } } } +// get a specific resource +void *DeviceFirmwareCompositeResource::getResource(FirmwareResourceIDs id) { + int index = (int)id; + if (index >= 0 && index < NUM_FIRMWARE_RESOURCE_IDS) { + return this->m_firmware_resource[index]; + } + return NULL; +} + \ No newline at end of file