source: flair-src/trunk/lib/FlairSensorActuator/src/Mb800.cpp @ 98

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

gps

File size: 3.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:   Mb800.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 mb800
14//
15//
16/*********************************************************************/
17
18#include "Mb800.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]29Mb800::Mb800(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;
34  serialport->SetRxTimeout(100000000);
[3]35}
36
[15]37Mb800::~Mb800() {
38  SafeStop();
39  Join();
[3]40}
41
[15]42void Mb800::Run(void) {
43  /** Debut init **/
44  char response[200] = {0};
[41]45  int size,written;
[3]46
[15]47  /** Fin init **/
[3]48
[15]49  /** Debut config **/
50  char to_send[] = "$PASHS,NME,ALL,A,OFF\r\n";
[41]51  written=serialport->Write(to_send, sizeof(to_send));
52  if (written< 0) {
53      Thread::Err("erreur Write (%s)\n", strerror(-written));
54  }
[42]55
[15]56  {
57    char to_send[] = "$PASHS,CPD,AFP,95.0\r\n";
[41]58    written=serialport->Write(to_send, sizeof(to_send));
59    if (written< 0) {
60      Thread::Err("erreur Write (%s)\n", strerror(-written));
61    }
[15]62  }
63  {
64    char to_send[] = "$PASHS,DIF,PRT,C,RT3\r\n";
[41]65    written=serialport->Write(to_send, sizeof(to_send));
66    if (written< 0) {
67      Thread::Err("erreur Write (%s)\n", strerror(-written));
68    }
[15]69  }
[42]70
[15]71  if ((NMEAFlags & GGA) != 0) {
72    char to_send[] = "$PASHS,NME,GGA,A,ON,0.05\r\n";
[41]73    written = serialport->Write(to_send, sizeof(to_send));
74    if (written< 0) {
75      Thread::Err("erreur Write (%s)\n", strerror(-written));
76    }
[15]77  }
78  if ((NMEAFlags & VTG) != 0) {
79    char to_send[] = "$PASHS,NME,VTG,A,ON,0.05\r\n";
[41]80    written = serialport->Write(to_send, sizeof(to_send));
81    if (written< 0) {
82      Thread::Err("erreur Write (%s)\n", strerror(-written));
83    }
[15]84  }
85  if ((NMEAFlags & GST) != 0) {
86    char to_send[] = "$PASHS,NME,GST,A,ON,0.05\r\n";
[41]87    written = serialport->Write(to_send, sizeof(to_send));
88    if (written< 0) {
89      Thread::Err("erreur Write (%s)\n", strerror(-written));
90    }
[15]91  }
[3]92
[15]93  Sync();
[3]94
[15]95  /** Fin config **/
[3]96
[15]97  /** Debut running loop **/
98  WarnUponSwitches(true);
[3]99
[15]100  while (!ToBeStopped()) {
101    SleepMS(10);
[42]102    size = 0;
[15]103    while (!ToBeStopped()) {
104      ssize_t read = serialport->Read(&response[size], 1);
105      if (read < 0) {
106        Thread::Err("erreur Read (%s)\n", strerror(-read));
107      }
[3]108
[15]109      if (response[size] == 0x0a)
110        break;
111      size++;
[42]112    }
[15]113    size++;
[42]114    parseFrame(response, size);
[15]115  }
116  /** fin running loop **/
117  WarnUponSwitches(false);
[3]118}
119
[15]120void Mb800::Sync(void) {
121  char data = 0;
122  ssize_t read = 0;
[42]123
[15]124  // attente fin trame
[41]125  while (data != 0x0a && !ToBeStopped()) {
[15]126    read = serialport->Read(&data, 1);
[41]127    SleepMS(10);
[42]128
[15]129    if (read < 0) {
130      Thread::Err("erreur Read (%s)\n", strerror(-read));
[3]131    }
[15]132  }
[3]133}
134
135} // end namespace sensor
136} // end namespace framewor
Note: See TracBrowser for help on using the repository browser.