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

Last change on this file since 164 was 157, checked in by Sanahuja Guillaume, 5 years ago

iadded isready to iodevice:
avoid problem of imu not ready in ardrone2

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