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

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

m

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