Modified for W5500 Ethernet initialize Added the Ethernet interface re-initialize code Added the connection retry

Dependents:   ThingPlug_Ethernet_Example

Fork of GMMP_mbed by Eric Jung

Committer:
lesmin
Date:
Sun Aug 09 14:55:24 2015 +0000
Revision:
1:29d7f5c53126
Parent:
0:7e575e5f88ec
Child:
2:0c4e3edf2918
guarding memory added for W5500

Who changed what in which revision?

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