Host library for controlling a WiConnect enabled Wi-Fi module.
Dependents: wiconnect-ota_example wiconnect-web_setup_example wiconnect-test-console wiconnect-tcp_server_example ... more
GhmMessage.cpp
00001 /** 00002 * ACKme WiConnect Host Library is licensed under the BSD licence: 00003 * 00004 * Copyright (c)2014 ACKme Networks. 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without modification, 00008 * are permitted provided that the following conditions are met: 00009 * 00010 * 1. Redistributions of source code must retain the above copyright notice, 00011 * this list of conditions and the following disclaimer. 00012 * 2. Redistributions in binary form must reproduce the above copyright notice, 00013 * this list of conditions and the following disclaimer in the documentation 00014 * and/or other materials provided with the distribution. 00015 * 3. The name of the author may not be used to endorse or promote products 00016 * derived from this software without specific prior written permission. 00017 * 00018 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR IMPLIED 00019 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00020 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00021 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00022 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00023 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00026 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00027 * OF SUCH DAMAGE. 00028 */ 00029 #include "Wiconnect.h" 00030 #include "api/types/GhmMessage.h" 00031 #include "internal/common.h" 00032 00033 00034 00035 00036 /*************************************************************************************************/ 00037 GhmMessage::GhmMessage() 00038 { 00039 next = NULL; 00040 previous = NULL; 00041 messageId[0] = 0; 00042 timestamp[0] = 0; 00043 length = 0; 00044 } 00045 00046 /*************************************************************************************************/ 00047 WiconnectResult GhmMessage::init(const char *msgIdStr, const char* timestampStr, const char *lengthStr) 00048 { 00049 intmax_t r; 00050 if(!StringUtil::parseHex(lengthStr, &r, 0, USHRT_MAX)) 00051 { 00052 return WICONNECT_RESPONSE_PARSE_ERROR; 00053 } 00054 length = (uint16_t)r; 00055 00056 strncpy(messageId, msgIdStr, sizeof(messageId)); 00057 strncpy(timestamp, timestampStr, sizeof(timestamp)); 00058 00059 return WICONNECT_SUCCESS; 00060 } 00061 00062 #ifdef WICONNECT_ENABLE_MALLOC 00063 /*************************************************************************************************/ 00064 void* GhmMessage::operator new(size_t size) 00065 { 00066 Wiconnect *wiconnect = Wiconnect::getInstance(); 00067 wiconnect_assert(wiconnect, "GhmMessage:new, malloc not defined", wiconnect->_malloc != NULL); 00068 return Wiconnect::getInstance()->_malloc(size); 00069 } 00070 00071 /*************************************************************************************************/ 00072 void GhmMessage::operator delete(void* ptr) 00073 { 00074 Wiconnect *wiconnect = Wiconnect::getInstance(); 00075 wiconnect_assert(wiconnect, "GhmMessage:delete, free not defined", wiconnect->_free != NULL); 00076 Wiconnect::getInstance()->_free(ptr); 00077 } 00078 #endif 00079 00080 /*************************************************************************************************/ 00081 const char* GhmMessage::getMessageId(char *buffer) const 00082 { 00083 const char *ptr; 00084 if(buffer != NULL) 00085 { 00086 strcpy(buffer, messageId); 00087 ptr = buffer; 00088 } 00089 else 00090 { 00091 ptr = messageId; 00092 } 00093 return ptr; 00094 } 00095 00096 /*************************************************************************************************/ 00097 const char* GhmMessage::getTimestamp(char *buffer) const 00098 { 00099 const char *ptr; 00100 if(buffer != NULL) 00101 { 00102 strcpy(buffer, timestamp); 00103 ptr = buffer; 00104 } 00105 else 00106 { 00107 ptr = timestamp; 00108 } 00109 return ptr; 00110 } 00111 00112 /*************************************************************************************************/ 00113 uint16_t GhmMessage::getLength() const 00114 { 00115 return length; 00116 } 00117 00118 /*************************************************************************************************/ 00119 const GhmMessage* GhmMessage::getNext() const 00120 { 00121 return next; 00122 } 00123 00124 /*************************************************************************************************/ 00125 const GhmMessage* GhmMessage::getPrevious() const 00126 { 00127 return previous; 00128 } 00129
Generated on Tue Jul 12 2022 17:35:58 by 1.7.2