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

Last change on this file was 268, checked in by Sanahuja Guillaume, 3 years ago

add defines for architectures to speed up compile time

File size: 2.2 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/*********************************************************************/
[268]17#ifdef ARMV7A
[3]18
19#include "Novatel.h"
20#include <SerialPort.h>
21#include <FrameworkManager.h>
22#include <string.h>
23
24using std::string;
25using namespace flair::core;
26
[15]27namespace flair {
28namespace sensor {
[3]29
[137]30Novatel::Novatel(string name,
[51]31                 SerialPort *serialport, NmeaGps::NMEAFlags_t NMEAFlags,
[15]32                 uint8_t priority)
[137]33    : NmeaGps(name, NMEAFlags), Thread(getFrameworkManager(), name, priority) {
[15]34  this->serialport = serialport;
[157]35 
36  SetIsReady(true);
[3]37}
38
[15]39Novatel::~Novatel() {
40  SafeStop();
41  Join();
[3]42}
43
[15]44void Novatel::Run(void) {
45  ssize_t written;
[3]46
[15]47  WarnUponSwitches(true);
[3]48
[15]49  char to_send[] = "log gpggalong ontime 0.05\n";
50  written = serialport->Write(to_send, sizeof(to_send));
51  if (written < 0) {
52    Thread::Err("erreur write (%s)\n", strerror(-written));
53  }
54  char to_send2[] = "log gpvtg ontime 0.05\n";
55  written = serialport->Write(to_send2, sizeof(to_send2));
56  if (written < 0) {
57    Thread::Err("erreur write (%s)\n", strerror(-written));
58  }
[3]59
[15]60  Sync();
[3]61
[15]62  while (!ToBeStopped()) {
[196]63    char response[1024] = {0};
64    int size = 0;
65    while (!ToBeStopped()) {
66      ssize_t read = serialport->Read(&response[size], 1);
67      if (read < 0) {
68        Thread::Err("erreur Read (%s)\n", strerror(-read));
[15]69      }
[196]70
71      if (response[size] == 0x0a ) break;
[15]72      size++;
[196]73      if (size==sizeof(response)) break;
[3]74    }
[196]75    if (size!=sizeof(response)) {
76      size++;
77      parseFrame(response, size);
78    } else {
79      Thread::Warn("frame too long for buffer\n");
80    }
[15]81  }
[3]82
[15]83  WarnUponSwitches(false);
[3]84}
85
[15]86void Novatel::Sync(void) {
87  char data = 0;
88  ssize_t Read = 0;
[3]89
[15]90  // attente fin trame
91  while (data != 0x0a) {
92    Read = serialport->Read(&data, 1);
93    if (Read < 0) {
94      Thread::Err("erreur Read (%s)\n", strerror(-Read));
[3]95    }
[15]96  }
[3]97}
98
99} // end namespace sensor
[170]100} // end namespace flair
[268]101
102#endif
Note: See TracBrowser for help on using the repository browser.