source: flair-src/branches/sanscv/lib/FlairSensorActuator/src/Mb800.cpp@ 412

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

removing opencv dependency

File size: 3.5 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#ifdef ARMV7A
18
19#include "Mb800.h"
20#include <SerialPort.h>
21#include <FrameworkManager.h>
22#include <string.h>
23
24using std::string;
25using namespace flair::core;
26
27namespace flair {
28namespace sensor {
29
30Mb800::Mb800(string name,
31 SerialPort *serialport, NmeaGps::NMEAFlags_t NMEAFlags,
32 uint8_t priority)
33 : NmeaGps(name, NMEAFlags), Thread(getFrameworkManager(), name, priority) {
34 this->serialport = serialport;
35 serialport->SetRxTimeout(100000000);
36
37 SetIsReady(true);
38}
39
40Mb800::~Mb800() {
41 SafeStop();
42 Join();
43}
44
45void Mb800::Run(void) {
46 int 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 char response[1024] = {0};
108 int 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 ) break;
116 size++;
117 if (size==sizeof(response)) break;
118 }
119 if (size!=sizeof(response)) {
120 size++;
121 parseFrame(response, size);
122 } else {
123 Thread::Warn("frame too long for buffer\n");
124 }
125 }
126
127 /** fin running loop **/
128 WarnUponSwitches(false);
129}
130
131void Mb800::Sync(void) {
132 char data = 0;
133 ssize_t read = 0;
134
135 // attente fin trame
136 while (data != 0x0a && !ToBeStopped()) {
137 read = serialport->Read(&data, 1);
138 SleepMS(10);
139
140 if (read < 0) {
141 Thread::Err("erreur Read (%s)\n", strerror(-read));
142 }
143 }
144}
145
146} // end namespace sensor
147} // end namespace flair
148
149#endif
Note: See TracBrowser for help on using the repository browser.