/elec/quadcopter

To get this branch, use:
bzr branch http://bzr.ed.am/elec/quadcopter

« back to all changes in this revision

Viewing changes to src/rc-interface/comms.cc

  • Committer: dan
  • Date: 2014-02-05 19:30:09 UTC
  • Revision ID: dan-20140205193009-r1fy3n31e4tfilo8
Added Ultra Sonic Prox sensor test prog

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
}
44
44
 
45
45
 
46
 
void Comms::write_channels( int channel_values[] )
 
46
static void write_raw_channel_data( int channel_values[] )
47
47
{
48
 
//      draw_graph( channel_values );
49
 
 
50
48
        Serial.write( -1 );
51
49
        Serial.write( -1 );
52
50
        unsigned char *data = reinterpret_cast< unsigned char * >( channel_values );
54
52
}
55
53
 
56
54
 
57
 
bool Comms::read_channels( int channel_values[] )
 
55
void Comms::write_channels( int channel_values[] )
58
56
{
59
 
        static unsigned char buf[ sizeof( int ) * ( NUM_MOTORS + 1 ) ];
60
 
        static unsigned int buflen = 0;
61
 
 
62
 
        bool frame_complete = false;
63
 
 
64
 
        while( buflen < sizeof( buf ) && Serial.available() )
65
 
        {
66
 
                // read byte
67
 
                buf[ buflen++ ] = Serial.read();
68
 
 
69
 
                // check if we've got a frame
70
 
                if( buflen > 1 &&
71
 
                        buf[ buflen - 1 ] == 0xff && buf[ buflen - 2 ] == 0xff )
72
 
                {
73
 
                        // got a complete frame?
74
 
                        if( buflen == sizeof( buf ) ) {
75
 
                                frame_complete = true;
76
 
 
77
 
                                // copy channel values
78
 
                                unsigned char *data =
79
 
                                        reinterpret_cast< unsigned char * >( channel_values );
80
 
                                memcpy( data, buf, sizeof( int ) * NUM_MOTORS );
81
 
                        }
82
 
 
83
 
                        // reset read buffer
84
 
                        buflen = 0;
85
 
                }
86
 
        }
87
 
 
88
 
        // reset read buffer in the case where the buffer is full, but there's been
89
 
        // no end-of-frame marker (i.e., bad data)
90
 
        if( buflen >= sizeof( buf ) )
91
 
                buflen = 0;
92
 
 
93
 
        return frame_complete;
 
57
        // draw_graph( channel_values );
 
58
        write_raw_channel_data( channel_values );
94
59
}
 
60