adds working DSM2 satellite receiver class

This commit is contained in:
Brendan Haines 2015-03-10 19:43:16 -06:00
parent 6d76979ea4
commit 72162d64e2
3 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,34 @@
#include "v2DSM2.h"
#include <iostream>
#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;
}

18
CopterController/v2DSM2.h Normal file
View File

@ -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

View File

@ -0,0 +1,15 @@
#include <iostream>
#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;
}