119 EVT_PAINT(MyFrame::OnPaint) |
125 EVT_PAINT(MyFrame::OnPaint) |
120 |
126 |
121 EVT_TIMER(TIMER_ID, MyFrame::OnTimer) |
127 EVT_TIMER(TIMER_ID, MyFrame::OnTimer) |
122 END_EVENT_TABLE() |
128 END_EVENT_TABLE() |
123 |
129 |
124 IMPLEMENT_APP(MyApp) |
130 IMPLEMENT_APP_NO_MAIN(MyApp); |
|
131 IMPLEMENT_WX_THEME_SUPPORT; |
|
132 |
|
133 void help() |
|
134 { |
|
135 printf("**************************************************************\n"); |
|
136 printf("* DS-401 Slave GUI *\n"); |
|
137 printf("* *\n"); |
|
138 printf("* Usage: *\n"); |
|
139 printf("* ./DS401_Slave_Gui [OPTIONS] *\n"); |
|
140 printf("* *\n"); |
|
141 printf("* OPTIONS: *\n"); |
|
142 printf("* -l : Can library [\"libcanfestival_can_virtual.so\"] *\n"); |
|
143 printf("* *\n"); |
|
144 printf("* Slave: *\n"); |
|
145 printf("* -i : Node id format [0x01 , 0x7F] *\n"); |
|
146 printf("* *\n"); |
|
147 printf("* CAN bus: *\n"); |
|
148 printf("* -b : bus name [\"1\"] *\n"); |
|
149 printf("* -B : 1M,500K,250K,125K,100K,50K,20K,10K *\n"); |
|
150 printf("* *\n"); |
|
151 printf("**************************************************************\n"); |
|
152 } |
|
153 |
|
154 |
|
155 int main(int argc,char **argv) |
|
156 { |
|
157 |
|
158 int c; |
|
159 extern char *optarg; |
|
160 char *snodeid; |
|
161 while ((c = getopt(argc, argv, "-b:B:l:i:s")) != EOF) |
|
162 { |
|
163 switch(c) |
|
164 { |
|
165 case 'b' : |
|
166 if (optarg[0] == 0) |
|
167 { |
|
168 help(); |
|
169 exit(1); |
|
170 } |
|
171 SlaveBoard.busname = optarg; |
|
172 break; |
|
173 case 'B' : |
|
174 if (optarg[0] == 0) |
|
175 { |
|
176 help(); |
|
177 exit(1); |
|
178 } |
|
179 SlaveBoard.baudrate = optarg; |
|
180 break; |
|
181 case 'l' : |
|
182 if (optarg[0] == 0) |
|
183 { |
|
184 help(); |
|
185 exit(1); |
|
186 } |
|
187 strncpy(LibraryPath, optarg, MAXLENGTH_LIBPATH); |
|
188 break; |
|
189 case 'i' : |
|
190 if (optarg[0] == 0) |
|
191 { |
|
192 help(); |
|
193 exit(1); |
|
194 } |
|
195 snodeid = optarg; |
|
196 sscanf(snodeid,"%x",&node_id_ext); |
|
197 break; |
|
198 case 's' : |
|
199 to_start = 1; |
|
200 break; |
|
201 default: |
|
202 help(); |
|
203 exit(1); |
|
204 } |
|
205 } |
|
206 wxEntry(argc,argv); |
|
207 } |
|
208 |
125 |
209 |
126 bool MyApp::OnInit() |
210 bool MyApp::OnInit() |
127 { |
211 { |
128 frame = new MyFrame( _T("I-O simulator")); |
212 frame = new MyFrame( _T("I-O simulator")); |
129 frame->Show(true); |
213 frame->Show(true); |
146 wxBoxSizer *myentrysizer; |
230 wxBoxSizer *myentrysizer; |
147 wxListBox *freqlist; |
231 wxListBox *freqlist; |
148 wxStaticBox *namebox; |
232 wxStaticBox *namebox; |
149 wxStaticBox *freqbox; |
233 wxStaticBox *freqbox; |
150 |
234 |
151 SetIcon(wxICON(monicone)); |
235 // SetIcon(wxICON(monicone)); |
152 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); |
236 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); |
153 helpMenu->Append(HELP_ABOUT, _T("&About...\tF1"), |
237 helpMenu->Append(HELP_ABOUT, _T("&About...\tF1"), |
154 _T("Show about dialog")); |
238 _T("Show about dialog")); |
155 fileMenu->Append(FILE_QUIT, _T("E&xit\tAlt-X"), |
239 fileMenu->Append(FILE_QUIT, _T("E&xit\tAlt-X"), |
156 _T("Quit this program")); |
240 _T("Quit this program")); |
176 |
260 |
177 myhsizer = new wxStaticBoxSizer( new wxStaticBox(panel, wxID_ANY, _T("Bus driver")), wxHORIZONTAL ); |
261 myhsizer = new wxStaticBoxSizer( new wxStaticBox(panel, wxID_ANY, _T("Bus driver")), wxHORIZONTAL ); |
178 mysizer->Add(myhsizer, 0, wxEXPAND | wxALL, 5); |
262 mysizer->Add(myhsizer, 0, wxEXPAND | wxALL, 5); |
179 load = new wxButton( panel, LOAD, _T("Load can driver")); |
263 load = new wxButton( panel, LOAD, _T("Load can driver")); |
180 myhsizer->Add(load, 0, wxLEFT, 5); |
264 myhsizer->Add(load, 0, wxLEFT, 5); |
181 drivername = new wxTextCtrl(panel, wxID_ANY, _T("No driver loaded!!")); |
265 drivername = new wxTextCtrl(panel, wxID_ANY, wxString((const char*)LibraryPath,wxConvLocal)); |
182 myhsizer->Add(drivername, 1, wxEXPAND | wxALL, 5); |
266 myhsizer->Add(drivername, 1, wxEXPAND | wxALL, 5); |
183 myentrysizer = new wxBoxSizer( wxHORIZONTAL ); |
267 myentrysizer = new wxBoxSizer( wxHORIZONTAL ); |
184 mysizer->Add(myentrysizer, 0, wxEXPAND | wxALL, 5); |
268 mysizer->Add(myentrysizer, 0, wxEXPAND | wxALL, 5); |
185 myhsizer = new wxStaticBoxSizer( new wxStaticBox(panel, wxID_ANY, _T("Bus name")), wxHORIZONTAL ); |
269 myhsizer = new wxStaticBoxSizer( new wxStaticBox(panel, wxID_ANY, _T("Bus name")), wxHORIZONTAL ); |
186 myentrysizer->Add(myhsizer, 0, wxEXPAND | wxALL, 5); |
270 myentrysizer->Add(myhsizer, 0, wxEXPAND | wxALL, 5); |
187 busname = new wxTextCtrl(panel, wxID_ANY, _T("0")); |
271 busname = new wxTextCtrl(panel, wxID_ANY, wxString((const char*)SlaveBoard.busname, wxConvLocal)); |
188 myhsizer->Add(busname, 0, wxLEFT, 5); |
272 myhsizer->Add(busname, 0, wxLEFT, 5); |
189 myhsizer = new wxStaticBoxSizer( new wxStaticBox(panel, wxID_ANY, _T("Node ID (Hexa)")), wxHORIZONTAL ); |
273 myhsizer = new wxStaticBoxSizer( new wxStaticBox(panel, wxID_ANY, _T("Node ID (Hexa)")), wxHORIZONTAL ); |
190 myentrysizer->Add(myhsizer, 0, wxEXPAND | wxALL, 5); |
274 myentrysizer->Add(myhsizer, 0, wxEXPAND | wxALL, 5); |
191 node_id = new wxSpinCtrl(panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 127, 1, _T("wxSpinCtrl")); |
275 node_id = new wxSpinCtrl(panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 127, node_id_ext, _T("wxSpinCtrl")); |
192 myhsizer->Add(node_id, 0, wxRIGHT, 5); |
276 myhsizer->Add(node_id, 0, wxRIGHT, 5); |
193 myhsizer = new wxStaticBoxSizer( new wxStaticBox(panel, wxID_ANY, _T("Baudrate")), wxHORIZONTAL ); |
277 myhsizer = new wxStaticBoxSizer( new wxStaticBox(panel, wxID_ANY, _T("Baudrate")), wxHORIZONTAL ); |
194 mysizer->Add(myhsizer, wxEXPAND | wxALL, wxEXPAND | wxALL, 5); |
278 mysizer->Add(myhsizer, wxEXPAND | wxALL, wxEXPAND | wxALL, 5); |
195 freqlist = new wxListBox( panel, FREQBOX, wxDefaultPosition, wxDefaultSize, 8, choices, wxLB_SINGLE | wxLB_HSCROLL); |
279 freqlist = new wxListBox( panel, FREQBOX, wxDefaultPosition, wxDefaultSize, 8, choices, wxLB_SINGLE | wxLB_HSCROLL); |
196 myhsizer->Add(freqlist, wxEXPAND | wxALL, wxEXPAND | wxALL, 5); |
280 myhsizer->Add(freqlist, wxEXPAND | wxALL, wxEXPAND | wxALL, 5); |
368 |
452 |
369 for (int i= 0; i < 28; i++) |
453 for (int i= 0; i < 28; i++) |
370 for (int j = 0; j < 44; j++) |
454 for (int j = 0; j < 44; j++) |
371 y[i][j] = 0; |
455 y[i][j] = 0; |
372 m_timer.Start(100); |
456 m_timer.Start(100); |
|
457 if(to_start) |
|
458 { |
|
459 Start(); |
|
460 } |
373 } |
461 } |
374 |
462 |
375 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) |
463 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) |
376 { |
464 { |
377 Close(true); |
465 Close(true); |
|
466 } |
|
467 |
|
468 void MyFrame::Start() |
|
469 { |
|
470 if (main_can(SlaveBoard, LibraryPath)) |
|
471 { |
|
472 printf("[KO]\n"); |
|
473 *textLog << wxT("----------------------------------------------------Initialization [KO]\n"); |
|
474 } |
|
475 else |
|
476 { |
|
477 printf("[OK]\n"); |
|
478 *textLog << wxT("----------------------------------------------------Initialization [OK]\n"); |
|
479 stop->Enable(true); |
|
480 start->Enable(false); |
|
481 } |
378 } |
482 } |
379 |
483 |
380 void MyFrame::OnStart(wxCommandEvent& WXUNUSED(event)) |
484 void MyFrame::OnStart(wxCommandEvent& WXUNUSED(event)) |
381 { |
485 { |
382 wxString s; |
486 wxString s; |
383 |
487 |
384 if (LibraryPath == NULL) |
|
385 { |
|
386 *textLog << wxT("No driver found!! ----------------------------------Initialization [KO]\n"); |
|
387 return; |
|
388 } |
|
389 if (SlaveBoard.baudrate == NULL) |
|
390 { |
|
391 *textLog << wxT("No baudrate found!! ----------------------------------Initialization [KO]\n"); |
|
392 return; |
|
393 } |
|
394 |
|
395 node_id_ext = node_id->GetValue(); |
488 node_id_ext = node_id->GetValue(); |
396 s = busname->GetValue(); |
489 s = busname->GetValue(); |
397 SlaveBoard.busname = wxstr_to_charbuf(s); |
490 strncpy(SlaveBoard.busname, s.mb_str(), MAXLENGTH_BUSNAME); |
398 *textLog << wxT("-- Bus name: ------> ") << s << wxT("\n"); |
491 *textLog << wxT("-- Bus name: ------> ") << s << wxT("\n"); |
399 *textLog << wxT("-- Node ID: -------> ") << node_id->GetValue() << wxT("\n"); |
492 *textLog << wxT("-- Node ID: -------> ") << node_id->GetValue() << wxT("\n"); |
400 |
493 Start(); |
401 if (main_can(SlaveBoard, LibraryPath)) |
494 } |
402 { |
495 |
403 printf("[KO]\n"); |
|
404 *textLog << wxT("----------------------------------------------------Initialization [KO]\n"); |
|
405 } |
|
406 else |
|
407 { |
|
408 printf("[OK]\n"); |
|
409 *textLog << wxT("----------------------------------------------------Initialization [OK]\n"); |
|
410 stop->Enable(true); |
|
411 start->Enable(false); |
|
412 } |
|
413 } |
|
414 |
496 |
415 void MyFrame::OnStop(wxCommandEvent& WXUNUSED(event)) |
497 void MyFrame::OnStop(wxCommandEvent& WXUNUSED(event)) |
416 { |
498 { |
417 |
499 |
418 *textLog << wxT("----------------------------------------------------Slave [STOPPED]") << wxT("\n"); |
500 *textLog << wxT("----------------------------------------------------Slave [STOPPED]") << wxT("\n"); |
419 stop_slave(); |
501 stop_slave(); |
420 stop->Enable(false); |
502 stop->Enable(false); |
421 start->Enable(true); |
503 start->Enable(true); |
422 charbuf_free(SlaveBoard.busname); |
|
423 } |
504 } |
424 |
505 |
425 void MyFrame::OnLoad(wxCommandEvent& WXUNUSED(event)) |
506 void MyFrame::OnLoad(wxCommandEvent& WXUNUSED(event)) |
426 { |
507 { |
427 wxFileDialog fd(this, wxT("Choose a node configuration file"), wxT(""), wxT("Slave.od"), wxT("*.so")); |
508 wxFileDialog fd(this, wxT("Choose a node configuration file"), wxT(""), wxT("Slave.od"), wxT("*.so")); |