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

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

gps

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
[15]29Novatel::Novatel(const FrameworkManager *parent, string name,
[51]30                 SerialPort *serialport, NmeaGps::NMEAFlags_t NMEAFlags,
[15]31                 uint8_t priority)
[51]32    : NmeaGps(parent, name, NMEAFlags), Thread(parent, name, priority) {
[15]33  this->serialport = serialport;
[3]34}
35
[15]36Novatel::~Novatel() {
37  SafeStop();
38  Join();
[3]39}
40
[15]41void Novatel::Run(void) {
42  char response[200] = {0};
43  int size;
44  ssize_t written;
[3]45
[15]46  WarnUponSwitches(true);
[3]47
[15]48  char to_send[] = "log gpggalong ontime 0.05\n";
49  written = serialport->Write(to_send, sizeof(to_send));
50  if (written < 0) {
51    Thread::Err("erreur write (%s)\n", strerror(-written));
52  }
53  char to_send2[] = "log gpvtg ontime 0.05\n";
54  written = serialport->Write(to_send2, sizeof(to_send2));
55  if (written < 0) {
56    Thread::Err("erreur write (%s)\n", strerror(-written));
57  }
[3]58
[15]59  Sync();
[3]60
[15]61  while (!ToBeStopped()) {
62    size = 0;
63    while (1) {
64      // ssize_t read = rt_dev_read(uart_fd, &response[size],1);
65      ssize_t Read = serialport->Read(&response[size], 1);
66      if (Read < 0) {
67        Thread::Err("erreur Read (%s)\n", strerror(-Read));
68      }
69      if (response[size] == 0x0a)
70        break;
71      size++;
[3]72    }
[15]73    size++;
74    parseFrame(response, size);
75  }
[3]76
[15]77  WarnUponSwitches(false);
[3]78}
79
[15]80void Novatel::Sync(void) {
81  char data = 0;
82  ssize_t Read = 0;
[3]83
[15]84  // attente fin trame
85  while (data != 0x0a) {
86    Read = serialport->Read(&data, 1);
87    if (Read < 0) {
88      Thread::Err("erreur Read (%s)\n", strerror(-Read));
[3]89    }
[15]90  }
[3]91}
92
93} // end namespace sensor
94} // end namespace framewor
Note: See TracBrowser for help on using the repository browser.