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