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

Last change on this file since 32 was 15, checked in by Bayard Gildas, 9 years ago

sources reformatted with flair-format-dir script

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