void wxGISLocalClientConnection::OnSocketEvent(wxSocketEvent& event) { event.Skip(false); wxLogDebug(wxT("wxClientTCPNetConnection: event")); switch(event.GetSocketEvent()) { case wxSOCKET_INPUT: wxLogDebug(wxT("wxClientTCPNetConnection: INPUT")); break; case wxSOCKET_OUTPUT: wxLogDebug(wxT("wxClientTCPNetConnection: OUTPUT")); break; case wxSOCKET_CONNECTION: wxLogDebug(wxT("wxClientTCPNetConnection: CONNECTION")); m_bIsConnected = true; m_bIsConnecting = false; { wxNetMessage msgin(enumGISNetCmdHello, enumGISNetCmdStUnk, enumGISPriorityHighest); wxGISNetEvent event(0, wxGISNET_MSG, msgin); PostEvent(event); } break; case wxSOCKET_LOST: wxLogDebug(wxT("wxClientTCPNetConnection: LOST")); { wxNetMessage msgin(enumGISNetCmdBye, enumGISNetCmdStUnk, enumGISPriorityHighest); if(!m_bIsConnected && m_bIsConnecting) { m_bIsConnecting = false; } else { m_bIsConnected = false; } wxGISNetEvent event(0, wxGISNET_MSG, msgin); PostEvent(event); } break; default: wxLogDebug(wxT("wxClientTCPNetConnection: default")); break; } }
void WIFIWindow::OnSocketEvent(wxSocketEvent& event) { wifi_scan_data *pt; unsigned char response_type; int i, ilocal; unsigned char *pbuffer; int *pcnt; int cnt; unsigned char buf[100]; int pt_eaten[64]; if(event.GetSocketEvent() == wxSOCKET_INPUT) { // Read the first 5 bytes of the reply, getting its total type and total length m_sock->Read(buf, 5); // Read the rest response_type = buf[0]; int *pint =(int *)(&buf[1]); int total_length = *pint; // get some memory to read the rest pbuffer = (unsigned char*) malloc(total_length * sizeof(unsigned char)); m_sock->Read(pbuffer, total_length-5); switch(response_type - 0x80) { case 'D' : m_bRX = true; // reset watchdog m_watchtick = 0; // Get the scan results station count pcnt = (int *)&pbuffer[0]; cnt = *pcnt; if(cnt > 64) cnt = 64; // be safe // Manage the data input // Some setup for(i=0 ; i < cnt ; i++) pt_eaten[i] = false; // First, check to see if any input station data is already present in local store // If it is (ESSID matches), then simply update the signal quality, and refresh the age. // Also, flag the fact that the input data has been eaten. for(i=0 ; i < cnt ; i++) { pt = (wifi_scan_data *)(&pbuffer[(sizeof(int) + i * 256)]); // skipping the first int if(strlen(pt->ESSID)) { for(int ilocal = 0 ; ilocal < NLOCALSTORE ; ilocal++) { if((!strcmp(pt->ESSID, station_data[ilocal].ESSID)) && (station_data[ilocal].bisvalid)) { station_data[ilocal].sig_quality = pt->sig_quality; station_data[ilocal].age = -1; pt_eaten[i] = true; } } } } // Now, age the local store by one for(ilocal = 0 ; ilocal < NLOCALSTORE ; ilocal++) if(station_data[ilocal].bisvalid) station_data[ilocal].age ++; // and free any entries that are over the specified age for(ilocal = 0 ; ilocal < NLOCALSTORE ; ilocal++) { if((station_data[ilocal].bisvalid) && (station_data[ilocal].age >= N_AGEDEATH)) { station_data[ilocal].bisvalid = false; station_data[ilocal].ESSID[0] = 0; } } // Now, check to see if any input data is un-eaten // If found, then try to allocate to a local store item for(i=0 ; i < cnt ; i++) { if(pt_eaten[i] == false) { pt = (wifi_scan_data *)(&pbuffer[(sizeof(int) + i * 256)]); if(strlen(pt->ESSID)) { for(ilocal = 0 ; ilocal < NLOCALSTORE ; ilocal++) { if(station_data[ilocal].bisvalid == false) { strcpy(station_data[ilocal].ESSID, pt->ESSID); station_data[ilocal].sig_quality = pt->sig_quality; station_data[ilocal].secure = pt->secure; station_data[ilocal].bisvalid = true; station_data[ilocal].age = 0; pt_eaten[i] = true; break; } } } } } // There may still be un-eaten input data at this point...... // For now, ignore it. If it is real, it will appear as soon as something else dies // Finally, send the data to the display window for(ilocal = 0 ; ilocal < NLOCALSTORE ; ilocal++) { if(station_data[ilocal].bisvalid) { // stats->pWiFi->SetStationQuality(ilocal, station_data[ilocal].sig_quality); // stats->pWiFi->SetStationSecureFlag(ilocal, station_data[ilocal].secure); // stats->pWiFi->SetStationAge(ilocal, station_data[ilocal].age); } // else // stats->pWiFi->SetStationQuality(ilocal, 0); } stats->Refresh(true); break; case 'S' : { /* StatusString = wxString(&buf[5]); // This may be useful later.... fi_status_data *status = (wifi_status_data *)&buf[5]; memcpy(&connected_ap_mac_addr, &status->currently_connected_ap, sizeof(struct sockaddr)); // Check for re-connect, if needed if(StatusString.StartsWith("Not")) { if(s_do_reconnect) { time_t tnow = wxDateTime::GetTimeNow(); last_connect_seconds = tnow - last_connect_time; do_reconnect(); } } m_statWindow->Refresh(); */ break; } case 'R' : { /* wxString wr(&buf[5]); m_logWindow->WriteText(wr); long ac_compass, ac_brg_commanded, ac_brg_current, ac_motor_dir; // Parse the Antenna Controller string if(!strncmp((const char *)&buf[5], "ANTC", 4)) // valid string { wxStringTokenizer tk(wr, wxT(":")); wxString token = tk.GetNextToken(); // skip ANTC token = tk.GetNextToken(); token.ToLong(&ac_compass); // compass heading token = tk.GetNextToken(); token.ToLong(&ac_brg_commanded); // last commanded antenna bearing token = tk.GetNextToken(); token.ToLong(&ac_brg_current); // current antenna brg token = tk.GetNextToken(); token.ToLong(&ac_motor_dir); // current motor state s_ac_compass = ac_compass; s_ac_brg_commanded = ac_brg_commanded; s_ac_brg_current = ac_brg_current; s_ac_motor_dir = ac_motor_dir; m_antWindow->Refresh(); } */ break; } case 'K' : { break; } default: break; } //switch free(pbuffer); } // if event.Skip(); }