00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "skin_config/config_user_interface.h"
00033 #include "skin_config/config_skin.h"
00034
00035
00036 #include <wx/stattext.h>
00037 #include <wx/statline.h>
00038 #include <wx/checkbox.h>
00039
00040
00041 #include <iostream>
00042 #include <string>
00043 #include <sstream>
00044 #include <math.h>
00045
00046
00047
00048
00049
00050 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size): wxFrame( NULL, -1, title, pos, size )
00051 {
00052
00053 skin_config_.bskin_driver_node_online = false;
00054
00055
00056 timer_ = new wxTimer(this, gui_id::ID_TIMER);
00057 timer_->Start(250);
00058 Connect(gui_id::ID_TIMER, wxEVT_TIMER, wxTimerEventHandler(MyFrame::subTopic), NULL, this);
00059
00060
00061 menubar = new wxMenuBar;
00062 file = new wxMenu;
00063 file->Append(gui_id::ID_About, wxT("&About..."));
00064 file->AppendSeparator();
00065 file->Append(wxID_EXIT, wxT("&Quit"));
00066 menubar->Append(file, wxT("&File"));
00067 SetMenuBar(menubar);
00068
00069 Connect(gui_id::ID_About, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyFrame::OnAbout));
00070 Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyFrame::OnQuit));
00071
00072 wxPanel *panel = new wxPanel(this, -1);
00073
00074 wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
00075
00076
00077 wxStaticText *headline = new wxStaticText(panel, -1, wxT("Sensor Skin configuration interface"));
00078
00079 wxFont headline_font = headline->GetFont();
00080 headline_font.SetWeight(wxBOLD);
00081 headline_font.SetPointSize(15);
00082 headline->SetFont(headline_font);
00083
00084 wxBoxSizer *hbox_headline = new wxBoxSizer(wxHORIZONTAL);
00085 hbox_headline->Add(headline, 0);
00086
00087 vbox->Add(hbox_headline, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 10);
00088
00089
00090 wxStaticLine *sline = new wxStaticLine(panel, wxID_ANY);
00091
00092 wxBoxSizer *hbox_line = new wxBoxSizer(wxHORIZONTAL);
00093 hbox_line->Add(sline, 1);
00094
00095 vbox->Add(hbox_line, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 5);
00096
00097 vbox->Add(-1, 15);
00098
00099
00101
00102
00103 wxFont heading_font = headline->GetFont();
00104 heading_font.SetWeight(wxBOLD);
00105 heading_font.SetPointSize(10);
00106
00107 wxFont normal_font = headline->GetFont();
00108 normal_font.SetWeight(wxLIGHT);
00109 normal_font.SetPointSize(7);
00110
00111
00113
00114
00115 wxBoxSizer *hbox_num_sens = new wxBoxSizer(wxHORIZONTAL);
00116 wxBoxSizer *vbox_num_sens_nv = new wxBoxSizer(wxVERTICAL);
00117
00118
00119 wxStaticText *stext_num_sens = new wxStaticText(panel, -1, wxT("Number of sensor elements (1 - 191)"), wxPoint(-1, -1), wxSize(-1, -1));
00120 stext_num_sens->SetFont(heading_font);
00121 vbox->Add(stext_num_sens, 0, wxLEFT, 35);
00122
00123 vbox->Add(-1, 5);
00124
00125
00126 wxStaticText *stext_num_sens_nv = new wxStaticText(panel, -1, wxT("new value"), wxPoint(-1, -1), wxSize(-1, -1));
00127 stext_num_sens_nv->SetFont(normal_font);
00128 vbox_num_sens_nv->Add(stext_num_sens_nv, 0, wxALIGN_CENTER_HORIZONTAL);
00129
00130
00131 twindow_num_sens_nv = new wxTextCtrl(panel, wxID_ANY, wxT(""), wxPoint(-1, -1), wxSize(-1, -1));
00132 vbox_num_sens_nv->Add(twindow_num_sens_nv, 0);
00133 hbox_num_sens->Add(vbox_num_sens_nv, 0, wxLEFT, 5);
00134
00135
00136 wxSize twindow_size = twindow_num_sens_nv->GetClientSize();
00137
00138
00139 wxButton *btn_num_sens_set = new wxButton(panel, gui_id::ID_NUM_SENS_SET, wxT("set"), wxPoint(-1, -1), wxSize(-1, -1));
00140 Connect(gui_id::ID_NUM_SENS_SET, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(MyFrame::OnNumSensSet));
00141 hbox_num_sens->Add(btn_num_sens_set, 0, wxALIGN_BOTTOM | wxLEFT, 5 * 3 + twindow_size.GetWidth() * 2 );
00142
00143 vbox->Add(hbox_num_sens, 0, wxLEFT , 35 );
00144
00145
00147
00148
00149 wxBoxSizer *hbox_stat_thres = new wxBoxSizer(wxHORIZONTAL);
00150 wxBoxSizer *vbox_stat_thres_fs = new wxBoxSizer(wxVERTICAL);
00151 wxBoxSizer *vbox_stat_thres_ts = new wxBoxSizer(wxVERTICAL);
00152 wxBoxSizer *vbox_stat_thres_nv = new wxBoxSizer(wxVERTICAL);
00153
00154 vbox->Add(-1, 10);
00155
00156
00157 wxStaticText *stext_stat_thres = new wxStaticText(panel, -1, wxT("Static Thresholds"), wxPoint(-1, -1), wxSize(-1, -1));
00158 stext_stat_thres->SetFont(heading_font);
00159 vbox->Add(stext_stat_thres, 0, wxLEFT, 35);
00160
00161 vbox->Add(-1, 5);
00162
00163
00164 wxStaticText *stext_stat_thres_fs = new wxStaticText(panel, -1, wxT("from SE-Nr."), wxPoint(-1, -1), wxSize(-1, -1));
00165 stext_stat_thres_fs->SetFont(normal_font);
00166 vbox_stat_thres_fs->Add(stext_stat_thres_fs, 0, wxALIGN_CENTER_HORIZONTAL);
00167
00168
00169 twindow_stat_thres_fs = new wxTextCtrl(panel, wxID_ANY, wxT(""), wxPoint(-1, -1), wxSize(-1, -1));
00170 vbox_stat_thres_fs->Add(twindow_stat_thres_fs, 0);
00171 hbox_stat_thres->Add(vbox_stat_thres_fs, 0, wxLEFT, 5);
00172
00173
00174 wxStaticText *stext_stat_thres_ts = new wxStaticText(panel, -1, wxT("to SE-Nr."), wxPoint(-1, -1), wxSize(-1, -1));
00175 stext_stat_thres_ts->SetFont(normal_font);
00176 vbox_stat_thres_ts->Add(stext_stat_thres_ts, 0, wxALIGN_CENTER_HORIZONTAL);
00177
00178
00179 twindow_stat_thres_ts = new wxTextCtrl(panel, wxID_ANY, wxT(""), wxPoint(-1, -1), wxSize(-1, -1));
00180 vbox_stat_thres_ts->Add(twindow_stat_thres_ts, 0);
00181 hbox_stat_thres->Add(vbox_stat_thres_ts, 0, wxLEFT, 5);
00182
00183
00184 wxStaticText *stext_stat_thres_nv = new wxStaticText(panel, -1, wxT("new value"), wxPoint(-1, -1), wxSize(-1, -1));
00185 stext_stat_thres_nv->SetFont(normal_font);
00186 vbox_stat_thres_nv->Add(stext_stat_thres_nv, 0, wxALIGN_CENTER_HORIZONTAL);
00187
00188
00189 twindow_stat_thres_nv = new wxTextCtrl(panel, wxID_ANY, wxT(""), wxPoint(-1, -1), wxSize(-1, -1));
00190 vbox_stat_thres_nv->Add(twindow_stat_thres_nv, 0);
00191 hbox_stat_thres->Add(vbox_stat_thres_nv, 0, wxLEFT, 5);
00192
00193
00194 wxButton *btn_stat_thres_set = new wxButton(panel, gui_id::ID_STAT_THRES_SET, wxT("set"), wxPoint(-1, -1), wxSize(-1, -1));
00195 Connect(gui_id::ID_STAT_THRES_SET, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(MyFrame::OnStatThresSet));
00196 hbox_stat_thres->Add(btn_stat_thres_set, 0, wxALIGN_BOTTOM | wxLEFT, 5 );
00197
00198 vbox->Add(hbox_stat_thres, 0, wxLEFT , 35);
00199
00200
00202
00203
00204 wxBoxSizer *hbox_dyn_thres = new wxBoxSizer(wxHORIZONTAL);
00205 wxBoxSizer *vbox_dyn_thres_cv = new wxBoxSizer(wxVERTICAL);
00206 wxBoxSizer *vbox_dyn_thres_nv = new wxBoxSizer(wxVERTICAL);
00207
00208 vbox->Add(-1, 10);
00209
00210
00211 wxStaticText *stext_dyn_thres = new wxStaticText(panel, -1, wxT("Dynamic Threshold"), wxPoint(-1, -1), wxSize(-1, -1));
00212 stext_dyn_thres->SetFont(heading_font);
00213 vbox->Add(stext_dyn_thres, 0, wxLEFT, 35);
00214
00215 vbox->Add(-1, 5);
00216
00217
00218 wxStaticText *stext_dyn_thres_cv = new wxStaticText(panel, -1, wxT("current value"), wxPoint(-1, -1), wxSize(-1, -1));
00219 stext_dyn_thres_cv->SetFont(normal_font);
00220 vbox_dyn_thres_cv->Add(stext_dyn_thres_cv, 0, wxALIGN_CENTER_HORIZONTAL);
00221
00222
00223 twindow_dyn_thres_cv = new wxTextCtrl(panel, wxID_ANY, wxT(""), wxPoint(-1, -1), wxSize(-1, -1));
00224 vbox_dyn_thres_cv->Add(twindow_dyn_thres_cv, 0);
00225 hbox_dyn_thres->Add(vbox_dyn_thres_cv, 0, wxLEFT, 5);
00226 twindow_dyn_thres_cv->SetEditable(false);
00227
00228
00229 wxStaticText *stext_dyn_thres_nv = new wxStaticText(panel, -1, wxT("new value"), wxPoint(-1, -1), wxSize(-1, -1));
00230 stext_dyn_thres_nv->SetFont(normal_font);
00231 vbox_dyn_thres_nv->Add(stext_dyn_thres_nv, 0, wxALIGN_CENTER_HORIZONTAL);
00232
00233
00234 twindow_dyn_thres_nv = new wxTextCtrl(panel, wxID_ANY, wxT(""), wxPoint(-1, -1), wxSize(-1, -1));
00235 vbox_dyn_thres_nv->Add(twindow_dyn_thres_nv, 0);
00236 hbox_dyn_thres->Add(vbox_dyn_thres_nv, 0, wxLEFT, 5);
00237
00238
00239 wxButton *btn_dyn_thres_set = new wxButton(panel, gui_id::ID_DYN_THRES_SET, wxT("set"), wxPoint(-1, -1), wxSize(-1, -1));
00240 Connect(gui_id::ID_DYN_THRES_SET, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(MyFrame::OnDynThresSet));
00241 hbox_dyn_thres->Add(btn_dyn_thres_set, 0, wxALIGN_BOTTOM | wxLEFT, 5 * 2 + twindow_size.GetWidth());
00242
00243
00244 wxSize tbutton_size = btn_dyn_thres_set->GetClientSize();
00245
00246 vbox->Add(hbox_dyn_thres, 0, wxLEFT , 35);
00247
00248
00250
00251
00252 wxBoxSizer *hbox_com_btn = new wxBoxSizer(wxHORIZONTAL);
00253
00254 vbox->Add(-1, 10);
00255
00256
00257 wxStaticText *stext_com_btn = new wxStaticText(panel, -1, wxT("Command Buttons"), wxPoint(-1, -1), wxSize(-1, -1));
00258 stext_com_btn->SetFont(heading_font);
00259 vbox->Add(stext_com_btn, 0, wxLEFT, 35);
00260
00261 vbox->Add(-1, 5);
00262
00263
00264 wxButton *btn_com_btn_rtf = new wxButton(panel, gui_id::ID_COM_BTN_RTF, wxT("Ram to Flash"), wxPoint(-1, -1), wxSize(twindow_size.GetWidth() * 2 + 5, -1));
00265 Connect(gui_id::ID_COM_BTN_RTF, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(MyFrame::OnRamToFlash));
00266 hbox_com_btn->Add(btn_com_btn_rtf, 0, wxALIGN_BOTTOM | wxLEFT, 5 );
00267
00268
00269 wxButton *btn_com_btn_is = new wxButton(panel, gui_id::ID_COM_BTN_IS, wxT("Init Skin"), wxPoint(-1, -1), wxSize(twindow_size.GetWidth() + tbutton_size.GetWidth() + 5, -1));
00270 Connect(gui_id::ID_COM_BTN_IS, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(MyFrame::OnInitSkin));
00271 hbox_com_btn->Add(btn_com_btn_is, 0, wxALIGN_BOTTOM | wxLEFT, 5 );
00272
00273 vbox->Add(hbox_com_btn, 0, wxLEFT , 35);
00274
00275
00276
00277 panel->SetSizer(vbox);
00278
00279 Centre();
00280 }
00281
00282 void MyFrame::subTopic(wxTimerEvent& evt)
00283 {
00284 ros::spinOnce();
00285 std::cout << "subTopic" << " \n";
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303 ros::Time dcurrent_time = ros::Time::now();
00304 if( (skin_config_.ui8sensor_number_ == 0) || (skin_config_.ui8dyn_thres_currentvalue_ == 255) || (( dcurrent_time > (skin_config_.dtime_subscription_ + ros::Duration((ceil(float(skin_config_.ui8sensor_number_) / 32.0) -1 ) * 0.1 + 0.25)))))
00305 {
00306
00307 skin_config_.bskin_driver_node_online = false;
00308 twindow_dyn_thres_cv->SetValue(wxT(""));
00309 }
00310 else
00311 {
00312
00313 skin_config_.bskin_driver_node_online = true;
00314 twindow_dyn_thres_cv->SetValue(wxString::Format(wxT("%i"),skin_config_.ui8dyn_thres_currentvalue_));
00315 }
00316
00317 if (!ros::ok())
00318 {
00319 Close();
00320 }
00321 }
00322
00323 void MyFrame::ShowDialog(wxString wxstr, bool successfullychanged)
00324 {
00325 std::cout << skin_config_.bskin_driver_node_online << std::endl;
00326 if( (skin_config_.bskin_driver_node_online == true) && (successfullychanged == true) )
00327 {
00328 wxMessageDialog *dial_info = new wxMessageDialog(NULL, wxstr, wxT("Info"), wxOK);
00329 dial_info->ShowModal();
00330 }
00331 else if( (skin_config_.bskin_driver_node_online == true) && (successfullychanged == false) )
00332 {
00333 wxMessageDialog *dial_info = new wxMessageDialog(NULL, wxT("Change of skin values failed"), wxT("Info"), wxOK | wxICON_ERROR);
00334 dial_info->ShowModal();
00335 }
00336 else
00337 {
00338 wxMessageDialog *dial_info = new wxMessageDialog(NULL, wxT("Subscriber node (skin_driver) is offline"), wxT("Info"), wxOK | wxICON_ERROR);
00339 dial_info->ShowModal();
00340 }
00341 }
00342
00343 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
00344 {
00345 Close(true);
00346 }
00347
00348 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
00349 {
00350 wxMessageBox( wxT("..... text text text ....."), wxT("Sensor Skin"), wxICON_INFORMATION, this );
00351 }
00352
00353 void MyFrame::OnRamToFlash(wxCommandEvent& event)
00354 {
00355
00356 bchange = skin_config_.OnRequestChanges(skin_pub::AppData_CommandByte, skin_pub::NoStep, skin_pub::OneByte, 4, skin_pub::sens_not_changed);
00357 ShowDialog(wxT("RAM was written into Flash"), bchange);
00358 }
00359
00360 void MyFrame::OnInitSkin(wxCommandEvent& event)
00361 {
00362
00363 bchange = skin_config_.OnRequestChanges(skin_pub::AppData_CommandByte, skin_pub::NoStep, skin_pub::OneByte, 1, skin_pub::sens_not_changed);
00364 ShowDialog(wxT("Skin is initialized"), bchange);
00365 }
00366
00367 void MyFrame::OnNumSensSet(wxCommandEvent& event)
00368 {
00369
00370 wxString num_sens_nv_wxstring = twindow_num_sens_nv->GetValue();
00371 long lnum_sens_nv;
00372 bool bvalid_number = false;
00373
00374 bvalid_number = num_sens_nv_wxstring.ToLong(&lnum_sens_nv, 10);
00375
00376 if((lnum_sens_nv < 1)||(lnum_sens_nv > 191))
00377 {
00378 bvalid_number = false;
00379 }
00380
00381 if(bvalid_number)
00382 {
00383 uint8_t ui8adr_pub[2];
00384 uint16_t ui16adr_pub;
00385
00386 ui16adr_pub = skin_pub::readadr_hi * 256 + skin_pub::readadr_lo + 3 + 8 * lnum_sens_nv;
00387
00388 ui8adr_pub[0] = uint8_t((ui16adr_pub & 0xFF00) >> 8);
00389 ui8adr_pub[1] = uint8_t(ui16adr_pub & 0xFF);
00390
00391
00392 bchange = skin_config_.OnRequestChanges(ui8adr_pub, skin_pub::NoStep, skin_pub::OneByte, skin_pub::EndOfChainMarker, skin_pub::sens_changed);
00393
00394 ros::Duration(0.05).sleep();
00395
00396
00397 bchange = skin_config_.OnRequestChanges(skin_pub::AppData_CommandByte, skin_pub::NoStep, skin_pub::OneByte, 1, skin_pub::sens_not_changed);
00398 ShowDialog(wxT("Number of sensors was changed to ") + num_sens_nv_wxstring + wxT("\n\nTo save the changes permanently the RAM has to be written into the Flash"), bchange);
00399 this->SetFocus();
00400 }
00401 else
00402 {
00403 ShowDialog(wxT("Please insert a valid number in the text window\n\nvalid number: 0 < number fo sensors < 192"), true);
00404 twindow_num_sens_nv->SetFocus();
00405 }
00406
00407 twindow_num_sens_nv->Clear();
00408
00409
00410 }
00411
00412 void MyFrame::OnStatThresSet(wxCommandEvent& event)
00413 {
00414
00415 wxString stat_thres_fs_wxstring = twindow_stat_thres_fs->GetValue();
00416 wxString stat_thres_ts_wxstring = twindow_stat_thres_ts->GetValue();
00417 wxString stat_thres_nv_wxstring = twindow_stat_thres_nv->GetValue();
00418
00419 long lstat_thres_fs;
00420 long lstat_thres_ts;
00421 long lstat_thres_nv;
00422
00423 bool bvalid_number = false;
00424
00425 bvalid_number = stat_thres_fs_wxstring.ToLong(&lstat_thres_fs, 10) && stat_thres_ts_wxstring.ToLong(&lstat_thres_ts, 10) && stat_thres_nv_wxstring.ToLong(&lstat_thres_nv, 10);
00426
00427
00428
00429
00430
00431
00432
00433 if( (lstat_thres_fs < 1)||(lstat_thres_fs > skin_config_.ui8sensor_number_)||(lstat_thres_ts < 1)||(lstat_thres_ts > skin_config_.ui8sensor_number_)||(lstat_thres_nv < 1)||(lstat_thres_nv > 250)||(lstat_thres_fs > lstat_thres_ts) )
00434 {
00435 bvalid_number = false;
00436 }
00437
00438 if(bvalid_number)
00439 {
00440 uint8_t ui8adr_pub[2];
00441 uint16_t ui16adr_pub;
00442
00443 ui16adr_pub = skin_pub::readadr_hi * 256 + skin_pub::readadr_lo + 3 + 8 * (lstat_thres_fs - 1);
00444
00445 ui8adr_pub[0] = uint8_t((ui16adr_pub & 0xFF00) >> 8);
00446 ui8adr_pub[1] = uint8_t(ui16adr_pub & 0xFF);
00447
00448
00449 bchange = skin_config_.OnRequestChanges(ui8adr_pub, skin_pub::EightSteps, uint8_t(lstat_thres_ts - lstat_thres_fs + 1), uint8_t(lstat_thres_nv), skin_pub::sens_not_changed);
00450
00451 ShowDialog(wxT("Static threshold was changed \n\nmodifications:\n\t from SE-Nr. = ") + stat_thres_fs_wxstring + wxT("\n\t to SE-Nr. = ") + stat_thres_ts_wxstring + wxT("\n\t new value = ") + stat_thres_nv_wxstring + wxT("\n\nTo save the changes permanently the RAM has to be written into the Flash"), bchange);
00452 this->SetFocus();
00453 }
00454 else
00455 {
00456 ShowDialog(wxT("Please insert a valid number of sensors\n\nvalid values:\n\t 0 < from SE-Nr. <= sens. numb.\n\t 0 < to SE-Nr. <= sens. numb.\n\t 0 < new value < 251\n\t from SE-Nr. <= to SE-Nr."), true);
00457 twindow_stat_thres_fs->SetFocus();
00458 }
00459
00460 twindow_stat_thres_fs->Clear();
00461 twindow_stat_thres_ts->Clear();
00462 twindow_stat_thres_nv->Clear();
00463 }
00464
00465 void MyFrame::OnDynThresSet(wxCommandEvent& event)
00466 {
00467
00468 wxString dyn_thres_nv_wxstring = twindow_dyn_thres_nv->GetValue();
00469 long ldyn_thres_nv;
00470 bool bvalid_number = false;
00471
00472 bvalid_number = dyn_thres_nv_wxstring.ToLong(&ldyn_thres_nv, 10);
00473
00474 if((ldyn_thres_nv < 1)||(ldyn_thres_nv > 128))
00475 {
00476 bvalid_number = false;
00477 }
00478
00479 if(bvalid_number)
00480 {
00481
00482 bchange = skin_config_.OnRequestChanges(skin_pub::AppData_DynLimit, skin_pub::NoStep, skin_pub::OneByte, uint8_t(ldyn_thres_nv), skin_pub::sens_not_changed);
00483
00484 ShowDialog(wxT("Dynamic threshold was changed to ") + dyn_thres_nv_wxstring + wxT("\n\nTo save the changes permanently the RAM has to be written into the Flash"), bchange);
00485 this->SetFocus();
00486 }
00487 else
00488 {
00489 ShowDialog(wxT("Please insert a valid number in the text window\n\nvalid number: 0 < dynamic threshold < 129"), true);
00490 twindow_dyn_thres_nv->SetFocus();
00491 }
00492
00493 twindow_dyn_thres_nv->Clear();
00494 }
00495
00496
00497
00498
00499
00500