source: flair-src/branches/sanscv/tools/Controller/Mavlink/src/Forwarder.cpp@ 418

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

removing opencv dependency

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: 2016/09/02
6// filename: Forwarder.cpp
7//
8// authors: Thomas Fuhrmann
9// Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11// version: $Id: $
12//
13// purpose: Forward input data to output data, using sockets
14//
15//
16/*********************************************************************/
17
18#include "Forwarder.h"
19
20#include <UdpSocket.h>
21#include <Thread.h>
22#include <FrameworkManager.h>
23
24//todo remove for tests
25#include <iostream>
26
27using namespace std;
28using namespace flair::core;
29
30Forwarder::Forwarder(string name, string &inputAddress,
31 int inputPort, string &outputAddress, int outputPort):
32 Thread(getFrameworkManager(), name, 6), inputAddress(inputAddress),
33 inputPort(inputPort), outputAddress(outputAddress),
34 outputPort(outputPort) {
35 cout << "MavPlanner Forwarder constructor" << endl;
36
37 // string tmpOutput = outputAddress + ":" + to_string(outputPort);
38 // cout << "MavPlanner Forwarder output address : " << tmpOutput << endl;
39
40 // cout << "input socket : " << inputAddress + ":" + to_string(inputPort) << endl;
41 // cout << "output socket : " << outputAddress + ":" + to_string(outputPort) << endl;
42
43 inputSocket = new UdpSocket((Thread *)this, "input socket", inputPort);
44 outputSocket = new UdpSocket((Thread *)this, "output socket", outputAddress + ":" + to_string(outputPort));
45}
46
47Forwarder::~Forwarder() {
48
49}
50
51void Forwarder::Run() {
52 if (getFrameworkManager()->ErrorOccured()) {
53 SafeStop();
54 Thread::Err("An error occurred, we don't launch the Run loop.\n");
55 }
56 int recvDataSize = 0;
57 char inputBuffer[200];
58 while (!ToBeStopped()) {
59 recvDataSize = inputSocket->RecvMessage(inputBuffer, 200, 1000000000);
60 outputSocket->SendMessage(inputBuffer, recvDataSize);
61 }
62}
Note: See TracBrowser for help on using the repository browser.