source: flair-src/trunk/lib/FlairSensorActuator/src/Novatel.cpp @ 157

Last change on this file since 157 was 157, checked in by Sanahuja Guillaume, 5 years ago

iadded isready to iodevice:
avoid problem of imu not ready in ardrone2

File size: 2.1 KB
Line 
1// %flair:license{
2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
4// %flair:license}
5//  created:    2013/08/23
6//  filename:   Novatel.cpp
7//
8//  author:     Guillaume Sanahuja
9//              Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11//  version:    $Id: $
12//
13//  purpose:    objet integrant le recepteur gps Novatel
14//
15//
16/*********************************************************************/
17
18#include "Novatel.h"
19#include <SerialPort.h>
20#include <FrameworkManager.h>
21#include <string.h>
22
23using std::string;
24using namespace flair::core;
25
26namespace flair {
27namespace sensor {
28
29Novatel::Novatel(string name,
30                 SerialPort *serialport, NmeaGps::NMEAFlags_t NMEAFlags,
31                 uint8_t priority)
32    : NmeaGps(name, NMEAFlags), Thread(getFrameworkManager(), name, priority) {
33  this->serialport = serialport;
34 
35  SetIsReady(true);
36}
37
38Novatel::~Novatel() {
39  SafeStop();
40  Join();
41}
42
43void Novatel::Run(void) {
44  char response[200] = {0};
45  int size;
46  ssize_t written;
47
48  WarnUponSwitches(true);
49
50  char to_send[] = "log gpggalong ontime 0.05\n";
51  written = serialport->Write(to_send, sizeof(to_send));
52  if (written < 0) {
53    Thread::Err("erreur write (%s)\n", strerror(-written));
54  }
55  char to_send2[] = "log gpvtg ontime 0.05\n";
56  written = serialport->Write(to_send2, sizeof(to_send2));
57  if (written < 0) {
58    Thread::Err("erreur write (%s)\n", strerror(-written));
59  }
60
61  Sync();
62
63  while (!ToBeStopped()) {
64    size = 0;
65    while (1) {
66      // ssize_t read = rt_dev_read(uart_fd, &response[size],1);
67      ssize_t Read = serialport->Read(&response[size], 1);
68      if (Read < 0) {
69        Thread::Err("erreur Read (%s)\n", strerror(-Read));
70      }
71      if (response[size] == 0x0a)
72        break;
73      size++;
74    }
75    size++;
76    parseFrame(response, size);
77  }
78
79  WarnUponSwitches(false);
80}
81
82void Novatel::Sync(void) {
83  char data = 0;
84  ssize_t Read = 0;
85
86  // attente fin trame
87  while (data != 0x0a) {
88    Read = serialport->Read(&data, 1);
89    if (Read < 0) {
90      Thread::Err("erreur Read (%s)\n", strerror(-Read));
91    }
92  }
93}
94
95} // end namespace sensor
96} // end namespace framewor
Note: See TracBrowser for help on using the repository browser.