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

Last change on this file since 194 was 194, checked in by Sanahuja Guillaume, 4 years ago

m

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