![](/media/cache/profiles/d741d4ae35aff8fd3674206068e40684.jpg.50x50_q85.jpg)
binary out test
main.cpp
- Committer:
- mfurukawa
- Date:
- 2018-08-06
- Revision:
- 0:33eee66305ae
- Child:
- 1:4c8086e3045d
File content as of revision 0:33eee66305ae:
#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"); } } } }