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

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

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

File size: 2.1 KB
RevLine 
[3]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[3]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
[15]26namespace flair {
27namespace sensor {
[3]28
[137]29Novatel::Novatel(string name,
[51]30                 SerialPort *serialport, NmeaGps::NMEAFlags_t NMEAFlags,
[15]31                 uint8_t priority)
[137]32    : NmeaGps(name, NMEAFlags), Thread(getFrameworkManager(), name, priority) {
[15]33  this->serialport = serialport;
[157]34 
35  SetIsReady(true);
[3]36}
37
[15]38Novatel::~Novatel() {
39  SafeStop();
40  Join();
[3]41}
42
[15]43void Novatel::Run(void) {
44  char response[200] = {0};
45  int size;
46  ssize_t written;
[3]47
[15]48  WarnUponSwitches(true);
[3]49
[15]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  }
[3]60
[15]61  Sync();
[3]62
[15]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++;
[3]74    }
[15]75    size++;
76    parseFrame(response, size);
77  }
[3]78
[15]79  WarnUponSwitches(false);
[3]80}
81
[15]82void Novatel::Sync(void) {
83  char data = 0;
84  ssize_t Read = 0;
[3]85
[15]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));
[3]91    }
[15]92  }
[3]93}
94
95} // end namespace sensor
96} // end namespace framewor
Note: See TracBrowser for help on using the repository browser.