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