3 #include <wx/textctrl.h>
4 #include <wx/spinctrl.h>
11 #include <wx/listbox.h>
12 #include <wx/dynarray.h>
13 #include <wx/dcclient.h>
15 #include <wx/spinctrl.h>
17 //#include "monicone.xpm"
20 #include "TestSlaveGui.h"
22 #include "canfestival.h"
25 #include "wx/wxprec.h"
40 #define MAXLENGTH_BUSNAME 32
41 #define MAXLENGTH_BAUDRATE 8
42 char _busname[MAXLENGTH_BUSNAME] = "vcan0";
43 char _baudrate[MAXLENGTH_BAUDRATE] = "500K";
44 s_BOARD SlaveBoard = {_busname, _baudrate};
45 #define MAXLENGTH_LIBPATH 1024
46 char LibraryPath[MAXLENGTH_LIBPATH] = "libcanfestival_can_virtual.so";
53 // Declare some IDs. These are arbitrary.
54 const int BOOKCTRL = 100;
55 const int FILE_QUIT = wxID_EXIT;
56 const int HELP_ABOUT = wxID_ABOUT;
58 const int REMOVE = 108;
60 const int FREQBOX = 110;
61 const int START = 112;
62 const int TEXTBOX1 = 113;
65 const int INBT1 = 118;
66 const int INBT2 = 119;
67 const int INBT3 = 120;
68 const int INBT4 = 121;
69 const int INBT5 = 122;
70 const int INBT6 = 123;
71 const int INBT7 = 124;
72 const int INBT8 = 125;
81 const int TIMER_ID = 130;
82 const int INST1 = 131;
83 const int INST2 = 132;
84 const int INST3 = 133;
85 const int INST4 = 134;
86 const int INST5 = 135;
87 const int INST6 = 136;
88 const int INST7 = 137;
89 const int INST8 = 138;
91 // Attach the event handlers. Put this after MyFrame declaration.
92 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
93 EVT_BUTTON(STOP, MyFrame::OnStop)
94 EVT_BUTTON(LOAD, MyFrame::OnLoad)
95 EVT_BUTTON(START, MyFrame::OnStart)
96 EVT_TOGGLEBUTTON(INBT1, MyFrame::OnInbt1)
97 EVT_TOGGLEBUTTON(INBT2, MyFrame::OnInbt2)
98 EVT_TOGGLEBUTTON(INBT3, MyFrame::OnInbt3)
99 EVT_TOGGLEBUTTON(INBT4, MyFrame::OnInbt4)
100 EVT_TOGGLEBUTTON(INBT5, MyFrame::OnInbt5)
101 EVT_TOGGLEBUTTON(INBT6, MyFrame::OnInbt6)
102 EVT_TOGGLEBUTTON(INBT7, MyFrame::OnInbt7)
103 EVT_TOGGLEBUTTON(INBT8, MyFrame::OnInbt8)
104 EVT_COMMAND_SCROLL(INS1, MyFrame::OnIns1)
105 EVT_COMMAND_SCROLL(INS2, MyFrame::OnIns2)
106 EVT_COMMAND_SCROLL(INS3, MyFrame::OnIns3)
107 EVT_COMMAND_SCROLL(INS4, MyFrame::OnIns4)
108 EVT_COMMAND_SCROLL(INS5, MyFrame::OnIns5)
109 EVT_COMMAND_SCROLL(INS6, MyFrame::OnIns6)
110 EVT_COMMAND_SCROLL(INS7, MyFrame::OnIns7)
111 EVT_COMMAND_SCROLL(INS8, MyFrame::OnIns8)
112 EVT_SPINCTRL(INST1, MyFrame::OnInst1)
113 EVT_SPINCTRL(INST2, MyFrame::OnInst2)
114 EVT_SPINCTRL(INST3, MyFrame::OnInst3)
115 EVT_SPINCTRL(INST4, MyFrame::OnInst4)
116 EVT_SPINCTRL(INST5, MyFrame::OnInst5)
117 EVT_SPINCTRL(INST6, MyFrame::OnInst6)
118 EVT_SPINCTRL(INST7, MyFrame::OnInst7)
119 EVT_SPINCTRL(INST8, MyFrame::OnInst8)
121 EVT_LISTBOX(FREQBOX, MyFrame::OnFreqBoxClick)
122 EVT_MENU(FILE_QUIT, MyFrame::OnQuit)
123 EVT_BUTTON(QUIT, MyFrame::OnQuit)
124 EVT_MENU(HELP_ABOUT, MyFrame::OnAbout)
125 EVT_PAINT(MyFrame::OnPaint)
127 EVT_TIMER(TIMER_ID, MyFrame::OnTimer)
130 IMPLEMENT_APP_NO_MAIN(MyApp);
131 IMPLEMENT_WX_THEME_SUPPORT;
135 printf("**************************************************************\n");
136 printf("* DS-401 Slave GUI *\n");
138 printf("* Usage: *\n");
139 printf("* ./DS401_Slave_Gui [OPTIONS] *\n");
141 printf("* OPTIONS: *\n");
142 printf("* -l : Can library [\"libcanfestival_can_virtual.so\"] *\n");
144 printf("* Slave: *\n");
145 printf("* -i : Node id format [0x01 , 0x7F] *\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");
151 printf("**************************************************************\n");
155 int main(int argc,char **argv)
161 while ((c = getopt(argc, argv, "-b:B:l:i:s")) != EOF)
171 SlaveBoard.busname = optarg;
179 SlaveBoard.baudrate = optarg;
187 strncpy(LibraryPath, optarg, MAXLENGTH_LIBPATH);
196 sscanf(snodeid,"%x",&node_id_ext);
212 frame = new MyFrame( _T("I-O simulator"));
217 MyFrame::MyFrame(const wxString& title)
218 : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(800, 740), wxDEFAULT_FRAME_STYLE, wxT("frame"))
219 ,m_timer(this, TIMER_ID)
221 wxMenu *fileMenu = new wxMenu;
222 wxMenu *helpMenu = new wxMenu;
227 wxBoxSizer *mysssizer;
228 wxBoxSizer *myhsizer;
229 wxBoxSizer *mybsizer;
230 wxBoxSizer *myentrysizer;
232 wxStaticBox *namebox;
233 wxStaticBox *freqbox;
235 // SetIcon(wxICON(monicone));
236 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
237 helpMenu->Append(HELP_ABOUT, _T("&About...\tF1"),
238 _T("Show about dialog"));
239 fileMenu->Append(FILE_QUIT, _T("E&xit\tAlt-X"),
240 _T("Quit this program"));
241 wxMenuBar *menuBar = new wxMenuBar();
242 menuBar->Append(fileMenu, _T("&File"));
243 menuBar->Append(helpMenu, _T("&Help"));
246 SetStatusText(_T("Lolitech."), 0);
247 SetStatusText(_T("Welcome."), 1);
249 book = new wxNotebook(this, BOOKCTRL);
251 panel = new wxPanel(book);
252 book->AddPage(panel, _T("Configuration"), true);
253 mysizer = new wxBoxSizer( wxVERTICAL );
254 panel->SetSizer(mysizer);
257 _T("10K"), _T("20K"), _T("50K"), _T("100K"),
258 _T("125K"), _T("250K"), _T("500K"), _T("1M")
261 myhsizer = new wxStaticBoxSizer( new wxStaticBox(panel, wxID_ANY, _T("Bus driver")), wxHORIZONTAL );
262 mysizer->Add(myhsizer, 0, wxEXPAND | wxALL, 5);
263 load = new wxButton( panel, LOAD, _T("Load can driver"));
264 myhsizer->Add(load, 0, wxLEFT, 5);
265 drivername = new wxTextCtrl(panel, wxID_ANY, wxString((const char*)LibraryPath,wxConvLocal));
266 myhsizer->Add(drivername, 1, wxEXPAND | wxALL, 5);
267 myentrysizer = new wxBoxSizer( wxHORIZONTAL );
268 mysizer->Add(myentrysizer, 0, wxEXPAND | wxALL, 5);
269 myhsizer = new wxStaticBoxSizer( new wxStaticBox(panel, wxID_ANY, _T("Bus name")), wxHORIZONTAL );
270 myentrysizer->Add(myhsizer, 0, wxEXPAND | wxALL, 5);
271 busname = new wxTextCtrl(panel, wxID_ANY, wxString((const char*)SlaveBoard.busname, wxConvLocal));
272 myhsizer->Add(busname, 0, wxLEFT, 5);
273 myhsizer = new wxStaticBoxSizer( new wxStaticBox(panel, wxID_ANY, _T("Node ID (Hexa)")), wxHORIZONTAL );
274 myentrysizer->Add(myhsizer, 0, wxEXPAND | wxALL, 5);
275 node_id = new wxSpinCtrl(panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 127, node_id_ext, _T("wxSpinCtrl"));
276 myhsizer->Add(node_id, 0, wxRIGHT, 5);
277 myhsizer = new wxStaticBoxSizer( new wxStaticBox(panel, wxID_ANY, _T("Baudrate")), wxHORIZONTAL );
278 mysizer->Add(myhsizer, wxEXPAND | wxALL, wxEXPAND | wxALL, 5);
279 freqlist = new wxListBox( panel, FREQBOX, wxDefaultPosition, wxDefaultSize, 8, choices, wxLB_SINGLE | wxLB_HSCROLL);
280 myhsizer->Add(freqlist, wxEXPAND | wxALL, wxEXPAND | wxALL, 5);
281 quit = new wxButton( panel, QUIT, _T("QUIT"));
282 mysizer->Add(quit, 0, wxALL, 5);
285 panel = new wxPanel(book);
286 book->AddPage(panel, wxT("Inputs"), true);
287 mysizer = new wxBoxSizer( wxVERTICAL );
288 panel->SetSizer(mysizer);
289 myhsizer = new wxStaticBoxSizer( new wxStaticBox(panel, wxID_ANY, _T("Read Inputs UNSIGNED8")), wxHORIZONTAL );
290 mysizer->Add(myhsizer, 0, wxEXPAND | wxALL, 30);
291 inbt1 = new wxToggleButton(panel, INBT1, wxT("1"));
292 inbt2 = new wxToggleButton(panel, INBT2, wxT("2"));
293 inbt3 = new wxToggleButton(panel, INBT3, wxT("3"));
294 inbt4 = new wxToggleButton(panel, INBT4, wxT("4"));
295 inbt5 = new wxToggleButton(panel, INBT5, wxT("5"));
296 inbt6 = new wxToggleButton(panel, INBT6, wxT("6"));
297 inbt7 = new wxToggleButton(panel, INBT7, wxT("7"));
298 inbt8 = new wxToggleButton(panel, INBT8, wxT("8"));
299 myhsizer->Add(inbt1, wxEXPAND | wxALL, 0, 5);
300 myhsizer->Add(inbt2, wxEXPAND | wxALL, 0, 5);
301 myhsizer->Add(inbt3, wxEXPAND | wxALL, 0, 5);
302 myhsizer->Add(inbt4, wxEXPAND | wxALL, 0, 5);
303 myhsizer->Add(inbt5, wxEXPAND | wxALL, 0, 5);
304 myhsizer->Add(inbt6, wxEXPAND | wxALL, 0, 5);
305 myhsizer->Add(inbt7, wxEXPAND | wxALL, 0, 5);
306 myhsizer->Add(inbt8, wxEXPAND | wxALL, 0, 5);
307 myhsizer = new wxStaticBoxSizer( new wxStaticBox(panel, wxID_ANY, _T("Analogue Inputs INTEGER16")), wxVERTICAL );
308 mysizer->Add(myhsizer, wxEXPAND | wxALL, wxEXPAND | wxALL, 30);
309 mysssizer = new wxBoxSizer( wxHORIZONTAL );
310 myhsizer->Add(mysssizer, 0, wxEXPAND | wxALL, 0);
311 inst1 = new wxSpinCtrl(panel, INST1, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, -32768, 32767, 0, _T("0"));
312 inst2 = new wxSpinCtrl(panel, INST2, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, -32768, 32767, 0, _T("0"));
313 inst3 = new wxSpinCtrl(panel, INST3, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, -32768, 32767, 0, _T("0"));
314 inst4 = new wxSpinCtrl(panel, INST4, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, -32768, 32767, 0, _T("0"));
315 inst5 = new wxSpinCtrl(panel, INST5, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, -32768, 32767, 0, _T("0"));
316 inst6 = new wxSpinCtrl(panel, INST6, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, -32768, 32767, 0, _T("0"));
317 inst7 = new wxSpinCtrl(panel, INST7, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, -32768, 32767, 0, _T("0"));
318 inst8 = new wxSpinCtrl(panel, INST8, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, -32768, 32767, 0, _T("0"));
319 mysssizer->Add(inst1, wxALL, 0, 5);
320 mysssizer->Add(inst2, wxALL, 0, 5);
321 mysssizer->Add(inst3, wxALL, 0, 5);
322 mysssizer->Add(inst4, wxALL, 0, 5);
323 mysssizer->Add(inst5, wxALL, 0, 5);
324 mysssizer->Add(inst6, wxALL, 0, 5);
325 mysssizer->Add(inst7, wxALL, 0, 5);
326 mysssizer->Add(inst8, wxALL, 0, 5);
327 mysssizer = new wxBoxSizer( wxHORIZONTAL );
328 myhsizer->Add(mysssizer, wxEXPAND | wxALL, wxEXPAND | wxALL, 0);
329 ins1 = new wxSlider(panel, INS1, 0, -32768, 32767, wxDefaultPosition, wxDefaultSize, wxSL_VERTICAL | wxSL_INVERSE, wxDefaultValidator, wxT("slider"));
330 ins2 = new wxSlider(panel, INS2, 0, -32768, 32767, wxDefaultPosition, wxDefaultSize, wxSL_VERTICAL | wxSL_INVERSE, wxDefaultValidator, wxT("slider"));
331 ins3 = new wxSlider(panel, INS3, 0, -32768, 32767, wxDefaultPosition, wxDefaultSize, wxSL_VERTICAL | wxSL_INVERSE, wxDefaultValidator, wxT("slider"));
332 ins4 = new wxSlider(panel, INS4, 0, -32768, 32767, wxDefaultPosition, wxDefaultSize, wxSL_VERTICAL | wxSL_INVERSE, wxDefaultValidator, wxT("slider"));
333 ins5 = new wxSlider(panel, INS5, 0, -32768, 32767, wxDefaultPosition, wxDefaultSize, wxSL_VERTICAL | wxSL_INVERSE, wxDefaultValidator, wxT("slider"));
334 ins6 = new wxSlider(panel, INS6, 0, -32768, 32767, wxDefaultPosition, wxDefaultSize, wxSL_VERTICAL | wxSL_INVERSE, wxDefaultValidator, wxT("slider"));
335 ins7 = new wxSlider(panel, INS7, 0, -32768, 32767, wxDefaultPosition, wxDefaultSize, wxSL_VERTICAL | wxSL_INVERSE, wxDefaultValidator, wxT("slider"));
336 ins8 = new wxSlider(panel, INS8, 0, -32768, 32767, wxDefaultPosition, wxDefaultSize, wxSL_VERTICAL | wxSL_INVERSE, wxDefaultValidator, wxT("slider"));
337 mysssizer->Add(ins1, wxEXPAND | wxALL, wxEXPAND | wxALL, 15);
338 mysssizer->Add(ins2, wxEXPAND | wxALL, wxEXPAND | wxALL, 15);
339 mysssizer->Add(ins3, wxEXPAND | wxALL, wxEXPAND | wxALL, 15);
340 mysssizer->Add(ins4, wxEXPAND | wxALL, wxEXPAND | wxALL, 15);
341 mysssizer->Add(ins5, wxEXPAND | wxALL, wxEXPAND | wxALL, 15);
342 mysssizer->Add(ins6, wxEXPAND | wxALL, wxEXPAND | wxALL, 15);
343 mysssizer->Add(ins7, wxEXPAND | wxALL, wxEXPAND | wxALL, 15);
344 mysssizer->Add(ins8, wxEXPAND | wxALL, wxEXPAND | wxALL, 15);
345 quit = new wxButton( panel, QUIT, _T("QUIT"));
346 mysizer->Add(quit, 0, wxALL, 5);
348 panel = new wxPanel(book);
349 book->AddPage(panel, wxT("Outputs"), true);
350 mysizer = new wxBoxSizer( wxVERTICAL );
351 panel->SetSizer(mysizer);
352 myhsizer = new wxStaticBoxSizer( new wxStaticBox(panel, wxID_ANY, _T("Write Outputs UNSIGNED8")), wxHORIZONTAL );
353 mysizer->Add(myhsizer, 0, wxEXPAND | wxALL, 30);
354 outbt1 = new wxToggleButton(panel, wxID_ANY, wxT("1"));
355 outbt2 = new wxToggleButton(panel, wxID_ANY, wxT("2"));
356 outbt3 = new wxToggleButton(panel, wxID_ANY, wxT("3"));
357 outbt4 = new wxToggleButton(panel, wxID_ANY, wxT("4"));
358 outbt5 = new wxToggleButton(panel, wxID_ANY, wxT("5"));
359 outbt6 = new wxToggleButton(panel, wxID_ANY, wxT("6"));
360 outbt7 = new wxToggleButton(panel, wxID_ANY, wxT("7"));
361 outbt8 = new wxToggleButton(panel, wxID_ANY, wxT("8"));
362 myhsizer->Add(outbt1, wxEXPAND | wxALL, 0, 5);
363 myhsizer->Add(outbt2, wxEXPAND | wxALL, 0, 5);
364 myhsizer->Add(outbt3, wxEXPAND | wxALL, 0, 5);
365 myhsizer->Add(outbt4, wxEXPAND | wxALL, 0, 5);
366 myhsizer->Add(outbt5, wxEXPAND | wxALL, 0, 5);
367 myhsizer->Add(outbt6, wxEXPAND | wxALL, 0, 5);
368 myhsizer->Add(outbt7, wxEXPAND | wxALL, 0, 5);
369 myhsizer->Add(outbt8, wxEXPAND | wxALL, 0, 5);
370 myhsizer = new wxStaticBoxSizer( new wxStaticBox(panel, wxID_ANY, _T("Analogue Output INTEGER16")), wxVERTICAL );
371 mysizer->Add(myhsizer, wxEXPAND | wxALL, wxEXPAND | wxALL, 30);
372 mysssizer = new wxBoxSizer( wxHORIZONTAL );
373 myhsizer->Add(mysssizer, 0, wxEXPAND | wxALL, 0);
374 outst1 = new wxStaticText(panel, wxID_ANY, wxT("label"), wxDefaultPosition, wxDefaultSize, 0, wxT("staticText"));
375 outst2 = new wxStaticText(panel, wxID_ANY, wxT("label"), wxDefaultPosition, wxDefaultSize, 0, wxT("staticText"));
376 outst3 = new wxStaticText(panel, wxID_ANY, wxT("label"), wxDefaultPosition, wxDefaultSize, 0, wxT("staticText"));
377 outst4 = new wxStaticText(panel, wxID_ANY, wxT("label"), wxDefaultPosition, wxDefaultSize, 0, wxT("staticText"));
378 mysssizer->Add(outst1, wxEXPAND | wxALL, wxEXPAND | wxALL, 5);
379 mysssizer->Add(outst2, wxEXPAND | wxALL, wxEXPAND | wxALL, 5);
380 mysssizer->Add(outst3, wxEXPAND | wxALL, wxEXPAND | wxALL, 5);
381 mysssizer->Add(outst4, wxEXPAND | wxALL, wxEXPAND | wxALL, 5);
382 mysssizer = new wxBoxSizer( wxHORIZONTAL );
383 myhsizer->Add(mysssizer, wxEXPAND | wxALL, wxEXPAND | wxALL, 0);
384 outs1 = new wxGauge(panel, wxID_ANY, 65535, wxDefaultPosition, wxDefaultSize, wxSL_VERTICAL | wxSL_INVERSE, wxDefaultValidator, wxT("gauge"));
385 outs2 = new wxGauge(panel, wxID_ANY, 65535, wxDefaultPosition, wxDefaultSize, wxSL_VERTICAL | wxSL_INVERSE, wxDefaultValidator, wxT("gauge"));
386 outs3 = new wxGauge(panel, wxID_ANY, 65535, wxDefaultPosition, wxDefaultSize, wxSL_VERTICAL | wxSL_INVERSE, wxDefaultValidator, wxT("gauge"));
387 outs4 = new wxGauge(panel, wxID_ANY, 65535, wxDefaultPosition, wxDefaultSize, wxSL_VERTICAL | wxSL_INVERSE, wxDefaultValidator, wxT("gauge"));
388 mysssizer->Add(outs1, wxEXPAND | wxALL, wxEXPAND | wxALL, 15);
389 mysssizer->Add(outs2, wxEXPAND | wxALL, wxEXPAND | wxALL, 15);
390 mysssizer->Add(outs3, wxEXPAND | wxALL, wxEXPAND | wxALL, 15);
391 mysssizer->Add(outs4, wxEXPAND | wxALL, wxEXPAND | wxALL, 15);
392 quit = new wxButton( panel, QUIT, _T("QUIT"));
393 mysizer->Add(quit, 0, wxALL, 5);
397 _T("Analogue Out 1"), _T("Analogue Out 2"),
398 _T("Analogue Out 3"), _T("Analogue Out 4"),
399 _T("Bool Out 1"), _T("Bool Out 2"),
400 _T("Bool Out 3"), _T("Bool Out 4"),
401 _T("Bool Out 5"), _T("Bool Out 6"),
402 _T("Bool Out 7"), _T("Bool Out 8"),
403 _T("Analogue Input 1"), _T("Analogue Input 2"),
404 _T("Analogue Input 3"), _T("Analogue Input 4"),
405 _T("Analogue Input 5"), _T("Analogue Input 6"),
406 _T("Analogue Input 7"), _T("Analogue Input 8"),
407 _T("Bool Input 1"), _T("Bool Input 2"),
408 _T("Bool Input 3"), _T("Bool Input 4"),
409 _T("Bool Input 5"), _T("Bool Input 6"),
410 _T("Bool Input 7"), _T("Bool Input 8"), };
411 panel = new wxPanel(book);
412 book->AddPage(panel, wxT("Graphic"), true);
413 mysizer = new wxBoxSizer( wxVERTICAL );
414 panel->SetSizer(mysizer);
415 myhsizer = new wxStaticBoxSizer( new wxStaticBox(panel, wxID_ANY, _T("Graphic")), wxVERTICAL );
416 mysizer->Add(myhsizer, 0, wxEXPAND | wxALL, 10);
417 mygraphpan = new wxPanel(panel, wxID_ANY, wxDefaultPosition, wxSize(0, 350), wxTAB_TRAVERSAL, wxT("Graphic"));
418 myhsizer->Add(mygraphpan, wxEXPAND | wxALL, wxEXPAND | wxALL, 15);
419 echelle = new wxSlider(panel, wxID_ANY, 44, 44, 1000, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL , wxDefaultValidator, wxT("slider"));
420 myhsizer->Add(echelle, 0, wxEXPAND | wxALL, 0);
421 mybsizer = new wxBoxSizer( wxHORIZONTAL );
422 mysizer->Add(mybsizer, wxEXPAND | wxALL, wxEXPAND | wxALL, 5);
423 myhsizer = new wxStaticBoxSizer( new wxStaticBox(panel, wxID_ANY, _T("Select viewable Inputs")), wxHORIZONTAL );
424 mybsizer->Add(myhsizer, wxEXPAND | wxALL, wxEXPAND | wxALL, 10);
425 inlist = new wxListBox( panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 28, choice, wxLB_EXTENDED | wxLB_HSCROLL);
426 myhsizer->Add(inlist, wxEXPAND | wxALL, wxEXPAND | wxALL, 5);
427 myhsizer = new wxStaticBoxSizer( new wxStaticBox(panel, wxID_ANY, _T("Legende")), wxHORIZONTAL );
428 mybsizer->Add(myhsizer, wxEXPAND | wxALL, wxEXPAND | wxALL, 10);
429 mylegpan = new wxPanel(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, wxT("Legende"));
430 myhsizer->Add(mylegpan, wxEXPAND | wxALL, wxEXPAND | wxALL, 15);
431 quit = new wxButton( panel, QUIT, _T("QUIT"));
432 mysizer->Add(quit, 0, wxALL, 5);
434 panel = new wxPanel(book);
435 book->InsertPage(0, panel, wxT("Control"), true);
436 mysizer = new wxBoxSizer( wxVERTICAL );
437 panel->SetSizer(mysizer);
438 myhsizer = new wxBoxSizer( wxHORIZONTAL );
439 myhsizer = new wxStaticBoxSizer( new wxStaticBox(panel, wxID_ANY, _T("Control your node")), wxHORIZONTAL );
440 mysizer->Add(myhsizer, 0, wxALL, 5);
441 start = new wxButton( panel, START, _T("START"));
442 stop = new wxButton( panel, STOP, _T("STOP"));
444 myhsizer->Add(start, 0, wxRIGHT, 5);
445 myhsizer->Add(stop, 0, wxLEFT, 5);
446 myhsizer = new wxStaticBoxSizer( new wxStaticBox(panel, wxID_ANY, _T("Operation log")), wxHORIZONTAL );
447 mysizer->Add(myhsizer, wxALL, wxEXPAND | wxALL, 5);
448 textLog = new wxTextCtrl( panel, TEXTBOX1, _T(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE, wxDefaultValidator, wxTextCtrlNameStr);
449 myhsizer->Add(textLog, wxALL, wxEXPAND | wxALL, 5);
450 quit = new wxButton( panel, QUIT, _T("QUIT"));
451 mysizer->Add(quit, 0, wxALL, 5);
453 for (int i= 0; i < 28; i++)
454 for (int j = 0; j < 44; j++)
463 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
468 void MyFrame::Start()
470 if (main_can(SlaveBoard, LibraryPath))
473 *textLog << wxT("----------------------------------------------------Initialization [KO]\n");
478 *textLog << wxT("----------------------------------------------------Initialization [OK]\n");
480 start->Enable(false);
484 void MyFrame::OnStart(wxCommandEvent& WXUNUSED(event))
488 node_id_ext = node_id->GetValue();
489 s = busname->GetValue();
490 strncpy(SlaveBoard.busname, s.mb_str(), MAXLENGTH_BUSNAME);
491 *textLog << wxT("-- Bus name: ------> ") << s << wxT("\n");
492 *textLog << wxT("-- Node ID: -------> ") << node_id->GetValue() << wxT("\n");
497 void MyFrame::OnStop(wxCommandEvent& WXUNUSED(event))
500 *textLog << wxT("----------------------------------------------------Slave [STOPPED]") << wxT("\n");
506 void MyFrame::OnLoad(wxCommandEvent& WXUNUSED(event))
508 wxFileDialog fd(this, wxT("Choose a node configuration file"), wxT(""), wxT("Slave.od"), wxT("*.so"));
510 if(fd.ShowModal() == wxID_OK)
513 drivername->AppendText(fd.GetPath());
514 *textLog << wxT("LibraryPath: ") << fd.GetPath() << wxT("\n");
515 strncpy(LibraryPath, fd.GetPath().mb_str(), MAXLENGTH_LIBPATH);
516 printf("path=%s",LibraryPath);
520 void MyFrame::OnInbt1(wxCommandEvent& WXUNUSED(event))
522 Read_Inputs_8_Bit[0] = Read_Inputs_8_Bit[0] ^ 0x1;
524 void MyFrame::OnInbt2(wxCommandEvent& WXUNUSED(event))
526 Read_Inputs_8_Bit[0] = Read_Inputs_8_Bit[0] ^ 0x2;
528 void MyFrame::OnInbt3(wxCommandEvent& WXUNUSED(event))
530 Read_Inputs_8_Bit[0] = Read_Inputs_8_Bit[0] ^ 0x4;
532 void MyFrame::OnInbt4(wxCommandEvent& WXUNUSED(event))
534 Read_Inputs_8_Bit[0] = Read_Inputs_8_Bit[0] ^ 0x8;
536 void MyFrame::OnInbt5(wxCommandEvent& WXUNUSED(event))
538 Read_Inputs_8_Bit[0] = Read_Inputs_8_Bit[0] ^ 0x10;
540 void MyFrame::OnInbt6(wxCommandEvent& WXUNUSED(event))
542 Read_Inputs_8_Bit[0] = Read_Inputs_8_Bit[0] ^ 0x20;
544 void MyFrame::OnInbt7(wxCommandEvent& WXUNUSED(event))
546 Read_Inputs_8_Bit[0] = Read_Inputs_8_Bit[0] ^ 0x40;
548 void MyFrame::OnInbt8(wxCommandEvent& WXUNUSED(event))
550 Read_Inputs_8_Bit[0] = Read_Inputs_8_Bit[0] ^ 0x80;
555 void MyFrame::OnIns1(wxScrollEvent &event)
557 Read_Analogue_Input_16_Bit[0] = ins1->GetValue();
558 inst1->SetValue(ins1->GetValue());
560 void MyFrame::OnIns2(wxScrollEvent &event)
562 Read_Analogue_Input_16_Bit[1] = ins2->GetValue();
563 inst2->SetValue(ins2->GetValue());
565 void MyFrame::OnIns3(wxScrollEvent &event)
567 Read_Analogue_Input_16_Bit[2] = ins3->GetValue();
568 inst3->SetValue(ins3->GetValue());
570 void MyFrame::OnIns4(wxScrollEvent &event)
572 Read_Analogue_Input_16_Bit[3] = ins4->GetValue();
573 inst4->SetValue(ins4->GetValue());
575 void MyFrame::OnIns5(wxScrollEvent &event)
577 Read_Analogue_Input_16_Bit[4] = ins5->GetValue();
578 inst5->SetValue(ins5->GetValue());
580 void MyFrame::OnIns6(wxScrollEvent &event)
582 Read_Analogue_Input_16_Bit[5] = ins6->GetValue();
583 inst6->SetValue(ins6->GetValue());
585 void MyFrame::OnIns7(wxScrollEvent &event)
587 Read_Analogue_Input_16_Bit[6] = ins7->GetValue();
588 inst7->SetValue(ins7->GetValue());
590 void MyFrame::OnIns8(wxScrollEvent &event)
592 Read_Analogue_Input_16_Bit[7] = ins8->GetValue();
593 inst8->SetValue(ins8->GetValue());
597 void MyFrame::OnInst1 ( wxSpinEvent &ev )
599 Read_Analogue_Input_16_Bit[0] = inst1->GetValue();
600 ins1->SetValue(inst1->GetValue());
602 void MyFrame::OnInst2 ( wxSpinEvent &ev )
604 Read_Analogue_Input_16_Bit[1] = inst2->GetValue();
605 ins2->SetValue(inst2->GetValue());
607 void MyFrame::OnInst3 ( wxSpinEvent &ev )
609 Read_Analogue_Input_16_Bit[2] = inst3->GetValue();
610 ins3->SetValue(inst3->GetValue());
612 void MyFrame::OnInst4 ( wxSpinEvent &ev )
614 Read_Analogue_Input_16_Bit[3] = inst4->GetValue();
615 ins4->SetValue(inst4->GetValue());
617 void MyFrame::OnInst5 ( wxSpinEvent &ev )
619 Read_Analogue_Input_16_Bit[4] = inst5->GetValue();
620 ins5->SetValue(inst5->GetValue());
622 void MyFrame::OnInst6 ( wxSpinEvent &ev )
624 Read_Analogue_Input_16_Bit[5] = inst6->GetValue();
625 ins6->SetValue(inst6->GetValue());
627 void MyFrame::OnInst7 ( wxSpinEvent &ev )
629 Read_Analogue_Input_16_Bit[6] = inst7->GetValue();
630 ins7->SetValue(inst7->GetValue());
632 void MyFrame::OnInst8 ( wxSpinEvent &ev )
634 Read_Analogue_Input_16_Bit[7] = inst8->GetValue();
635 ins8->SetValue(inst8->GetValue());
639 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
642 msg.Printf( _T("About.\n\n")
643 _T("Input-Output simulation by GRANDEMANGE Nicolas for CanFestival!!"));
645 wxMessageBox(msg, _T("About !!!"), wxOK | wxICON_INFORMATION, this);
649 void MyFrame::OnFreqBoxClick( wxCommandEvent &event )
653 wxstr = event.GetString();
654 strncpy(SlaveBoard.baudrate, wxstr.mb_str(),MAXLENGTH_BAUDRATE);
655 *textLog << wxT("Baudrate:") << event.GetString() << wxT("\n");
658 static int is_set(int i,
662 inlist->GetSelections(in);
663 for (int j = 0; j < in.GetCount(); j++)
665 if (i == (in[j] + 1))
673 static int get_bit(UNS8 input, int bit)
675 return input & (((UNS8)1) << bit) ? 1 : 0;
678 void MyFrame::Paint()
680 double vmax = old_max;
681 double vmin = old_min;
682 double vdelta = vmax - vmin;
683 double vech = ((float)vdelta) / 10.0;
685 double hmax = frame->echelle->GetValue();
686 double hech = hdelta / 11;
688 double d = 300 / vdelta;
699 wxColor col[8] = {wxColor("BLUE"), wxColor("RED"), wxColor("GREEN"), wxColor("GREY"),
700 wxColor("ORANGE"), wxColor("YELLOW"), wxColor("PINK"), wxColor("BLACK")};
702 g = (Gtime / hdelta) * 44.00;
704 wxClientDC MonDc(mygraphpan);
707 MonDc.SetPen(wxPen(wxColour(200,200,200), 5, wxSOLID));
708 MonDc.DrawRectangle((int) left, (int)top, 660, 300);
710 MonDc.SetPen(wxPen(wxColor(150,200,150), 2, wxSOLID));
711 MonDc.SetFont(wxFont(9, wxSWISS , wxNORMAL, wxNORMAL, false, wxT("Arial Black")));
712 for (i=0; i < 11; i++)
714 tmpi = (vmin + (vech * i));
715 tmps.Printf(wxT("%d"), (int)tmpi);
716 MonDc.DrawRotatedText(tmps, 0, (int)(293 - (30 * i) + top), 0);
718 for (i=0; i < 12; i++)
720 tmpi = (hech * i * 100);
722 tmps.Printf(wxT("%ims"), (int)tmpi);
724 tmps.Printf(wxT("%is"), (int)(tmpi / 1000));
725 MonDc.DrawRotatedText(tmps, (int)((60 * i) + left) - 10, (int)(317 + top), 0);
727 for (j=1; j < 10; j++)
728 MonDc.DrawLine((int)left, (int)(300 - (30 * j) + top), (int)(left + 660), (int)(300 - (30 * j) + top));
729 MonDc.SetPen(wxPen(wxColor(150,200,150), 2, wxSOLID));
730 for (j=1; j < 22; j++)
731 MonDc.DrawLine((int)(30 * j + left), (int)(300 + top), (int)(30 * j + left), (int)(top));
732 MonDc.SetPen(wxPen(wxColor(150,170,150), 1, wxSOLID));
733 for (j=1; j < 22; j++)
734 MonDc.DrawLine((int)(30 * j + left - 15), (int)(300 + top), (int)(30 * j + left - 15), (int)(top));
735 MonDc.DrawLine((int)(30 * 22 + left - 15), (int)(300 + top), (int)(30 * 22 + left - 15), (int)(top));
737 double m = (- vmin) * d;
738 MonDc.SetPen(wxPen(wxColor(170,170,150), 3, wxSOLID));
739 MonDc.DrawLine((int)(left), (int)(300 + top - m), (int)(left + 660), (int)(300 + top - m));
741 wxClientDC MaLeg(mylegpan);
744 MaLeg.SetPen(wxPen(wxColour(150,200,100), 2, wxSOLID));
745 MaLeg.SetFont(wxFont(7, wxSWISS , wxNORMAL, wxNORMAL, false, wxT("Arial Black")));
746 for (int k=1, tmpi = 0; k < 30; k++)
748 if ((tmpi < 8) && is_set(k, inlist, in))
751 tmps.Printf(wxT("Analogue Output %d"), k);
752 if ((k > 4) && (k <= 12))
753 tmps.Printf(wxT("Bool Output %d"), k - 4);
754 if ((k > 12) && (k <= 20))
755 tmps.Printf(wxT("Analogue Input %d"), k - 12);
756 if ((k > 20) && (k <= 28))
757 tmps.Printf(wxT("Bool Input %d"), k - 20);
759 MaLeg.DrawRotatedText(tmps, 0, 10 * tmpi , 0);
760 MaLeg.SetPen(wxPen(col[tmpi], 4, wxSOLID));
761 MaLeg.DrawLine(100, 10 * tmpi + 6, 115, 10 * tmpi + 6);
762 //////////////////////////////////////////DAW////////////////////////////////////////
763 MonDc.SetPen(wxPen(col[tmpi], 4, wxSOLID));
765 y[k - 1][(int)g] = Write_Analogue_Output_16_Bit[k - 1];
766 if ((k > 4) && (k <= 12))
767 y[k - 1][(int)g] = get_bit(Write_Outputs_8_Bit[0] ,k - 4);
768 if ((k > 12) && (k <= 20))
769 y[k - 1][(int)g] = Read_Analogue_Input_16_Bit[k - 1 -12];
770 if ((k > 20) && (k <= 28))
771 y[k - 1][(int)g] = get_bit(Read_Inputs_8_Bit[0] ,k - 20);
773 if (y[k - 1][(int)g] > old_max)
774 old_max = y[k - 1][(int)g];
775 if (y[k - 1][(int)g] < old_min)
776 old_min = y[k - 1][(int)g];
777 for (j=1; j < (g + 1) ; j++)
779 p = (y[k - 1][j - 1] - vmin) * d;
780 q = (y[k - 1][j ] - vmin) * d;
781 MonDc.DrawLine((int)(15 * (j - 1) + left), (int)(300 + top - p), (int)(15 * j + left), (int)(300 + top - q));
783 /////////////////////////////////////////////////////////////////////////////////////
789 void actu_output(void)
793 frame->outbt1->SetValue(get_bit(Write_Outputs_8_Bit[0], 1));
794 frame->outbt2->SetValue(get_bit(Write_Outputs_8_Bit[0], 2));
795 frame->outbt3->SetValue(get_bit(Write_Outputs_8_Bit[0], 3));
796 frame->outbt4->SetValue(get_bit(Write_Outputs_8_Bit[0], 4));
797 frame->outbt5->SetValue(get_bit(Write_Outputs_8_Bit[0], 5));
798 frame->outbt6->SetValue(get_bit(Write_Outputs_8_Bit[0], 6));
799 frame->outbt7->SetValue(get_bit(Write_Outputs_8_Bit[0], 7));
800 frame->outbt8->SetValue(get_bit(Write_Outputs_8_Bit[0], 8));
802 frame->outs1->SetValue(Write_Analogue_Output_16_Bit[0] + 32768);
803 frame->outs2->SetValue(Write_Analogue_Output_16_Bit[1] + 32768);
804 frame->outs3->SetValue(Write_Analogue_Output_16_Bit[2] + 32768);
805 frame->outs4->SetValue(Write_Analogue_Output_16_Bit[3] + 32768);
806 tmp.Printf(wxT(" %i"), Write_Analogue_Output_16_Bit[0]);
807 frame->outst1->SetLabel(tmp);
808 tmp.Printf(wxT(" %i"), Write_Analogue_Output_16_Bit[1]);
809 frame->outst2->SetLabel(tmp);
810 tmp.Printf(wxT(" %i"), Write_Analogue_Output_16_Bit[2]);
811 frame->outst3->SetLabel(tmp);
812 tmp.Printf(wxT(" %i"), Write_Analogue_Output_16_Bit[3]);
813 frame->outst4->SetLabel(tmp);
830 void MyFrame::OnTimer(wxTimerEvent& event)
832 actu();// do whatever you want to do every second here
835 void MyFrame::OnPaint( wxPaintEvent &event )