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: Novatel.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 Novatel
|
---|
14 | //
|
---|
15 | //
|
---|
16 | /*********************************************************************/
|
---|
17 |
|
---|
18 | #include "Novatel.h"
|
---|
19 | #include <SerialPort.h>
|
---|
20 | #include <FrameworkManager.h>
|
---|
21 | #include <string.h>
|
---|
22 |
|
---|
23 | using std::string;
|
---|
24 | using namespace flair::core;
|
---|
25 |
|
---|
26 | namespace flair {
|
---|
27 | namespace sensor {
|
---|
28 |
|
---|
29 | Novatel::Novatel(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 |
|
---|
35 | SetIsReady(true);
|
---|
36 | }
|
---|
37 |
|
---|
38 | Novatel::~Novatel() {
|
---|
39 | SafeStop();
|
---|
40 | Join();
|
---|
41 | }
|
---|
42 |
|
---|
43 | void Novatel::Run(void) {
|
---|
44 | ssize_t written;
|
---|
45 |
|
---|
46 | WarnUponSwitches(true);
|
---|
47 |
|
---|
48 | char to_send[] = "log gpggalong ontime 0.05\n";
|
---|
49 | written = serialport->Write(to_send, sizeof(to_send));
|
---|
50 | if (written < 0) {
|
---|
51 | Thread::Err("erreur write (%s)\n", strerror(-written));
|
---|
52 | }
|
---|
53 | char to_send2[] = "log gpvtg ontime 0.05\n";
|
---|
54 | written = serialport->Write(to_send2, sizeof(to_send2));
|
---|
55 | if (written < 0) {
|
---|
56 | Thread::Err("erreur write (%s)\n", strerror(-written));
|
---|
57 | }
|
---|
58 |
|
---|
59 | Sync();
|
---|
60 |
|
---|
61 | while (!ToBeStopped()) {
|
---|
62 | char response[1024] = {0};
|
---|
63 | int size = 0;
|
---|
64 | while (!ToBeStopped()) {
|
---|
65 | ssize_t read = serialport->Read(&response[size], 1);
|
---|
66 | if (read < 0) {
|
---|
67 | Thread::Err("erreur Read (%s)\n", strerror(-read));
|
---|
68 | }
|
---|
69 |
|
---|
70 | if (response[size] == 0x0a ) break;
|
---|
71 | size++;
|
---|
72 | if (size==sizeof(response)) break;
|
---|
73 | }
|
---|
74 | if (size!=sizeof(response)) {
|
---|
75 | size++;
|
---|
76 | parseFrame(response, size);
|
---|
77 | } else {
|
---|
78 | Thread::Warn("frame too long for buffer\n");
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | WarnUponSwitches(false);
|
---|
83 | }
|
---|
84 |
|
---|
85 | void Novatel::Sync(void) {
|
---|
86 | char data = 0;
|
---|
87 | ssize_t Read = 0;
|
---|
88 |
|
---|
89 | // attente fin trame
|
---|
90 | while (data != 0x0a) {
|
---|
91 | Read = serialport->Read(&data, 1);
|
---|
92 | if (Read < 0) {
|
---|
93 | Thread::Err("erreur Read (%s)\n", strerror(-Read));
|
---|
94 | }
|
---|
95 | }
|
---|
96 | }
|
---|
97 |
|
---|
98 | } // end namespace sensor
|
---|
99 | } // end namespace flair
|
---|