40#include "wificlient.h"
43static int wifi_s_dns_test_flag;
49EVT_PAINT(WIFIWindow::OnPaint)
50EVT_ACTIVATE(WIFIWindow::OnActivate)
51EVT_CLOSE(WIFIWindow::OnCloseWindow)
53EVT_SOCKET(WIFI_SOCKET_ID, WIFIWindow::OnSocketEvent)
54EVT_TIMER(TIMER_WIFI1, WIFIWindow::OnTimer1)
60 : wxWindow(frame, wxID_ANY, wxPoint(20, 20), wxSize(5, 5), wxSIMPLE_BORDER)
63 parent_frame = (
MyFrame *)frame;
66 m_pdata_server_string =
new wxString(WiFiServerName);
69 m_timer_active =
false;
72 wxString msg(_T(
"WiFi Server is...."));
73 msg.Append(*m_pdata_server_string);
76 if (m_pdata_server_string->Contains(_T(
"TCP/IP"))) {
77 wxString WIFI_data_ip;
78 WIFI_data_ip = m_pdata_server_string->Mid(7);
80 if (!WIFI_data_ip.IsEmpty()) {
82 m_sock =
new wxSocketClient();
85 m_sock->SetEventHandler(*
this, WIFI_SOCKET_ID);
87 m_sock->SetNotify(wxSOCKET_CONNECTION_FLAG | wxSOCKET_INPUT_FLAG |
112#define SLEEP_TEST_SEC 2
114 for (
int is = 0; is < SLEEP_TEST_SEC * 10; is++) {
116 if (wifi_s_dns_test_flag)
break;
119 if (!wifi_s_dns_test_flag) {
120 wxString msg(WIFI_data_ip);
121 msg.Prepend(_T(
"Could not resolve TCP/IP host '"));
122 msg.Append(_T(
"'\n Suggestion: Try 'xxx.xxx.xxx.xxx' notation"));
126 m_sock->Notify(FALSE);
132 addr.Hostname(WIFI_data_ip);
133 addr.Service(SERVER_PORT);
137 m_sock->SetFlags(wxSOCKET_WAITALL | wxSOCKET_BLOCK);
138 m_sock->Connect(addr, FALSE);
141 for (
int ilocal = 0; ilocal < NLOCALSTORE; ilocal++) {
142 station_data[ilocal].bisvalid =
false;
145 Timer1.SetOwner(
this, TIMER_WIFI1);
146 m_scan_interval_msec = 10000;
147 Timer1.Start(m_scan_interval_msec, wxTIMER_CONTINUOUS);
148 m_timer_active =
true;
155WIFIWindow::~WIFIWindow() {
delete m_pdata_server_string; }
157void WIFIWindow::OnCloseWindow(wxCloseEvent &event) {
160 m_sock->Notify(FALSE);
166void WIFIWindow::GetSource(wxString &source) {
167 source = *m_pdata_server_string;
170void WIFIWindow::OnActivate(wxActivateEvent &event) {}
172void WIFIWindow::OnPaint(wxPaintEvent &event) { wxPaintDC dc(
this); }
174void WIFIWindow::Pause(
void) {
175 if (m_timer_active) Timer1.Stop();
177 if (m_sock) m_sock->Notify(FALSE);
180void WIFIWindow::UnPause(
void) {
181 if (m_timer_active) Timer1.Start(m_scan_interval_msec, wxTIMER_CONTINUOUS);
183 if (m_sock) m_sock->Notify(TRUE);
187void WIFIWindow::OnSocketEvent(wxSocketEvent &event) {
189 unsigned char response_type;
192 unsigned char *pbuffer;
195 unsigned char buf[100];
198 if (event.GetSocketEvent() == wxSOCKET_INPUT) {
201 m_sock->Read(buf, 5);
204 response_type = buf[0];
205 int *pint = (
int *)(&buf[1]);
206 int total_length = *pint;
209 pbuffer = (
unsigned char *)malloc(total_length *
sizeof(
unsigned char));
211 m_sock->Read(pbuffer, total_length - 5);
213 switch (response_type - 0x80) {
219 pcnt = (
int *)&pbuffer[0];
222 if (cnt > 64) cnt = 64;
226 for (i = 0; i < cnt; i++) pt_eaten[i] =
false;
233 for (i = 0; i < cnt; i++) {
235 sizeof(
int) + i * 256)]);
236 if (strlen(pt->ESSID)) {
237 for (
int ilocal = 0; ilocal < NLOCALSTORE; ilocal++) {
238 if ((!strcmp(pt->ESSID, station_data[ilocal].ESSID)) &&
239 (station_data[ilocal].bisvalid)) {
240 station_data[ilocal].sig_quality = pt->sig_quality;
241 station_data[ilocal].age = -1;
249 for (ilocal = 0; ilocal < NLOCALSTORE; ilocal++)
250 if (station_data[ilocal].bisvalid) station_data[ilocal].age++;
253 for (ilocal = 0; ilocal < NLOCALSTORE; ilocal++) {
254 if ((station_data[ilocal].bisvalid) &&
255 (station_data[ilocal].age >= N_AGEDEATH)) {
256 station_data[ilocal].bisvalid =
false;
257 station_data[ilocal].ESSID[0] = 0;
263 for (i = 0; i < cnt; i++) {
264 if (pt_eaten[i] ==
false) {
266 if (strlen(pt->ESSID)) {
267 for (ilocal = 0; ilocal < NLOCALSTORE; ilocal++) {
268 if (station_data[ilocal].bisvalid ==
false) {
269 strcpy(station_data[ilocal].ESSID, pt->ESSID);
270 station_data[ilocal].sig_quality = pt->sig_quality;
271 station_data[ilocal].secure = pt->secure;
272 station_data[ilocal].bisvalid =
true;
273 station_data[ilocal].age = 0;
287 for (ilocal = 0; ilocal < NLOCALSTORE; ilocal++) {
288 if (station_data[ilocal].bisvalid) {
300 g_ChartBarWin->Refresh(
true);
387void WIFIWindow::OnTimer1(wxTimerEvent &event) {
390 if (m_sock->IsConnected()) {
393 if (m_watchtick++ > WIFI_DOG_TIMEOUT)
396 g_ChartBarWin->Refresh(
true);
401 m_sock =
new wxSocketClient();
402 m_sock->SetEventHandler(*
this, WIFI_SOCKET_ID);
404 m_sock->SetNotify(wxSOCKET_CONNECTION_FLAG | wxSOCKET_INPUT_FLAG |
406 m_sock->Notify(TRUE);
407 m_sock->SetFlags(wxSOCKET_WAITALL | wxSOCKET_BLOCK);
415 unsigned char c = WIFI_TRANSMIT_DATA_EXT;
416 m_sock->Write(&c, 1);
421 g_ChartBarWin->Refresh(
true);
423 m_sock->Connect(addr, FALSE);
427 Timer1.Start(m_scan_interval_msec, wxTIMER_CONTINUOUS);
436WIFIDNSTestThread::WIFIDNSTestThread(
const wxString &name_or_ip) {
437 m_pip =
new wxString(name_or_ip);
442WIFIDNSTestThread::~WIFIDNSTestThread() {
delete m_pip; }
444void *WIFIDNSTestThread::Entry() {
445 wifi_s_dns_test_flag = 0;
448 addr.Hostname(*m_pip);
450 wifi_s_dns_test_flag = 1;