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

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