[2] | 1 | // %flair:license{
|
---|
[15] | 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
[2] | 4 | // %flair:license}
|
---|
| 5 | // created: 2011/08/31
|
---|
| 6 | // filename: FrameworkManager.cpp
|
---|
| 7 | //
|
---|
| 8 | // author: Guillaume Sanahuja
|
---|
| 9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 10 | //
|
---|
| 11 | // version: $Id: $
|
---|
| 12 | //
|
---|
| 13 | // purpose: Classe de base de la librairie
|
---|
| 14 | //
|
---|
| 15 | //
|
---|
| 16 | /*********************************************************************/
|
---|
| 17 |
|
---|
| 18 | #include "FrameworkManager_impl.h"
|
---|
| 19 | #include "FrameworkManager.h"
|
---|
| 20 | #include "Widget_impl.h"
|
---|
| 21 | #include <unistd.h>
|
---|
| 22 | #include "IODevice.h"
|
---|
| 23 | #include "IODevice_impl.h"
|
---|
| 24 | #include "TabWidget.h"
|
---|
| 25 | #include "Layout.h"
|
---|
| 26 | #include "PushButton.h"
|
---|
| 27 | #include "communication.h"
|
---|
| 28 | #include "config.h"
|
---|
| 29 | #include "Watchdog.h"
|
---|
| 30 | #include <errno.h>
|
---|
| 31 | #include <string.h>
|
---|
| 32 | #include <arpa/inet.h>
|
---|
| 33 | #include <sys/mman.h>
|
---|
| 34 | #include <execinfo.h>
|
---|
| 35 | #include <signal.h>
|
---|
| 36 | #include <fcntl.h>
|
---|
| 37 | #ifdef __XENO__
|
---|
| 38 | #include <native/task.h>
|
---|
| 39 | #endif
|
---|
| 40 |
|
---|
| 41 | using namespace std;
|
---|
| 42 | using namespace flair::core;
|
---|
| 43 | using namespace flair::gui;
|
---|
| 44 |
|
---|
[15] | 45 | ui_com *FrameworkManager_impl::com = NULL;
|
---|
| 46 | FrameworkManager_impl *FrameworkManager_impl::_this = NULL;
|
---|
[2] | 47 |
|
---|
| 48 | namespace {
|
---|
| 49 | #ifdef __XENO__
|
---|
| 50 |
|
---|
| 51 | #ifdef SIGDEBUG
|
---|
[15] | 52 | static const char *reason_str[] = {
|
---|
| 53 | "undefined", "received signal", "invoked syscall", "triggered fault",
|
---|
| 54 | "affected by priority inversion", "missing mlockall", "runaway thread",
|
---|
| 55 | };
|
---|
[2] | 56 |
|
---|
[15] | 57 | void warn_upon_switch(int sig, siginfo_t *si, void *context) {
|
---|
| 58 | unsigned int reason = si->si_value.sival_int;
|
---|
| 59 | void *bt[32];
|
---|
| 60 | int nentries;
|
---|
[2] | 61 | #ifdef SIGDEBUG_WATCHDOG
|
---|
[15] | 62 | printf("\nSIGDEBUG received, reason %d: %s\n", reason,
|
---|
| 63 | reason <= SIGDEBUG_WATCHDOG ? reason_str[reason] : "<unknown>");
|
---|
[2] | 64 | #endif
|
---|
[15] | 65 | // Dump a backtrace of the frame which caused the switch to secondary mode:
|
---|
| 66 | nentries = backtrace(bt, sizeof(bt) / sizeof(bt[0]));
|
---|
| 67 | backtrace_symbols_fd(bt, nentries, fileno(stdout));
|
---|
| 68 | }
|
---|
| 69 | #else // SIGDEBUG
|
---|
| 70 | void warn_upon_switch(int sig __attribute__((unused))) {
|
---|
| 71 | void *bt[32];
|
---|
| 72 | int nentries;
|
---|
[2] | 73 |
|
---|
[15] | 74 | /* Dump a backtrace of the frame which caused the switch to
|
---|
| 75 | secondary mode: */
|
---|
| 76 | nentries = backtrace(bt, sizeof(bt) / sizeof(bt[0]));
|
---|
| 77 | backtrace_symbols_fd(bt, nentries, fileno(stdout));
|
---|
| 78 | }
|
---|
| 79 | #endif // SIGDEBUG
|
---|
[2] | 80 | #endif //__XENO__
|
---|
[15] | 81 | void seg_fault(int sig __attribute__((unused))) {
|
---|
| 82 | void *bt[32];
|
---|
| 83 | int nentries;
|
---|
[2] | 84 |
|
---|
[15] | 85 | printf("Segmentation fault:\n");
|
---|
| 86 | /* Dump a backtrace of the frame which caused the segfault: */
|
---|
| 87 | nentries = backtrace(bt, sizeof(bt) / sizeof(bt[0]));
|
---|
| 88 | backtrace_symbols_fd(bt, nentries, fileno(stdout));
|
---|
[2] | 89 |
|
---|
[15] | 90 | exit(1);
|
---|
[2] | 91 | }
|
---|
[15] | 92 | }
|
---|
[2] | 93 |
|
---|
[15] | 94 | FrameworkManager_impl::FrameworkManager_impl(FrameworkManager *self,
|
---|
| 95 | string name)
|
---|
| 96 | : Thread(self, "FrameworkManager", FRAMEWORK_TASK_PRIORITY) {
|
---|
| 97 | this->self = self;
|
---|
| 98 | is_logging = false;
|
---|
| 99 | logger_defined = false;
|
---|
| 100 | disable_errors = false;
|
---|
| 101 | ui_defined = false;
|
---|
| 102 | rcv_buf = NULL;
|
---|
[20] | 103 | gcs_watchdog = NULL;
|
---|
[15] | 104 | _this = this;
|
---|
[2] | 105 |
|
---|
[15] | 106 | // Avoids memory swapping for this program
|
---|
| 107 | mlockall(MCL_CURRENT | MCL_FUTURE);
|
---|
[2] | 108 |
|
---|
[15] | 109 | // catch segfault
|
---|
| 110 | signal(SIGSEGV, seg_fault);
|
---|
[2] | 111 |
|
---|
[15] | 112 | // catch primary->secondary switch
|
---|
[2] | 113 | #ifdef __XENO__
|
---|
| 114 | #ifdef SIGDEBUG
|
---|
[45] | 115 | struct sigaction sa;
|
---|
[15] | 116 | sigemptyset(&sa.sa_mask);
|
---|
| 117 | sa.sa_sigaction = warn_upon_switch;
|
---|
| 118 | sa.sa_flags = SA_SIGINFO;
|
---|
| 119 | sigaction(SIGDEBUG, &sa, NULL);
|
---|
[2] | 120 | #else
|
---|
[15] | 121 | signal(SIGXCPU, warn_upon_switch);
|
---|
[2] | 122 | #endif
|
---|
| 123 |
|
---|
[15] | 124 | string task_name = "Framework_" + name;
|
---|
| 125 | int status = rt_task_shadow(NULL, task_name.c_str(), 10, 0);
|
---|
| 126 | if (status != 0) {
|
---|
| 127 | self->Err("rt_task_shadow error (%s)\n", strerror(-status));
|
---|
| 128 | }
|
---|
[2] | 129 |
|
---|
| 130 | #endif //__XENO__
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | void FrameworkManager_impl::ConnectionLost(void) {
|
---|
[15] | 134 | Err("connection lost\n");
|
---|
| 135 | gcs_watchdog->SafeStop();
|
---|
| 136 | connection_lost = true;
|
---|
[2] | 137 | }
|
---|
| 138 |
|
---|
| 139 | FrameworkManager_impl::~FrameworkManager_impl() {
|
---|
[15] | 140 | // Printf("destruction FrameworkManager_impl\n");
|
---|
| 141 | int status;
|
---|
[2] | 142 |
|
---|
[15] | 143 | SafeStop();
|
---|
| 144 | Join();
|
---|
[2] | 145 |
|
---|
[15] | 146 | if (rcv_buf != NULL)
|
---|
| 147 | free(rcv_buf);
|
---|
[2] | 148 |
|
---|
[15] | 149 | if (logger_defined == true) {
|
---|
| 150 | continuer = false;
|
---|
| 151 | (void)pthread_join(log_th, NULL);
|
---|
[2] | 152 |
|
---|
[15] | 153 | status = DeletePipe(&cmd_pipe);
|
---|
| 154 | if (status != 0) {
|
---|
| 155 | Err("Error deleting pipe (%s)\n", strerror(-status));
|
---|
| 156 | }
|
---|
| 157 | status = DeletePipe(&data_pipe);
|
---|
| 158 | if (status != 0) {
|
---|
| 159 | Err("Error deleting pipe (%s)\n", strerror(-status));
|
---|
| 160 | }
|
---|
[2] | 161 |
|
---|
| 162 | #ifdef __XENO__
|
---|
[15] | 163 | status = rt_heap_delete(&log_heap);
|
---|
| 164 | if (status != 0) {
|
---|
| 165 | Err("rt_heap_delete error (%s)\n", strerror(-status));
|
---|
| 166 | }
|
---|
[2] | 167 | #endif
|
---|
| 168 |
|
---|
[15] | 169 | logs.clear();
|
---|
| 170 | }
|
---|
[2] | 171 |
|
---|
[15] | 172 | if (file_doc != NULL)
|
---|
| 173 | xmlFreeDoc(file_doc);
|
---|
[2] | 174 |
|
---|
[15] | 175 | if (ui_defined)
|
---|
| 176 | delete top_layout;
|
---|
[2] | 177 |
|
---|
[15] | 178 | if (com != NULL) {
|
---|
| 179 | delete com;
|
---|
| 180 | status = UDT::close(com_sock);
|
---|
| 181 | if (status != 0)
|
---|
| 182 | printf("Error udt::close %s", UDT::getlasterror().getErrorMessage());
|
---|
[2] | 183 |
|
---|
[15] | 184 | status = UDT::close(file_sock);
|
---|
| 185 | if (status != 0)
|
---|
| 186 | printf("Error udt::close %s", UDT::getlasterror().getErrorMessage());
|
---|
[2] | 187 |
|
---|
[15] | 188 | SleepMS(200); // a revoir, sinon UDT::cleanup bloque en RT
|
---|
| 189 | UDT::cleanup();
|
---|
| 190 | }
|
---|
[2] | 191 |
|
---|
[15] | 192 | // Printf("destruction FrameworkManager_impl ok\n");
|
---|
[2] | 193 | }
|
---|
| 194 |
|
---|
[15] | 195 | void FrameworkManager_impl::SetupConnection(string address, uint16_t port,
|
---|
| 196 | size_t rcv_buf_size) {
|
---|
| 197 | UDT::startup();
|
---|
| 198 | this->rcv_buf_size = rcv_buf_size;
|
---|
[2] | 199 |
|
---|
[15] | 200 | // socket file_socket, doit être créé en premier, cf station sol
|
---|
| 201 | Printf("Connecting to %s:%i\n", address.c_str(), port);
|
---|
| 202 | file_sock = GetSocket(address, port);
|
---|
| 203 | com_sock = GetSocket(address, port);
|
---|
[2] | 204 |
|
---|
[15] | 205 | // receive buffer allocation
|
---|
| 206 | rcv_buf = (char *)malloc(rcv_buf_size);
|
---|
| 207 | if (rcv_buf == NULL) {
|
---|
| 208 | Err("receive buffer malloc error\n");
|
---|
| 209 | }
|
---|
[2] | 210 |
|
---|
[15] | 211 | com = new ui_com(this, com_sock);
|
---|
[2] | 212 |
|
---|
[15] | 213 | // file managment
|
---|
| 214 | bool blocking = true;
|
---|
| 215 | UDT::setsockopt(file_sock, 0, UDT_SNDSYN, &blocking, sizeof(bool));
|
---|
| 216 | UDT::setsockopt(file_sock, 0, UDT_RCVSYN, &blocking, sizeof(bool));
|
---|
[2] | 217 |
|
---|
[20] | 218 | int timeout = 100; // ms
|
---|
[15] | 219 | UDT::setsockopt(com_sock, 0, UDT_RCVTIMEO, &timeout, sizeof(int));
|
---|
[2] | 220 |
|
---|
[15] | 221 | Start();
|
---|
[2] | 222 |
|
---|
[15] | 223 | // watchdog for connection with ground station
|
---|
| 224 | connection_lost = false;
|
---|
| 225 | gcs_watchdog = new Watchdog(
|
---|
| 226 | this, std::bind(&FrameworkManager_impl::ConnectionLost, this),
|
---|
| 227 | (Time)1000000000);
|
---|
| 228 | gcs_watchdog->Start();
|
---|
[2] | 229 | }
|
---|
| 230 |
|
---|
| 231 | void FrameworkManager_impl::SetupUserInterface(string xml_file) {
|
---|
[15] | 232 | ui_defined = true;
|
---|
| 233 | this->xml_file = xml_file;
|
---|
[2] | 234 |
|
---|
[15] | 235 | // top_layout=new Layout(NULL,XML_ROOT_ELEMENT,XML_ROOT_TYPE);
|
---|
| 236 | top_layout = new Layout(NULL, self->ObjectName(), XML_ROOT_TYPE);
|
---|
[2] | 237 |
|
---|
[15] | 238 | // xml setup of the main widget
|
---|
| 239 | if (xml_file != "") {
|
---|
| 240 | xmlNodePtr *file_node = &(((Widget *)(top_layout))->pimpl_->file_node);
|
---|
| 241 | file_doc = xmlParseFile(xml_file.c_str());
|
---|
| 242 | if (file_doc == NULL) {
|
---|
| 243 | self->Warn("XML document not parsed successfully. Creating a new one.\n");
|
---|
| 244 | file_doc = xmlNewDoc((xmlChar *)"1.0");
|
---|
| 245 | *file_node = xmlNewNode(NULL, (xmlChar *)XML_ROOT_TYPE);
|
---|
| 246 | xmlSetProp(*file_node, (xmlChar *)"name",
|
---|
| 247 | (xmlChar *)ObjectName().c_str());
|
---|
| 248 | xmlDocSetRootElement(file_doc, *file_node);
|
---|
| 249 | // PrintXml();
|
---|
[2] | 250 | } else {
|
---|
[15] | 251 | *file_node = xmlDocGetRootElement(file_doc);
|
---|
| 252 | if (xmlStrcmp((*file_node)->name, (xmlChar *)XML_ROOT_TYPE)) {
|
---|
| 253 | self->Warn("%s, no match found in xml file\n", XML_ROOT_TYPE);
|
---|
| 254 | *file_node = xmlNewNode(NULL, (xmlChar *)XML_ROOT_TYPE);
|
---|
| 255 | xmlSetProp(*file_node, (xmlChar *)"name",
|
---|
| 256 | (xmlChar *)ObjectName().c_str());
|
---|
| 257 | xmlDocSetRootElement(file_doc, *file_node);
|
---|
| 258 | }
|
---|
[2] | 259 | }
|
---|
[15] | 260 | } else {
|
---|
| 261 | self->Err("xml file not defined\n");
|
---|
| 262 | }
|
---|
[2] | 263 |
|
---|
[15] | 264 | // gui
|
---|
| 265 | tabwidget =
|
---|
| 266 | new TabWidget(top_layout->At(0, 0), XML_MAIN_TABWIDGET, TabWidget::North);
|
---|
| 267 | save_button =
|
---|
| 268 | new PushButton(top_layout->At(1, 0),
|
---|
| 269 | "save config on target (" + self->ObjectName() + ")");
|
---|
| 270 | // load_button=new PushButton(top_layout->At(1,1),"load config on target (" +
|
---|
| 271 | // self->ObjectName() + ")");
|
---|
[2] | 272 | }
|
---|
| 273 |
|
---|
[15] | 274 | // in case of RT, this thread switches to secondary mode when calling
|
---|
| 275 | // com->Receive
|
---|
| 276 | // it switches back to RT in ProcessXML when mutex are locked
|
---|
| 277 | void FrameworkManager_impl::Run(void) {
|
---|
| 278 | while (!ToBeStopped()) {
|
---|
| 279 | ssize_t bytesRead;
|
---|
[2] | 280 |
|
---|
[15] | 281 | bytesRead = com->Receive(rcv_buf, rcv_buf_size);
|
---|
[2] | 282 |
|
---|
[15] | 283 | if (bytesRead == (ssize_t)rcv_buf_size)
|
---|
| 284 | Err("FrameworkManager max receive size, augmenter le buffer size!\n");
|
---|
[2] | 285 |
|
---|
[15] | 286 | if (bytesRead > 0) {
|
---|
| 287 | // printf("recu %ld, trame %x\n",bytesRead,(uint8_t)rcv_buf[0]);
|
---|
| 288 | // rcv_buf[bytesRead-1]=0;//pour affichage
|
---|
| 289 | // printf("%s\n",rcv_buf);
|
---|
[2] | 290 |
|
---|
[15] | 291 | switch ((uint8_t)rcv_buf[0]) {
|
---|
| 292 | case XML_HEADER: {
|
---|
| 293 | xmlDoc *doc;
|
---|
| 294 | rcv_buf[bytesRead] = 0;
|
---|
[2] | 295 |
|
---|
[15] | 296 | doc = xmlReadMemory(rcv_buf, (int)bytesRead, "include.xml",
|
---|
| 297 | "ISO-8859-1", 0);
|
---|
| 298 | xmlNode *cur_node = NULL;
|
---|
[2] | 299 |
|
---|
[15] | 300 | for (cur_node = xmlDocGetRootElement(doc); cur_node;
|
---|
| 301 | cur_node = cur_node->next) {
|
---|
| 302 | if (cur_node->type == XML_ELEMENT_NODE) {
|
---|
| 303 | if (!xmlStrcmp(cur_node->name, (xmlChar *)XML_ROOT_TYPE)) {
|
---|
[2] | 304 | #ifdef __XENO__
|
---|
[15] | 305 | WarnUponSwitches(
|
---|
| 306 | true); // ProcessXML should not switch to secondary mode
|
---|
[2] | 307 | #endif
|
---|
[15] | 308 | top_layout->Widget::pimpl_->ProcessXML(cur_node->children);
|
---|
[2] | 309 | #ifdef __XENO__
|
---|
[15] | 310 | WarnUponSwitches(false); // other parts of this thread can switch
|
---|
| 311 | // to secondary mode
|
---|
[2] | 312 | #endif
|
---|
[15] | 313 | break;
|
---|
| 314 | }
|
---|
| 315 | }
|
---|
| 316 | }
|
---|
[2] | 317 |
|
---|
[15] | 318 | xmlFreeDoc(doc);
|
---|
[2] | 319 |
|
---|
[15] | 320 | if (save_button->Clicked())
|
---|
| 321 | SaveXml();
|
---|
[2] | 322 |
|
---|
[15] | 323 | SaveXmlChange(rcv_buf);
|
---|
[2] | 324 |
|
---|
[15] | 325 | break;
|
---|
| 326 | }
|
---|
| 327 | case WATCHDOG_HEADER: {
|
---|
| 328 | gcs_watchdog->Touch();
|
---|
| 329 | break;
|
---|
| 330 | }
|
---|
| 331 | default:
|
---|
| 332 | Err("unknown id: %x\n", (uint8_t)rcv_buf[0]);
|
---|
| 333 | break;
|
---|
| 334 | }
|
---|
| 335 | } else {
|
---|
| 336 | if (com->ConnectionLost())
|
---|
| 337 | SleepMS(10); // avoid infinite loop in this case
|
---|
[2] | 338 | }
|
---|
[15] | 339 | }
|
---|
[2] | 340 | }
|
---|
| 341 |
|
---|
[15] | 342 | void FrameworkManager_impl::SaveXml(void) {
|
---|
| 343 | if (ui_defined)
|
---|
| 344 | xmlSaveFormatFile(xml_file.c_str(), file_doc, 1);
|
---|
[2] | 345 | }
|
---|
| 346 |
|
---|
[15] | 347 | void FrameworkManager_impl::SaveXmlChange(char *buf) {
|
---|
| 348 | if (is_logging == true) {
|
---|
| 349 | FILE *xml_change;
|
---|
| 350 | char filename[256];
|
---|
| 351 | Time time = GetTime();
|
---|
[2] | 352 |
|
---|
[15] | 353 | sprintf(filename, "%s/changes_at_%lld.xml", log_path.c_str(), time);
|
---|
[2] | 354 |
|
---|
[15] | 355 | xml_change = fopen(filename, "a");
|
---|
| 356 | fprintf(xml_change, "%s", buf);
|
---|
| 357 | fclose(xml_change);
|
---|
[2] | 358 |
|
---|
[15] | 359 | sprintf(filename, "changes_at_%lld.xml", time);
|
---|
| 360 | xml_changes.push_back(filename);
|
---|
| 361 | }
|
---|
[2] | 362 | }
|
---|
| 363 |
|
---|
[15] | 364 | void FrameworkManager_impl::SendFile(string path, string name) {
|
---|
| 365 | char *buf, *more_buf;
|
---|
| 366 | int size;
|
---|
| 367 | filebuf *pbuf;
|
---|
| 368 | ssize_t nb_write;
|
---|
| 369 | string filename = path + "/" + name;
|
---|
[2] | 370 |
|
---|
[15] | 371 | // open the file
|
---|
| 372 | fstream ifs(filename.c_str(), ios::in | ios::binary);
|
---|
| 373 | ifs.seekg(0, ios::end);
|
---|
| 374 | size = ifs.tellg();
|
---|
| 375 | ifs.seekg(0, ios::beg);
|
---|
| 376 | pbuf = ifs.rdbuf();
|
---|
[2] | 377 |
|
---|
[15] | 378 | if (size <= 0) {
|
---|
| 379 | Err("error opening file %s\n", filename.c_str());
|
---|
| 380 | return;
|
---|
| 381 | }
|
---|
[2] | 382 |
|
---|
[15] | 383 | buf = (char *)malloc(sizeof(uint8_t) + sizeof(int) + name.size());
|
---|
| 384 | if (buf == NULL) {
|
---|
| 385 | Err("malloc error, not sending file\n");
|
---|
| 386 | return;
|
---|
| 387 | }
|
---|
[2] | 388 |
|
---|
[15] | 389 | if (IsBigEndian()) {
|
---|
| 390 | buf[0] = FILE_INFO_BIG_ENDIAN;
|
---|
| 391 | } else {
|
---|
| 392 | buf[0] = FILE_INFO_LITTLE_ENDIAN;
|
---|
| 393 | }
|
---|
[2] | 394 |
|
---|
[15] | 395 | memcpy(buf + 1, &size, sizeof(int));
|
---|
| 396 | memcpy(buf + 1 + sizeof(int), name.c_str(), name.size());
|
---|
| 397 | Printf("sending %s, size: %i\n", filename.c_str(), size);
|
---|
| 398 | // send file information
|
---|
| 399 | UDT::sendmsg(file_sock, buf, sizeof(uint8_t) + sizeof(int) + name.size(), -1,
|
---|
| 400 | true);
|
---|
[2] | 401 |
|
---|
[15] | 402 | more_buf = (char *)realloc((void *)buf, size);
|
---|
| 403 | if (more_buf == NULL) {
|
---|
| 404 | Err("realloc error, not sending file\n");
|
---|
| 405 | free(buf);
|
---|
| 406 | return;
|
---|
| 407 | } else {
|
---|
| 408 | buf = more_buf;
|
---|
| 409 | }
|
---|
[2] | 410 |
|
---|
[15] | 411 | pbuf->sgetn(buf, size);
|
---|
| 412 | // send the file
|
---|
| 413 | nb_write = UDT::sendmsg(file_sock, buf, size, -1, true);
|
---|
[2] | 414 |
|
---|
[15] | 415 | if (nb_write < 0) {
|
---|
| 416 | Err("UDT::sendmsg error (%s)\n", UDT::getlasterror().getErrorMessage());
|
---|
| 417 | } else if (nb_write != size) {
|
---|
| 418 | Err("UDT::sendmsg error, sent %ld/%i\n", nb_write, size);
|
---|
| 419 | }
|
---|
[2] | 420 |
|
---|
[15] | 421 | ifs.close();
|
---|
| 422 | free(buf);
|
---|
[2] | 423 | }
|
---|
| 424 |
|
---|
[15] | 425 | void FrameworkManager_impl::FinishSending() {
|
---|
| 426 | char rm_cmd[256];
|
---|
[2] | 427 |
|
---|
[15] | 428 | // send orignal xml
|
---|
| 429 | SendFile(log_path, "setup.xml");
|
---|
| 430 | sprintf(rm_cmd, "rm %s/setup.xml", log_path.c_str());
|
---|
| 431 | system(rm_cmd);
|
---|
| 432 |
|
---|
| 433 | // send xml changes
|
---|
| 434 | for (size_t i = 0; i < xml_changes.size(); i++) {
|
---|
| 435 | // Printf("%s\n",xml_changes.at(i).c_str());
|
---|
| 436 | SendFile(log_path, xml_changes.at(i).c_str());
|
---|
| 437 | sprintf(rm_cmd, "rm %s/%s", log_path.c_str(), xml_changes.at(i).c_str());
|
---|
[2] | 438 | system(rm_cmd);
|
---|
[15] | 439 | }
|
---|
| 440 | xml_changes.clear();
|
---|
[2] | 441 |
|
---|
[15] | 442 | // end notify
|
---|
| 443 | char buf = END;
|
---|
| 444 | int nb_write = UDT::sendmsg(file_sock, &buf, 1, -1, true);
|
---|
[2] | 445 |
|
---|
[15] | 446 | if (nb_write < 0) {
|
---|
| 447 | Err("UDT::sendmsg error (%s)\n", UDT::getlasterror().getErrorMessage());
|
---|
| 448 | } else if (nb_write != 1) {
|
---|
| 449 | Err("UDT::sendmsg error, sent %i/%i\n", nb_write, 1);
|
---|
| 450 | }
|
---|
[20] | 451 |
|
---|
| 452 | //wait end ACK
|
---|
| 453 | int nb_read = UDT::recvmsg(file_sock,&buf,1);
|
---|
| 454 | if(nb_read<0) {
|
---|
| 455 | Err("UDT::recvmsg error (%s)\n",UDT::getlasterror().getErrorMessage());
|
---|
| 456 | } else if (nb_read != 1) {
|
---|
| 457 | Err("UDT::recvmsg error, sent %i/%i\n",nb_read,1);
|
---|
| 458 | }
|
---|
[15] | 459 | }
|
---|
[2] | 460 |
|
---|
[15] | 461 | UDTSOCKET FrameworkManager_impl::GetSocket(string address, uint16_t port) {
|
---|
| 462 | while (1) {
|
---|
| 463 | UDTSOCKET new_fd;
|
---|
| 464 | new_fd = UDT::socket(AF_INET, SOCK_DGRAM, 0);
|
---|
| 465 | if (new_fd == UDT::INVALID_SOCK) {
|
---|
| 466 | Err("socket error: %s\n", UDT::getlasterror().getErrorMessage());
|
---|
| 467 | return 0;
|
---|
[2] | 468 | }
|
---|
| 469 |
|
---|
[15] | 470 | sockaddr_in serv_addr;
|
---|
| 471 | serv_addr.sin_family = AF_INET;
|
---|
| 472 | serv_addr.sin_port = htons(short(port));
|
---|
[2] | 473 |
|
---|
[15] | 474 | if (inet_pton(AF_INET, address.c_str(), &serv_addr.sin_addr) <= 0) {
|
---|
| 475 | Err("incorrect network address\n");
|
---|
| 476 | return 0;
|
---|
| 477 | }
|
---|
[2] | 478 |
|
---|
[15] | 479 | memset(&(serv_addr.sin_zero), '\0', 8);
|
---|
[2] | 480 |
|
---|
[15] | 481 | if (UDT::ERROR ==
|
---|
| 482 | UDT::connect(new_fd, (sockaddr *)&serv_addr, sizeof(serv_addr))) {
|
---|
| 483 | // Printf("connect error: %s
|
---|
| 484 | // %i\n",UDT::getlasterror().getErrorMessage(),UDT::getlasterror().getErrorCode());
|
---|
| 485 | UDT::close(new_fd);
|
---|
| 486 | if (UDT::getlasterror().getErrorCode() != 1001 &&
|
---|
| 487 | UDT::getlasterror().getErrorCode() != 1002) {
|
---|
| 488 | Err("connect error: %s\n", UDT::getlasterror().getErrorMessage());
|
---|
| 489 | return 0;
|
---|
| 490 | }
|
---|
| 491 | } else {
|
---|
| 492 | // printf("connected to
|
---|
| 493 | // %s:%i\n",inet_ntoa(serv_addr.sin_addr),serv_addr.sin_port);
|
---|
| 494 | return new_fd;
|
---|
[2] | 495 | }
|
---|
[15] | 496 | }
|
---|
[2] | 497 | }
|
---|
| 498 |
|
---|
| 499 | #ifdef __XENO__
|
---|
[15] | 500 | int FrameworkManager_impl::CreatePipe(RT_PIPE *fd, string name) {
|
---|
| 501 | name = self->ObjectName() + "-" + name;
|
---|
| 502 | // xenomai limitation
|
---|
| 503 | if (name.size() > 31)
|
---|
| 504 | self->Err("rt_pipe_create error (%s is too long)\n", name.c_str());
|
---|
| 505 | // start log writter
|
---|
[2] | 506 | #ifdef RT_PIPE_SIZE
|
---|
[15] | 507 | return rt_pipe_create(fd, name.c_str(), P_MINOR_AUTO, RT_PIPE_SIZE);
|
---|
[2] | 508 | #else
|
---|
[15] | 509 | return rt_pipe_create(fd, name.c_str(), P_MINOR_AUTO, 0);
|
---|
[2] | 510 | #endif
|
---|
| 511 | }
|
---|
| 512 | #else
|
---|
[15] | 513 | int FrameworkManager_impl::CreatePipe(int (*fd)[2], string name) {
|
---|
| 514 | // if(pipe2(fd[0],O_NONBLOCK) == -1)
|
---|
| 515 | if (pipe(fd[0]) == -1) {
|
---|
| 516 | return errno;
|
---|
| 517 | } else {
|
---|
| 518 | int attr = fcntl((*fd)[0], F_GETFL, 0);
|
---|
| 519 | if (attr == -1) {
|
---|
| 520 | return errno;
|
---|
[2] | 521 | }
|
---|
[15] | 522 | if (fcntl((*fd)[0], F_SETFL, attr | O_NONBLOCK) == -1) {
|
---|
| 523 | return errno;
|
---|
| 524 | }
|
---|
| 525 | attr = fcntl((*fd)[1], F_GETFL, 0);
|
---|
| 526 | if (attr == -1) {
|
---|
| 527 | return errno;
|
---|
| 528 | }
|
---|
| 529 | if (fcntl((*fd)[1], F_SETFL, attr | O_NONBLOCK) == -1) {
|
---|
| 530 | return errno;
|
---|
| 531 | }
|
---|
[2] | 532 |
|
---|
[15] | 533 | return 0;
|
---|
| 534 | }
|
---|
[2] | 535 | }
|
---|
| 536 | #endif
|
---|
| 537 |
|
---|
| 538 | #ifdef __XENO__
|
---|
[15] | 539 | int FrameworkManager_impl::DeletePipe(RT_PIPE *fd) {
|
---|
| 540 | return rt_pipe_delete(fd);
|
---|
[2] | 541 | }
|
---|
| 542 | #else
|
---|
[15] | 543 | int FrameworkManager_impl::DeletePipe(int (*fd)[2]) {
|
---|
| 544 | int status1 = close((*fd)[0]);
|
---|
| 545 | int status2 = close((*fd)[1]);
|
---|
| 546 | if (status1 == 0 && status2 == 0)
|
---|
| 547 | return 0;
|
---|
| 548 | if (status1 != 0)
|
---|
| 549 | return status1;
|
---|
| 550 | if (status2 != 0)
|
---|
| 551 | return status2;
|
---|
[2] | 552 | }
|
---|
| 553 | #endif
|
---|
| 554 |
|
---|
| 555 | void FrameworkManager_impl::SetupLogger(string log_path) {
|
---|
[15] | 556 | if (logger_defined == true) {
|
---|
| 557 | Warn("SetupLogger() was already called.\n");
|
---|
| 558 | return;
|
---|
| 559 | }
|
---|
[2] | 560 |
|
---|
[15] | 561 | this->log_path = log_path;
|
---|
[2] | 562 |
|
---|
[15] | 563 | int status = CreatePipe(&cmd_pipe, "log_cmd");
|
---|
| 564 | if (status != 0) {
|
---|
| 565 | Err("Error creating pipe (%s)\n", strerror(-status));
|
---|
| 566 | return;
|
---|
| 567 | }
|
---|
[2] | 568 |
|
---|
[15] | 569 | status = CreatePipe(&data_pipe, "log_data");
|
---|
| 570 | if (status != 0) {
|
---|
| 571 | Err("Error creating pipe (%s)\n", strerror(-status));
|
---|
| 572 | return;
|
---|
| 573 | }
|
---|
[2] | 574 |
|
---|
| 575 | #ifdef __XENO__
|
---|
[15] | 576 | string tmp_name;
|
---|
| 577 | tmp_name = self->ObjectName() + "-log_heap";
|
---|
| 578 | status = rt_heap_create(&log_heap, tmp_name.c_str(), LOG_HEAP, H_FIFO);
|
---|
| 579 | if (status != 0) {
|
---|
| 580 | Err("rt_heap_create error (%s)\n", strerror(-status));
|
---|
| 581 | return;
|
---|
| 582 | }
|
---|
[2] | 583 | #endif //__XENO__
|
---|
| 584 |
|
---|
[15] | 585 | continuer = true;
|
---|
[2] | 586 |
|
---|
| 587 | #ifdef NRT_STACK_SIZE
|
---|
[15] | 588 | // Initialize thread creation attributes
|
---|
| 589 | pthread_attr_t attr;
|
---|
| 590 | if (pthread_attr_init(&attr) != 0) {
|
---|
| 591 | Err("pthread_attr_init error\n");
|
---|
| 592 | return;
|
---|
| 593 | }
|
---|
[2] | 594 |
|
---|
[15] | 595 | if (pthread_attr_setstacksize(&attr, NRT_STACK_SIZE) != 0) {
|
---|
| 596 | Err("pthread_attr_setstacksize error\n");
|
---|
| 597 | return;
|
---|
| 598 | }
|
---|
[2] | 599 |
|
---|
[15] | 600 | if (pthread_create(&log_th, &attr, write_log_user, (void *)this) < 0)
|
---|
[2] | 601 | #else
|
---|
[15] | 602 | if (pthread_create(&log_th, NULL, write_log_user, (void *)this) < 0)
|
---|
[2] | 603 | #endif
|
---|
[15] | 604 | {
|
---|
| 605 | Err("pthread_create error\n");
|
---|
| 606 | return;
|
---|
| 607 | }
|
---|
[2] | 608 | #ifdef NRT_STACK_SIZE
|
---|
[15] | 609 | if (pthread_attr_destroy(&attr) != 0) {
|
---|
| 610 | Err("pthread_attr_destroy error\n");
|
---|
| 611 | return;
|
---|
| 612 | }
|
---|
[2] | 613 | #endif
|
---|
| 614 |
|
---|
[15] | 615 | logger_defined = true;
|
---|
[2] | 616 | }
|
---|
| 617 |
|
---|
[15] | 618 | void FrameworkManager_impl::AddDeviceToLog(IODevice *device) {
|
---|
| 619 | if (logger_defined == false) {
|
---|
| 620 | Err("SetupLogger() was not called, not starting log\n");
|
---|
| 621 | return;
|
---|
| 622 | }
|
---|
[2] | 623 |
|
---|
[15] | 624 | if (is_logging == false) {
|
---|
| 625 | if (device->pimpl_->SetToBeLogged()) {
|
---|
| 626 | log_desc_t tmp;
|
---|
| 627 | tmp.device = device;
|
---|
| 628 | logs.push_back(tmp);
|
---|
| 629 | } else {
|
---|
| 630 | Warn("not adding it twice\n");
|
---|
[2] | 631 | }
|
---|
[15] | 632 | } else {
|
---|
| 633 | Err("impossible while logging\n");
|
---|
| 634 | }
|
---|
[2] | 635 | }
|
---|
| 636 |
|
---|
[15] | 637 | void FrameworkManager_impl::StartLog(void) {
|
---|
| 638 | if (logger_defined == false) {
|
---|
| 639 | Err("SetupLogger() was not called, not starting log\n");
|
---|
| 640 | return;
|
---|
| 641 | }
|
---|
[2] | 642 |
|
---|
[15] | 643 | ssize_t written;
|
---|
| 644 | size_t nb_err = 0;
|
---|
[2] | 645 |
|
---|
[15] | 646 | if (logs.size() == 0) {
|
---|
| 647 | Warn("Not starting log: nothing to log!\n");
|
---|
| 648 | return;
|
---|
| 649 | }
|
---|
[2] | 650 |
|
---|
[15] | 651 | if (is_logging == false) {
|
---|
| 652 | for (size_t i = 0; i < logs.size(); i++) {
|
---|
[2] | 653 |
|
---|
[15] | 654 | logs.at(i).running = true;
|
---|
| 655 | logs.at(i).dbtFile = NULL;
|
---|
| 656 | logs.at(i).size = logs.at(i).device->pimpl_->LogSize();
|
---|
[2] | 657 | #ifdef __XENO__
|
---|
[15] | 658 | written =
|
---|
| 659 | rt_pipe_write(&cmd_pipe, &logs.at(i), sizeof(log_desc_t), P_NORMAL);
|
---|
[2] | 660 | #else
|
---|
[15] | 661 | written = write(cmd_pipe[1], &logs.at(i), sizeof(log_desc_t));
|
---|
[2] | 662 | #endif
|
---|
| 663 |
|
---|
[15] | 664 | if (written < 0) {
|
---|
| 665 | Err("write pipe error (%s)\n", strerror(-written));
|
---|
| 666 | nb_err++;
|
---|
| 667 | logs.at(i).running = false;
|
---|
| 668 | } else if (written != sizeof(log_desc_t)) {
|
---|
| 669 | Err("write pipe error %ld/%ld\n", written, sizeof(log_desc_t));
|
---|
| 670 | nb_err++;
|
---|
| 671 | logs.at(i).running = false;
|
---|
| 672 | }
|
---|
| 673 | }
|
---|
[2] | 674 |
|
---|
[15] | 675 | if (nb_err != logs.size())
|
---|
| 676 | is_logging = true;
|
---|
| 677 | } else {
|
---|
| 678 | Warn("Already logging\n");
|
---|
| 679 | }
|
---|
[2] | 680 | }
|
---|
| 681 |
|
---|
[15] | 682 | void FrameworkManager_impl::StopLog(void) {
|
---|
| 683 | ssize_t written;
|
---|
[2] | 684 |
|
---|
[15] | 685 | if (is_logging == true) {
|
---|
| 686 | for (size_t i = 0; i < logs.size(); i++) {
|
---|
| 687 | logs.at(i).running = false;
|
---|
| 688 | }
|
---|
| 689 | // send only one running false condition, user thread will stop and send all
|
---|
[2] | 690 | #ifdef __XENO__
|
---|
[15] | 691 | written =
|
---|
| 692 | rt_pipe_write(&cmd_pipe, &logs.at(0), sizeof(log_desc_t), P_NORMAL);
|
---|
[2] | 693 | #else
|
---|
[15] | 694 | written = write(cmd_pipe[1], &logs.at(0), sizeof(log_desc_t));
|
---|
[2] | 695 | #endif
|
---|
| 696 |
|
---|
[15] | 697 | if (written < 0) {
|
---|
| 698 | Err("write pipe error (%s)\n", strerror(-written));
|
---|
| 699 | return;
|
---|
| 700 | } else if (written != sizeof(log_desc_t)) {
|
---|
| 701 | Err("write pipe error %ld/%ld\n", written, sizeof(log_desc_t));
|
---|
| 702 | return;
|
---|
| 703 | }
|
---|
[2] | 704 |
|
---|
[15] | 705 | is_logging = false;
|
---|
| 706 | } else {
|
---|
| 707 | Warn("Not logging\n");
|
---|
| 708 | }
|
---|
[2] | 709 | }
|
---|
| 710 |
|
---|
[15] | 711 | char *FrameworkManager_impl::GetBuffer(size_t sz) {
|
---|
| 712 | // Printf("alloc %i\n",sz);
|
---|
[2] | 713 | #ifdef __XENO__
|
---|
[15] | 714 | void *ptr;
|
---|
| 715 | int status = rt_heap_alloc(&log_heap, sz, TM_NONBLOCK, &ptr);
|
---|
| 716 | if (status != 0) {
|
---|
| 717 | Err("rt_heap_alloc error (%s)\n", strerror(-status));
|
---|
| 718 | ptr = NULL;
|
---|
| 719 | }
|
---|
| 720 | return (char *)ptr;
|
---|
[2] | 721 | #else
|
---|
[15] | 722 | return (char *)malloc(sz);
|
---|
[2] | 723 | #endif
|
---|
| 724 | }
|
---|
| 725 |
|
---|
[15] | 726 | void FrameworkManager_impl::ReleaseBuffer(char *buf) {
|
---|
[2] | 727 | #ifdef __XENO__
|
---|
[15] | 728 | int status = rt_heap_free(&log_heap, buf);
|
---|
[2] | 729 |
|
---|
[15] | 730 | if (status != 0) {
|
---|
| 731 | Err("rt_heap_free error (%s)\n", strerror(-status));
|
---|
| 732 | }
|
---|
[2] | 733 | #else
|
---|
[15] | 734 | free(buf);
|
---|
[2] | 735 | #endif
|
---|
| 736 | }
|
---|
| 737 |
|
---|
[15] | 738 | void FrameworkManager_impl::WriteLog(const char *buf, size_t size) {
|
---|
| 739 | ssize_t written;
|
---|
[2] | 740 |
|
---|
| 741 | #ifdef __XENO__
|
---|
[15] | 742 | written = rt_pipe_write(&data_pipe, buf, size, P_NORMAL);
|
---|
[2] | 743 | #else
|
---|
[15] | 744 | written = write(data_pipe[1], buf, size);
|
---|
[2] | 745 | #endif
|
---|
| 746 |
|
---|
[15] | 747 | if (written < 0) {
|
---|
| 748 | Err("erreur write pipe (%s)\n", strerror(-written));
|
---|
| 749 | } else if (written != (ssize_t)size) {
|
---|
| 750 | Err("erreur write pipe %ld/%ld\n", written, size);
|
---|
| 751 | }
|
---|
[2] | 752 | }
|
---|
| 753 |
|
---|
[15] | 754 | void *FrameworkManager_impl::write_log_user(void *arg) {
|
---|
| 755 | int cmd_pipe = -1;
|
---|
| 756 | int data_pipe = -1;
|
---|
| 757 | string filename;
|
---|
| 758 | fd_set set;
|
---|
| 759 | struct timeval timeout;
|
---|
| 760 | FrameworkManager_impl *caller = (FrameworkManager_impl *)arg;
|
---|
| 761 | int rv;
|
---|
[2] | 762 |
|
---|
[15] | 763 | vector<log_desc_t> logs;
|
---|
[2] | 764 |
|
---|
| 765 | #ifdef __XENO__
|
---|
[15] | 766 | filename = NRT_PIPE_PATH + caller->self->ObjectName() + "-log_cmd";
|
---|
| 767 | while (cmd_pipe < 0) {
|
---|
| 768 | cmd_pipe = open(filename.c_str(), O_RDWR);
|
---|
| 769 | if (cmd_pipe < 0 && errno != ENOENT)
|
---|
| 770 | caller->self->Err("open rt_pipe error: %s %i\n", filename.c_str(), errno);
|
---|
| 771 | usleep(1000);
|
---|
| 772 | }
|
---|
| 773 | filename = NRT_PIPE_PATH + caller->self->ObjectName() + "-log_data";
|
---|
| 774 | while (data_pipe < 0) {
|
---|
| 775 | data_pipe = open(filename.c_str(), O_RDWR);
|
---|
| 776 | if (data_pipe < 0 && errno != ENOENT)
|
---|
| 777 | caller->self->Err("open rt_pipe error: %s %i\n", filename.c_str(), errno);
|
---|
| 778 | usleep(1000);
|
---|
| 779 | }
|
---|
[2] | 780 | #else
|
---|
[15] | 781 | cmd_pipe = caller->cmd_pipe[0];
|
---|
| 782 | data_pipe = caller->data_pipe[0];
|
---|
[2] | 783 | #endif
|
---|
| 784 |
|
---|
[15] | 785 | while (caller->continuer == true) {
|
---|
| 786 | FD_ZERO(&set);
|
---|
| 787 | FD_SET(cmd_pipe, &set);
|
---|
| 788 | FD_SET(data_pipe, &set);
|
---|
[2] | 789 |
|
---|
[15] | 790 | timeout.tv_sec = 0;
|
---|
| 791 | timeout.tv_usec = SELECT_TIMEOUT_MS * 1000;
|
---|
| 792 | rv = select(FD_SETSIZE, &set, NULL, NULL, &timeout);
|
---|
[2] | 793 |
|
---|
[15] | 794 | if (rv == -1) {
|
---|
| 795 | caller->Err("select error\n"); // an error accured
|
---|
| 796 | } else if (rv == 0) {
|
---|
| 797 | // printf("timeout write_log_user %s\n",caller->ObjectName().c_str()); //
|
---|
| 798 | // a timeout occured
|
---|
| 799 | } else {
|
---|
| 800 | if (FD_ISSET(cmd_pipe, &set)) {
|
---|
| 801 | log_desc_t tmp;
|
---|
| 802 | read(cmd_pipe, &tmp, sizeof(log_desc_t));
|
---|
| 803 |
|
---|
| 804 | if (tmp.running == true) // start logging
|
---|
[2] | 805 | {
|
---|
[15] | 806 | filename =
|
---|
| 807 | caller->log_path + "/" + caller->FileName(tmp.device) + ".dbt";
|
---|
| 808 | printf("Creating log file %s (log size %i)\n", filename.c_str(),
|
---|
| 809 | (int)tmp.size);
|
---|
| 810 | tmp.dbtFile = inithdFile((char *)filename.c_str(), UAV, tmp.size);
|
---|
| 811 | logs.push_back(tmp);
|
---|
| 812 |
|
---|
| 813 | if (logs.size() == 1) {
|
---|
| 814 | filename = caller->log_path + "/setup.xml";
|
---|
| 815 | xmlSaveFile(filename.c_str(), caller->file_doc);
|
---|
| 816 | }
|
---|
| 817 | } else // stop logging
|
---|
[2] | 818 | {
|
---|
[20] | 819 | //disable watchdog temporarly
|
---|
| 820 | //this is necessary because GCS is no longer sending the heartbeat when receiving files...
|
---|
| 821 | //TODO: add a thread in GCS for receiving file
|
---|
| 822 | //but be careful that with a xbee modem for exemple, sending files can saturate communication and
|
---|
| 823 | //avoid the heartbeat to be received... so disabling watchdog is not a so bad option...
|
---|
| 824 | if(caller->gcs_watchdog!=NULL) {
|
---|
| 825 | caller->gcs_watchdog->SafeStop();
|
---|
| 826 | caller->gcs_watchdog->Join();
|
---|
| 827 | }
|
---|
[15] | 828 | for (size_t i = 0; i < logs.size(); i++) {
|
---|
| 829 | if (logs.at(i).dbtFile != NULL) {
|
---|
| 830 | close_hdfile(logs.at(i).dbtFile);
|
---|
[2] | 831 |
|
---|
[15] | 832 | filename = caller->FileName(logs.at(i).device) + ".dbt";
|
---|
| 833 | caller->SendFile(caller->log_path, filename);
|
---|
[2] | 834 |
|
---|
[15] | 835 | fstream txt_file;
|
---|
| 836 | filename = caller->FileName(logs.at(i).device) + ".txt";
|
---|
| 837 | txt_file.open((caller->log_path + "/" + filename).c_str(),
|
---|
| 838 | fstream::out);
|
---|
| 839 | txt_file << "1: time (us)\n2: time (ns)\n";
|
---|
| 840 | int index = 3;
|
---|
| 841 | logs.at(i).device->pimpl_->WriteLogsDescriptors(txt_file, &index);
|
---|
| 842 | txt_file.close();
|
---|
[2] | 843 |
|
---|
[15] | 844 | caller->SendFile(caller->log_path, filename);
|
---|
| 845 | }
|
---|
| 846 | }
|
---|
| 847 | // a revoir celui ci est le xml enregistré et pas forcement l'actuel
|
---|
| 848 | // if(caller->xml_file!="") caller->SendFile(caller->xml_file);
|
---|
| 849 | caller->FinishSending();
|
---|
[2] | 850 |
|
---|
[15] | 851 | logs.clear();
|
---|
[20] | 852 | //enable watchdog again
|
---|
| 853 | if(caller->gcs_watchdog!=NULL) {
|
---|
| 854 | caller->gcs_watchdog->Start();
|
---|
| 855 | }
|
---|
[15] | 856 | }
|
---|
| 857 | }
|
---|
[2] | 858 |
|
---|
[15] | 859 | if (FD_ISSET(data_pipe, &set)) {
|
---|
| 860 | log_header_t header;
|
---|
| 861 | read(data_pipe, &header, sizeof(log_header_t));
|
---|
[2] | 862 |
|
---|
[15] | 863 | for (size_t i = 0; i < logs.size(); i++) {
|
---|
| 864 | if (logs.at(i).device == header.device) {
|
---|
| 865 | char *buf = (char *)malloc(header.size);
|
---|
| 866 | read(data_pipe, buf, header.size);
|
---|
| 867 | // printf("%s \n",header.device->ObjectName().c_str());
|
---|
| 868 | // for(int i=0;i<header.size;i++) printf("%x ",buf[i]);
|
---|
| 869 | // printf("\n");
|
---|
| 870 | if (logs.at(i).size == header.size) {
|
---|
| 871 | if (logs.at(i).dbtFile != NULL) {
|
---|
| 872 | write_hdfile(
|
---|
| 873 | logs.at(i).dbtFile, buf, (road_time_t)(header.time / 1000),
|
---|
| 874 | (road_timerange_t)(header.time % 1000), header.size);
|
---|
| 875 | } else {
|
---|
| 876 | printf("err\n");
|
---|
| 877 | }
|
---|
| 878 | } else {
|
---|
| 879 | caller->self->Err("%s log size is not correct %i/%i\n",
|
---|
| 880 | header.device->ObjectName().c_str(),
|
---|
| 881 | header.size, logs.at(i).size);
|
---|
[2] | 882 | }
|
---|
[15] | 883 | free(buf);
|
---|
| 884 | }
|
---|
[2] | 885 | }
|
---|
[15] | 886 | }
|
---|
[2] | 887 | }
|
---|
[15] | 888 | }
|
---|
[2] | 889 |
|
---|
| 890 | #ifdef __XENO__
|
---|
[15] | 891 | close(cmd_pipe);
|
---|
| 892 | close(data_pipe);
|
---|
[2] | 893 | #endif
|
---|
| 894 |
|
---|
[15] | 895 | pthread_exit(0);
|
---|
[2] | 896 | }
|
---|
| 897 |
|
---|
[15] | 898 | string FrameworkManager_impl::FileName(IODevice *device) {
|
---|
| 899 | return getFrameworkManager()->ObjectName() + "_" + device->ObjectName();
|
---|
[2] | 900 | }
|
---|
| 901 |
|
---|
[15] | 902 | void FrameworkManager_impl::PrintXml(void) const {
|
---|
| 903 | xmlChar *xmlbuff;
|
---|
| 904 | int buffersize;
|
---|
| 905 | xmlDocDumpFormatMemory(file_doc, &xmlbuff, &buffersize, 1);
|
---|
| 906 | Printf("xml:\n%s\n", xmlbuff);
|
---|
| 907 | xmlFree(xmlbuff);
|
---|
[2] | 908 | }
|
---|