mbedConnectorInterface back port from mbedOS v3 using mbed-client C++ call interface
source/DeviceFirmwareCompositeResource.cpp@25:492acd2b0398, 2016-06-12 (annotated)
- Committer:
- ansond
- Date:
- Sun Jun 12 03:06:48 2016 +0000
- Revision:
- 25:492acd2b0398
- Parent:
- 15:c11dbe4d354c
updates
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 13:9edad7677211 | 1 | /** |
ansond | 13:9edad7677211 | 2 | * @file DeviceFirmwareCompositeResource.cpp |
ansond | 13:9edad7677211 | 3 | * @brief mbed CoAP Endpoint Device Firmware Composited Resource |
ansond | 13:9edad7677211 | 4 | * @author Doug Anson |
ansond | 13:9edad7677211 | 5 | * @version 1.0 |
ansond | 13:9edad7677211 | 6 | * @see |
ansond | 13:9edad7677211 | 7 | * |
ansond | 13:9edad7677211 | 8 | * Copyright (c) 2014 |
ansond | 13:9edad7677211 | 9 | * |
ansond | 13:9edad7677211 | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
ansond | 13:9edad7677211 | 11 | * you may not use this file except in compliance with the License. |
ansond | 13:9edad7677211 | 12 | * You may obtain a copy of the License at |
ansond | 13:9edad7677211 | 13 | * |
ansond | 13:9edad7677211 | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
ansond | 13:9edad7677211 | 15 | * |
ansond | 13:9edad7677211 | 16 | * Unless required by applicable law or agreed to in writing, software |
ansond | 13:9edad7677211 | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
ansond | 13:9edad7677211 | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ansond | 13:9edad7677211 | 19 | * See the License for the specific language governing permissions and |
ansond | 13:9edad7677211 | 20 | * limitations under the License. |
ansond | 13:9edad7677211 | 21 | */ |
ansond | 13:9edad7677211 | 22 | |
ansond | 13:9edad7677211 | 23 | // Class |
ansond | 13:9edad7677211 | 24 | #include "mbed-connector-interface/DeviceFirmwareCompositeResource.h" |
ansond | 13:9edad7677211 | 25 | |
ansond | 13:9edad7677211 | 26 | // Endpoint Class |
ansond | 13:9edad7677211 | 27 | #include "mbed-connector-interface/ConnectorEndpoint.h" |
ansond | 13:9edad7677211 | 28 | |
ansond | 13:9edad7677211 | 29 | // Options Builder |
ansond | 13:9edad7677211 | 30 | #include "mbed-connector-interface/OptionsBuilder.h" |
ansond | 13:9edad7677211 | 31 | |
ansond | 13:9edad7677211 | 32 | // DeviceManagementResponder |
ansond | 13:9edad7677211 | 33 | #include "mbed-connector-interface/DeviceManagementResponder.h" |
ansond | 13:9edad7677211 | 34 | |
ansond | 13:9edad7677211 | 35 | // DeviceStringResource |
ansond | 13:9edad7677211 | 36 | #include "mbed-connector-interface/DeviceStringResource.h" |
ansond | 13:9edad7677211 | 37 | |
ansond | 13:9edad7677211 | 38 | // DeviceIntegerResource |
ansond | 13:9edad7677211 | 39 | #include "mbed-connector-interface/DeviceIntegerResource.h" |
ansond | 13:9edad7677211 | 40 | |
ansond | 13:9edad7677211 | 41 | // DeviceFirmwareUpdateResource |
ansond | 13:9edad7677211 | 42 | #include "mbed-connector-interface/DeviceFirmwareUpdateResource.h" |
ansond | 13:9edad7677211 | 43 | |
ansond | 13:9edad7677211 | 44 | // DeviceFirmwareManifestResource |
ansond | 13:9edad7677211 | 45 | #include "mbed-connector-interface/DeviceFirmwareManifestResource.h" |
ansond | 13:9edad7677211 | 46 | |
ansond | 13:9edad7677211 | 47 | // Default Constructor |
ansond | 13:9edad7677211 | 48 | DeviceFirmwareCompositeResource::DeviceFirmwareCompositeResource(const Logger *logger,const char *obj_name,const void *dm_responder) { |
ansond | 13:9edad7677211 | 49 | this->m_logger = (Logger *)logger; |
ansond | 13:9edad7677211 | 50 | this->m_dm_responder = (void *)dm_responder; |
ansond | 13:9edad7677211 | 51 | this->m_obj_name = (char *)obj_name; |
ansond | 14:d9ce4e56684e | 52 | for(int i=0;i<NUM_FIRMWARE_RESOURCE_IDS;++i) { |
ansond | 13:9edad7677211 | 53 | this->m_firmware_resource[i] = NULL; |
ansond | 13:9edad7677211 | 54 | } |
ansond | 13:9edad7677211 | 55 | } |
ansond | 13:9edad7677211 | 56 | |
ansond | 13:9edad7677211 | 57 | // Copy Constructor |
ansond | 13:9edad7677211 | 58 | DeviceFirmwareCompositeResource::DeviceFirmwareCompositeResource(const DeviceFirmwareCompositeResource &res) { |
ansond | 13:9edad7677211 | 59 | this->m_logger = res.m_logger; |
ansond | 13:9edad7677211 | 60 | this->m_dm_responder = res.m_dm_responder; |
ansond | 13:9edad7677211 | 61 | this->m_obj_name = res.m_obj_name; |
ansond | 14:d9ce4e56684e | 62 | for(int i=0;i<NUM_FIRMWARE_RESOURCE_IDS;++i) { |
ansond | 13:9edad7677211 | 63 | this->m_firmware_resource[i] = res.m_firmware_resource[i]; |
ansond | 13:9edad7677211 | 64 | } |
ansond | 13:9edad7677211 | 65 | } |
ansond | 13:9edad7677211 | 66 | |
ansond | 13:9edad7677211 | 67 | // Destructor |
ansond | 13:9edad7677211 | 68 | DeviceFirmwareCompositeResource::~DeviceFirmwareCompositeResource() { |
ansond | 13:9edad7677211 | 69 | } |
ansond | 13:9edad7677211 | 70 | |
ansond | 13:9edad7677211 | 71 | // Build out our Firmware Resources |
ansond | 13:9edad7677211 | 72 | void DeviceFirmwareCompositeResource::buildResources() { |
ansond | 14:d9ce4e56684e | 73 | // LWM2M_PAYLOAD_ID (TODO: Needs to be OPAQUE and full firmware blob...) |
ansond | 14:d9ce4e56684e | 74 | 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); |
ansond | 13:9edad7677211 | 75 | |
ansond | 14:d9ce4e56684e | 76 | // LWM2M_MANIFEST_ID |
ansond | 14:d9ce4e56684e | 77 | 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); |
ansond | 13:9edad7677211 | 78 | |
ansond | 14:d9ce4e56684e | 79 | // LWM2M_UPDATE_ID |
ansond | 14:d9ce4e56684e | 80 | 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); |
ansond | 13:9edad7677211 | 81 | |
ansond | 14:d9ce4e56684e | 82 | // LWM2M_STATE_ID |
ansond | 14:d9ce4e56684e | 83 | 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); |
ansond | 13:9edad7677211 | 84 | |
ansond | 14:d9ce4e56684e | 85 | // LWM2M_RESULT_ID |
ansond | 25:492acd2b0398 | 86 | 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); |
ansond | 13:9edad7677211 | 87 | |
ansond | 14:d9ce4e56684e | 88 | // LWM2M_PKGNAME_ID |
ansond | 14:d9ce4e56684e | 89 | 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); |
ansond | 13:9edad7677211 | 90 | |
ansond | 14:d9ce4e56684e | 91 | // LWM2M_PKGVERSION_ID |
ansond | 14:d9ce4e56684e | 92 | 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); |
ansond | 13:9edad7677211 | 93 | |
ansond | 13:9edad7677211 | 94 | // Establish default values for State and Result |
ansond | 14:d9ce4e56684e | 95 | this->m_firmware_resource[LWM2M_STATE_ID]->put("1"); // idle == 1 |
ansond | 14:d9ce4e56684e | 96 | this->m_firmware_resource[LWM2M_RESULT_ID]->put("0"); // default result == 0 |
ansond | 13:9edad7677211 | 97 | |
ansond | 14:d9ce4e56684e | 98 | // Tie firmare composite resource for future updating by the dm_responder functions |
ansond | 13:9edad7677211 | 99 | DeviceManagementResponder *dmr = (DeviceManagementResponder *)this->m_dm_responder; |
ansond | 14:d9ce4e56684e | 100 | dmr->setFirmwareCompositeResource(this); |
ansond | 13:9edad7677211 | 101 | } |
ansond | 13:9edad7677211 | 102 | |
ansond | 13:9edad7677211 | 103 | // add resources |
ansond | 13:9edad7677211 | 104 | void DeviceFirmwareCompositeResource::addResources(void *cfg) { |
ansond | 13:9edad7677211 | 105 | // our Endpoint configuration |
ansond | 13:9edad7677211 | 106 | Connector::OptionsBuilder *configure_options = (Connector::OptionsBuilder *)cfg; |
ansond | 13:9edad7677211 | 107 | |
ansond | 13:9edad7677211 | 108 | // loop through the internal resources and add them... |
ansond | 14:d9ce4e56684e | 109 | for(int i=0;i<NUM_FIRMWARE_RESOURCE_IDS;++i) { |
ansond | 13:9edad7677211 | 110 | if (this->m_firmware_resource[i] != NULL) { |
ansond | 13:9edad7677211 | 111 | configure_options->addResource(this->m_firmware_resource[i]); |
ansond | 13:9edad7677211 | 112 | } |
ansond | 13:9edad7677211 | 113 | } |
ansond | 13:9edad7677211 | 114 | } |
ansond | 13:9edad7677211 | 115 | |
ansond | 14:d9ce4e56684e | 116 | // get a specific resource |
ansond | 14:d9ce4e56684e | 117 | void *DeviceFirmwareCompositeResource::getResource(FirmwareResourceIDs id) { |
ansond | 14:d9ce4e56684e | 118 | int index = (int)id; |
ansond | 14:d9ce4e56684e | 119 | if (index >= 0 && index < NUM_FIRMWARE_RESOURCE_IDS) { |
ansond | 14:d9ce4e56684e | 120 | return this->m_firmware_resource[index]; |
ansond | 14:d9ce4e56684e | 121 | } |
ansond | 14:d9ce4e56684e | 122 | return NULL; |
ansond | 14:d9ce4e56684e | 123 | } |
ansond | 14:d9ce4e56684e | 124 | |
ansond | 13:9edad7677211 | 125 | |
ansond | 13:9edad7677211 | 126 |