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

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

add defines for architectures to speed up compile time

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