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
00033
00034
00035
00036
00037 #define PF(p) //p
00038
00039 #include <iostream>
00040 #include <sstream>
00041 #include <string>
00042 #include <gtkmm/dialog.h>
00043 #include <window1.hh>
00044 #include <cstdio>
00045 #include <cstdlib>
00046 #include "misc.h"
00047 #include "wmp_config.h"
00048 #include "core/interface/Msg.h"
00049 #include "math.h"
00050 #include "bridge.hh"
00051 #include "rec_param_dlg.hh"
00052 #include "area_wrapper.h"
00053 #include "wmp_specific.hh"
00054 #include "statistics.h"
00055 #include "wmp_config.h"
00056
00057 #include "core/include/frames.h"
00058 #include "config.h"
00059 #include "main_window.hh"
00060 #include "area.h"
00061 #include "MyArea.hh"
00062 #include "prim.h"
00063 #include "pcap_layer.h"
00064 #include <iostream>
00065 #include <fstream>
00066 #include <gtkmm/main.h>
00067 #include <gtkmm/messagedialog.h>
00068 #include <gtkmm/window.h>
00069 #include <iostream>
00070 #include <gtkmm/filechooserdialog.h>
00071 #include <gtkmm/stock.h>
00072 #include <gtkmm/widget.h>
00073 #include <glibmm/keyfile.h>
00074 #include <sys/types.h>
00075 #include <sys/stat.h>
00076 #include <unistd.h>
00077 #include "enhanced_io.h"
00078 #include <iomanip>
00079 #include <vte-0.0/vte/vte.h>
00080 #include <fcntl.h>
00081
00082 using namespace std;
00083
00084 class main_window* mw;
00085 extern char sniff_iface[16];
00086 extern char iface[16];
00087
00088
00089 std::string nts(char val) {
00090 std::ostringstream oss;
00091 oss << (int) val;
00092 return oss.str();
00093 };
00094 std::string nts(unsigned char val) {
00095 std::ostringstream oss;
00096 oss << (int) val;
00097 return oss.str();
00098 };
00099
00100 template<class T>
00101 std::string nts(T val) {
00102 std::ostringstream oss;
00103 oss << (T) val;
00104 return oss.str();
00105 };
00106
00107 template<class T>
00108 std::string hnts(T val) {
00109 std::ostringstream oss;
00110 oss << std::hex;
00111 oss << val;
00112 return oss.str();
00113 };
00114
00115
00116
00117
00118 void dec2bin(long decimal, char *binary) {
00119 PF(fprintf(stderr,"**PF** dec2bin \n");)
00120 int k = 0, n = 0;
00121 int remain;
00122 char temp[80];
00123 do {
00124 remain = decimal % 2;
00125 decimal = decimal / 2;
00126 temp[k++] = remain + '0';
00127 } while (k < 8);
00128 while (k >= 0)
00129 binary[n++] = temp[--k];
00130 binary[n - 1] = 0;
00131 }
00132
00133
00134
00135 void print_path(char * path, int dest) {
00136 char buf[10000];
00137 sprintf(buf,"Digraph Path {\n");
00138 int prev_message_type = 0, previous = 0;
00139 char len = *path;
00140 char * p = &path[1];
00141 path[(unsigned int) len] = 40 + dest;
00142 int hops = 1;
00143 for (int i = 0; i < len; i++) {
00144 int message_type = *p / 10;
00145 int dest = *p % 10;
00146
00147
00148 if (i==0){
00149 previous = dest;
00150 prev_message_type = message_type;
00151 p++;
00152 continue;
00153 }
00154 char aux[1000];
00155 char color[10];
00156 switch (prev_message_type) {
00157 case 2:
00158 strcpy(color, "red");
00159 break;
00160 case 3:
00161 strcpy(color, "green");
00162 break;
00163 case 4:
00164 strcpy(color, "blue");
00165 break;
00166 case 5:
00167 strcpy(color, "black");
00168 break;
00169 }
00170
00171 sprintf(aux, "\tnode%d -> node%d [color=%s, label=%d];\n",
00172 previous, dest, color, hops);
00173
00174 strcat(buf, aux);
00175 if ((message_type == 4) && (prev_message_type == 2) && prev_message_type != -1) {
00176 sprintf(aux, "\tnode%d -> node%d [color=green, label=%d];\n",
00177 dest, dest, hops+1);
00178 strcat(buf, aux);
00179 hops++;
00180 }
00181 p++;
00182 hops++;
00183 previous = dest;
00184 prev_message_type = message_type;
00185
00186 }
00187 strcat(buf, "}\n");
00188 char txt[1000];
00189 sprintf(txt,"echo \"%s\" | dot -Tpng | display &",buf);
00190
00191
00192
00193 int ret = system (txt);
00194 if (ret!=0){
00195 fprintf(stderr,"Error executing %s\n", txt);
00196 }
00197 }
00198
00199 void main_window::on_hscale_position_value_changed() {
00200
00201 if (playing || recording)
00202 return;
00203 fill_screen();
00204 }
00205
00206 void main_window::on_hscale_zoom_value_changed() {
00207 PF(fprintf(stderr,"**PF** main_window::on_hscale_zoom_value_changed \n");)
00208 if (recording || playing){
00209 return;
00210 }
00211 fill_screen();
00212 }
00213 bool main_window::on_main_window_expose_event(GdkEventExpose *ev) {
00214 if ( Gdk::WINDOW_STATE_MAXIMIZED & get_state() )
00215 cerr << "trueaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" << endl;
00216 return false;
00217
00218 }
00219
00220 void main_window::fill_tree(wmpFrame * r, long long ptime, int pos_in_file) {
00221 Gtk::TreeModel::Children children = m_refTreeModel->children();
00222 for (Gtk::TreeModel::Children::iterator iter = children.begin(); iter
00223 != children.end(); ++iter) {
00224 Gtk::TreeModel::Row row = *iter;
00225 string exp_name((Glib::ustring(row[m_Columns.m_col_name])).c_str());
00226 Gtk::TreeModel::Path p = m_refTreeModel->get_path(iter);
00227 rows_expanded[exp_name] = xfield_tw->row_expanded(p);
00228 }
00229
00230 m_refTreeModel->clear();
00231 double ms;
00232 int sec;
00233 sec = (int) ((double) ptime / 1000000.0);
00234 ms = (double) (ptime % 1000000) / 1000.0;
00235 row_append("Time", nts(sec) + "s " + nts(ms) + "ms");
00236 if (pos_in_file >= 0)
00237 row_child_append("Id", nts(pos_in_file));
00238 update_frame_labels(r);
00239 show_routing_data(r);
00240 show_qos_data(r);
00241 show_broadcast_data(r);
00242
00243 children = m_refTreeModel->children();
00244 for (Gtk::TreeModel::Children::iterator iter = children.begin(); iter
00245 != children.end(); ++iter) {
00246 Gtk::TreeModel::Row row = *iter;
00247 string exp_name((Glib::ustring(row[m_Columns.m_col_name])).c_str());
00248 bool to_expand = rows_expanded[exp_name];
00249 if (to_expand) {
00250 Gtk::TreeModel::Path p = m_refTreeModel->get_path(iter);
00251 xfield_tw->expand_row(p, true);
00252 }
00253 }
00254
00255 }
00256
00257 void main_window::updater(){
00258 while(1){
00259 usleep(100000);
00260 gdk_threads_enter();
00261 areadx->queue_draw();
00262 areasx->queue_draw();
00263 MyArea->queue_draw();
00264 gdk_threads_leave();
00265
00266 timered_show_t = true;
00267 idx3++;
00268
00269
00270 if (playing) {
00271 continue_play();
00272 continue ;
00273 }
00274 if (recording) {
00275 int best, actual;
00276 char txt[128];
00277 simData_Hdr * p = (simData_Hdr *) data_backup;
00278 frame_time = p->time;
00279 get_actual_gct(&best, &actual);
00280
00281 sprintf(txt, "%llds %5.3fms", frame_time / 1000000, (float) (frame_time
00282 % 1000000) / 1000.0);
00283
00284 gdk_threads_enter();
00285 label68->set_text(txt);
00286 sprintf(txt, "Frames: %d", play_idx);
00287 label69->set_text(txt);
00288 sprintf(txt, "Max EFZ: %d", best);
00289 label70->set_text(txt);
00290 sprintf(txt, "Present EFZ: %d", actual);
00291 label71->set_text(txt);
00292 gdk_threads_leave();
00293
00294 timer++;
00295 if (timer % 10 == 0) {
00296 MyArea->resetActive();
00297 if (w2 && w2->is_visible()) {
00298 w2->m_refTreeModel->clear();
00299 statistics_publish(w2);
00300 }
00301 }
00302 continue ;
00303 }
00304 }
00305 }
00306
00307 void main_window::notify_selection(int n) {
00308 PF(fprintf(stderr,"**PF** main_window::notify_selection \n");)
00309 int v = (int) (n - hscale_zoom->get_value() / 2);
00310 if (v < 0){
00311 v = 0;
00312 }
00313 hscale_position->set_value(v);
00314 io_go_to(n);
00315 char data[2500];
00316 int bytes = io_read_next_sim_data(&data[0]);
00317 if (bytes > 0) {
00318 draw_stuffs(&data[0], n, 0, 1, 1);
00319
00320 }
00321 MyArea->set_selected(n);
00322 }
00323
00324 void main_window::reset(int val) {
00325 char txt[256];
00326 sprintf(txt, "wmpSniffer - %s", filename);
00327 this->set_title(txt);
00328 kf->set_string("Files", "Last_Opened" ,filename);
00329 nnodes = io_open_sim_data(filename);
00330 if (val!=-1){
00331 nnodes = val;
00332 }
00333
00334 areadx->clearRobots();
00335 areasx->clearRobots();
00336 if (nnodes == 0){
00337 nnodes = kf->get_integer("Recording", "Num_Of_Nodes");
00338 }
00339 if (nnodes > 0) {
00340 int n = io_get_sim_data_num_of_elements();
00341 double dist = 150;
00342 float ang = 2.0 * M_PI / nnodes;
00343 for (int i = 0; i < nnodes; i++) {
00344 areadx->addRobot("N" + nts(i));
00345 int xp = (int) (dist * cos((float) i * ang));
00346 int yp = (int) (dist * sin((float) i * ang));
00347 areadx->setRobotPose(i, alignment21->get_width()/2 + xp, yp, 0, 0);
00348 }
00349
00350 for (int i = 0; i < nnodes; i++) {
00351 areasx->addRobot("N" + nts(i));
00352 int xp = (int) (dist * cos((float) i * ang));
00353 int yp = (int) (dist * sin((float) i * ang));
00354 areasx->setRobotPose(i, alignment21->get_width()/2 + xp, yp, 0, 0);
00355 }
00356
00357 MyArea->setNumOfNodes(nnodes);
00358 if (n - 2 > 0){
00359 hscale_position->set_range(0, n - 2);
00360
00361 spinbutton1->set_range(0, 1000000000);
00362 hscale_position->set_sensitive(true);
00363 spinbutton1->set_sensitive(true);
00364 button23->set_sensitive(true);
00365 button6->set_sensitive(true);
00366 button7->set_sensitive(true);
00367 } else{
00368 hscale_position->set_range(0,100);
00369 hscale_position->set_sensitive(false);
00370 spinbutton1->set_range(0, 100);
00371 spinbutton1->set_sensitive(false);
00372 button23->set_sensitive(false);
00373 button6->set_sensitive(false );
00374 button7->set_sensitive(false);
00375 }
00376 hscale_zoom->set_range(20, 100);
00377 hscale_position->set_value(0);
00378 hscale_zoom->set_value(50);
00379 this->fill_screen();
00380 } else {
00381 areadx->clearLinks();
00382 areadx->clearRobots();
00383
00384 areasx->clearLinks();
00385 areasx->clearRobots();
00386
00387 MyArea->clean_window();
00388 MyArea->setNumOfNodes(4);
00389 hscale_position->set_range(0, 100);
00390 hscale_zoom->set_value(50);
00391 hscale_zoom->set_range(20, 100);
00392 }
00393 }
00394
00395 void main_window::on_w_resize(GdkEventConfigure* event) {
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407 sigc::slot<bool> my_slot = sigc::bind(sigc::mem_fun(*this,&main_window::MyCallback), 1);
00408
00409
00410 sigc::connection conn = Glib::signal_timeout().connect(my_slot,
00411 50);
00412
00413 }
00414 bool main_window::MyCallback(int n) {
00415 vpaned1->set_position(vpaned1->get_height()*0.7);
00416 hpaned->set_position(hpaned->get_width()*0.7);
00417 double dist = 150;
00418 float ang = 2.0 * M_PI / nnodes;
00419 for (int i = 0; i < nnodes; i++) {
00420 int xp = (int) (dist * cos((float) i * ang));
00421 int yp = (int) (dist * sin((float) i * ang));
00422 areadx->setRobotPose(i, alignment21->get_width() / 2 + xp, yp, 0, 0);
00423 }
00424
00425 for (int i = 0; i < nnodes; i++) {
00426 int xp = (int) (dist * cos((float) i * ang));
00427 int yp = (int) (dist * sin((float) i * ang));
00428 areasx->setRobotPose(i, alignment21->get_width() / 2 + xp, yp, 0, 0);
00429 }
00430 return false;
00431 }
00432
00433 main_window::~main_window() {
00434
00435 }
00436 #include "icon.h"
00437 main_window::main_window(char * s_iface) :
00438 main_window_glade() {
00439 set_icon(Gdk::Pixbuf::create_from_xpm_data(icon));
00440 PF(fprintf(stderr,"**PF** main_window::main_window \n");)
00441 prim_cb->hide();
00442 mw = this;
00443 w1 = NULL;
00444 w2 = NULL;
00445 k = playing = recording = 0;
00446
00447
00448
00449 struct stat st;
00450 ostringstream oss,oss2;
00451 oss << getenv("HOME") << "/.wmpSniffer";
00452 oss2 << oss.str();
00453
00454 if(stat(oss.str().c_str(),&st) != 0){
00455 std::cerr << "Creating Directory..." << oss.str().c_str() << std::endl;
00456 mkdir(oss.str().c_str(),0x777);
00457 }
00458 oss << "/wmpSniffer.conf";
00459 oss2 << "/active";
00460
00461 FILE * flock = fopen(oss2.str().c_str(),"w");
00462 if (flock!=0) {
00463 fclose(flock);
00464 }
00465
00466 cfg_file = oss.str();
00467
00468 areadx = new class area();
00469 areasx = new class area();
00470 areadx->setMargins(200, 200, -200, -200);
00471 areasx->setMargins(200, 200, -200, -200);
00472
00473
00474
00475 alignment22->add(*areasx);
00476 alignment21->add(*areadx);
00477 nt_frame->set_visible(false);
00478
00479 MyArea = new class MyArea();
00480
00481 align1d->add(*MyArea);
00482
00483 this->signal_configure_event().connect_notify(sigc::mem_fun(this,
00484 &main_window::on_w_resize));
00485
00486
00487 this->signal_scroll_event().connect(sigc::mem_fun(*this,
00488 &main_window::on_main_window_scroll_event), false);
00489 Glib::signal_timeout().connect(sigc::mem_fun(*this,
00490 &main_window::timer_callback), 100);
00491 this->add_events(Gdk::EXPOSURE_MASK | Gdk::POINTER_MOTION_MASK
00492 | Gdk::POINTER_MOTION_HINT_MASK | Gdk::BUTTON_MOTION_MASK
00493 | Gdk::BUTTON1_MOTION_MASK | Gdk::BUTTON2_MOTION_MASK
00494 | Gdk::BUTTON3_MOTION_MASK | Gdk::BUTTON_PRESS_MASK);
00495 m_refTreeModel = Gtk::TreeStore::create(m_Columns);
00496 xfield_tw->set_model(m_refTreeModel);
00497 xfield_tw->append_column("Message ",
00498 m_Columns.m_col_name);
00499 xfield_tw->append_column("Value", m_Columns.m_col_value);
00500
00501 MyArea->show();
00502 areadx->show();
00503 areasx->show();
00504
00505 io_init();
00506 time_t tiempo;
00507 struct tm *tmPtr;
00508 tiempo = time(NULL);
00509 tmPtr = localtime(&tiempo);
00510
00511
00512
00513 kf = new Glib::KeyFile();
00514 try {
00515 kf->load_from_file(cfg_file.c_str());
00516 } catch (...) {
00517 cerr << "Config file not found, using default values..." << endl;
00518 kf->set_integer("Recording", "Num_Of_Nodes", 7);
00519 kf->set_integer("Recording", "Rec_Type", 1);
00520 kf->set_string("Recording", "Filename", "");
00521 kf->set_string("Recording", "Executable", "");
00522 kf->set_integer("Recording", "Shmem_compile", 1);
00523 kf->set_integer("Recording", "Shmem_execute", 1);
00524 kf->set_string("Recording", "Args", "%i %n");
00525 kf->set_string("Files", "Last_Opened", "rt-wmp.vis");
00526 kf->set_string("Interfaces", "Sniffer", "wlan0");
00527 kf->set_string("Interfaces", "Remote_Sniffer", "eth0");
00528 kf->set_integer("Gui", "Show_Prim", 1);
00529 kf->set_integer("Gui", "Show_2D", 1);
00530 kf->set_integer("Gui", "Show_Text", 0);
00531 kf->set_integer("Gui", "Show_Frames", 1);
00532 kf->set_integer("Gui", "Show_Foreign", 0);
00533 }
00534 int val = kf->get_integer("Gui", "Show_Prim");
00535 prim_cb->set_active(val);
00536 val = kf->get_integer("Gui", "Show_Foreign");
00537 foreign_cb->set_active(val);
00538 val=kf->get_integer("Gui", "Show_2D");
00539 d2_cb->set_active(val);
00540 val=kf->get_integer("Gui", "Show_Text");
00541 text_cb->set_active(val);
00542 val=kf->get_integer("Gui", "Show_Frames");
00543 d1_cb->set_active(val);
00544
00545 if (s_iface != NULL){
00546 kf->set_string("Interfaces", "Sniffer" ,s_iface);
00547 }
00548
00549 Glib::ustring s = kf->get_string("Interfaces", "Sniffer");
00550 sprintf(iface,"%s",s.c_str());
00551 s = kf->get_string("Interfaces", "Remote_Sniffer");
00552 sprintf(sniff_iface,"%s",s.c_str());
00553
00554 s = kf->get_string("Files", "Last_Opened");
00555 sprintf(filename,"%s",s.c_str());
00556 reset();
00557
00558 Gtk::Menu::MenuList& menulist = m_Menu_Popup.items();
00559 menulist.push_back(Gtk::Menu_Helpers::MenuElem("_Show_path", sigc::mem_fun(
00560 *this, &main_window::show_path)));
00561 m_Menu_Popup.accelerate(*this);
00562 xfield_tw->signal_button_press_event().connect(sigc::mem_fun(*this, &main_window::on_xfield_tw_button_press_event), false);
00563 xfield_tw->modify_font(Pango::FontDescription("Courier"));
00564
00565 hpaned->set_position(hpaned->get_width()*0.7);
00566 vpaned1->set_position(vpaned1->get_height()*0.7);
00567 hpaned1->set_position(hpaned1->get_width()*0.5);
00568
00569 timer = idx3 = 0;
00570 Glib::Thread *const updater = Glib::Thread::create(
00571 sigc::mem_fun(this, &main_window::updater), true);
00572 w3 = 0;
00573 }
00574 void main_window::show_path(){
00575 #ifdef ENABLE_WMP_DEBUG
00576 if (selectedFrame.hdr.type==MESSAGE){
00577 print_path(selectedFrame.hdr.path,selectedFrame.msg.dest);
00578 }
00579 #endif
00580 }
00581
00582 bool main_window::on_xfield_tw_button_press_event(GdkEventButton *ev) {
00583 if ((ev->type == GDK_BUTTON_PRESS) && (ev->button == 3)) {
00584 if (selectedFrame.hdr.type==MESSAGE){
00585 m_Menu_Popup.popup(ev->button, ev->time);
00586 }
00587 }
00588 return false;
00589 }
00590
00591 void getDataString(void * q, int size, char * txt){
00592 if (size > 2500) size = 2500;
00593 char *k = (char * ) q;
00594 for (int i=0, j=0;i < size ; i++){
00595 if (k[i]>=32 && k[i]<=126){
00596 txt[j] = k[i];
00597 } else{
00598 txt[j] = '.';
00599 }
00600 j++;
00601 if (j%33==32){
00602 txt[j] = '\n';
00603 j++;
00604 }
00605 txt[j] = 0;
00606 }
00607 }
00608
00609 void main_window::update_frame_info(simData_Hdr * p, wmpFrame * q) {
00610 row_append("Frame Info", "");
00611 row_child_append("Type", nts(p->frame_type));
00612 row_child_append("Len", nts(p->len) + "B");
00613
00614 row_child_append("Num nodes", nts(p->num_nodes));
00615
00616
00617 double time = (double) p->time / 1000;
00618 row_child_append("Time", nts(time));
00619 row_child_append("Protocol", "0x"+hnts(p->proto));
00620 char txt[p->len + 1000];
00621 getDataString(q,p->len,txt);
00622 row_child_append("RAW", txt);
00623 }
00624
00625 void main_window::saveRowsStatus() {
00626 Gtk::TreeModel::Children children = m_refTreeModel->children();
00627 for (Gtk::TreeModel::Children::iterator iter = children.begin(); iter
00628 != children.end(); ++iter) {
00629 Gtk::TreeModel::Row row = *iter;
00630 string exp_name((Glib::ustring(row[m_Columns.m_col_name])).c_str());
00631 Gtk::TreeModel::Path p = m_refTreeModel->get_path(iter);
00632 rows_expanded[exp_name] = xfield_tw->row_expanded(p);
00633 }
00634 }
00635
00636 void main_window::restoreRowsStatus() {
00637 Gtk::TreeModel::Children children = m_refTreeModel->children();
00638 for (Gtk::TreeModel::Children::iterator iter = children.begin(); iter
00639 != children.end(); ++iter) {
00640 Gtk::TreeModel::Row row = *iter;
00641 string exp_name((Glib::ustring(row[m_Columns.m_col_name])).c_str());
00642 bool to_expand = rows_expanded[exp_name];
00643 if (to_expand) {
00644 Gtk::TreeModel::Path p = m_refTreeModel->get_path(iter);
00645 xfield_tw->expand_row(p, true);
00646 }
00647 }
00648 }
00649
00650 void main_window::draw_stuffs(char * data, int pos_in_file, int show_f,
00651 int show_2D_f, int show_t) {
00652 PF(fprintf(stderr,"**PF** main_window::draw_stuffs \n");)
00653 simData_Hdr * p = (simData_Hdr *) data;
00654 wmpFrame * r = (wmpFrame *) (data + sizeof(simData_Hdr));
00655
00656 frame_time = p->time;
00657 selectedFrame = *r;
00658 MyArea->setActive(r->hdr.from);
00659
00660 if (show_t) {
00661
00662 double ms;
00663 int sec;
00664 sec = (int) ((double) p->time / 1000000.0);
00665 ms = (double) (p->time % 1000000) / 1000.0;
00666
00667 saveRowsStatus();
00668 m_refTreeModel->clear();
00669 row_append("Time", nts(sec) + "s " + nts(ms) + "ms");
00670 row_child_append("Id", nts(pos_in_file));
00671 update_frame_info(p, r);
00672
00673 if (p->frame_type != SP_FOREIGN) {
00674 update_frame_labels(r);
00675 show_routing_data(r);
00676 show_qos_data(r);
00677 show_broadcast_data(r);
00678
00679 }
00680 restoreRowsStatus();
00681
00682 }
00683
00684 if (show_f) {
00685 int col = r->hdr.type;
00686 int nt = (r->hdr.type == TOKEN);
00687 if (p->frame_type == SP_LUS_WMP_FRAME_DUP) {
00688 col = 9;
00689 MyArea->insertOne(r->hdr.from, r->hdr.to, p->time, pos_in_file,
00690 r->hdr.serial, col, nt);
00691 k++;
00692 } else if (p->frame_type == SP_FOREIGN) {
00693 col = 8;
00694 nt = 2;
00695 MyArea->insertOne(0, p->num_nodes - 1, p->time, pos_in_file, 0,
00696 col, nt);
00697 k++;
00698 } else {
00699 if (r->hdr.type == MESSAGE){
00700 if (!mBitsIsSet(r->msg.type, 4)){
00701 col = 11;
00702 }
00703 #ifdef WMP_ROUTING_tree
00704 if (!mBitsIsSet(r->msg.type,4)){
00705 col = 10;
00706 }
00707 #endif
00708 }
00709 if (r->hdr.type == DROP_TOKEN){
00710 col = 0;
00711 }
00712 if (r->hdr.type == ACK){
00713 col = 1;
00714 }
00715 int f_idx = MyArea->insertOne(r->hdr.from, r->hdr.to, p->time,
00716 pos_in_file, r->hdr.serial, col, nt);
00717 k++;
00718 if (r->hdr.retries > 0) {
00719 MyArea->addMark(f_idx);
00720 }
00721 if (p->time_source == 99) {
00722 MyArea->addLeftCross(f_idx);
00723 }
00724
00725
00726
00727
00728 MyArea->addDot(f_idx, r->hdr.from, 0);
00729
00730
00731
00732
00733 #ifdef ENABLE_WMP_DEBUG
00734 if (r->hdr.last_to >0) {
00735 MyArea->addCross(f_idx);
00736 }
00737 #endif
00738 }
00739 }
00740
00741 #ifdef ENABLE_WMP_DEBUG
00742 if (r->hdr.sender_pow >= 0){
00743 areadx->setRobotPose(r->hdr.from,10*r->hdr.sender_x, 10*r->hdr.sender_y, 0, 0);
00744 areasx->setRobotPose(r->hdr.from,10*r->hdr.sender_x, 10*r->hdr.sender_y, 0, 0);
00745 } else {
00746 for (int i = 0; i < nnodes; i++) {
00747 if (q->pose_is_valid) {
00748 areadx->setRobotPose(i, q->x, q->y, q->a, 0);
00749 areasx->setRobotPose(i, q->x, q->y, q->a, 0);
00750 } else {
00751 float dist = 100;
00752 float ang = 2.0 * M_PI / nnodes;
00753 int xp = (int) (dist * cos((float)i * ang));
00754 int yp = (int) (dist * sin((float)i * ang));
00755
00756 }
00757 q++;
00758 }
00759 }
00760 #endif
00761 if (show_2D_f) {
00762 if (p->frame_type != SP_FOREIGN) {
00763 areadx->clearLinks(2);
00764 areasx->clearLinks(2);
00765
00766
00767
00768
00769
00770
00771 #ifdef WMP_ROUTING_tree
00772 areadx->clearLinks(1);
00773 areasx->clearLinks(1);
00774 char * p1;
00775
00776
00777 areasx->addLink(r->hdr.from, r->hdr.to,1, r->hdr.type, 2);
00778
00779
00780 p1 = wmp_get_frame_routing_pointer(r, nnodes);
00781 for (int i = 0; i < nnodes; i++) {
00782 if (p1[i]>=0 && p1[i]<32) {
00783
00784 areasx->addLink(i,p1[i],0,0,1,1);
00785 }
00786 }
00787
00788 if (r->hdr.type == TOKEN){
00789 p1 = wmp_get_frame_routing_pointer(r, nnodes) + 2 * nnodes;
00790
00791
00792 for (int i = 0; i < nnodes; i++) {
00793 if (p1[i]>=0 && p1[i]<32) {
00794 areadx->addLink(i, p1[i], 0, 0, 1, 1);
00795 }
00796 }
00797 } else{
00798 areadx->clearLinks();
00799
00800 }
00801
00802
00803
00804 for (int i = 0; i < nnodes; i++) {
00805 if (i == r->hdr.to) {
00806 areadx->setRobotColor(i, r->hdr.type);
00807 areasx->setRobotColor(i, r->hdr.type);
00808 } else {
00809 areadx->setRobotColor(i, 0);
00810 areasx->setRobotColor(i, 0);
00811 }
00812 }
00813 #else
00814
00815
00816
00817 if (r->hdr.type == TOKEN) {
00818 areadx->clearLinks(0);
00819 areadx->clearLinks(1);
00820 areasx->clearLinks(0);
00821 areasx->clearLinks(1);
00822 char * p1 = wmp_get_frame_routing_pointer(r, nnodes);
00823 char p2[nnodes*nnodes];
00824 memcpy(p2,p1,nnodes*nnodes);
00825 if (prim_cb->get_active()) {
00826 try {
00827 prim(p1, nnodes);
00828 } catch (...) {
00829
00830 }
00831 }
00832
00833 int idxxx=0;
00834 for (int i = 0; i < nnodes; i++) {
00835 for (int j = 0; j < nnodes; j++) {
00836 if ((*p1) && i != j) {
00837 float val = (float) (p2[idxxx]);
00838 areadx->addLink(i, j, 0, 0, val, 1);
00839 }
00840 p1++;
00841 idxxx++;
00842 }
00843 }
00844
00845 idxxx=0;
00846 char *p3 = p2;
00847 for (int i = 0; i < nnodes; i++) {
00848 for (int j = 0; j < nnodes; j++) {
00849 if ((*p3) && i != j) {
00850 float val = (float) (*p3);
00851 areasx->addLink(i, j, 0, 0, val, 1);
00852 }
00853 p3++;
00854
00855 }
00856 }
00857 }
00858 int color=r->hdr.type;
00859 if (color==6){
00860 color = 1;
00861 }
00862
00863 areadx->addLink(r->hdr.from, r->hdr.to,1, color,2);
00864 areasx->addLink(r->hdr.from, r->hdr.to,1, color,2);
00865 #endif
00866
00867
00868 for (int i = 0; i < nnodes; i++) {
00869 if (i == r->hdr.from || i == r->hdr.to){
00870 areadx->setRobotColor(i, r->hdr.type);
00871 }else{
00872 areadx->setRobotColor(i, 0);
00873 }
00874 }
00875 }
00876 }
00877
00878 }
00879
00880 void main_window::begin_play() {
00881 PF(fprintf(stderr,"**PF** main_window::begin_play \n");)
00882 int pos = (int) hscale_position->get_value();
00883 hscale_position->set_sensitive(false);
00884 hscale_zoom->set_sensitive(false);
00885 MyArea->clean_window();
00886 io_go_to(pos);
00887 play_idx = 0, play_idx2 = pos;
00888 playing = 1;
00889 }
00890
00891 void main_window::statistics(char * text) {
00892 PF(fprintf(stderr,"**PF** main_window::statistics \n");)}
00893
00894 void main_window::continue_play() {
00895 PF(fprintf(stderr,"**PF** main_window::continue_play \n");)
00896 char data[2500];
00897 int bytes = io_read_next_sim_data(&data[0]);
00898 if (bytes > 0) {
00899 int elem = (int) hscale_zoom->get_value();
00900 if (play_idx > elem)
00901 MyArea->delete_older();
00902 int n = MyArea->get_older_offset();
00903 if (n >= 0)
00904 hscale_position->set_value(n);
00905 draw_stuffs(&data[0], play_idx2, 1, 1, 1);
00906 play_idx++;
00907 play_idx2++;
00908 } else
00909 stop_playing();
00910 }
00911
00912 void main_window::stop_playing() {
00913 PF(fprintf(stderr,"**PF** main_window::stop_playing \n");)
00914 playing = 0;
00915 togglebutton1->set_active(false);
00916 hscale_position->set_sensitive(true);
00917 hscale_zoom->set_sensitive(true);
00918 }
00919
00920 #include "window3.hh"
00921
00922 int shmem_pre_init();
00923
00924 bool main_window::begin_online_record() {
00925 PF(fprintf(stderr,"**PF** main_window::begin_record \n");)
00926
00927 if (w2){
00928 w2->hide();
00929 delete(w2);
00930 w2 = 0;
00931 }
00932
00933 rp_dlg = new class rec_param_dlg();
00934
00935 int nn = kf->get_integer("Recording", "Num_Of_Nodes");
00936 rp_dlg->num_node_spin->set_value(nn);
00937 int rec_type_rb = kf->get_integer("Recording", "Rec_Type");
00938
00939 string args = kf->get_string("Recording", "Args");
00940 rp_dlg->param_txt->set_text(args);
00941
00942
00943 string shmem_file = kf->get_string("Recording", "Executable");
00944 if (rec_type_rb == 1) {
00945 rp_dlg->real_rb->set_active();
00946 } else if (rec_type_rb == 3) {
00947 rp_dlg->marte_rb->set_active();
00948 }else if (rec_type_rb == 4) {
00949 rp_dlg->shmem_rb->set_active();
00950 }
00951 rp_dlg->compile_cb->set_active(kf->get_integer("Recording", "Shmem_compile"));
00952 rp_dlg->exec_cb->set_active(kf->get_integer("Recording", "Shmem_execute"));
00953
00954 rp_dlg->shmem_file->set_text(shmem_file.c_str());
00955 rp_dlg->filename_txt->set_text(this->filename);
00956
00957 int res = rp_dlg->run();
00958 if (res == Gtk::RESPONSE_CANCEL) {
00959 delete (rp_dlg);
00960 return false;
00961 }
00962
00963 nn = rp_dlg->num_node_spin->get_value_as_int();
00964 kf->set_integer("Recording", "Num_Of_Nodes", nn);
00965
00966 bool compilee = rp_dlg->compile_cb->get_active();
00967 bool executee = rp_dlg->exec_cb->get_active();
00968 kf->set_integer("Recording", "Shmem_compile", rp_dlg->compile_cb->get_active());
00969 kf->set_integer("Recording", "Shmem_execute", rp_dlg->exec_cb->get_active());
00970 kf->set_integer("Recording", "Rec_Type", rec_type_rb);
00971 kf->set_string("Recording", "Executable",rp_dlg->shmem_file->get_text());
00972 kf->set_string("Recording", "Args",rp_dlg->param_txt->get_text());
00973
00974 save_cfg_file();
00975
00976
00977 ostringstream oss;
00978 oss << "rt-wmp-" << nn << "N.vis";
00979
00980 strcpy(this->filename,rp_dlg->filename_txt->get_text().c_str());
00981 io_change_file(this->filename);
00982
00983
00984
00985 this->set_title("wmpSniffer -" + std::string(this->filename));
00986 kf->set_string("Files", "Last_Opened" ,this->filename);
00987
00988 hscale_position->set_value(0);
00989 hscale_position->set_sensitive(false);
00990 hscale_zoom->set_sensitive(false);
00991 button23->set_sensitive(false);
00992 spinbutton1->set_sensitive(false);
00993 nnodes = nn;
00994 reset(nn);
00995
00996 if (rp_dlg->real_rb->get_active()) {
00997 rec_type = ST_PCAP;
00998 rec_type_rb = 1;
00999 } else if (rp_dlg->marte_rb->get_active()) {
01000 rec_type = ST_MARTE;
01001 rec_type_rb = 3;
01002 } else if (rp_dlg->shmem_rb->get_active()) {
01003 rec_type = ST_SHARED_MEM;
01004 rec_type_rb = 4;
01005 if (rp_dlg->shmem_file->get_text() != "") {
01006 if (compilee || executee) {
01007 if (w3 == 0) {
01008 w3 = new window3();
01009 }
01010 w3->create(nn);
01011 w3->show();
01012 shmem_pre_init();
01013 w3->compile_and_execute(rp_dlg->compile_cb->get_active(),
01014 rp_dlg->exec_cb->get_active(),
01015 rp_dlg->log_cb->get_active(), nn,
01016 rp_dlg->shmem_file->get_text(),
01017 rp_dlg->param_txt->get_text());
01018 }
01019 }
01020 }
01021 rp_dlg->hide();
01022 delete (rp_dlg);
01023 reset_actual_gct();
01024 play_idx = 0;
01025 if (!begin_record()){
01026 return false;
01027 }
01028 return true;
01029 }
01030
01031 bool main_window::begin_record(){
01032 recording = 1;
01033 play_idx = 0;
01034
01035 sleep(1);
01036 areadx->clearLinks();
01037 areadx->clearLinks(1);
01038 areadx->clearRobots();
01039 areasx->clearLinks();
01040 areasx->clearLinks(1);
01041 areasx->clearRobots();
01042 MyArea->clean_window();
01043 MyArea->setNumOfNodes(nnodes);
01044 double dist = 200;
01045
01046
01047 float ang = 2.0 * M_PI / nnodes;
01048 for (int i = 0; i < nnodes; i++) {
01049 areadx->addRobot("N" + nts(i));
01050 int xp = (int) (dist * cos((float) i * ang));
01051 int yp = (int) (dist * sin((float) i * ang));
01052 areadx->setRobotPose(i, alignment21->get_width()/2 + xp, yp, 0, 0);
01053 }
01054
01055
01056 for (int i = 0; i < nnodes; i++) {
01057 areasx->addRobot("N" + nts(i));
01058 int xp = (int) (dist * cos((float) i * ang));
01059 int yp = (int) (dist * sin((float) i * ang));
01060 areasx->setRobotPose(i, alignment21->get_width()/2 + xp, yp, 0, 0);
01061 }
01062
01063 areadx->clearPoints();
01064 areadx->addPoint(-sim_xsize / 2, -sim_ysize / 2, 0);
01065 areadx->addPoint(sim_xsize / 2, sim_ysize / 2, 0);
01066
01067 areasx->clearPoints();
01068 areasx->addPoint(-sim_xsize / 2, -sim_ysize / 2, 0);
01069 areasx->addPoint(sim_xsize / 2, sim_ysize / 2, 0);
01070
01071 hscale_zoom->set_value(50);
01072 reset_actual_gct();
01073 if (!start_bridge(nnodes, rec_type)){
01074 return false;
01075 }
01076 return true;
01077 }
01078
01079 void main_window::continue_record(char * data, int data_size) {
01080 PF(fprintf(stderr,"**PF** main_window::continue_record \n");)
01081 int elem = (int) hscale_zoom->get_value();
01082 if (play_idx > elem){
01083 MyArea->delete_older();
01084 }
01085 if (!d1_cb->get_active()){
01086 MyArea->clean_window();
01087 play_idx = 0;
01088 }
01089 draw_stuffs(&data[0], play_idx, d1_cb->get_active(), d2_cb->get_active(), text_cb->get_active() && !tw_has_focus && timered_show_t);
01090 timered_show_t = false;
01091 memcpy(data_backup, data, data_size);
01092 play_idx++;
01093 simData_Hdr * p = (simData_Hdr *) data;
01094 wmpFrame * r = (wmpFrame *) (data + sizeof(simData_Hdr));
01095
01096 if (w2 && w2->is_visible()) {
01097 if (p->is_wmp) {
01098 statistics_new_frame(r, p->time, play_idx, 1000);
01099 }
01100 }
01101 }
01102 void main_window::recording_stopped(){
01103 gdk_threads_enter();
01104 if (w3) {
01105 w3->die();
01106 }
01107 recording = false;
01108 hscale_position->set_sensitive(true);
01109 hscale_zoom->set_sensitive(true);
01110 gdk_threads_leave();
01111
01112 sleep(1);
01113
01114 gdk_threads_enter();
01115 reset();
01116 hscale_position->set_sensitive(true);
01117 hscale_zoom->set_sensitive(true);
01118 button8->set_sensitive(true);
01119 button6->set_sensitive(true);
01120 button7->set_sensitive(true);
01121 button13->set_sensitive(true);
01122 button9->set_sensitive(true);
01123 togglebutton1->set_sensitive(true);
01124 rec_tb->set_sensitive(true);
01125 rec_tb->set_active(false);
01126 gdk_threads_leave();
01127 }
01128
01129 void main_window::request_stop_recording() {
01130 PF(fprintf(stderr,"**PF** main_window::stop_recording \n");)
01131 stop_bridge();
01132 if (rec_type == ST_SHARED_MEM) {
01133 }
01134 }
01135
01136 void main_window::fill_screen() {
01137 PF(fprintf(stderr,"**PF** main_window::fill_screen \n");)
01138 int pos = (int) hscale_position->get_value();
01139 int elem = (int) hscale_zoom->get_value();
01140 MyArea->clean_window();
01141 char data[2500];
01142 k = 0;
01143 if (io_go_to(pos)<0) {
01144 return;
01145 };
01146
01147 for (int i = 0; i < elem; i++) {
01148 int bytes = io_read_next_sim_data(&data[0]);
01149
01150 if (bytes <= 0){
01151 continue;
01152 }
01153
01154 if (i == elem - 1) {
01155 draw_stuffs(&data[0], pos, 1, 1, 1);
01156 }else{
01157 draw_stuffs(&data[0], pos, 1, 1, 0);
01158 }
01159 pos++;
01160 }
01161
01162 }
01163
01164 bool main_window::on_main_window_motion_notify_event(GdkEventMotion *ev) {
01165 PF(fprintf(stderr,"**PF** main_window::on_main_window_motion_notify_event \n");)
01166 update_pose_labels();
01167 if (playing || recording) return false;
01168 int v1 = MyArea->get_selected_time();
01169 int v2 = MyArea->get_mouse_on_time();
01170 int v3 = MyArea->get_mouse_on_serial();
01171 int v4 = MyArea->get_selected_serial();
01172 label71->set_text("");
01173 label70->set_text("");
01174 label69->set_text("");
01175 if (v1 > 0 && v2 > 0) {
01176 label70->set_text("D: " + nts((int) (v2 - v1) / 1000000) + "s " + nts(
01177 (double) ((v2 - v1) % 1000000) / 1000.0) + "ms");
01178 }
01179 if (v3 > 0) {
01180 label68->set_text("Serial: " + nts(v3));
01181 if (v4 > 0) {
01182 label69->set_text("SD: " + nts(abs((int) (v4 - v3))));
01183 } else {
01184
01185 }
01186 } else {
01187
01188 }
01189 return false;
01190 }
01191
01192 bool main_window::on_main_window_button_press_event(GdkEventButton *ev) {
01193 PF(fprintf(stderr,"**PF** main_window::on_main_window_button_press_event \n");)
01194 if (playing || recording) return true;
01195
01196 if ((ev->type == GDK_BUTTON_PRESS)) {
01197
01198 int s = MyArea->get_offset_of_selected();
01199 if (s >= 0) {
01200 char data[2500];
01201 io_go_to(s);
01202 io_read_next_sim_data(data);
01203
01204
01205
01206
01207 draw_stuffs(data, s, 0, 1, 1);
01208 }
01209 if (ev->button == 3 && selectedFrame.hdr.type == MESSAGE) {
01210 m_Menu_Popup.popup(ev->button, ev->time);
01211 }
01212 }
01213 return true;
01214 }
01215
01216 void main_window::update_pose_labels() {
01217 PF(fprintf(stderr,"**PF** main_window::update_pose_labels \n");)
01218 double x, y, a;
01219 int t = areadx->get_selected();
01220 if (t >= 0) {
01221 int res = areadx->getRobotPose(t, &x, &y, &a);
01222 if (res >= 0) {
01223
01224 }
01225 }
01226 }
01227 int main_window::checkstring(char * txt) {
01228 PF(fprintf(stderr,"**PF** main_window::checkstring \n");)
01229
01230 for (int i = 0; i < strlen(txt); i++) {
01231
01232 if (txt[i] < (char) 32 || txt[i] > (char) 125){
01233 return 0;
01234 }
01235 }
01236 return 1;
01237
01238 }
01239 void main_window::show_broadcast_data(wmpFrame *f) {
01240 #ifdef ENABLE_BC_SUPPORT
01241 if (f->hdr.bc_len > 0) {
01242 row_append("Broadcast", "");
01243 row_child_append("BC Type", nts(f->hdr.bc_type));
01244 if (f->hdr.bc_type == BC_TYPE_PLUS) {
01245 Simple_bc * sbc =
01246 (Simple_bc*) wmp_get_frame_tail_pointer(f, nnodes);
01247 row_child_append("BC Len", nts(sbc->len));
01248
01249 row_child_append("MaxPri", nts(sbc->maxPri));
01250 row_child_append("MaxPriId", nts(sbc->idMaxPri));
01251 row_child_append("Age", nts((int) sbc->age));
01252
01253
01254
01255 row_child_append("Destination", "");
01256 for (int i = 0; i < 16; i++) {
01257 int val = (sbc->dest & (unsigned int) pow(2.0, (double) i)) > 0;
01258 if (val) {
01259 row_child_child_append("Node", nts(i));
01260 }
01261 }
01262 char txt[sbc->len + 1000];
01263 getDataString(&sbc->data,sbc->len,txt);
01264 row_child_append("Data", txt);
01265 }
01266 }
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286 #endif
01287 }
01288
01289 void main_window::show_routing_data(wmpFrame *f) {
01290 PF(fprintf(stderr,"**PF** main_window::show_routing_data \n");)
01291 #ifdef WMP_ROUTING_tree
01292 if (f->hdr.type == TOKEN) {
01293 row_append("Status", " ");
01294 char * cp = wmp_get_frame_routing_pointer_tree(f,nnodes);
01295 cp += nnodes;
01296 ostringstream s1, s2;
01297 for (int i = 0; i < nnodes; i++) {
01298 s1 << "Node " << i;
01299 char txt[20];
01300 dec2bin((unsigned char) cp[i], txt);
01301 s2 << (char) txt[0] << " " << (char) txt[1] << " " << (char) txt[2]
01302 << " " << &txt[3];
01303 row_child_append(s1.str(), s2.str());
01304 s1.str("");
01305 s2.str("");
01306 }
01307 }
01308 #else
01309 if (f->hdr.type == TOKEN){
01310
01311 row_append("Routing", " ");
01312
01313 char lqm[10000], tmp[2000];
01314 sprintf(lqm, "%s","");
01315 char *cp = (char *) f;
01316 cp += sizeof(Token_Hdr) + sizeof(Token);
01317
01318 strcat(lqm, " ");
01319 for (int i = 0; i < nnodes; i++) {
01320 sprintf(tmp, "%3d ", i);
01321 strcat(lqm, tmp);
01322 }
01323 strcat(lqm, "\n");
01324
01325 strcat(lqm, " ");
01326 for (int i = 0; i < nnodes; i++) {
01327 sprintf(tmp, "----");
01328 strcat(lqm, tmp);
01329 }
01330 strcat(lqm, "\n");
01331
01332 for (int i = 0; i < nnodes; i++) {
01333 sprintf(tmp, "%2d - ", i);
01334 strcat(lqm, tmp);
01335 for (int j = 0; j < nnodes; j++) {
01336 if (i != j) {
01337 sprintf(tmp, "%3d ", (int) *cp);
01338 strcat(lqm, tmp);
01339 } else {
01340 strcat(lqm, " 0 ");
01341 }
01342 cp++;
01343 }
01344 strcat(lqm, "\n");
01345 }
01346 xfield_tw->modify_font(Pango::FontDescription("Courier"));
01347 row_child_append("LQM", lqm);
01348 row_append("Status", " ");
01349 row_child_append("Node Id", "R L U NEXT");
01350 cp = (char *) f;
01351 cp += sizeof(Token_Hdr) + sizeof(Token);
01352 ostringstream s1, s2;
01353 for (int i = 0; i < nnodes; i++) {
01354 s1 << "Node " << i;
01355 char txt[20];
01356 dec2bin((unsigned char) *cp, txt);
01357 s2 << (char) txt[0] << " " << (char) txt[1] << " " << (char) txt[2]
01358 << " " << &txt[3];
01359 row_child_append(s1.str(), s2.str());
01360 s1.str("");
01361 s2.str("");
01362 cp += (nnodes + 1);
01363 }
01364 }
01365 #endif
01366 }
01367
01368 void main_window::update_frame_labels(wmpFrame * f) {
01369
01370 PF(fprintf(stderr,"**PF** main_window:: \n");)
01371
01372 #ifdef ENABLE_WMP_DEBUG
01373 row_append("Debug","");
01374
01375 row_child_append("Timeout",nts(f->hdr.timeout));
01376 row_child_append("Elapsed",nts(abs(f->hdr.last_to)));
01377 row_child_append("Informing Serial",nts(f->hdr.last_to_serial));
01378 row_child_append("Informing reported Key",nts(f->hdr.last_to_key));
01379 #ifdef V8
01380 row_child_append("Debug Text",std::string(f->hdr.debug));
01381 #endif
01382 int key = f->hdr.serial * 10000 + f->hdr.from * 1000 + f->hdr.to
01383 * 100 + f->hdr.retries * 10 + f->hdr.type;
01384 row_child_append("Frame Key",nts(key));
01385 row_child_append("Live config cmd ",nts(f->hdr.lc_cmd));
01386 row_child_append("Live config val ",nts(f->hdr.lc_value));
01387
01388 ostringstream oss;
01389 row_child_append("Reason",oss.str().c_str());
01390 int j=0;
01391 for (double i=0; i<6; i += 1.0, j++) {
01392 int val = ((((int) f->hdr.reason) & ((int)pow(2.0,i))) > 0);
01393 if (val) {
01394 switch (j) {
01395 case 0: row_child_child_append("SEARCHING","");
01396 break;
01397 case 1: row_child_child_append("SEARCH ALL","");
01398 break;
01399 case 2: row_child_child_append("NOTHING TO SEND","");
01400 break;
01401 case 3: row_child_child_append("ISOLATED","");
01402 break;
01403 case 4: row_child_child_append("GOING BACK","");
01404 break;
01405 case 5: row_child_child_append("GOING FORWARD","");
01406 break;
01407 case 6: row_child_child_append("NET INACTIVITY","");
01408 break;
01409 }
01410 }
01411 }
01412
01413 oss.str("");
01414
01415
01416
01417
01418
01419
01420 row_child_append("CPU Time",nts(f->hdr.node_tx_id));
01421
01422
01423 row_append("Position","");
01424 row_child_append("x",nts(f->hdr.sender_x));
01425 row_child_append("y",nts(f->hdr.sender_y));
01426 row_child_append("Power (mw)",nts(f->hdr.sender_pow));
01427
01428 #endif
01429
01430
01431 row_append("Header", "");
01432 row_child_append("Rssi", nts(f->hdr.rssi));
01433 row_child_append("Noise", nts(f->hdr.noise));
01434 row_child_append("Type", nts(f->hdr.type));
01435 row_child_append("Serial", nts((int) f->hdr.serial));
01436 row_child_append("From", nts((int)f->hdr.from));
01437 row_child_append("To", nts((int)f->hdr.to));
01438 row_child_append("Retries", nts(f->hdr.retries));
01439 row_child_append("Ack", nts(f->hdr.ack));
01440 row_child_append("Flow Control", nts(f->hdr.fc));
01441 row_child_append("Loop Id", nts(f->hdr.loop_id));
01442 row_child_append("Burst", nts(f->hdr.burst));
01443 row_child_append("Sleep", nts(f->hdr.sleep));
01444 row_child_append("Waiting", nts(f->hdr.waiting));
01445
01446
01447
01448 if (f->hdr.type == TOKEN) {
01449 row_append("Token", "");
01450 row_child_append("Beginner", nts((int) f->tkn.beginner));
01451 row_child_append("Max Priority", nts((int)f->tkn.maxPri));
01452 row_child_append("Id Max Pri", nts((int)f->tkn.idMaxPri));
01453 row_child_append("Age", nts((int) f->tkn.age));
01454 row_child_append("Ack Hash", nts((int) f->tkn.ack_hash));
01455 row_child_append("Ack Part", nts((int) f->tkn.ack_part));
01456
01457
01458
01459 } else if (f->hdr.type == AUTHORIZATION) {
01460 row_append("Authorization", "");
01461 row_child_append("Source", nts(f->aut.src));
01462 row_child_append("Destination", nts(f->aut.dest));
01463 row_child_append("Ack Hash", nts(f->aut.ack_hash));
01464 row_child_append("Ack Part", nts(f->aut.ack_part));
01465 ostringstream o1;
01466 for (int i = 0; i < nnodes; i++) {
01467 o1 << (int) (bool) (mBitsIsSet(f->aut.reached,i) != 0);
01468 }
01469 row_child_append("Reached", o1.str());
01470 } else if (f->hdr.type == MESSAGE) {
01471 row_append("Message", "");
01472 row_child_append("Type", "");
01473
01474 if (mBitsIsSet(f->msg.type,4)) {
01475 row_child_child_append("Aura", "Msg");
01476 } else {
01477 row_child_child_append("Aura", "Auth");
01478 }
01479 if (mBitsIsSet(f->msg.type,1)) {
01480 row_child_child_append("Burst", "Yes");
01481 } else {
01482 row_child_child_append("Burst", "No");
01483 }
01484 if (mBitsIsSet(f->msg.type,2)) {
01485 row_child_child_append("Rescheduled", "Yes");
01486 } else {
01487 row_child_child_append("Rescheduled", "No");
01488 }
01489 row_child_append("Source", nts(f->msg.src));
01490 row_child_append("Destination", nts(f->msg.dest));
01491 row_child_append("Port", nts(f->msg.port));
01492 row_child_append("Priority", nts((int)f->msg.priority));
01493 row_child_append("Length", nts(f->msg.len));
01494 row_child_append("Age", nts((int) f->msg.age));
01495
01496 row_child_append("Msg Hash", nts(f->msg.msg_hash));
01497 row_child_append("Msg Part ID", nts(f->msg.part_id));
01498
01499 ostringstream o1;
01500 for (int i = 0; i < nnodes; i++) {
01501 o1 << (int) (bool) (mBitsIsSet(f->msg.reached,i) != 0);
01502 }
01503 row_child_append("Reached", o1.str());
01504
01505
01506 char txt[f->msg.len + 100];
01507
01508 if (f->msg.len > 0){
01509 getDataString(wmp_get_message_data_pointer(f),f->msg.len,txt);
01510 row_child_append("Data", txt);
01511 }
01512
01513
01514
01515 #ifdef ENABLE_BC_SUPPORT
01516 if (f->hdr.bc_extra == 77){
01517 row_child_append("Rescheduled","Yes");
01518 }else{
01519 row_child_append("Rescheduled","No");
01520 }
01521 #endif
01522 #ifdef ENABLE_WMP_DEBUG
01523 ostringstream o1;
01524 for (int i = 0; i < nnodes; i++) {
01525 o1 << (int) (bool) (mBitsIsSet(f->msg.reached,i) != 0);
01526 }
01527 row_child_append("Reached", o1.str());
01528
01529 row_child_append("PATH: ", nts(f->hdr.path[0]));
01530 if (f->hdr.path[0] < 32) {
01531 for (int i = 1; i <= f->hdr.path[0]; i++) {
01532 if (f->hdr.path[i] >= 40) {
01533 row_child_child_append("Msg", nts(int(f->hdr.path[i] - 40)));
01534 } else if (f->hdr.path[i] >= 30) {
01535 row_child_child_append("Auth",
01536 nts(int(f->hdr.path[i] - 30)));
01537 } else if (f->hdr.path[i] >= 20) {
01538 row_child_child_append("Token", nts(
01539 int(f->hdr.path[i] - 20)));
01540 }
01541 }
01542 }
01543 #endif
01544 } else if (f->hdr.type == DROP_TOKEN) {
01545 row_append("Drop", "");
01546 row_child_append("Drop Serial", nts(f->drop.drop_serial));
01547 }else if (f->hdr.type == ACK) {
01548 row_append("Ack", "");
01549 row_child_append("Ack Serial", nts(f->drop.drop_serial));
01550 }
01551 }
01552
01553 void main_window::show_qos_data(wmpFrame * f) {
01554 #ifdef ENABLE_QOS_SUPPORT
01555 if (f->hdr.subtype == 97) {
01556 row_append("QOS", "");
01557 row_child_append("Loop Id", nts(f->hdr.loop_id));
01558 row_child_append("Remaining", nts(f->hdr.remaining));
01559 #ifdef ENABLE_WMP_DEBUG
01560
01561 row_child_append("Discarded", "");
01562 for (int i = 0; i< nnodes; i++){
01563 row_child_child_append("Messages",nts(f->hdr.qos_discarded[i]));
01564 }
01565 row_child_append("Msg this loop",nts(f->hdr.msg_this_loop));
01566 #endif
01567
01568 char qos_ac_interval;
01569 char qos_ac_pri;
01570 unsigned short qos_ac_lot;
01571 row_child_append("Access Control", "");
01572 row_child_child_append("Interval", nts(int(f->hdr.qos_ac_interval)));
01573 row_child_child_append("Priority", nts(int(f->hdr.qos_ac_pri)));
01574 row_child_child_append("Acc. LOT", nts(int(f->hdr.qos_ac_lot)));
01575 for (int i = 0; i < QOS_MAX_SRC; i++) {
01576 row_child_append("Flow " + nts(i), "");
01577 row_child_child_append("Source", nts(f->hdr.qos_src[i]));
01578 row_child_child_append("Destination", nts(f->hdr.qos_dst[i]));
01579 row_child_child_append("Deadline", nts(f->hdr.deadline[i]));
01580 row_child_child_append("Priority", nts(f->hdr.qos_priority[i]));
01581 }
01582 if (f->hdr.type == MESSAGE) {
01583 row_child_append("Data", "");
01584 QoS_Packet_Header * qph = (QoS_Packet_Header *) wmp_get_message_data_pointer(f);
01585 row_child_child_append("QoS Size", nts((int) qph->size));
01586 row_child_child_append("QoS Serial ", nts( qph->serial));
01587 row_child_child_append("Orig Src ", nts((int) qph->orig_src));
01588 row_child_child_append("Samples ", nts((int) qph->samples));
01589 row_child_child_append("Flow ", nts((int) qph->flow));
01590 row_child_child_append("Checksum ", nts((int) qph->cs));
01591 row_child_child_append("El. queue ", nts((int) qph->eq));
01592 #ifdef ENABLE_WMP_DEBUG
01593 row_child_append("Stop Count",nts(qph->stop_count));
01594 for (int i = 0; i< qph->stop_count ; i++){
01595 row_child_child_append("Node Id",nts(qph->stop_node_id[i]));
01596 row_child_child_append("Delay",nts(qph->stop_delay[i]));
01597 }
01598 #endif
01599
01600 }
01601 }
01602 #endif
01603 }
01604
01605 void main_window::on_button6_clicked() {
01606 PF(fprintf(stderr,"**PF** main_window::on_button6_clicked \n");)
01607 if (playing)
01608 return;
01609 hscale_position->set_value(hscale_position->get_value() + 1);
01610 }
01611
01612 void main_window::on_button7_clicked() {
01613 PF(fprintf(stderr,"**PF** main_window::on_button7_clicked \n");)
01614 if (playing)
01615 return;
01616 hscale_position->set_value(hscale_position->get_value() - 1);
01617 }
01618
01619 void main_window::on_togglebutton1_clicked() {
01620 PF(fprintf(stderr,"**PF** main_window::on_togglebutton1_clicked \n");)
01621 bool act = togglebutton1->get_active();
01622 if (act) {
01623 begin_play();
01624 } else {
01625 stop_playing();
01626 }
01627 button8->set_sensitive(!act);
01628 button9->set_sensitive(!act);
01629 button6->set_sensitive(!act);
01630 button7->set_sensitive(!act);
01631 button13->set_sensitive(!act);
01632 }
01633
01634
01635 void main_window::on_rec_btn_clicked(){
01636 }
01637
01638
01639 void main_window::on_togglebutton2_clicked() {
01640 return;
01641 PF(fprintf(stderr,"**PF** main_window::on_togglebutton2_clicked \n");)
01642
01643
01644
01645
01646
01647
01648
01649
01650 }
01651
01652 void main_window::save_cfg_file(){
01653
01654 int val=prim_cb->get_active();
01655 kf->set_integer("Gui", "Show_Prim",val);
01656
01657 val = foreign_cb->get_active();
01658 kf->set_integer("Gui", "Show_Foreign",val);
01659
01660 val = d2_cb->get_active();
01661 kf->set_integer("Gui", "Show_2D",val);
01662
01663 val = text_cb->get_active();
01664 kf->set_integer("Gui", "Show_Text",val);
01665
01666 val = d1_cb->get_active();
01667 kf->set_integer("Gui", "Show_Frames",val);
01668
01669
01670 this->set_focus(*spinbutton1);
01671 std::ofstream cf;
01672 cf.open(cfg_file.c_str(), ofstream::out);
01673 cf << kf->to_data();
01674 cf.close();
01675 }
01676
01677 bool main_window::on_exit(){
01678 save_cfg_file();
01679
01680 return true;
01681 }
01682
01683 void main_window::on_button8_clicked() {
01684
01685 ostringstream oss;
01686 oss << getenv("HOME") << "/.wmpSniffer/active";
01687 unlink((const char*) oss.str().c_str());
01688 io_close_sim_data();
01689 Gtk::Main::quit();
01690 }
01691
01692 void main_window::on_button9_clicked() {
01693 PF(fprintf(stderr,"**PF** main_window::on_button9_clicked \n");)
01694 Gtk::MessageDialog
01695 dialog(*this, "RT-WMP Statistics for the last execution");
01696
01697 if (w2 == NULL) {
01698 w2 = new window2(this);
01699 }
01700 w2->show();
01701 if (!recording) {
01702 w2->show_statistics(this->filename);
01703 } else {
01704 w2->show_statistics_from_values();
01705 }
01706
01707 }
01708
01709 bool main_window::on_main_window_scroll_event(GdkEventScroll * e) {
01710 PF(fprintf(stderr,"**PF** main_window::on_main_window_scroll_event \n");)
01711 if (e->direction == GDK_SCROLL_UP) {
01712 on_button7_clicked();
01713 } else if (e->direction == GDK_SCROLL_DOWN) {
01714 on_button6_clicked();
01715 }
01716 return true;
01717 }
01718 void main_window::on_button13_clicked() {
01719 if (w1 == NULL) {
01720 w1 = new window1(this);
01721 }
01722 w1->show();
01723 }
01724
01725 void main_window::on_nuevo1_activate() {
01726 PF(fprintf(stderr,"**PF** main_window::on_nuevo1_activate \n");)
01727 Gtk::FileChooserDialog dialog("Please choose a Filename",
01728 Gtk::FILE_CHOOSER_ACTION_SAVE);
01729 dialog.set_transient_for(*this);
01730 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
01731 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
01732 dialog.set_current_name("hola");
01733 int result = dialog.run();
01734 if (result == Gtk::RESPONSE_CANCEL)
01735 return;
01736
01737
01738 char new_filename[256];
01739 strcpy(new_filename, dialog.get_filename().c_str());
01740 if (strstr(new_filename, ".vis") == NULL)
01741 strcat(new_filename, ".vis");
01742 strcpy(filename, new_filename);
01743
01744 io_change_file();
01745 reset();
01746 }
01747
01748 void main_window::on_abrir1_activate() {
01749 PF(fprintf(stderr,"**PF** main_window::on_abrir1_activate \n");)
01750
01751 Gtk::FileChooserDialog dialog("Please choose a File",
01752 Gtk::FILE_CHOOSER_ACTION_OPEN);
01753 dialog.set_transient_for(*this);
01754 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
01755 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
01756 Gtk::FileFilter filter_vis;
01757 filter_vis.set_name("wmpSniffer files (*.vis)");
01758 filter_vis.add_pattern("*.vis");
01759 dialog.add_filter(filter_vis);
01760 int result = dialog.run();
01761 if (result == Gtk::RESPONSE_CANCEL){
01762 return;
01763 }
01764 io_change_file();
01765 sprintf(filename, "%s", dialog.get_filename().c_str());
01766 reset();
01767 }
01768 void main_window::on_guardar1_activate() {
01769 PF(fprintf(stderr,"**PF** main_window::on_guardar1_activate \n");)
01770 }
01771
01772 void main_window::on_guardar_como1_activate() {
01773 PF(fprintf(stderr,"**PF** main_window::on_guardar_como1_activate \n");)
01774
01775 Gtk::FileChooserDialog dialog("Please choose a Filename",
01776 Gtk::FILE_CHOOSER_ACTION_SAVE);
01777 dialog.set_transient_for(*this);
01778 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
01779 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
01780 Gtk::FileFilter filter_vis;
01781 filter_vis.set_name("wmpSniffer files (*.vis)");
01782 filter_vis.add_pattern("*.vis");
01783 dialog.add_filter(filter_vis);
01784 int result = dialog.run();
01785 if (result == Gtk::RESPONSE_CANCEL)
01786 return;
01787
01788 io_change_file();
01789
01790 char cmd[256];
01791 char new_filename[256];
01792 strcpy(new_filename, dialog.get_filename().c_str());
01793 if (strstr(new_filename, ".vis") == NULL)
01794 strcat(new_filename, ".vis");
01795 sprintf(cmd, "cp %s %s", filename, new_filename);
01796 if (system(cmd) == -1) {
01797 fprintf(stderr, "*** WARNING: Unable to execute 'cp %s %s'\n",
01798 filename, new_filename);
01799 }
01800 strcpy(filename, new_filename);
01801 reset();
01802 }
01803
01804
01805 void main_window::on_salir1_activate() {
01806 PF(fprintf(stderr,"**PF** main_window::on_salir1_activate \n");)
01807
01808 _exit(0);
01809 }
01810 void main_window::on_acerca_de1_activate() {
01811 PF(fprintf(stderr,"**PF** main_window::on_acerca_de1_activate \n");)
01812 Gtk::MessageDialog dialog(*this, "wmpSniffer v0.2b");
01813 dialog.set_secondary_text(
01814 "Written by Danilo Tardioli\nUniversity of Zaragoza\nemail:dantard@unizar.es\nThanks to: Domenico Sicignano\n and Samuel Cabrero");
01815 dialog.run();
01816 }
01817
01818 void main_window::on_cortar1_activate() {
01819 PF(fprintf(stderr,"**PF** main_window::on_cortar1_activate \n");)
01820 }
01821 void main_window::on_copiar1_activate() {
01822 PF(fprintf(stderr,"**PF** main_window::on_copiar1_activate \n");)
01823 }
01824 void main_window::on_pegar1_activate() {
01825 PF(fprintf(stderr,"**PF** main_window::on_pegar1_activate \n");)
01826 }
01827 void main_window::on_borrar1_activate() {
01828 PF(fprintf(stderr,"**PF** main_window::on_borrar1_activate \n");)
01829 rec_tb->set_active(true);
01830 }
01831
01832 void main_window::on_button23_clicked(){
01833 double val = spinbutton1->get_value();
01834 int y = io_get_pose_from_serial(val);
01835
01836 y = y > 50 ? y - 50 : 0;
01837 hscale_position->set_value(y);
01838 }
01839 void main_window::on_spinbutton1_activate(){
01840 on_button23_clicked();
01841 }
01842
01843
01844
01845 void new_frame(char * data, int data_size) {
01846 PF(fprintf(stderr,"**PF** new_frame \n");)
01847 gdk_threads_enter();
01848 mw->continue_record(data,data_size);
01849 gdk_threads_leave();
01850 }
01851
01852 void main_window::row_child_append(string txt1, string txt2) {
01853 Gtk::TreeModel::iterator iter_child =
01854 m_refTreeModel->append(row.children());
01855 subrow = *iter_child;
01856
01857
01858 (*iter_child)[m_Columns.m_col_name] = txt1;
01859 (*iter_child)[m_Columns.m_col_value] = txt2;
01860
01861 }
01862 void main_window::row_child_child_append(string txt1, string txt2) {
01863 Gtk::TreeModel::iterator iter_child = m_refTreeModel->append(
01864 subrow.children());
01865 (*iter_child)[m_Columns.m_col_name] = txt1;
01866 (*iter_child)[m_Columns.m_col_value] = txt2;
01867
01868 }
01869
01870 void main_window::row_child_child_append(string txt1, int id, int val,
01871 string uni) {
01872 ostringstream s1, s2;
01873 s1 << txt1 << " " << id;
01874 s2 << val << " " << uni;
01875 Gtk::TreeModel::iterator iter_child = m_refTreeModel->append(
01876 subrow.children());
01877 subrow = *iter_child;
01878 (*iter_child)[m_Columns.m_col_name] = s1.str();
01879 (*iter_child)[m_Columns.m_col_value] = s2.str();
01880 }
01881
01882 void main_window::row_append(string txt1, string txt2) {
01883 row = *(m_refTreeModel->append());
01884 row[m_Columns.m_col_name] = txt1;
01885 row[m_Columns.m_col_value] = txt2;
01886 }
01887
01888
01889 bool main_window::on_xfield_tw_focus_in_event(GdkEventFocus *ev){
01890 tw_has_focus=true;
01891 Glib::RefPtr<Gtk::TreeSelection> refTreeSelection =
01892 xfield_tw->get_selection();
01893 Gtk::TreeModel::iterator iter = refTreeSelection->get_selected();
01894
01895 if (iter) {
01896 Gtk::TreeModel::Row row = *iter;
01897 }
01898 return true;
01899 }
01900
01901
01902 bool main_window::on_xfield_tw_focus_out_event(GdkEventFocus *ev){
01903 tw_has_focus=false;
01904 return true;
01905 }
01906
01907 void main_window::on_xfield_tw_row_collapsed(const Gtk::TreeModel::iterator& iter, const Gtk::TreeModel::Path& path){
01908
01909 }
01910 void main_window::on_xfield_tw_row_expanded(const Gtk::TreeModel::iterator& iter, const Gtk::TreeModel::Path& path){
01911
01912 }
01913
01914 void main_window::on_import_activate(){
01915 }
01916
01917 void main_window::on_create_log_activate(){
01918 io_go_to(0);
01919 char data[2500];
01920 simData_Hdr * p = (simData_Hdr *) data;
01921 wmpFrame * r = (wmpFrame *) (data + sizeof(simData_Hdr));
01922 logger_init(1,nnodes);
01923 while (io_read_next_sim_data(data)>0){
01924 if (r->hdr.type == (char) MESSAGE && (int) r->hdr.to == r->msg.dest){
01925 logger_printData(r->msg.dest,r,p->time);
01926 }
01927 usleep(1);
01928 }
01929 }
01930
01931
01932
01933 void setRobotPose(int id, double x0, double y0, double ang, int col) {
01934 mw->areadx->setRobotPose(id, x0, y0, ang, col);
01935 }
01936 void addLink(int r1, int r2, int arrow, int col, float value, int set) {
01937 mw->areadx->addLink(r1, r2, arrow, col, value, set);
01938 }
01939 void addLink(int r1, int r2, int arrow, int col, int set) {
01940 mw->areadx->addLink(r1, r2, arrow, col, set);
01941 }
01942
01943 void clearLinks(int set) {
01944 mw->areadx->clearLinks(set);
01945 }
01946
01947 void getRobotPose(int id, double* x0, double* y0, double* ang) {
01948 mw->areadx->getRobotPose(id, x0, y0, ang);
01949 }
01950 int getSelected() {
01951 return mw->areadx->get_selected();
01952 }
01953 int addRobot() {
01954 return mw->areadx->addRobot();
01955 }
01956 void setRobotColor(int idx, int c) {
01957 mw->areadx->setRobotColor(idx, c);
01958 }
01959
01960 void addPoint(int x, int y, int color, int with_respect_to_robot) {
01961 mw->areadx->addPoint(x, y, color, with_respect_to_robot);
01962 }
01963
01964 void getSimParam(double & threshold, double & x_size, double & y_size) {
01965 threshold = mw->sim_thresh;
01966 x_size = mw->sim_xsize;
01967 y_size = mw->sim_ysize;
01968 }
01969
01970 void lowerLayersRecStop(){
01971
01972 }
01973
01974 bool showForeign(){
01975 return mw->foreign_cb->get_active();
01976 }
01977
01978 void informBridgeOff(){
01979 mw->recording_stopped();
01980 }
01981
01982
01983 void main_window::on_rec_tb_toggled(){}
01984
01985 void main_window::on_rec_tb_released(){
01986 if (recording){
01987 rec_tb->set_sensitive(false);
01988 request_stop_recording();
01989 }else{
01990 recording = begin_online_record();
01991 button8->set_sensitive(!recording);
01992 button6->set_sensitive(!recording);
01993 button7->set_sensitive(!recording);
01994 button13->set_sensitive(!recording);
01995 button9->set_sensitive(!recording);
01996 togglebutton1->set_sensitive(!recording);
01997 rec_tb->set_active(recording);
01998 }
01999 }
02000
02001 void main_window::on_rec_tb_activate(){}
02002
02003 bool main_window::timer_callback(){
02004 return true;
02005 }