etisserant@246: #include etisserant@246: #include etisserant@246: #include etisserant@246: #include etisserant@246: #include etisserant@246: #include etisserant@246: #include etisserant@246: #include etisserant@246: #include etisserant@295: #include etisserant@246: #include etisserant@246: #include etisserant@246: #include etisserant@246: #include etisserant@246: #include etisserant@246: etisserant@295: //#include "monicone.xpm" etisserant@246: greg@329: #if defined(WIN32) && !defined(__CYGWIN__) greg@329: #include etisserant@382: extern "C" etisserant@382: { etisserant@382: #include "getopt.h" greg@329: } greg@329: #endif greg@329: etisserant@246: #include "main.h" etisserant@246: #include "TestSlaveGui.h" etisserant@382: extern "C" etisserant@382: { etisserant@382: #include "canfestival.h" etisserant@382: #include "ObjDict.h" etisserant@246: } etisserant@246: #include "wx/wxprec.h" etisserant@246: etisserant@246: #ifdef __BORLANDC__ etisserant@382: #pragma hdrstop etisserant@246: #endif etisserant@246: etisserant@246: #ifndef WX_PRECOMP etisserant@382: #include "wx/wx.h" etisserant@246: #endif etisserant@246: etisserant@246: etisserant@382: wxTextCtrl *textLog; etisserant@382: int node_id_ext; etisserant@295: int to_start = 0; etisserant@385: int openInput = 0; etisserant@385: int openOutput = 0; etisserant@385: etisserant@382: MyFrame *frame; etisserant@295: #define MAXLENGTH_BUSNAME 32 etisserant@295: #define MAXLENGTH_BAUDRATE 8 etisserant@382: char _busname[MAXLENGTH_BUSNAME] = "vcan0"; etisserant@382: char _baudrate[MAXLENGTH_BAUDRATE] = "500K"; etisserant@382: s_BOARD SlaveBoard = { _busname, _baudrate }; etisserant@382: etisserant@295: #define MAXLENGTH_LIBPATH 1024 etisserant@382: char LibraryPath[MAXLENGTH_LIBPATH] = "libcanfestival_can_virtual.so"; etisserant@246: etisserant@331: #if defined(WIN32) etisserant@331: #define LIB_EXTENT wxT("*.dll") etisserant@331: #else etisserant@331: #define LIB_EXTENT wxT("*.so") etisserant@331: #endif etisserant@331: etisserant@246: // Declare some IDs. These are arbitrary. etisserant@246: const int BOOKCTRL = 100; etisserant@246: const int FILE_QUIT = wxID_EXIT; etisserant@246: const int HELP_ABOUT = wxID_ABOUT; etisserant@246: const int ADD = 105; etisserant@246: const int REMOVE = 108; etisserant@246: const int QUIT = 109; etisserant@246: const int FREQBOX = 110; etisserant@246: const int START = 112; etisserant@246: const int TEXTBOX1 = 113; etisserant@246: const int STOP = 114; etisserant@246: const int LOAD = 115; etisserant@246: const int INBT1 = 118; etisserant@246: const int INBT2 = 119; etisserant@246: const int INBT3 = 120; etisserant@246: const int INBT4 = 121; etisserant@246: const int INBT5 = 122; etisserant@246: const int INBT6 = 123; etisserant@246: const int INBT7 = 124; etisserant@246: const int INBT8 = 125; etisserant@246: const int INS1 = 126; etisserant@246: const int INS2 = 127; etisserant@246: const int INS3 = 128; etisserant@246: const int INS4 = 129; etisserant@246: const int INS5 = 135; etisserant@246: const int INS6 = 136; etisserant@246: const int INS7 = 137; etisserant@246: const int INS8 = 138; etisserant@246: const int TIMER_ID = 130; etisserant@246: const int INST1 = 131; etisserant@246: const int INST2 = 132; etisserant@246: const int INST3 = 133; etisserant@246: const int INST4 = 134; etisserant@246: const int INST5 = 135; etisserant@246: const int INST6 = 136; etisserant@246: const int INST7 = 137; etisserant@246: const int INST8 = 138; etisserant@246: etisserant@246: // Attach the event handlers. Put this after MyFrame declaration. etisserant@382: BEGIN_EVENT_TABLE (MyFrame, wxFrame) etisserant@382: EVT_BUTTON (STOP, MyFrame::OnStop) etisserant@382: EVT_BUTTON (LOAD, MyFrame::OnLoad) etisserant@382: EVT_BUTTON (START, MyFrame::OnStart) etisserant@382: EVT_TOGGLEBUTTON (INBT1, MyFrame::OnInbt1) etisserant@382: EVT_TOGGLEBUTTON (INBT2, MyFrame::OnInbt2) etisserant@382: EVT_TOGGLEBUTTON (INBT3, MyFrame::OnInbt3) etisserant@382: EVT_TOGGLEBUTTON (INBT4, MyFrame::OnInbt4) etisserant@382: EVT_TOGGLEBUTTON (INBT5, MyFrame::OnInbt5) etisserant@382: EVT_TOGGLEBUTTON (INBT6, MyFrame::OnInbt6) etisserant@382: EVT_TOGGLEBUTTON (INBT7, MyFrame::OnInbt7) etisserant@382: EVT_TOGGLEBUTTON (INBT8, MyFrame::OnInbt8) etisserant@382: EVT_COMMAND_SCROLL (INS1, MyFrame::OnIns1) etisserant@382: EVT_COMMAND_SCROLL (INS2, MyFrame::OnIns2) etisserant@382: EVT_COMMAND_SCROLL (INS3, MyFrame::OnIns3) etisserant@382: EVT_COMMAND_SCROLL (INS4, MyFrame::OnIns4) etisserant@382: EVT_COMMAND_SCROLL (INS5, MyFrame::OnIns5) etisserant@382: EVT_COMMAND_SCROLL (INS6, MyFrame::OnIns6) etisserant@382: EVT_COMMAND_SCROLL (INS7, MyFrame::OnIns7) etisserant@382: EVT_COMMAND_SCROLL (INS8, MyFrame::OnIns8) etisserant@382: EVT_SPINCTRL (INST1, MyFrame::OnInst1) etisserant@382: EVT_SPINCTRL (INST2, MyFrame::OnInst2) etisserant@382: EVT_SPINCTRL (INST3, MyFrame::OnInst3) etisserant@382: EVT_SPINCTRL (INST4, MyFrame::OnInst4) etisserant@382: EVT_SPINCTRL (INST5, MyFrame::OnInst5) etisserant@382: EVT_SPINCTRL (INST6, MyFrame::OnInst6) etisserant@382: EVT_SPINCTRL (INST7, MyFrame::OnInst7) etisserant@382: EVT_SPINCTRL (INST8, MyFrame::OnInst8) etisserant@382: EVT_LISTBOX (FREQBOX, MyFrame::OnFreqBoxClick) etisserant@382: EVT_MENU (FILE_QUIT, MyFrame::OnQuit) etisserant@382: EVT_BUTTON (QUIT, MyFrame::OnQuit) EVT_MENU (HELP_ABOUT, MyFrame::OnAbout) etisserant@385: EVT_TIMER (TIMER_ID, MyFrame::OnTimer) etisserant@382: END_EVENT_TABLE ()IMPLEMENT_APP_NO_MAIN (MyApp); etisserant@295: IMPLEMENT_WX_THEME_SUPPORT; etisserant@295: etisserant@382: void etisserant@382: help () etisserant@382: { etisserant@382: printf ("**************************************************************\n"); etisserant@382: printf ("* DS-401 Slave GUI *\n"); etisserant@382: printf ("* *\n"); etisserant@382: printf ("* Usage: *\n"); etisserant@382: printf ("* ./DS401_Slave_Gui [OPTIONS] *\n"); etisserant@382: printf ("* *\n"); etisserant@382: printf ("* OPTIONS: *\n"); etisserant@382: printf etisserant@382: ("* -l : Can library [\"libcanfestival_can_virtual.so\"] *\n"); etisserant@382: printf ("* *\n"); etisserant@382: printf ("* Slave: *\n"); etisserant@382: printf ("* -i : Node id format [0x01 , 0x7F] *\n"); etisserant@382: printf ("* *\n"); etisserant@382: printf ("* CAN bus: *\n"); etisserant@382: printf etisserant@382: ("* -b : bus name [\"1\"] *\n"); etisserant@382: printf ("* -B : 1M,500K,250K,125K,100K,50K,20K,10K *\n"); etisserant@382: printf ("* *\n"); etisserant@382: printf ("**************************************************************\n"); etisserant@382: } etisserant@382: etisserant@382: etisserant@382: int etisserant@382: main (int argc, char **argv) etisserant@295: { etisserant@295: etisserant@295: int c; etisserant@295: extern char *optarg; etisserant@295: char *snodeid; etisserant@385: while ((c = getopt (argc, argv, "-b:B:l:i:sIO")) != EOF) etisserant@295: { etisserant@382: switch (c) etisserant@382: { etisserant@382: case 'b': etisserant@382: if (optarg[0] == 0) etisserant@382: { etisserant@382: help (); etisserant@382: exit (1); etisserant@382: } etisserant@382: SlaveBoard.busname = optarg; etisserant@382: break; etisserant@382: case 'B': etisserant@382: if (optarg[0] == 0) etisserant@382: { etisserant@382: help (); etisserant@382: exit (1); etisserant@382: } etisserant@382: SlaveBoard.baudrate = optarg; etisserant@382: break; etisserant@382: case 'l': etisserant@382: if (optarg[0] == 0) etisserant@382: { etisserant@382: help (); etisserant@382: exit (1); etisserant@382: } etisserant@382: strncpy (LibraryPath, optarg, MAXLENGTH_LIBPATH); etisserant@382: break; etisserant@382: case 'i': etisserant@382: if (optarg[0] == 0) etisserant@382: { etisserant@382: help (); etisserant@382: exit (1); etisserant@382: } etisserant@382: snodeid = optarg; etisserant@382: sscanf (snodeid, "%x", &node_id_ext); etisserant@382: break; etisserant@382: case 's': etisserant@382: to_start = 1; etisserant@382: break; etisserant@385: case 'I': etisserant@385: openInput = 1; etisserant@385: break; etisserant@385: case 'O': etisserant@385: openOutput = 1; etisserant@385: break; etisserant@382: default: etisserant@382: help (); etisserant@382: exit (1); etisserant@382: } etisserant@295: } etisserant@382: wxEntry (argc, argv); etisserant@382: } etisserant@382: etisserant@382: etisserant@382: bool etisserant@382: MyApp::OnInit () etisserant@382: { etisserant@385: frame = new MyFrame (wxString::Format(wxT("CanOpen virtual DS-401 - Id : %d"),node_id_ext)); etisserant@382: frame->Show (true); etisserant@385: if(openInput) frame->book->SetSelection(2); etisserant@385: else if(openOutput) frame->book->SetSelection(3); etisserant@382: return true; etisserant@382: } etisserant@382: etisserant@382: MyFrame::MyFrame (const wxString & title):wxFrame (NULL, wxID_ANY, title, wxDefaultPosition, wxSize (800, 740), etisserant@382: wxDEFAULT_FRAME_STYLE, wxT ("frame")), m_timer (this, etisserant@382: TIMER_ID) etisserant@382: { etisserant@382: wxMenu * etisserant@382: fileMenu = new wxMenu; etisserant@382: wxMenu * etisserant@382: helpMenu = new wxMenu; etisserant@382: wxPanel * etisserant@382: panel; etisserant@382: wxButton * etisserant@382: quit; etisserant@382: wxButton * etisserant@382: load; etisserant@382: wxBoxSizer * etisserant@382: mysizer; etisserant@382: wxBoxSizer * etisserant@382: mysssizer; etisserant@382: wxBoxSizer * etisserant@382: myhsizer; etisserant@382: wxBoxSizer * etisserant@382: mybsizer; etisserant@382: wxBoxSizer * etisserant@382: myentrysizer; etisserant@382: wxListBox * etisserant@382: freqlist; etisserant@382: wxStaticBox * etisserant@382: namebox; etisserant@382: wxStaticBox * etisserant@382: freqbox; etisserant@246: etisserant@295: // SetIcon(wxICON(monicone)); etisserant@382: SetBackgroundColour (wxSystemSettings::GetColour (wxSYS_COLOUR_BTNFACE)); etisserant@382: helpMenu->Append (HELP_ABOUT, _T ("&About...\tF1"), etisserant@382: _T ("Show about dialog")); etisserant@382: fileMenu->Append (FILE_QUIT, _T ("E&xit\tAlt-X"), _T ("Quit this program")); etisserant@382: wxMenuBar * etisserant@382: menuBar = new wxMenuBar (); etisserant@382: menuBar->Append (fileMenu, _T ("&File")); etisserant@382: menuBar->Append (helpMenu, _T ("&Help")); etisserant@382: SetMenuBar (menuBar); etisserant@382: CreateStatusBar (2); etisserant@382: SetStatusText (_T ("Lolitech."), 0); etisserant@382: SetStatusText (_T ("Welcome."), 1); etisserant@382: etisserant@382: book = new wxNotebook (this, BOOKCTRL); etisserant@382: etisserant@382: panel = new wxPanel (book); etisserant@382: book->AddPage (panel, _T ("Configuration"), true); etisserant@382: mysizer = new wxBoxSizer (wxVERTICAL); etisserant@382: panel->SetSizer (mysizer); etisserant@382: wxString etisserant@382: choices[] = { etisserant@382: _T ("10K"), _T ("20K"), _T ("50K"), _T ("100K"), etisserant@382: _T ("125K"), _T ("250K"), _T ("500K"), _T ("1M") etisserant@382: }; etisserant@382: etisserant@382: myhsizer = etisserant@382: new wxStaticBoxSizer (new etisserant@382: wxStaticBox (panel, wxID_ANY, _T ("Bus driver")), etisserant@382: wxHORIZONTAL); etisserant@382: mysizer->Add (myhsizer, 0, wxEXPAND | wxALL, 5); etisserant@382: load = new wxButton (panel, LOAD, _T ("Load can driver")); etisserant@382: myhsizer->Add (load, 0, wxLEFT, 5); etisserant@382: drivername = etisserant@382: new wxTextCtrl (panel, wxID_ANY, etisserant@382: wxString ((const char *) LibraryPath, wxConvLocal)); etisserant@382: myhsizer->Add (drivername, 1, wxEXPAND | wxALL, 5); etisserant@382: myentrysizer = new wxBoxSizer (wxHORIZONTAL); etisserant@382: mysizer->Add (myentrysizer, 0, wxEXPAND | wxALL, 5); etisserant@382: myhsizer = etisserant@382: new wxStaticBoxSizer (new wxStaticBox (panel, wxID_ANY, _T ("Bus name")), etisserant@382: wxHORIZONTAL); etisserant@382: myentrysizer->Add (myhsizer, 0, wxEXPAND | wxALL, 5); etisserant@382: busname = etisserant@382: new wxTextCtrl (panel, wxID_ANY, etisserant@382: wxString ((const char *) SlaveBoard.busname, etisserant@382: wxConvLocal)); etisserant@382: myhsizer->Add (busname, 0, wxLEFT, 5); etisserant@382: myhsizer = etisserant@382: new wxStaticBoxSizer (new etisserant@382: wxStaticBox (panel, wxID_ANY, etisserant@385: _T ("Node ID (Decimal)")), wxHORIZONTAL); etisserant@382: myentrysizer->Add (myhsizer, 0, wxEXPAND | wxALL, 5); etisserant@382: node_id = etisserant@382: new wxSpinCtrl (panel, wxID_ANY, wxEmptyString, wxDefaultPosition, etisserant@382: wxDefaultSize, wxSP_ARROW_KEYS, 1, 127, node_id_ext, etisserant@382: _T ("wxSpinCtrl")); etisserant@382: myhsizer->Add (node_id, 0, wxRIGHT, 5); etisserant@382: myhsizer = etisserant@382: new wxStaticBoxSizer (new wxStaticBox (panel, wxID_ANY, _T ("Baudrate")), etisserant@382: wxHORIZONTAL); etisserant@382: mysizer->Add (myhsizer, wxEXPAND | wxALL, wxEXPAND | wxALL, 5); etisserant@382: freqlist = etisserant@382: new wxListBox (panel, FREQBOX, wxDefaultPosition, wxDefaultSize, 8, etisserant@382: choices, wxLB_SINGLE | wxLB_HSCROLL); etisserant@382: myhsizer->Add (freqlist, wxEXPAND | wxALL, wxEXPAND | wxALL, 5); etisserant@382: quit = new wxButton (panel, QUIT, _T ("QUIT")); etisserant@382: mysizer->Add (quit, 0, wxALL, 5); etisserant@382: etisserant@382: etisserant@382: panel = new wxPanel (book); etisserant@382: book->AddPage (panel, wxT ("Inputs"), true); etisserant@382: mysizer = new wxBoxSizer (wxVERTICAL); etisserant@382: panel->SetSizer (mysizer); etisserant@382: myhsizer = etisserant@382: new wxStaticBoxSizer (new etisserant@382: wxStaticBox (panel, wxID_ANY, etisserant@382: _T ("Read Inputs UNSIGNED8")), etisserant@382: wxHORIZONTAL); etisserant@382: mysizer->Add (myhsizer, 0, wxEXPAND | wxALL, 30); etisserant@382: inbt1 = new wxToggleButton (panel, INBT1, wxT ("1")); etisserant@382: inbt2 = new wxToggleButton (panel, INBT2, wxT ("2")); etisserant@382: inbt3 = new wxToggleButton (panel, INBT3, wxT ("3")); etisserant@382: inbt4 = new wxToggleButton (panel, INBT4, wxT ("4")); etisserant@382: inbt5 = new wxToggleButton (panel, INBT5, wxT ("5")); etisserant@382: inbt6 = new wxToggleButton (panel, INBT6, wxT ("6")); etisserant@382: inbt7 = new wxToggleButton (panel, INBT7, wxT ("7")); etisserant@382: inbt8 = new wxToggleButton (panel, INBT8, wxT ("8")); etisserant@382: myhsizer->Add (inbt1, wxEXPAND | wxALL, 0, 5); etisserant@382: myhsizer->Add (inbt2, wxEXPAND | wxALL, 0, 5); etisserant@382: myhsizer->Add (inbt3, wxEXPAND | wxALL, 0, 5); etisserant@382: myhsizer->Add (inbt4, wxEXPAND | wxALL, 0, 5); etisserant@382: myhsizer->Add (inbt5, wxEXPAND | wxALL, 0, 5); etisserant@382: myhsizer->Add (inbt6, wxEXPAND | wxALL, 0, 5); etisserant@382: myhsizer->Add (inbt7, wxEXPAND | wxALL, 0, 5); etisserant@382: myhsizer->Add (inbt8, wxEXPAND | wxALL, 0, 5); etisserant@382: myhsizer = etisserant@382: new wxStaticBoxSizer (new etisserant@382: wxStaticBox (panel, wxID_ANY, etisserant@382: _T ("Analogue Inputs INTEGER16")), etisserant@382: wxVERTICAL); etisserant@382: mysizer->Add (myhsizer, wxEXPAND | wxALL, wxEXPAND | wxALL, 30); etisserant@382: mysssizer = new wxBoxSizer (wxHORIZONTAL); etisserant@382: myhsizer->Add (mysssizer, 0, wxEXPAND | wxALL, 0); etisserant@382: inst1 = etisserant@382: new wxSpinCtrl (panel, INST1, wxEmptyString, wxDefaultPosition, etisserant@382: wxDefaultSize, wxSP_ARROW_KEYS, -32768, 32767, 0, etisserant@382: _T ("0")); etisserant@382: inst2 = etisserant@382: new wxSpinCtrl (panel, INST2, wxEmptyString, wxDefaultPosition, etisserant@382: wxDefaultSize, wxSP_ARROW_KEYS, -32768, 32767, 0, etisserant@382: _T ("0")); etisserant@382: inst3 = etisserant@382: new wxSpinCtrl (panel, INST3, wxEmptyString, wxDefaultPosition, etisserant@382: wxDefaultSize, wxSP_ARROW_KEYS, -32768, 32767, 0, etisserant@382: _T ("0")); etisserant@382: inst4 = etisserant@382: new wxSpinCtrl (panel, INST4, wxEmptyString, wxDefaultPosition, etisserant@382: wxDefaultSize, wxSP_ARROW_KEYS, -32768, 32767, 0, etisserant@382: _T ("0")); etisserant@382: inst5 = etisserant@382: new wxSpinCtrl (panel, INST5, wxEmptyString, wxDefaultPosition, etisserant@382: wxDefaultSize, wxSP_ARROW_KEYS, -32768, 32767, 0, etisserant@382: _T ("0")); etisserant@382: inst6 = etisserant@382: new wxSpinCtrl (panel, INST6, wxEmptyString, wxDefaultPosition, etisserant@382: wxDefaultSize, wxSP_ARROW_KEYS, -32768, 32767, 0, etisserant@382: _T ("0")); etisserant@382: inst7 = etisserant@382: new wxSpinCtrl (panel, INST7, wxEmptyString, wxDefaultPosition, etisserant@382: wxDefaultSize, wxSP_ARROW_KEYS, -32768, 32767, 0, etisserant@382: _T ("0")); etisserant@382: inst8 = etisserant@382: new wxSpinCtrl (panel, INST8, wxEmptyString, wxDefaultPosition, etisserant@382: wxDefaultSize, wxSP_ARROW_KEYS, -32768, 32767, 0, etisserant@382: _T ("0")); etisserant@382: mysssizer->Add (inst1, wxALL, 0, 5); etisserant@382: mysssizer->Add (inst2, wxALL, 0, 5); etisserant@382: mysssizer->Add (inst3, wxALL, 0, 5); etisserant@382: mysssizer->Add (inst4, wxALL, 0, 5); etisserant@382: mysssizer->Add (inst5, wxALL, 0, 5); etisserant@382: mysssizer->Add (inst6, wxALL, 0, 5); etisserant@382: mysssizer->Add (inst7, wxALL, 0, 5); etisserant@382: mysssizer->Add (inst8, wxALL, 0, 5); etisserant@382: mysssizer = new wxBoxSizer (wxHORIZONTAL); etisserant@382: myhsizer->Add (mysssizer, wxEXPAND | wxALL, wxEXPAND | wxALL, 0); etisserant@382: ins1 = etisserant@382: new wxSlider (panel, INS1, 0, -32768, 32767, wxDefaultPosition, etisserant@382: wxDefaultSize, wxSL_VERTICAL | wxSL_INVERSE, etisserant@382: wxDefaultValidator, wxT ("slider")); etisserant@382: ins2 = etisserant@382: new wxSlider (panel, INS2, 0, -32768, 32767, wxDefaultPosition, etisserant@382: wxDefaultSize, wxSL_VERTICAL | wxSL_INVERSE, etisserant@382: wxDefaultValidator, wxT ("slider")); etisserant@382: ins3 = etisserant@382: new wxSlider (panel, INS3, 0, -32768, 32767, wxDefaultPosition, etisserant@382: wxDefaultSize, wxSL_VERTICAL | wxSL_INVERSE, etisserant@382: wxDefaultValidator, wxT ("slider")); etisserant@382: ins4 = etisserant@382: new wxSlider (panel, INS4, 0, -32768, 32767, wxDefaultPosition, etisserant@382: wxDefaultSize, wxSL_VERTICAL | wxSL_INVERSE, etisserant@382: wxDefaultValidator, wxT ("slider")); etisserant@382: ins5 = etisserant@382: new wxSlider (panel, INS5, 0, -32768, 32767, wxDefaultPosition, etisserant@382: wxDefaultSize, wxSL_VERTICAL | wxSL_INVERSE, etisserant@382: wxDefaultValidator, wxT ("slider")); etisserant@382: ins6 = etisserant@382: new wxSlider (panel, INS6, 0, -32768, 32767, wxDefaultPosition, etisserant@382: wxDefaultSize, wxSL_VERTICAL | wxSL_INVERSE, etisserant@382: wxDefaultValidator, wxT ("slider")); etisserant@382: ins7 = etisserant@382: new wxSlider (panel, INS7, 0, -32768, 32767, wxDefaultPosition, etisserant@382: wxDefaultSize, wxSL_VERTICAL | wxSL_INVERSE, etisserant@382: wxDefaultValidator, wxT ("slider")); etisserant@382: ins8 = etisserant@382: new wxSlider (panel, INS8, 0, -32768, 32767, wxDefaultPosition, etisserant@382: wxDefaultSize, wxSL_VERTICAL | wxSL_INVERSE, etisserant@382: wxDefaultValidator, wxT ("slider")); etisserant@382: mysssizer->Add (ins1, wxEXPAND | wxALL, wxEXPAND | wxALL, 15); etisserant@382: mysssizer->Add (ins2, wxEXPAND | wxALL, wxEXPAND | wxALL, 15); etisserant@382: mysssizer->Add (ins3, wxEXPAND | wxALL, wxEXPAND | wxALL, 15); etisserant@382: mysssizer->Add (ins4, wxEXPAND | wxALL, wxEXPAND | wxALL, 15); etisserant@382: mysssizer->Add (ins5, wxEXPAND | wxALL, wxEXPAND | wxALL, 15); etisserant@382: mysssizer->Add (ins6, wxEXPAND | wxALL, wxEXPAND | wxALL, 15); etisserant@382: mysssizer->Add (ins7, wxEXPAND | wxALL, wxEXPAND | wxALL, 15); etisserant@382: mysssizer->Add (ins8, wxEXPAND | wxALL, wxEXPAND | wxALL, 15); etisserant@382: quit = new wxButton (panel, QUIT, _T ("QUIT")); etisserant@382: mysizer->Add (quit, 0, wxALL, 5); etisserant@382: etisserant@382: panel = new wxPanel (book); etisserant@382: book->AddPage (panel, wxT ("Outputs"), true); etisserant@382: mysizer = new wxBoxSizer (wxVERTICAL); etisserant@382: panel->SetSizer (mysizer); etisserant@382: myhsizer = etisserant@382: new wxStaticBoxSizer (new etisserant@382: wxStaticBox (panel, wxID_ANY, etisserant@382: _T ("Write Outputs UNSIGNED8")), etisserant@382: wxHORIZONTAL); etisserant@382: mysizer->Add (myhsizer, 0, wxEXPAND | wxALL, 30); etisserant@382: outbt1 = new wxToggleButton (panel, wxID_ANY, wxT ("1")); etisserant@382: outbt2 = new wxToggleButton (panel, wxID_ANY, wxT ("2")); etisserant@382: outbt3 = new wxToggleButton (panel, wxID_ANY, wxT ("3")); etisserant@382: outbt4 = new wxToggleButton (panel, wxID_ANY, wxT ("4")); etisserant@382: outbt5 = new wxToggleButton (panel, wxID_ANY, wxT ("5")); etisserant@382: outbt6 = new wxToggleButton (panel, wxID_ANY, wxT ("6")); etisserant@382: outbt7 = new wxToggleButton (panel, wxID_ANY, wxT ("7")); etisserant@382: outbt8 = new wxToggleButton (panel, wxID_ANY, wxT ("8")); etisserant@382: myhsizer->Add (outbt1, wxEXPAND | wxALL, 0, 5); etisserant@382: myhsizer->Add (outbt2, wxEXPAND | wxALL, 0, 5); etisserant@382: myhsizer->Add (outbt3, wxEXPAND | wxALL, 0, 5); etisserant@382: myhsizer->Add (outbt4, wxEXPAND | wxALL, 0, 5); etisserant@382: myhsizer->Add (outbt5, wxEXPAND | wxALL, 0, 5); etisserant@382: myhsizer->Add (outbt6, wxEXPAND | wxALL, 0, 5); etisserant@382: myhsizer->Add (outbt7, wxEXPAND | wxALL, 0, 5); etisserant@382: myhsizer->Add (outbt8, wxEXPAND | wxALL, 0, 5); etisserant@382: myhsizer = etisserant@382: new wxStaticBoxSizer (new etisserant@382: wxStaticBox (panel, wxID_ANY, etisserant@382: _T ("Analogue Output INTEGER16")), etisserant@382: wxVERTICAL); etisserant@382: mysizer->Add (myhsizer, wxEXPAND | wxALL, wxEXPAND | wxALL, 30); etisserant@382: mysssizer = new wxBoxSizer (wxHORIZONTAL); etisserant@382: myhsizer->Add (mysssizer, 0, wxEXPAND | wxALL, 0); etisserant@382: outst1 = etisserant@382: new wxStaticText (panel, wxID_ANY, wxT ("label"), wxDefaultPosition, etisserant@382: wxDefaultSize, 0, wxT ("staticText")); etisserant@382: outst2 = etisserant@382: new wxStaticText (panel, wxID_ANY, wxT ("label"), wxDefaultPosition, etisserant@382: wxDefaultSize, 0, wxT ("staticText")); etisserant@382: outst3 = etisserant@382: new wxStaticText (panel, wxID_ANY, wxT ("label"), wxDefaultPosition, etisserant@382: wxDefaultSize, 0, wxT ("staticText")); etisserant@382: outst4 = etisserant@382: new wxStaticText (panel, wxID_ANY, wxT ("label"), wxDefaultPosition, etisserant@382: wxDefaultSize, 0, wxT ("staticText")); etisserant@382: mysssizer->Add (outst1, wxEXPAND | wxALL, wxEXPAND | wxALL, 5); etisserant@382: mysssizer->Add (outst2, wxEXPAND | wxALL, wxEXPAND | wxALL, 5); etisserant@382: mysssizer->Add (outst3, wxEXPAND | wxALL, wxEXPAND | wxALL, 5); etisserant@382: mysssizer->Add (outst4, wxEXPAND | wxALL, wxEXPAND | wxALL, 5); etisserant@382: mysssizer = new wxBoxSizer (wxHORIZONTAL); etisserant@382: myhsizer->Add (mysssizer, wxEXPAND | wxALL, wxEXPAND | wxALL, 0); etisserant@382: outs1 = etisserant@382: new wxGauge (panel, wxID_ANY, 65535, wxDefaultPosition, wxDefaultSize, etisserant@382: wxSL_VERTICAL | wxSL_INVERSE, wxDefaultValidator, etisserant@382: wxT ("gauge")); etisserant@382: outs2 = etisserant@382: new wxGauge (panel, wxID_ANY, 65535, wxDefaultPosition, wxDefaultSize, etisserant@382: wxSL_VERTICAL | wxSL_INVERSE, wxDefaultValidator, etisserant@382: wxT ("gauge")); etisserant@382: outs3 = etisserant@382: new wxGauge (panel, wxID_ANY, 65535, wxDefaultPosition, wxDefaultSize, etisserant@382: wxSL_VERTICAL | wxSL_INVERSE, wxDefaultValidator, etisserant@382: wxT ("gauge")); etisserant@382: outs4 = etisserant@382: new wxGauge (panel, wxID_ANY, 65535, wxDefaultPosition, wxDefaultSize, etisserant@382: wxSL_VERTICAL | wxSL_INVERSE, wxDefaultValidator, etisserant@382: wxT ("gauge")); etisserant@382: mysssizer->Add (outs1, wxEXPAND | wxALL, wxEXPAND | wxALL, 15); etisserant@382: mysssizer->Add (outs2, wxEXPAND | wxALL, wxEXPAND | wxALL, 15); etisserant@382: mysssizer->Add (outs3, wxEXPAND | wxALL, wxEXPAND | wxALL, 15); etisserant@382: mysssizer->Add (outs4, wxEXPAND | wxALL, wxEXPAND | wxALL, 15); etisserant@382: quit = new wxButton (panel, QUIT, _T ("QUIT")); etisserant@382: mysizer->Add (quit, 0, wxALL, 5); etisserant@382: etisserant@382: wxString etisserant@382: choice[] = { etisserant@382: _T ("Analogue Out 1"), _T ("Analogue Out 2"), etisserant@382: _T ("Analogue Out 3"), _T ("Analogue Out 4"), etisserant@382: _T ("Bool Out 1"), _T ("Bool Out 2"), etisserant@382: _T ("Bool Out 3"), _T ("Bool Out 4"), etisserant@382: _T ("Bool Out 5"), _T ("Bool Out 6"), etisserant@382: _T ("Bool Out 7"), _T ("Bool Out 8"), etisserant@382: _T ("Analogue Input 1"), _T ("Analogue Input 2"), etisserant@382: _T ("Analogue Input 3"), _T ("Analogue Input 4"), etisserant@382: _T ("Analogue Input 5"), _T ("Analogue Input 6"), etisserant@382: _T ("Analogue Input 7"), _T ("Analogue Input 8"), etisserant@382: _T ("Bool Input 1"), _T ("Bool Input 2"), etisserant@382: _T ("Bool Input 3"), _T ("Bool Input 4"), etisserant@382: _T ("Bool Input 5"), _T ("Bool Input 6"), etisserant@382: _T ("Bool Input 7"), _T ("Bool Input 8"), etisserant@382: }; etisserant@382: etisserant@382: panel = new wxPanel (book); etisserant@382: book->InsertPage (0, panel, wxT ("Control"), true); etisserant@382: mysizer = new wxBoxSizer (wxVERTICAL); etisserant@382: panel->SetSizer (mysizer); etisserant@382: myhsizer = new wxBoxSizer (wxHORIZONTAL); etisserant@382: myhsizer = etisserant@382: new wxStaticBoxSizer (new etisserant@382: wxStaticBox (panel, wxID_ANY, etisserant@382: _T ("Control your node")), etisserant@382: wxHORIZONTAL); etisserant@382: mysizer->Add (myhsizer, 0, wxALL, 5); etisserant@382: start = new wxButton (panel, START, _T ("START")); etisserant@382: stop = new wxButton (panel, STOP, _T ("STOP")); etisserant@382: stop->Enable (false); etisserant@382: myhsizer->Add (start, 0, wxRIGHT, 5); etisserant@382: myhsizer->Add (stop, 0, wxLEFT, 5); etisserant@382: myhsizer = etisserant@382: new wxStaticBoxSizer (new etisserant@382: wxStaticBox (panel, wxID_ANY, _T ("Operation log")), etisserant@382: wxHORIZONTAL); etisserant@382: mysizer->Add (myhsizer, wxALL, wxEXPAND | wxALL, 5); etisserant@382: textLog = etisserant@382: new wxTextCtrl (panel, TEXTBOX1, _T (""), wxDefaultPosition, etisserant@382: wxDefaultSize, wxTE_MULTILINE, wxDefaultValidator, etisserant@382: wxTextCtrlNameStr); etisserant@382: myhsizer->Add (textLog, wxALL, wxEXPAND | wxALL, 5); etisserant@382: quit = new wxButton (panel, QUIT, _T ("QUIT")); etisserant@382: mysizer->Add (quit, 0, wxALL, 5); etisserant@382: etisserant@382: m_timer.Start (100); etisserant@382: if (to_start) etisserant@246: { etisserant@382: Start (); etisserant@246: } etisserant@246: } etisserant@246: etisserant@382: void etisserant@382: MyFrame::OnQuit (wxCommandEvent & WXUNUSED (event)) etisserant@382: { etisserant@382: Close (true); etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: MyFrame::Start () etisserant@382: { etisserant@382: if (main_can (SlaveBoard, LibraryPath)) etisserant@246: { etisserant@382: printf ("[KO]\n"); etisserant@407: fflush(stdout); etisserant@382: *textLog << etisserant@382: wxT etisserant@382: ("----------------------------------------------------Initialization [KO]\n"); etisserant@246: } etisserant@382: else etisserant@382: { etisserant@382: printf ("[OK]\n"); etisserant@407: fflush(stdout); etisserant@382: *textLog << etisserant@382: wxT etisserant@382: ("----------------------------------------------------Initialization [OK]\n"); etisserant@382: stop->Enable (true); etisserant@382: start->Enable (false); etisserant@382: } etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnStart (wxCommandEvent & WXUNUSED (event)) etisserant@382: { etisserant@382: wxString s; etisserant@385: etisserant@382: node_id_ext = node_id->GetValue (); etisserant@382: s = busname->GetValue (); etisserant@382: strncpy (SlaveBoard.busname, s.mb_str (), MAXLENGTH_BUSNAME); etisserant@382: *textLog << wxT ("-- Bus name: ------> ") << s << wxT ("\n"); etisserant@382: *textLog << wxT ("-- Node ID: -------> ") << node_id-> etisserant@382: GetValue () << wxT ("\n"); etisserant@385: SetTitle(wxString::Format(wxT("CanOpen virtual DS-401 - Id : %d"),node_id-> etisserant@385: GetValue ())); etisserant@382: Start (); etisserant@382: } etisserant@382: etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnStop (wxCommandEvent & WXUNUSED (event)) etisserant@382: { etisserant@382: etisserant@382: *textLog << etisserant@382: wxT etisserant@382: ("----------------------------------------------------Slave [STOPPED]") << etisserant@382: wxT ("\n"); etisserant@382: stop_slave (); etisserant@382: stop->Enable (false); etisserant@382: start->Enable (true); etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnLoad (wxCommandEvent & WXUNUSED (event)) etisserant@382: { etisserant@382: wxFileDialog fd (this, wxT ("Choose a can driver library"), wxT (""), etisserant@382: wxT (""), LIB_EXTENT); etisserant@382: etisserant@382: if (fd.ShowModal () == wxID_OK) etisserant@382: { etisserant@382: drivername->Clear (); etisserant@382: drivername->AppendText (fd.GetPath ()); etisserant@382: *textLog << wxT ("LibraryPath: ") << fd.GetPath () << wxT ("\n"); etisserant@382: strncpy (LibraryPath, fd.GetPath ().mb_str (), MAXLENGTH_LIBPATH); etisserant@382: printf ("path=%s", LibraryPath); etisserant@382: } etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnInbt1 (wxCommandEvent & WXUNUSED (event)) etisserant@382: { etisserant@382: Read_Inputs_8_Bit[0] = Read_Inputs_8_Bit[0] ^ 0x1; etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnInbt2 (wxCommandEvent & WXUNUSED (event)) etisserant@382: { etisserant@382: Read_Inputs_8_Bit[0] = Read_Inputs_8_Bit[0] ^ 0x2; etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnInbt3 (wxCommandEvent & WXUNUSED (event)) etisserant@382: { etisserant@382: Read_Inputs_8_Bit[0] = Read_Inputs_8_Bit[0] ^ 0x4; etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnInbt4 (wxCommandEvent & WXUNUSED (event)) etisserant@382: { etisserant@382: Read_Inputs_8_Bit[0] = Read_Inputs_8_Bit[0] ^ 0x8; etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnInbt5 (wxCommandEvent & WXUNUSED (event)) etisserant@382: { etisserant@382: Read_Inputs_8_Bit[0] = Read_Inputs_8_Bit[0] ^ 0x10; etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnInbt6 (wxCommandEvent & WXUNUSED (event)) etisserant@382: { etisserant@382: Read_Inputs_8_Bit[0] = Read_Inputs_8_Bit[0] ^ 0x20; etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnInbt7 (wxCommandEvent & WXUNUSED (event)) etisserant@382: { etisserant@382: Read_Inputs_8_Bit[0] = Read_Inputs_8_Bit[0] ^ 0x40; etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnInbt8 (wxCommandEvent & WXUNUSED (event)) etisserant@382: { etisserant@382: Read_Inputs_8_Bit[0] = Read_Inputs_8_Bit[0] ^ 0x80; etisserant@382: } etisserant@382: etisserant@382: etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnIns1 (wxScrollEvent & event) etisserant@382: { etisserant@382: Read_Analogue_Input_16_Bit[0] = ins1->GetValue (); etisserant@382: inst1->SetValue (ins1->GetValue ()); etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnIns2 (wxScrollEvent & event) etisserant@382: { etisserant@382: Read_Analogue_Input_16_Bit[1] = ins2->GetValue (); etisserant@382: inst2->SetValue (ins2->GetValue ()); etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnIns3 (wxScrollEvent & event) etisserant@382: { etisserant@382: Read_Analogue_Input_16_Bit[2] = ins3->GetValue (); etisserant@382: inst3->SetValue (ins3->GetValue ()); etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnIns4 (wxScrollEvent & event) etisserant@382: { etisserant@382: Read_Analogue_Input_16_Bit[3] = ins4->GetValue (); etisserant@382: inst4->SetValue (ins4->GetValue ()); etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnIns5 (wxScrollEvent & event) etisserant@382: { etisserant@382: Read_Analogue_Input_16_Bit[4] = ins5->GetValue (); etisserant@382: inst5->SetValue (ins5->GetValue ()); etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnIns6 (wxScrollEvent & event) etisserant@382: { etisserant@382: Read_Analogue_Input_16_Bit[5] = ins6->GetValue (); etisserant@382: inst6->SetValue (ins6->GetValue ()); etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnIns7 (wxScrollEvent & event) etisserant@382: { etisserant@382: Read_Analogue_Input_16_Bit[6] = ins7->GetValue (); etisserant@382: inst7->SetValue (ins7->GetValue ()); etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnIns8 (wxScrollEvent & event) etisserant@382: { etisserant@382: Read_Analogue_Input_16_Bit[7] = ins8->GetValue (); etisserant@382: inst8->SetValue (ins8->GetValue ()); etisserant@382: } etisserant@382: etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnInst1 (wxSpinEvent & ev) etisserant@382: { etisserant@382: Read_Analogue_Input_16_Bit[0] = inst1->GetValue (); etisserant@382: ins1->SetValue (inst1->GetValue ()); etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnInst2 (wxSpinEvent & ev) etisserant@382: { etisserant@382: Read_Analogue_Input_16_Bit[1] = inst2->GetValue (); etisserant@382: ins2->SetValue (inst2->GetValue ()); etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnInst3 (wxSpinEvent & ev) etisserant@382: { etisserant@382: Read_Analogue_Input_16_Bit[2] = inst3->GetValue (); etisserant@382: ins3->SetValue (inst3->GetValue ()); etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnInst4 (wxSpinEvent & ev) etisserant@382: { etisserant@382: Read_Analogue_Input_16_Bit[3] = inst4->GetValue (); etisserant@382: ins4->SetValue (inst4->GetValue ()); etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnInst5 (wxSpinEvent & ev) etisserant@382: { etisserant@382: Read_Analogue_Input_16_Bit[4] = inst5->GetValue (); etisserant@382: ins5->SetValue (inst5->GetValue ()); etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnInst6 (wxSpinEvent & ev) etisserant@382: { etisserant@382: Read_Analogue_Input_16_Bit[5] = inst6->GetValue (); etisserant@382: ins6->SetValue (inst6->GetValue ()); etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnInst7 (wxSpinEvent & ev) etisserant@382: { etisserant@382: Read_Analogue_Input_16_Bit[6] = inst7->GetValue (); etisserant@382: ins7->SetValue (inst7->GetValue ()); etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnInst8 (wxSpinEvent & ev) etisserant@382: { etisserant@382: Read_Analogue_Input_16_Bit[7] = inst8->GetValue (); etisserant@382: ins8->SetValue (inst8->GetValue ()); etisserant@382: } etisserant@382: etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnAbout (wxCommandEvent & WXUNUSED (event)) etisserant@382: { etisserant@382: wxString msg; etisserant@382: msg.Printf (_T ("About.\n\n") etisserant@382: _T etisserant@382: ("Input-Output simulation by GRANDEMANGE Nicolas for CanFestival!!")); etisserant@382: etisserant@382: wxMessageBox (msg, _T ("About !!!"), wxOK | wxICON_INFORMATION, this); etisserant@382: } etisserant@382: etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnFreqBoxClick (wxCommandEvent & event) etisserant@382: { etisserant@382: wxString wxstr; etisserant@382: etisserant@382: wxstr = event.GetString (); etisserant@382: strncpy (SlaveBoard.baudrate, wxstr.mb_str (), MAXLENGTH_BAUDRATE); etisserant@382: *textLog << wxT ("Baudrate:") << event.GetString () << wxT ("\n"); etisserant@382: } etisserant@382: etisserant@382: static int etisserant@382: is_set (int i, wxListBox * inlist, wxArrayInt in) etisserant@382: { etisserant@382: inlist->GetSelections (in); etisserant@382: for (int j = 0; j < in.GetCount (); j++) etisserant@382: { etisserant@382: if (i == (in[j] + 1)) etisserant@246: { etisserant@382: return (i); etisserant@246: } etisserant@382: } etisserant@382: return (0); etisserant@382: } etisserant@382: etisserant@382: static int etisserant@382: get_bit (UNS8 input, int bit) etisserant@382: { etisserant@382: return input & (((UNS8) 1) << bit - 1) ? 1 : 0; etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: actu_output (void) etisserant@382: { etisserant@382: wxString tmp; etisserant@382: etisserant@382: frame->outbt1->SetValue (get_bit (Write_Outputs_8_Bit[0], 1)); etisserant@382: frame->outbt2->SetValue (get_bit (Write_Outputs_8_Bit[0], 2)); etisserant@382: frame->outbt3->SetValue (get_bit (Write_Outputs_8_Bit[0], 3)); etisserant@382: frame->outbt4->SetValue (get_bit (Write_Outputs_8_Bit[0], 4)); etisserant@382: frame->outbt5->SetValue (get_bit (Write_Outputs_8_Bit[0], 5)); etisserant@382: frame->outbt6->SetValue (get_bit (Write_Outputs_8_Bit[0], 6)); etisserant@382: frame->outbt7->SetValue (get_bit (Write_Outputs_8_Bit[0], 7)); etisserant@382: frame->outbt8->SetValue (get_bit (Write_Outputs_8_Bit[0], 8)); etisserant@382: etisserant@382: frame->outs1->SetValue (Write_Analogue_Output_16_Bit[0] + 32768); etisserant@382: frame->outs2->SetValue (Write_Analogue_Output_16_Bit[1] + 32768); etisserant@382: frame->outs3->SetValue (Write_Analogue_Output_16_Bit[2] + 32768); etisserant@382: frame->outs4->SetValue (Write_Analogue_Output_16_Bit[3] + 32768); etisserant@382: tmp.Printf (wxT (" %i"), Write_Analogue_Output_16_Bit[0]); etisserant@382: frame->outst1->SetLabel (tmp); etisserant@382: tmp.Printf (wxT (" %i"), Write_Analogue_Output_16_Bit[1]); etisserant@382: frame->outst2->SetLabel (tmp); etisserant@382: tmp.Printf (wxT (" %i"), Write_Analogue_Output_16_Bit[2]); etisserant@382: frame->outst3->SetLabel (tmp); etisserant@382: tmp.Printf (wxT (" %i"), Write_Analogue_Output_16_Bit[3]); etisserant@382: frame->outst4->SetLabel (tmp); etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: actu (void) etisserant@382: { etisserant@382: actu_output (); etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnTimer (wxTimerEvent & event) etisserant@382: { etisserant@382: actu (); // do whatever you want to do every second here etisserant@382: } etisserant@382: etisserant@382: void etisserant@382: MyFrame::OnPaint (wxPaintEvent & event) etisserant@382: { etisserant@382: //Paint(); etisserant@382: }