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

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

modifs gps

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