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

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

sources reformatted with flair-format-dir script

File size: 2.7 KB
RevLine 
[3]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[3]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
[15]26namespace flair {
27namespace sensor {
[3]28
[15]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);
[3]35}
36
[15]37Mb800::~Mb800() {
38 SafeStop();
39 Join();
[3]40}
41
[15]42void Mb800::Run(void) {
43 /** Debut init **/
44 char response[200] = {0};
45 int size;
[3]46
[15]47 /** Fin init **/
[3]48
[15]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";
[3]55 serialport->Write(to_send, sizeof(to_send));
[15]56 }
57 {
58 char to_send[] = "$PASHS,DIF,PRT,C,RT3\r\n";
59 serialport->Write(to_send, sizeof(to_send));
60 }
[3]61
[15]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 }
[3]77
[15]78 Sync();
[3]79
[15]80 /** Fin config **/
[3]81
[15]82 /** Debut running loop **/
83 WarnUponSwitches(true);
[3]84
[15]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 }
[3]93
[15]94 if (response[size] == 0x0a)
95 break;
96 size++;
[3]97 }
[15]98 size++;
99 parseFrame(response, size);
100 }
101 /** fin running loop **/
102 WarnUponSwitches(false);
[3]103}
104
[15]105void Mb800::Sync(void) {
106 char data = 0;
107 ssize_t read = 0;
[3]108
[15]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));
[3]114 }
[15]115 }
[3]116}
117
118} // end namespace sensor
119} // end namespace framewor
Note: See TracBrowser for help on using the repository browser.