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

Last change on this file since 14 was 3, checked in by Sanahuja Guillaume, 9 years ago

sensoractuator

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