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