From 72162d64e2d3b471fb14a38d550182ea334c3231 Mon Sep 17 00:00:00 2001 From: Brendan Date: Tue, 10 Mar 2015 19:43:16 -0600 Subject: [PATCH] adds working DSM2 satellite receiver class --- CopterController/v2DSM2.cpp | 34 +++++++++++++++++++++++++++++++ CopterController/v2DSM2.h | 18 ++++++++++++++++ CopterController/v2DSM2tester.cpp | 15 ++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 CopterController/v2DSM2.cpp create mode 100644 CopterController/v2DSM2.h create mode 100644 CopterController/v2DSM2tester.cpp diff --git a/CopterController/v2DSM2.cpp b/CopterController/v2DSM2.cpp new file mode 100644 index 0000000..1c21a40 --- /dev/null +++ b/CopterController/v2DSM2.cpp @@ -0,0 +1,34 @@ +#include "v2DSM2.h" + +#include +#include "wiringSerial.h" + +#define VALUE_MASK 0x3FF + +v2DSM2::v2DSM2( int mode ) +{ + std::cout << "opening serial port..." << std::flush; + fd = serialOpen( "/dev/ttyAMA0", 115200 ); + std::cout << "SUCCESS " << fd << std::endl; + std::cout << "flushing serial..." << std::flush; + serialFlush(fd); + std::cout << "SUCCESS" << std::endl; +} + +void v2DSM2::update() +{ + int i = 0; + + if( serialDataAvail(fd) < 16 ) return; + + for( i = 0; i < 8; i++ ) + data[ i ] = ( (int)(serialGetchar(fd)) << 8 ) + serialGetchar(fd); + + *(values + 0) = data[7] & VALUE_MASK; //Throttle + *(values + 1) = data[1] & VALUE_MASK; //Aileron + *(values + 2) = data[3] & VALUE_MASK; //Elevator + *(values + 3) = data[5] & VALUE_MASK; //Rudder + *(values + 4) = data[4] & VALUE_MASK; //Gear + *(values + 5) = data[2] & VALUE_MASK; //Aux1 + return; +} diff --git a/CopterController/v2DSM2.h b/CopterController/v2DSM2.h new file mode 100644 index 0000000..dff6534 --- /dev/null +++ b/CopterController/v2DSM2.h @@ -0,0 +1,18 @@ +#ifndef V2DSM2_H +#define V2DSM2_H + +class v2DSM2 +{ +public: + v2DSM2( int mode = 1024 ); + + void update(); + int values[7]; +private: + int fd; + int valueMask; + char thisByte, lastByte; + int data[7]; +}; + +#endif \ No newline at end of file diff --git a/CopterController/v2DSM2tester.cpp b/CopterController/v2DSM2tester.cpp new file mode 100644 index 0000000..0ac2fc5 --- /dev/null +++ b/CopterController/v2DSM2tester.cpp @@ -0,0 +1,15 @@ +#include +#include "v2DSM2.h" + +using namespace std; + +int main(int argc, char const *argv[]) +{ + v2DSM2 dsm; + while( true ) + { + dsm.update(); + cout << "THRO " << dsm.values[0] << "\tAILE " << dsm.values[1] << "\tELEV " << dsm.values[2] << "\tRUDD " << dsm.values[3] << "\tGEAR " << dsm.values[4] << "\tAUX1 " << dsm.values[5] << endl; + } + return 0; +} \ No newline at end of file