void EthernetCallback(uint32_t ui32Event, void *pvData, uint32_t ui32Param) { uint8_t *pD = (uint8_t *)pvData; // // Handle events from the Ethernet client layer. // switch(ui32Event) { // // Ethernet client has received data. // case ETH_CLIENT_EVENT_RECEIVE: { // handle packet recieve parsing pD is data ui32Param is length memcpy(OnionClient::recvPkt->getBuffer(),pD,ui32Param); OnionClient::recvPkt->setPayloadLength(ui32Param-3); available = true; } // // Ethernet client has connected to the specified server/host and port. // case ETH_CLIENT_EVENT_CONNECT: { // update state of connection OnionClient::socketConnected = true; break; } // // Ethernet client has obtained IP address via DHCP. // case ETH_CLIENT_EVENT_DHCP: { EthClientDNSResolve(); break; } // // Ethernet client has received DNS response. // case ETH_CLIENT_EVENT_DNS: { if(ui32Param != 0) { // // If DNS resolved successfully, initialize the socket and // stack. // EthClientTCPConnect(); } else { // Report error / update state (no dns available) } break; } // // Ethernet client has disconnected from the server/host. // case ETH_CLIENT_EVENT_DISCONNECT: { // // Close the socket. // OnionClient::socketConnected = false; EthClientTCPDisconnect(); break; } // // All other cases are unhandled. // case ETH_CLIENT_EVENT_SEND: { break; } case ETH_CLIENT_EVENT_ERROR: { break; } default: { break; } } }
//***************************************************************************** // // Gets the current weather information for a given city. // //***************************************************************************** int32_t WeatherCurrent(tWeatherSource eWeatherSource, const char *pcQuery, tWeatherReport *psWeatherReport, tEventFunction pfnEvent) { int32_t i32Idx; // // If the requested source is not valid or there is no call back then // just fail. // if((eWeatherSource != iWSrcOpenWeatherMap) || (g_sWeather.pfnEvent)) { return (-1); } g_sWeather.pfnEvent = pfnEvent; g_sWeather.psWeatherReport = psWeatherReport; // // Copy the base current request to the buffer. // i32Idx = MergeRequest(0, g_cWeatherRequest, sizeof(g_cWeatherRequest), false); // // Append the request. // i32Idx = MergeRequest(i32Idx, pcQuery, sizeof(g_sWeather.pcRequest), true); // // Append the request mode. // i32Idx = MergeRequest(i32Idx, g_cMode, sizeof(g_cMode), false); // // Append the App ID. // i32Idx = MergeRequest(i32Idx, g_cAPPIDOpenWeather, sizeof(g_cAPPIDOpenWeather), false); // // Append the "HTTP:/1.1" string. // i32Idx = MergeRequest(i32Idx, g_cHTTP11, sizeof(g_cHTTP11), false); // // Save the size of this request. // g_sWeather.ui32RequestSize = i32Idx; // // Connect or reconnect to port 80. // g_sEnet.eState = iEthTCPConnectWait; // // Current weather report request. // g_sEnet.ulRequest = WEATHER_CURRENT; // // Connect to server // if(EthClientTCPConnect(80) != ERR_OK) { return(-1); } return(0); }