This is the sample program that can see the decode result of barcode data on Watson IoT.
Dependencies: AsciiFont DisplayApp GR-PEACH_video LCD_shield_config LWIPBP3595Interface_STA_for_mbed-os USBDevice
DataWrapper.cpp
00001 /** 00002 * @file DataWrapper.cpp 00003 * @brief mbed CoAP Endpoint Resource Data Wrapper 00004 * @author Doug Anson 00005 * @version 1.0 00006 * @see 00007 * 00008 * Copyright (c) 2014 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 // Class Support 00024 #include "mbed-connector-interface/DataWrapper.h" 00025 00026 // constructor 00027 DataWrapper::DataWrapper(uint8_t *data,int data_length) { 00028 this->m_data = data; 00029 this->m_data_length = 0; 00030 this->m_data_length_max = data_length; 00031 this->m_alloced = false; 00032 this->reset(); 00033 } 00034 00035 // constructor (alloc) 00036 DataWrapper::DataWrapper(int data_length) { 00037 this->m_data = (uint8_t *)malloc(data_length+1); 00038 memset(this->m_data,0,data_length+1); 00039 this->m_data_length = 0; 00040 this->m_data_length_max = data_length; 00041 this->m_alloced = true; 00042 } 00043 00044 // copy constructor 00045 DataWrapper::DataWrapper(const DataWrapper &data) { 00046 this->m_data = data.m_data; 00047 this->m_data_length = data.m_data_length; 00048 this->m_data_length_max = data.m_data_length_max; 00049 this->m_alloced = data.m_alloced; 00050 } 00051 00052 // destructor 00053 DataWrapper::~DataWrapper() { 00054 if (this->m_alloced && this->m_data != NULL) free(this->m_data); 00055 } 00056 00057 // wrap 00058 void DataWrapper::wrap(uint8_t *data,int data_length) { 00059 this->reset(); 00060 if (data != NULL && data_length > 0) { 00061 int length = data_length; 00062 if (length > this->m_data_length_max) length = this->m_data_length_max; 00063 memcpy(this->m_data,data,length); 00064 this->m_data_length = length; 00065 } 00066 } 00067 00068 // unwrap 00069 void DataWrapper::unwrap(uint8_t *data,int data_length) { 00070 this->reset(); 00071 if (data != NULL && data_length > 0) { 00072 int length = data_length; 00073 if (length > this->m_data_length_max) length = this->m_data_length_max; 00074 memcpy(this->m_data,data,length); 00075 this->m_data_length = length; 00076 } 00077 } 00078 00079 // reset 00080 void DataWrapper::reset() { 00081 if (this->m_data != NULL && this->m_data_length_max > 0) 00082 memset(this->m_data,0,this->m_data_length_max); 00083 this->m_data_length = 0; 00084 } 00085 00086 // set the app key 00087 void DataWrapper::setAppKey(uint8_t * /* appkey */,int /* appkey_length */) { 00088 // do nothing in the base class 00089 ; 00090 } 00091 00092
Generated on Tue Jul 12 2022 18:38:05 by 1.7.2