binary out test

Dependencies:   mbed

Revision:
0:33eee66305ae
Child:
1:4c8086e3045d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Aug 06 08:24:37 2018 +0000
@@ -0,0 +1,58 @@
+#include "mbed.h"
+
+#define SampleFreq  5   // [Hz]
+
+// define serial objects
+Serial          pc(USBTX, USBRX);
+
+DigitalOut myled(LED1);
+
+Ticker          ticker;
+Timer           timer;
+
+unsigned int usCycle = 1000000/SampleFreq ;
+uint8_t dummy_code[6] = {0x01, 0x02, 0xF3, 0xF4, 0x85, 0x86} ;
+uint8_t u8buf[6];
+
+void eventFunc(void)
+{//
+//    timer.reset();
+//    timer.start();
+    
+    // limitation on sending bytes at 921600bps - 92bits(under 100us/sample)
+    // requirement : 1kHz sampling
+    // = 921.5 bits/sample
+    // = 115.1 bytes/sample
+    // = 12.7 bytes/axis(9dof, including delimeter) each data uses float type value, equals to 4 bytes as binary description
+        
+    memcpy(u8buf, dummy_code, sizeof(uint8_t) * 6);
+    //fwrite(u8buf, sizeof(uint8_t), 6, stdout);
+    for(int i=0;i<6;i++)
+        putc(dummy_code[i], stdout);
+        
+    // terminator for ascii sending only // 
+    printf("\r\n");
+}
+
+int main()
+{   
+    pc.baud(921600); //921600 / 115200
+    char c;
+ 
+    while(1) {
+        if(pc.readable()){
+            c = pc.getc();
+        
+            if(c == 's') {
+                // define callback event
+                 ticker.attach_us(eventFunc, 1000000.0f/SampleFreq);
+            }    
+            else if(c == 'r') {
+                ticker.detach();
+                printf("terminated\r\n");
+            }    
+        }
+    }
+     
+
+}