An example Program for the SimpleSerialProtocol Library, This program will receive a packet, then echo it back to the client

Dependencies:   mbed SimpleSerialProtocol MODSERIAL

A simple example program that receives a packet over serial and echos it back.

I include this java program to show an example client application, all this program does is send packets as fast as it can without filling up its output buffer, the mbed will echo these packets back.

This is a good benchmark of the serial connection, and should show about 11KB/s at 115200baud

/media/uploads/p3p/serialecho.zip

example command: java -jar SerialEcho.jar com3 115200

Revision:
2:8799090c0fe4
Parent:
0:109a0b974600
Child:
10:f6862abba2d5
--- a/main.cpp	Thu Nov 24 23:21:44 2011 +0000
+++ b/main.cpp	Mon Jan 16 22:46:45 2012 +0000
@@ -1,60 +1,28 @@
-#include "mbed.h"
-#include "Protocol.h"
-
-//class will receive a packet and echo it back out
-class TestProtocol : public SimpleSerialProtocol::Protocol {
-public:
-    TestProtocol() : Protocol(p9, p10, NC) { //LED1 to 4 for a status led, NC to disable
-        _dma_port = 1; //set the dma port, must be unique per class 0 - 9
-    }
-    virtual ~TestProtocol() {};
-
-#pragma pack(push, 1) //must pack the structure to byte boundary for raw recast to work reliably
-    struct PacketInterface {
-        PacketInterface() {
-            type = 1; // initialise the type
-        }
-        uint8_t type;
-        uint8_t data;
-        uint16_t datashort;
-        uint32_t dataint;
-        float datafloat;
-    };
-#pragma pack(pop)
-
-    virtual void decode() {
-        switch (_packet._type) {
-            case 1:
-                if (_packet._size == sizeof( PacketInterface)) { //check that the packet in the correct size to avoid memory corruption
-                    PacketInterface* message;
-                    message = reinterpret_cast<PacketInterface*>(_packet._data); //cast the raw data to the packet struct
-                    
-                    //use the data through the struct interface
-                    uint8_t temp = message->data;
-                    short temp1 = message->datashort;
-                    int temp2 = message->dataint;
-                    float temp3 = message->datafloat;
-                    
-                    PacketInterface sendMessage; // initialise a packet to send
-                    sendMessage.data = temp;
-                    sendMessage.datashort = temp1;
-                    sendMessage.dataint = temp2;
-                    sendMessage.datafloat = temp3;
-                    sendPacket<PacketInterface>(&sendMessage); //send the packet (async)
-                }
-                break;
-            default:
-                break;
-        }
-    }
-};
-
-TestProtocol testProtocol;
-
-//the main loop
-int main() {
-    testProtocol.initialise();
-    while (1) {
-        testProtocol.update();
-    }
-}
+#include "mbed.h"
+#include "Protocol.h"
+#include "TestProtocol.h"
+
+//valid test packet bytes
+//
+// 255 127 // packet start 2 bytes 
+// 12 // payload size 1 byte
+// 0 0 0 0 0 0 0 0 0 0 0 0 // payload data
+// 16 // checksum 1 byte
+
+//checksum calculation
+//
+//    uint8_t tmp_checksum = 16;
+//    for (int i = 0; i < packet_size; i++) {
+//        tmp_checksum ^= packet[i];
+//    }
+//    return tmp_checksum;
+
+TestProtocol testProtocol;
+
+//the main loop
+int main() {
+    testProtocol.initialise();    
+    while (1) {
+        testProtocol.update();
+    }
+}