source: flair-src/trunk/lib/FlairSensorActuator/src/ParrotGps.cpp@ 4

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

sensoractuator

File size: 1.9 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: 2014/06/04
6// filename: ParrotGps.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 de l'ardrone2
14//
15//
16/*********************************************************************/
17
18#include "ParrotGps.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
31ParrotGps::ParrotGps(const FrameworkManager* parent,string name,SerialPort *serialport,Gps::NMEAFlags_t NMEAFlags,uint8_t priority) : Thread(parent,name,priority), Gps(parent,name,NMEAFlags)
32{
33 this->serialport=serialport;
34
35 serialport->SetBaudrate(4800);
36 serialport->SetRxTimeout(100000000);
37}
38
39ParrotGps::~ParrotGps()
40{
41 SafeStop();
42 Join();
43}
44
45void ParrotGps::Run(void)
46{
47 char response[200] = {0};
48 int size;
49
50 Sync();
51
52 WarnUponSwitches(true);
53
54 while(!ToBeStopped())
55 {
56 SleepMS(10);
57 size=0;
58 while(!ToBeStopped())
59 {
60 ssize_t read = serialport->Read(&response[size],1);
61 if(read<0)
62 {
63 Thread::Err("erreur Read (%s)\n",strerror(-read));
64 }
65 if(response[size]==0x0a) break;
66 size++;
67 }
68 size++;
69 parseFrame(response, size);
70
71 }
72
73 WarnUponSwitches(false);
74}
75
76void ParrotGps::Sync(void)
77{
78 char data=0;
79 ssize_t read = 0;
80
81 //attente fin trame
82 while(data!=0x0a)
83 {
84 read = serialport->Read(&data,1);
85 if(read<0)
86 {
87 Thread::Err("erreur Read (%s)\n",strerror(-read));
88 }
89 }
90}
91
92} // end namespace sensor
93} // end namespace framewor
Note: See TracBrowser for help on using the repository browser.