mbedConnectorInterface back port from mbedOS v3 using mbed-client C++ call interface

Committer:
ansond
Date:
Wed Jun 08 22:32:08 2016 +0000
Revision:
13:9edad7677211
Child:
14:d9ce4e56684e
updated to latest revision with new DM functions

Who changed what in which revision?

UserRevisionLine numberNew 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 13:9edad7677211 52 for(int i=0;i<NUM_FIRMWARE_RESOURCES;++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 13:9edad7677211 62 for(int i=0;i<NUM_FIRMWARE_RESOURCES;++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 13:9edad7677211 73 // LWM2M_DEV_FIRMWARE_PACKAGE_ID == 0 (TODO: Needs to be OPAQUE and full firmware blob...)
ansond 13:9edad7677211 74 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);
ansond 13:9edad7677211 75
ansond 13:9edad7677211 76 // LWM2M_DEV_FIRMWARE_PACKAGE_URI_ID == 1
ansond 13:9edad7677211 77 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);
ansond 13:9edad7677211 78
ansond 13:9edad7677211 79 // LWM2M_DEV_FIRMWARE_UPDATE_ID == 2
ansond 13:9edad7677211 80 this->m_firmware_resource[2] = new DeviceFirmwareUpdateResource(this->m_logger,this->m_obj_name,LWM2M_DEV_FIRMWARE_UPDATE_ID,this->m_dm_responder,false);
ansond 13:9edad7677211 81
ansond 13:9edad7677211 82 // LWM2M_DEV_FIRMWARE_STATE_ID == 3
ansond 13:9edad7677211 83 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);
ansond 13:9edad7677211 84
ansond 13:9edad7677211 85 // LWM2M_DEV_FIRMWARE_RESULT_ID == 5
ansond 13:9edad7677211 86 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);
ansond 13:9edad7677211 87
ansond 13:9edad7677211 88 // LWM2M_DEV_FIRMWARE_PKG_NAME_ID = 6
ansond 13:9edad7677211 89 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);
ansond 13:9edad7677211 90
ansond 13:9edad7677211 91 // LWM2M_DEV_FIRMWARE_PKG_VERSION_ID = 7
ansond 13:9edad7677211 92 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);
ansond 13:9edad7677211 93
ansond 13:9edad7677211 94 // Establish default values for State and Result
ansond 13:9edad7677211 95 this->m_firmware_resource[3]->put("1"); // idle == 1
ansond 13:9edad7677211 96 this->m_firmware_resource[5]->put("0"); // default result
ansond 13:9edad7677211 97
ansond 13:9edad7677211 98 // Tie State and Result resources for future updating by the dm_responder functions
ansond 13:9edad7677211 99 DeviceManagementResponder *dmr = (DeviceManagementResponder *)this->m_dm_responder;
ansond 13:9edad7677211 100 dmr->setStateResource(this->m_firmware_resource[3]);
ansond 13:9edad7677211 101 dmr->setResultResource(this->m_firmware_resource[5]);
ansond 13:9edad7677211 102 }
ansond 13:9edad7677211 103
ansond 13:9edad7677211 104 // add resources
ansond 13:9edad7677211 105 void DeviceFirmwareCompositeResource::addResources(void *cfg) {
ansond 13:9edad7677211 106 // our Endpoint configuration
ansond 13:9edad7677211 107 Connector::OptionsBuilder *configure_options = (Connector::OptionsBuilder *)cfg;
ansond 13:9edad7677211 108
ansond 13:9edad7677211 109 // loop through the internal resources and add them...
ansond 13:9edad7677211 110 for(int i=0;i<NUM_FIRMWARE_RESOURCES;++i) {
ansond 13:9edad7677211 111 if (this->m_firmware_resource[i] != NULL) {
ansond 13:9edad7677211 112 configure_options->addResource(this->m_firmware_resource[i]);
ansond 13:9edad7677211 113 }
ansond 13:9edad7677211 114 }
ansond 13:9edad7677211 115 }
ansond 13:9edad7677211 116
ansond 13:9edad7677211 117
ansond 13:9edad7677211 118