ThingPlug GMMP library for mbed

Dependents:   ThingPlug_WiFi_Example

Committer:
lesmin
Date:
Thu Jul 23 00:55:15 2015 +0000
Revision:
0:32c20cfb2b30
Child:
1:272f2e355446
initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lesmin 0:32c20cfb2b30 1 /** GMMP 공통 정의
lesmin 0:32c20cfb2b30 2 * @file GMMP.cpp
lesmin 0:32c20cfb2b30 3 * @date 2015/07/20
lesmin 0:32c20cfb2b30 4 * @version 0.0.1.0
lesmin 0:32c20cfb2b30 5 **/
lesmin 0:32c20cfb2b30 6
lesmin 0:32c20cfb2b30 7 #ifndef GMMP_h
lesmin 0:32c20cfb2b30 8 #define GMMP_h
lesmin 0:32c20cfb2b30 9
lesmin 0:32c20cfb2b30 10 /*
lesmin 0:32c20cfb2b30 11 #include <stdio.h>
lesmin 0:32c20cfb2b30 12 #include <stdlib.h>
lesmin 0:32c20cfb2b30 13 #include <string.h>
lesmin 0:32c20cfb2b30 14 #include <time.h>
lesmin 0:32c20cfb2b30 15 #include <pthread.h>
lesmin 0:32c20cfb2b30 16 #include <unistd.h>
lesmin 0:32c20cfb2b30 17 #include <stdarg.h>
lesmin 0:32c20cfb2b30 18 */
lesmin 0:32c20cfb2b30 19
lesmin 0:32c20cfb2b30 20 //#include <inttypes.h>
lesmin 0:32c20cfb2b30 21 //#include <Time.h>
lesmin 0:32c20cfb2b30 22 //#include <Arduino.h>
lesmin 0:32c20cfb2b30 23
lesmin 0:32c20cfb2b30 24 #define USE_SNIC_WIFI //Murata Type YD Wi-Fi
lesmin 0:32c20cfb2b30 25 //#define USE_WIZNET_W5500
lesmin 0:32c20cfb2b30 26
lesmin 0:32c20cfb2b30 27 #if defined(TARGET_LPC1768)
lesmin 0:32c20cfb2b30 28 #include "EthernetInterface.h"
lesmin 0:32c20cfb2b30 29 #elif defined(TARGET_NUCLEO_F411RE) || defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F303RE) || defined(TARGET_NUCLEO_F334R8) || defined(TARGET_NUCLEO_L152RE)
lesmin 0:32c20cfb2b30 30
lesmin 0:32c20cfb2b30 31 #ifdef USE_SNIC_WIFI
lesmin 0:32c20cfb2b30 32 #include "SNIC_WifiInterface.h"
lesmin 0:32c20cfb2b30 33 #endif//USE_SNIC_WIFI
lesmin 0:32c20cfb2b30 34
lesmin 0:32c20cfb2b30 35 #ifdef USE_WIZNET_W5500
lesmin 0:32c20cfb2b30 36 #include "WIZnetInterface.h"
lesmin 0:32c20cfb2b30 37 #endif//USE_WIZNET_W5500
lesmin 0:32c20cfb2b30 38 #endif
lesmin 0:32c20cfb2b30 39
lesmin 0:32c20cfb2b30 40 #include "NTPClient.h"
lesmin 0:32c20cfb2b30 41
lesmin 0:32c20cfb2b30 42 #include "GMMP.h"
lesmin 0:32c20cfb2b30 43
lesmin 0:32c20cfb2b30 44 byte g_serverIp[LEN_IP] ; ///< 서버 IP 정보를 저장한다.
lesmin 0:32c20cfb2b30 45 int g_nServerPort = 0; ///< 서버 Port 정보를 저장한다.
lesmin 0:32c20cfb2b30 46
lesmin 0:32c20cfb2b30 47 char g_szAuthID[LEN_AUTH_ID];///< OMP Portal을 통해 사전에 등록된 M2M GW 의 Serial Number 저장 변수, 자동화를 위해 사용된다.
lesmin 0:32c20cfb2b30 48
lesmin 0:32c20cfb2b30 49 char g_szAuthKey[LEN_AUTH_KEY]; ///< 등록 절차 시 OMP에서 할당 받은 AuthKey 저장 변수, 자동화를 위해 사용된다.
lesmin 0:32c20cfb2b30 50
lesmin 0:32c20cfb2b30 51 char g_szDomainCode[LEN_DOMAIN_CODE]; ///< OMP Portal을 통해 사전에 등록된 서비스 영역별 구분 코드 저장 변수, 자동화를 위해 사용된다.
lesmin 0:32c20cfb2b30 52
lesmin 0:32c20cfb2b30 53 char g_szGWID[LEN_GW_ID]; ///< OMP에서 할당 받은 Gateway의 ID 문자열 저장 변수, 자동화를 위해 사용된다.
lesmin 0:32c20cfb2b30 54
lesmin 0:32c20cfb2b30 55 /**
lesmin 0:32c20cfb2b30 56 * @brief OMP서버로 부터 수신한 패킷을 제공할 콜백함수 포인트 구조체
lesmin 0:32c20cfb2b30 57 * @param pstGMMPHeader GMMP Header의 구조체 포인트
lesmin 0:32c20cfb2b30 58 * @param pstBody GMMP Body의 구조체 포인트
lesmin 0:32c20cfb2b30 59 * @return 성공:0, 실패: 1이상 , 에러코드 참조
lesmin 0:32c20cfb2b30 60 */
lesmin 0:32c20cfb2b30 61 typedef int (*callback_Reg)(GMMPHeader* pstGMMPHeader, void* pstBody);
lesmin 0:32c20cfb2b30 62
lesmin 0:32c20cfb2b30 63 callback_Reg g_CallFunctionRegRecv = NULL; ///< OMP서버로 부터 수신한 패킷을 제공할 콜백함수 포인트 변수.
lesmin 0:32c20cfb2b30 64 //callback_Reg g_CallHeartbeatRegRecv = NULL; ///< OMP서버로 부터 수신한 패킷 중 Heartbeat 패킷을 제공할 콜백함수 포인트 변수. (TCP Always On mode에서만 사용된다.)
lesmin 0:32c20cfb2b30 65
lesmin 0:32c20cfb2b30 66 void Uninitialize()
lesmin 0:32c20cfb2b30 67 {
lesmin 0:32c20cfb2b30 68 InitMemory();
lesmin 0:32c20cfb2b30 69 CloseSocket();
lesmin 0:32c20cfb2b30 70 }
lesmin 0:32c20cfb2b30 71
lesmin 0:32c20cfb2b30 72
lesmin 0:32c20cfb2b30 73
lesmin 0:32c20cfb2b30 74 int Initialize(byte* serverIp,
lesmin 0:32c20cfb2b30 75 const int nPort,
lesmin 0:32c20cfb2b30 76 const char* pszDomainCode,
lesmin 0:32c20cfb2b30 77 const char* pszGWAuthID,
lesmin 0:32c20cfb2b30 78 byte* mac)
lesmin 0:32c20cfb2b30 79 {
lesmin 0:32c20cfb2b30 80 debugln("Initialize()");
lesmin 0:32c20cfb2b30 81
lesmin 0:32c20cfb2b30 82 InitMemory();
lesmin 0:32c20cfb2b30 83
lesmin 0:32c20cfb2b30 84 //delay(2000);
lesmin 0:32c20cfb2b30 85 #if defined(TARGET_LPC1768)
lesmin 0:32c20cfb2b30 86 EthernetInterface eth;
lesmin 0:32c20cfb2b30 87 #elif defined(TARGET_NUCLEO_F411RE) || defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F303RE) || defined(TARGET_NUCLEO_F334R8) || defined(TARGET_NUCLEO_L152RE)
lesmin 0:32c20cfb2b30 88
lesmin 0:32c20cfb2b30 89 #ifdef USE_SNIC_WIFI
lesmin 0:32c20cfb2b30 90 C_SNIC_WifiInterface wifi( D8, D2, NC, NC, D3);
lesmin 0:32c20cfb2b30 91
lesmin 0:32c20cfb2b30 92 #define MBED_AP_SSID "T-Smart"
lesmin 0:32c20cfb2b30 93 /** Securiry Options
lesmin 0:32c20cfb2b30 94 e_SEC_OPEN = 0x00, //Open
lesmin 0:32c20cfb2b30 95 e_SEC_WEP = 0x01, // WEP
lesmin 0:32c20cfb2b30 96 e_SEC_WPA_TKIP = 0x02, // WPA-PSK(TKIP)
lesmin 0:32c20cfb2b30 97 e_SEC_WPA2_AES = 0x04, // WPA2-PSK(AES)
lesmin 0:32c20cfb2b30 98 e_SEC_WPA2_MIXED = 0x06, // WPA2-PSK(TKIP/AES)
lesmin 0:32c20cfb2b30 99 e_SEC_WPA_AES = 0x07 // WPA-PSK(AES) **/
lesmin 0:32c20cfb2b30 100 #define MBED_AP_SECURITY_TYPE e_SEC_OPEN
lesmin 0:32c20cfb2b30 101 #define MBED_AP_SECUTIRY_KEY ""
lesmin 0:32c20cfb2b30 102
lesmin 0:32c20cfb2b30 103 #endif//USE_SNIC_WIFI
lesmin 0:32c20cfb2b30 104
lesmin 0:32c20cfb2b30 105 #ifdef USE_WIZNET_W5500
lesmin 0:32c20cfb2b30 106 //unsigned char MAC_Addr[6] = {0x00,0x08,0xDC,0x12,0x34,0x56};
lesmin 0:32c20cfb2b30 107 SPI spi(PA_7, PA_6, PA_5); // mosi, miso, sclk
lesmin 0:32c20cfb2b30 108 WIZnetInterface ethernet(&spi, PB_6, PA_9);//scs(PB_6), nRESET(PA_9); // reset pin is dummy, don't affect any pin of WIZ550io
lesmin 0:32c20cfb2b30 109 #endif//USE_WIZNET_W5500
lesmin 0:32c20cfb2b30 110
lesmin 0:32c20cfb2b30 111 #endif
lesmin 0:32c20cfb2b30 112 //NTPClient ntp;
lesmin 0:32c20cfb2b30 113
lesmin 0:32c20cfb2b30 114 infoln("Getting IP...");
lesmin 0:32c20cfb2b30 115
lesmin 0:32c20cfb2b30 116 #if defined(TARGET_LPC1768)
lesmin 0:32c20cfb2b30 117 eth.init(); //Use DHCP
lesmin 0:32c20cfb2b30 118 eth.connect();
lesmin 0:32c20cfb2b30 119 wait(0.5);
lesmin 0:32c20cfb2b30 120 printf("IP Address is %s\r\n", eth.getIPAddress());
lesmin 0:32c20cfb2b30 121 #elif defined(TARGET_NUCLEO_F411RE) || defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F303RE) || defined(TARGET_NUCLEO_F334R8) || defined(TARGET_NUCLEO_L152RE)
lesmin 0:32c20cfb2b30 122
lesmin 0:32c20cfb2b30 123 #ifdef USE_SNIC_WIFI
lesmin 0:32c20cfb2b30 124 wifi.init();
lesmin 0:32c20cfb2b30 125
lesmin 0:32c20cfb2b30 126 wait(0.5);
lesmin 0:32c20cfb2b30 127 int s = wifi.disconnect();
lesmin 0:32c20cfb2b30 128 if( s != 0 ) {
lesmin 0:32c20cfb2b30 129 return -1;
lesmin 0:32c20cfb2b30 130 }
lesmin 0:32c20cfb2b30 131
lesmin 0:32c20cfb2b30 132 wait(0.3);
lesmin 0:32c20cfb2b30 133 // Connect AP
lesmin 0:32c20cfb2b30 134 wifi.connect( MBED_AP_SSID
lesmin 0:32c20cfb2b30 135 , strlen(MBED_AP_SSID)
lesmin 0:32c20cfb2b30 136 , MBED_AP_SECURITY_TYPE
lesmin 0:32c20cfb2b30 137 , MBED_AP_SECUTIRY_KEY
lesmin 0:32c20cfb2b30 138 , strlen(MBED_AP_SECUTIRY_KEY) );
lesmin 0:32c20cfb2b30 139 wait(0.5);
lesmin 0:32c20cfb2b30 140 wifi.setIPConfig( true ); //Use DHCP
lesmin 0:32c20cfb2b30 141 wait(0.5);
lesmin 0:32c20cfb2b30 142
lesmin 0:32c20cfb2b30 143 tagWIFI_STATUS_T wifi_status;
lesmin 0:32c20cfb2b30 144 if( wifi.getWifiStatus(&wifi_status) ) printf("wifi_status error!\r\n");
lesmin 0:32c20cfb2b30 145
lesmin 0:32c20cfb2b30 146 printf("MAC Address is %s\r\n", wifi_status.mac_address);
lesmin 0:32c20cfb2b30 147 printf("IP Address is %s\r\n", wifi.getIPAddress());
lesmin 0:32c20cfb2b30 148 #endif//USE_SNIC_WIFI
lesmin 0:32c20cfb2b30 149
lesmin 0:32c20cfb2b30 150 #ifdef USE_WIZNET_W5500
lesmin 0:32c20cfb2b30 151 //mbed_mac_address((char *)MAC_Addr); //Use mbed mac addres
lesmin 0:32c20cfb2b30 152
lesmin 0:32c20cfb2b30 153 int ret = ethernet.init(mac);
lesmin 0:32c20cfb2b30 154 printf("SPI Initialized \r\n");
lesmin 0:32c20cfb2b30 155 wait(1); // 1 second for stable state
lesmin 0:32c20cfb2b30 156
lesmin 0:32c20cfb2b30 157 printf("W5500 Networking Started \r\n");
lesmin 0:32c20cfb2b30 158 wait(1); // 1 second for stable state
lesmin 0:32c20cfb2b30 159
lesmin 0:32c20cfb2b30 160 if (!ret) {
lesmin 0:32c20cfb2b30 161 printf("Initialized, MAC: %s\r\n", ethernet.getMACAddress());
lesmin 0:32c20cfb2b30 162 ret = ethernet.connect();
lesmin 0:32c20cfb2b30 163 if (!ret) {
lesmin 0:32c20cfb2b30 164 printf("IP: %s, MASK: %s, GW: %s\r\n",
lesmin 0:32c20cfb2b30 165 ethernet.getIPAddress(), ethernet.getNetworkMask(), ethernet.getGateway());
lesmin 0:32c20cfb2b30 166 } else {
lesmin 0:32c20cfb2b30 167 printf("Error ethernet.connect() - ret = %d\r\n", ret);
lesmin 0:32c20cfb2b30 168 //exit(0);
lesmin 0:32c20cfb2b30 169 }
lesmin 0:32c20cfb2b30 170 } else {
lesmin 0:32c20cfb2b30 171 printf("Error ethernet.init() - ret = %d\r\n", ret);
lesmin 0:32c20cfb2b30 172 //exit(0);
lesmin 0:32c20cfb2b30 173 }
lesmin 0:32c20cfb2b30 174
lesmin 0:32c20cfb2b30 175 #endif//USE_WIZNET_W5500
lesmin 0:32c20cfb2b30 176 #endif
lesmin 0:32c20cfb2b30 177
lesmin 0:32c20cfb2b30 178
lesmin 0:32c20cfb2b30 179 NTPClient ntp;
lesmin 0:32c20cfb2b30 180 printf("Trying to update time...\r\n");
lesmin 0:32c20cfb2b30 181 //if (ntp.setTime("0.pool.ntp.org") == 0)
lesmin 0:32c20cfb2b30 182 // if (ntp.setTime("time-a.timefreq.bldrdoc.gov") == 0)
lesmin 0:32c20cfb2b30 183 // if (ntp.setTime("kr.pool.ntp.org") == 0)
lesmin 0:32c20cfb2b30 184 if (ntp.setTime("211.233.40.78") == 0) //MURATA UDP does not support DNS resolver...
lesmin 0:32c20cfb2b30 185 {
lesmin 0:32c20cfb2b30 186 printf("Set time successfully\r\n");
lesmin 0:32c20cfb2b30 187 time_t ctTime;
lesmin 0:32c20cfb2b30 188 ctTime = time(NULL);
lesmin 0:32c20cfb2b30 189 // printf("Time is set to (UTC): %s\r\n", ctime(&ctTime));
lesmin 0:32c20cfb2b30 190 ctTime += 32400; // GMT+9/Seoul
lesmin 0:32c20cfb2b30 191 printf("Time is set to (GMT+9): %s\r\n", ctime(&ctTime));
lesmin 0:32c20cfb2b30 192 }
lesmin 0:32c20cfb2b30 193 else
lesmin 0:32c20cfb2b30 194 {
lesmin 0:32c20cfb2b30 195 printf("Error\r\n");
lesmin 0:32c20cfb2b30 196 }
lesmin 0:32c20cfb2b30 197
lesmin 0:32c20cfb2b30 198
lesmin 0:32c20cfb2b30 199 if(SetServerInfo(serverIp, nPort, pszGWAuthID, pszDomainCode) != 0)
lesmin 0:32c20cfb2b30 200 {
lesmin 0:32c20cfb2b30 201 return LIB_PARAM_ERROR;
lesmin 0:32c20cfb2b30 202 }
lesmin 0:32c20cfb2b30 203 SetTID(0);
lesmin 0:32c20cfb2b30 204
lesmin 0:32c20cfb2b30 205 return GMMP_SUCCESS;
lesmin 0:32c20cfb2b30 206 }
lesmin 0:32c20cfb2b30 207
lesmin 0:32c20cfb2b30 208 void SetAuthKey(const char* pszAuthKey)
lesmin 0:32c20cfb2b30 209 {
lesmin 0:32c20cfb2b30 210 memcpy(g_szAuthKey, pszAuthKey, strlen(pszAuthKey));
lesmin 0:32c20cfb2b30 211 }
lesmin 0:32c20cfb2b30 212
lesmin 0:32c20cfb2b30 213 void SetGWID(const char* pszGWID)
lesmin 0:32c20cfb2b30 214 {
lesmin 0:32c20cfb2b30 215 if(pszGWID != NULL)
lesmin 0:32c20cfb2b30 216 {
lesmin 0:32c20cfb2b30 217 memcpy(g_szGWID, pszGWID, strlen(pszGWID));
lesmin 0:32c20cfb2b30 218 }
lesmin 0:32c20cfb2b30 219 }
lesmin 0:32c20cfb2b30 220
lesmin 0:32c20cfb2b30 221 char* GetGWID()
lesmin 0:32c20cfb2b30 222 {
lesmin 0:32c20cfb2b30 223 return g_szGWID;
lesmin 0:32c20cfb2b30 224 }
lesmin 0:32c20cfb2b30 225
lesmin 0:32c20cfb2b30 226 int SetServerInfo(byte* serverIp, int nPort, const char* pszAuthID, const char* pszDoamainCode)
lesmin 0:32c20cfb2b30 227 {
lesmin 0:32c20cfb2b30 228 /*
lesmin 0:32c20cfb2b30 229 if(pszAuthID == NULL || strlen(pszAuthID) > LEN_AUTH_ID
lesmin 0:32c20cfb2b30 230 || pszDoamainCode == NULL || strlen(pszDoamainCode) > LEN_DOMAIN_CODE)
lesmin 0:32c20cfb2b30 231 {
lesmin 0:32c20cfb2b30 232 return LIB_PARAM_ERROR;
lesmin 0:32c20cfb2b30 233 }
lesmin 0:32c20cfb2b30 234 */
lesmin 0:32c20cfb2b30 235
lesmin 0:32c20cfb2b30 236 memcpy(g_serverIp, serverIp, LEN_IP);
lesmin 0:32c20cfb2b30 237 memcpy(g_szAuthID, pszAuthID, strlen(pszAuthID));
lesmin 0:32c20cfb2b30 238 memcpy(g_szDomainCode, pszDoamainCode, strlen(pszDoamainCode));
lesmin 0:32c20cfb2b30 239
lesmin 0:32c20cfb2b30 240 g_nServerPort = nPort;
lesmin 0:32c20cfb2b30 241
lesmin 0:32c20cfb2b30 242 int nRet = SetIntiSocket();
lesmin 0:32c20cfb2b30 243 if(nRet != GMMP_SUCCESS)
lesmin 0:32c20cfb2b30 244 {
lesmin 0:32c20cfb2b30 245 return nRet;
lesmin 0:32c20cfb2b30 246 }
lesmin 0:32c20cfb2b30 247
lesmin 0:32c20cfb2b30 248 return GMMP_SUCCESS;
lesmin 0:32c20cfb2b30 249 }
lesmin 0:32c20cfb2b30 250
lesmin 0:32c20cfb2b30 251 void SetCallFunction(int (* pCallFunctionName)(GMMPHeader* pstGMMPHeader, void* pstBody))
lesmin 0:32c20cfb2b30 252 {
lesmin 0:32c20cfb2b30 253 g_CallFunctionRegRecv = (callback_Reg)pCallFunctionName;
lesmin 0:32c20cfb2b30 254 }
lesmin 0:32c20cfb2b30 255
lesmin 0:32c20cfb2b30 256 int GO_Reg(const char* pszGWID,
lesmin 0:32c20cfb2b30 257 const char* pszManufactureID)
lesmin 0:32c20cfb2b30 258 {
lesmin 0:32c20cfb2b30 259 debugln("GO_Reg()");
lesmin 0:32c20cfb2b30 260 SetTID(GetTID()+1);
lesmin 0:32c20cfb2b30 261
lesmin 0:32c20cfb2b30 262 int nRet = GMMP_SetReg(g_szAuthID, g_szAuthKey, g_szDomainCode, pszGWID, pszManufactureID);
lesmin 0:32c20cfb2b30 263 debugln("GO_SetReg() Done");
lesmin 0:32c20cfb2b30 264
lesmin 0:32c20cfb2b30 265 return nRet;
lesmin 0:32c20cfb2b30 266 }
lesmin 0:32c20cfb2b30 267
lesmin 0:32c20cfb2b30 268 int GO_DeReg(const char* pszGWID, const char* pszDeviceID)
lesmin 0:32c20cfb2b30 269 {
lesmin 0:32c20cfb2b30 270 SetTID(GetTID()+1);
lesmin 0:32c20cfb2b30 271
lesmin 0:32c20cfb2b30 272 int nRet = GMMP_SetDeReg(g_szAuthID, g_szAuthKey, g_szDomainCode, pszGWID, pszDeviceID);
lesmin 0:32c20cfb2b30 273
lesmin 0:32c20cfb2b30 274 return nRet;
lesmin 0:32c20cfb2b30 275 }
lesmin 0:32c20cfb2b30 276
lesmin 0:32c20cfb2b30 277 int GO_Profile(const char* pszGWID,
lesmin 0:32c20cfb2b30 278 const char* pszDeviceID,
lesmin 0:32c20cfb2b30 279 const long nTID /*=0*/)
lesmin 0:32c20cfb2b30 280 {
lesmin 0:32c20cfb2b30 281 if(nTID == 0) {
lesmin 0:32c20cfb2b30 282 SetTID(GetTID()+1);
lesmin 0:32c20cfb2b30 283 } else {
lesmin 0:32c20cfb2b30 284 SetTID(nTID);
lesmin 0:32c20cfb2b30 285 }
lesmin 0:32c20cfb2b30 286
lesmin 0:32c20cfb2b30 287 int nRet = GMMP_SetProfile(g_szAuthID, g_szAuthKey, g_szDomainCode, pszGWID, pszDeviceID);
lesmin 0:32c20cfb2b30 288
lesmin 0:32c20cfb2b30 289 return nRet;
lesmin 0:32c20cfb2b30 290 }
lesmin 0:32c20cfb2b30 291
lesmin 0:32c20cfb2b30 292 int GO_Delivery(const char* pszGWID,
lesmin 0:32c20cfb2b30 293 const char* pszDeviceID,
lesmin 0:32c20cfb2b30 294 const char cReportType,
lesmin 0:32c20cfb2b30 295 const char cMediaType,
lesmin 0:32c20cfb2b30 296 const char* pszMessageBody)
lesmin 0:32c20cfb2b30 297 {
lesmin 0:32c20cfb2b30 298 SetTID(GetTID()+1);
lesmin 0:32c20cfb2b30 299
lesmin 0:32c20cfb2b30 300 int nRet = GMMP_SetDelivery(g_szAuthID, g_szAuthKey, g_szDomainCode, pszGWID, pszDeviceID, cReportType, cMediaType, pszMessageBody, 1, 1);
lesmin 0:32c20cfb2b30 301
lesmin 0:32c20cfb2b30 302 return nRet;
lesmin 0:32c20cfb2b30 303 }
lesmin 0:32c20cfb2b30 304
lesmin 0:32c20cfb2b30 305 int GO_Control(const char* pszGWID,
lesmin 0:32c20cfb2b30 306 const char* pszDeviceID,
lesmin 0:32c20cfb2b30 307 long nTID,
lesmin 0:32c20cfb2b30 308 const char cControlType,
lesmin 0:32c20cfb2b30 309 const char cResultCode)
lesmin 0:32c20cfb2b30 310 {
lesmin 0:32c20cfb2b30 311 SetTID(nTID);
lesmin 0:32c20cfb2b30 312
lesmin 0:32c20cfb2b30 313 return GMMP_SetControl(g_szAuthID, g_szAuthKey, g_szDomainCode, pszGWID, pszDeviceID, cControlType, cResultCode);
lesmin 0:32c20cfb2b30 314 }
lesmin 0:32c20cfb2b30 315
lesmin 0:32c20cfb2b30 316 int GO_Notifi(const char* pszGWID,
lesmin 0:32c20cfb2b30 317 const char* pszDeviceID,
lesmin 0:32c20cfb2b30 318 const char cControlType,
lesmin 0:32c20cfb2b30 319 const char cResultCode,
lesmin 0:32c20cfb2b30 320 const char* pszMessageBody,
lesmin 0:32c20cfb2b30 321 const int nMessageBodySize)
lesmin 0:32c20cfb2b30 322 {
lesmin 0:32c20cfb2b30 323 int nRet = GMMP_SetNotifi(g_szAuthID, g_szAuthKey, g_szDomainCode, pszGWID, pszDeviceID, cControlType, cResultCode, pszMessageBody, nMessageBodySize);
lesmin 0:32c20cfb2b30 324
lesmin 0:32c20cfb2b30 325 return nRet;
lesmin 0:32c20cfb2b30 326 }
lesmin 0:32c20cfb2b30 327
lesmin 0:32c20cfb2b30 328 int GO_HB(const char* pszGWID)
lesmin 0:32c20cfb2b30 329 {
lesmin 0:32c20cfb2b30 330 int nRet = GMMP_SetHB(g_szAuthID, g_szAuthKey, g_szDomainCode, pszGWID);
lesmin 0:32c20cfb2b30 331
lesmin 0:32c20cfb2b30 332 return nRet;
lesmin 0:32c20cfb2b30 333 }
lesmin 0:32c20cfb2b30 334
lesmin 0:32c20cfb2b30 335 int OG_Reg_Recv(GMMPHeader* pstGMMPHeader, stGwRegistrationRspHdr* pstGWBody, stDeviceRegistrationRspHdr* pstDeviceBody)
lesmin 0:32c20cfb2b30 336 {
lesmin 0:32c20cfb2b30 337 int nRet = 0;
lesmin 0:32c20cfb2b30 338
lesmin 0:32c20cfb2b30 339 if(g_CallFunctionRegRecv != NULL)
lesmin 0:32c20cfb2b30 340 {
lesmin 0:32c20cfb2b30 341 if(pstGWBody != NULL)
lesmin 0:32c20cfb2b30 342 {
lesmin 0:32c20cfb2b30 343 nRet= (*g_CallFunctionRegRecv)(pstGMMPHeader, pstGWBody);
lesmin 0:32c20cfb2b30 344
lesmin 0:32c20cfb2b30 345 if(nRet != GMMP_SUCCESS)
lesmin 0:32c20cfb2b30 346 {
lesmin 0:32c20cfb2b30 347 return nRet;
lesmin 0:32c20cfb2b30 348 }
lesmin 0:32c20cfb2b30 349 }
lesmin 0:32c20cfb2b30 350 else
lesmin 0:32c20cfb2b30 351 {
lesmin 0:32c20cfb2b30 352 nRet = (*g_CallFunctionRegRecv)(pstGMMPHeader, pstDeviceBody);
lesmin 0:32c20cfb2b30 353
lesmin 0:32c20cfb2b30 354 if(nRet != GMMP_SUCCESS)
lesmin 0:32c20cfb2b30 355 {
lesmin 0:32c20cfb2b30 356 return nRet;
lesmin 0:32c20cfb2b30 357 }
lesmin 0:32c20cfb2b30 358 }
lesmin 0:32c20cfb2b30 359 }
lesmin 0:32c20cfb2b30 360
lesmin 0:32c20cfb2b30 361 return GMMP_SUCCESS;
lesmin 0:32c20cfb2b30 362 }
lesmin 0:32c20cfb2b30 363
lesmin 0:32c20cfb2b30 364 int OG_DeReg_Recv(GMMPHeader* pstGMMPHeader, stGwDeRegistrationRspHdr* pstGWBody, stDeviceDeRegistrationRspHdr* pstDeviceBody)
lesmin 0:32c20cfb2b30 365 {
lesmin 0:32c20cfb2b30 366 if(g_CallFunctionRegRecv != NULL)
lesmin 0:32c20cfb2b30 367 {
lesmin 0:32c20cfb2b30 368 if(pstGWBody != NULL)
lesmin 0:32c20cfb2b30 369 {
lesmin 0:32c20cfb2b30 370 return (*g_CallFunctionRegRecv)(pstGMMPHeader, pstGWBody);
lesmin 0:32c20cfb2b30 371 }
lesmin 0:32c20cfb2b30 372 else
lesmin 0:32c20cfb2b30 373 {
lesmin 0:32c20cfb2b30 374 return (*g_CallFunctionRegRecv)(pstGMMPHeader, pstDeviceBody);
lesmin 0:32c20cfb2b30 375 }
lesmin 0:32c20cfb2b30 376 }
lesmin 0:32c20cfb2b30 377
lesmin 0:32c20cfb2b30 378 return GMMP_SUCCESS;
lesmin 0:32c20cfb2b30 379 }
lesmin 0:32c20cfb2b30 380
lesmin 0:32c20cfb2b30 381 int OG_Profile_Recv(GMMPHeader* pstGMMPHeader, stProfileRspHdr* pstBody)
lesmin 0:32c20cfb2b30 382 {
lesmin 0:32c20cfb2b30 383 if(g_CallFunctionRegRecv != NULL)
lesmin 0:32c20cfb2b30 384 {
lesmin 0:32c20cfb2b30 385 return (*g_CallFunctionRegRecv)(pstGMMPHeader, pstBody);
lesmin 0:32c20cfb2b30 386 }
lesmin 0:32c20cfb2b30 387
lesmin 0:32c20cfb2b30 388 return GMMP_SUCCESS;
lesmin 0:32c20cfb2b30 389 }
lesmin 0:32c20cfb2b30 390
lesmin 0:32c20cfb2b30 391 int OG_Delivery_Recv(GMMPHeader* pstGMMPHeader, stPacketDeliveryRspHdr* pstBody)
lesmin 0:32c20cfb2b30 392 {
lesmin 0:32c20cfb2b30 393 if(g_CallFunctionRegRecv != NULL)
lesmin 0:32c20cfb2b30 394 {
lesmin 0:32c20cfb2b30 395 return (*g_CallFunctionRegRecv)(pstGMMPHeader, pstBody);
lesmin 0:32c20cfb2b30 396 }
lesmin 0:32c20cfb2b30 397
lesmin 0:32c20cfb2b30 398 return GMMP_SUCCESS;
lesmin 0:32c20cfb2b30 399 }
lesmin 0:32c20cfb2b30 400
lesmin 0:32c20cfb2b30 401 int OG_Ctrl_Recv(GMMPHeader* pstGMMPHeader, stControlReqHdr* pstBody)
lesmin 0:32c20cfb2b30 402 {
lesmin 0:32c20cfb2b30 403 if(g_CallFunctionRegRecv != NULL)
lesmin 0:32c20cfb2b30 404 {
lesmin 0:32c20cfb2b30 405 return (*g_CallFunctionRegRecv)(pstGMMPHeader, pstBody);
lesmin 0:32c20cfb2b30 406 }
lesmin 0:32c20cfb2b30 407
lesmin 0:32c20cfb2b30 408 return GMMP_SUCCESS;
lesmin 0:32c20cfb2b30 409 }
lesmin 0:32c20cfb2b30 410
lesmin 0:32c20cfb2b30 411 int OG_HB_Recv(GMMPHeader* pstGMMPHeader, stHeartBeatMsgRspHdr* pstBody)
lesmin 0:32c20cfb2b30 412 {
lesmin 0:32c20cfb2b30 413 if(g_CallFunctionRegRecv != NULL)
lesmin 0:32c20cfb2b30 414 {
lesmin 0:32c20cfb2b30 415 return (*g_CallFunctionRegRecv)(pstGMMPHeader, pstBody);
lesmin 0:32c20cfb2b30 416 }
lesmin 0:32c20cfb2b30 417
lesmin 0:32c20cfb2b30 418 return GMMP_SUCCESS;
lesmin 0:32c20cfb2b30 419 }
lesmin 0:32c20cfb2b30 420
lesmin 0:32c20cfb2b30 421 int OG_Notifi_Recv(GMMPHeader* pstGMMPHeader, stNotificationRspHdr* pstBody)
lesmin 0:32c20cfb2b30 422 {
lesmin 0:32c20cfb2b30 423 if(g_CallFunctionRegRecv != NULL)
lesmin 0:32c20cfb2b30 424 {
lesmin 0:32c20cfb2b30 425 return (*g_CallFunctionRegRecv)(pstGMMPHeader, pstBody);
lesmin 0:32c20cfb2b30 426 }
lesmin 0:32c20cfb2b30 427
lesmin 0:32c20cfb2b30 428 return GMMP_SUCCESS;
lesmin 0:32c20cfb2b30 429 }
lesmin 0:32c20cfb2b30 430
lesmin 0:32c20cfb2b30 431 int GetReadData(GMMPHeader* pstGMMPHeader, void** pBody)
lesmin 0:32c20cfb2b30 432 {
lesmin 0:32c20cfb2b30 433 int nHeaderCound = 0;
lesmin 0:32c20cfb2b30 434 int nRet = 0;
lesmin 0:32c20cfb2b30 435
lesmin 0:32c20cfb2b30 436 while(true)
lesmin 0:32c20cfb2b30 437 {
lesmin 0:32c20cfb2b30 438 nRet = GMMP_Read(pstGMMPHeader, pBody);
lesmin 0:32c20cfb2b30 439 if(nRet == GMMP_HEADER_SIZE_ERROR) {
lesmin 0:32c20cfb2b30 440 if(nHeaderCound > 3) {
lesmin 0:32c20cfb2b30 441 break;
lesmin 0:32c20cfb2b30 442 }
lesmin 0:32c20cfb2b30 443 nHeaderCound++;
lesmin 0:32c20cfb2b30 444 continue;
lesmin 0:32c20cfb2b30 445 }
lesmin 0:32c20cfb2b30 446 else if(nRet == GMMP_SUCCESS) {
lesmin 0:32c20cfb2b30 447 break;
lesmin 0:32c20cfb2b30 448 }
lesmin 0:32c20cfb2b30 449 else {
lesmin 0:32c20cfb2b30 450 return nRet;
lesmin 0:32c20cfb2b30 451 }
lesmin 0:32c20cfb2b30 452 }
lesmin 0:32c20cfb2b30 453
lesmin 0:32c20cfb2b30 454 GMMP_Recv(pstGMMPHeader, *pBody);
lesmin 0:32c20cfb2b30 455
lesmin 0:32c20cfb2b30 456 return nRet;
lesmin 0:32c20cfb2b30 457 }
lesmin 0:32c20cfb2b30 458
lesmin 0:32c20cfb2b30 459 long Char2int(void* pBuffer, int nSize)
lesmin 0:32c20cfb2b30 460 {
lesmin 0:32c20cfb2b30 461 if(nSize != sizeof(long)) {
lesmin 0:32c20cfb2b30 462 return 0;
lesmin 0:32c20cfb2b30 463 }
lesmin 0:32c20cfb2b30 464
lesmin 0:32c20cfb2b30 465 long nInt = 0;
lesmin 0:32c20cfb2b30 466 memcpy(&nInt, pBuffer, sizeof(long));
lesmin 0:32c20cfb2b30 467 return btoli(nInt);
lesmin 0:32c20cfb2b30 468 }
lesmin 0:32c20cfb2b30 469
lesmin 0:32c20cfb2b30 470 int Char2short(void* pBuffer, short nSize)
lesmin 0:32c20cfb2b30 471 {
lesmin 0:32c20cfb2b30 472 if(nSize != sizeof(short)) {
lesmin 0:32c20cfb2b30 473 return 0;
lesmin 0:32c20cfb2b30 474 }
lesmin 0:32c20cfb2b30 475
lesmin 0:32c20cfb2b30 476 short nShort = 0;
lesmin 0:32c20cfb2b30 477 memcpy(&nShort, pBuffer, sizeof(short));
lesmin 0:32c20cfb2b30 478 return btols(nShort);
lesmin 0:32c20cfb2b30 479 }
lesmin 0:32c20cfb2b30 480
lesmin 0:32c20cfb2b30 481 void InitMemory()
lesmin 0:32c20cfb2b30 482 {
lesmin 0:32c20cfb2b30 483 memset(g_szDomainCode, 0 , sizeof(g_szAuthID));
lesmin 0:32c20cfb2b30 484 memset(g_szAuthID, 0 , sizeof(g_szAuthID));
lesmin 0:32c20cfb2b30 485 memset(g_szAuthKey, 0 , sizeof(g_szAuthKey));
lesmin 0:32c20cfb2b30 486 memset(g_szGWID, 0 , sizeof(g_szGWID));
lesmin 0:32c20cfb2b30 487
lesmin 0:32c20cfb2b30 488 g_nServerPort = 0;
lesmin 0:32c20cfb2b30 489
lesmin 0:32c20cfb2b30 490 g_CallFunctionRegRecv = NULL;
lesmin 0:32c20cfb2b30 491 }
lesmin 0:32c20cfb2b30 492
lesmin 0:32c20cfb2b30 493 #endif