SerialFlow allows to send and receive packaged arrays of integer values via serial port.

SerialFlow allows to send and receive packaged arrays of integer(short only) values via serial port.

Packet format:

  1. begin - 0x12
  2. end - 0x13
  3. value separator - 0x10
  4. escape - 0x7D

Simple packet example:
0x12,0x1,0x0,0x10,0x7D,0x12,0x0,0x13
corresponds to: [1,18]

Now handles only short int values. Example:

#include "mbed.h"
#include "SerialFlow.h"
SerialFlow pc(USBTX, USBRX);
AnalogIn gyro_x(p17); // data from gyro x axis
AnalogIn gyro_y(p18); // data from gyro y axis

int main(){
    // two short values
    pc.setPacketFormat(SerialFlow::COMPLEX_1, 2, 2);
    while(1){
        pc.setPacketValue((short)(gyro_x*1023.0));
        pc.setPacketValue((short)(gyro_y*1023.0));
        pc.sendPacket();
        wait(0.01);
    }
}

On the PC side you can use this program to catch data flows: http://www.poprobot.ru/files/sfmonitor_0.9.zip

Files at this revision

API Documentation at this revision

Comitter:
Decimus
Date:
Mon Sep 17 20:21:31 2012 +0000
Parent:
1:5f80d8d44549
Child:
3:7cbfd422c98e
Commit message:
Method "baud"

Changed in this revision

SerialFlow.cpp Show annotated file Show diff for this revision Revisions of this file
SerialFlow.h Show annotated file Show diff for this revision Revisions of this file
--- a/SerialFlow.cpp	Tue Sep 11 07:38:40 2012 +0000
+++ b/SerialFlow.cpp	Mon Sep 17 20:21:31 2012 +0000
@@ -28,6 +28,10 @@
     _collecting = 0;
 }
 
+void SerialFlow::baud(int baud_rate) {
+    _serial.baud(baud_rate);
+}
+
 void SerialFlow::setPacketFormat(DataFormat p_format, char v_length, char p_size) {
     _p_format = p_format;
     _p_size = p_size;
--- a/SerialFlow.h	Tue Sep 11 07:38:40 2012 +0000
+++ b/SerialFlow.h	Mon Sep 17 20:21:31 2012 +0000
@@ -39,6 +39,12 @@
     
     SerialFlow(PinName tx, PinName rx);
 
+    /** Set porta baud rate
+     *
+     * @param baud_rate Port baud rate.
+     */
+    void baud(int baud_rate);
+
     /** Set data packet format
      *
      * @param p_format Format type constant.