![](/media/cache/profiles/d741d4ae35aff8fd3674206068e40684.jpg.50x50_q85.jpg)
binary out test
main.cpp@0:33eee66305ae, 2018-08-06 (annotated)
- Committer:
- mfurukawa
- Date:
- Mon Aug 06 08:24:37 2018 +0000
- Revision:
- 0:33eee66305ae
- Child:
- 1:4c8086e3045d
initial commit and publish;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mfurukawa | 0:33eee66305ae | 1 | #include "mbed.h" |
mfurukawa | 0:33eee66305ae | 2 | |
mfurukawa | 0:33eee66305ae | 3 | #define SampleFreq 5 // [Hz] |
mfurukawa | 0:33eee66305ae | 4 | |
mfurukawa | 0:33eee66305ae | 5 | // define serial objects |
mfurukawa | 0:33eee66305ae | 6 | Serial pc(USBTX, USBRX); |
mfurukawa | 0:33eee66305ae | 7 | |
mfurukawa | 0:33eee66305ae | 8 | DigitalOut myled(LED1); |
mfurukawa | 0:33eee66305ae | 9 | |
mfurukawa | 0:33eee66305ae | 10 | Ticker ticker; |
mfurukawa | 0:33eee66305ae | 11 | Timer timer; |
mfurukawa | 0:33eee66305ae | 12 | |
mfurukawa | 0:33eee66305ae | 13 | unsigned int usCycle = 1000000/SampleFreq ; |
mfurukawa | 0:33eee66305ae | 14 | uint8_t dummy_code[6] = {0x01, 0x02, 0xF3, 0xF4, 0x85, 0x86} ; |
mfurukawa | 0:33eee66305ae | 15 | uint8_t u8buf[6]; |
mfurukawa | 0:33eee66305ae | 16 | |
mfurukawa | 0:33eee66305ae | 17 | void eventFunc(void) |
mfurukawa | 0:33eee66305ae | 18 | {// |
mfurukawa | 0:33eee66305ae | 19 | // timer.reset(); |
mfurukawa | 0:33eee66305ae | 20 | // timer.start(); |
mfurukawa | 0:33eee66305ae | 21 | |
mfurukawa | 0:33eee66305ae | 22 | // limitation on sending bytes at 921600bps - 92bits(under 100us/sample) |
mfurukawa | 0:33eee66305ae | 23 | // requirement : 1kHz sampling |
mfurukawa | 0:33eee66305ae | 24 | // = 921.5 bits/sample |
mfurukawa | 0:33eee66305ae | 25 | // = 115.1 bytes/sample |
mfurukawa | 0:33eee66305ae | 26 | // = 12.7 bytes/axis(9dof, including delimeter) each data uses float type value, equals to 4 bytes as binary description |
mfurukawa | 0:33eee66305ae | 27 | |
mfurukawa | 0:33eee66305ae | 28 | memcpy(u8buf, dummy_code, sizeof(uint8_t) * 6); |
mfurukawa | 0:33eee66305ae | 29 | //fwrite(u8buf, sizeof(uint8_t), 6, stdout); |
mfurukawa | 0:33eee66305ae | 30 | for(int i=0;i<6;i++) |
mfurukawa | 0:33eee66305ae | 31 | putc(dummy_code[i], stdout); |
mfurukawa | 0:33eee66305ae | 32 | |
mfurukawa | 0:33eee66305ae | 33 | // terminator for ascii sending only // |
mfurukawa | 0:33eee66305ae | 34 | printf("\r\n"); |
mfurukawa | 0:33eee66305ae | 35 | } |
mfurukawa | 0:33eee66305ae | 36 | |
mfurukawa | 0:33eee66305ae | 37 | int main() |
mfurukawa | 0:33eee66305ae | 38 | { |
mfurukawa | 0:33eee66305ae | 39 | pc.baud(921600); //921600 / 115200 |
mfurukawa | 0:33eee66305ae | 40 | char c; |
mfurukawa | 0:33eee66305ae | 41 | |
mfurukawa | 0:33eee66305ae | 42 | while(1) { |
mfurukawa | 0:33eee66305ae | 43 | if(pc.readable()){ |
mfurukawa | 0:33eee66305ae | 44 | c = pc.getc(); |
mfurukawa | 0:33eee66305ae | 45 | |
mfurukawa | 0:33eee66305ae | 46 | if(c == 's') { |
mfurukawa | 0:33eee66305ae | 47 | // define callback event |
mfurukawa | 0:33eee66305ae | 48 | ticker.attach_us(eventFunc, 1000000.0f/SampleFreq); |
mfurukawa | 0:33eee66305ae | 49 | } |
mfurukawa | 0:33eee66305ae | 50 | else if(c == 'r') { |
mfurukawa | 0:33eee66305ae | 51 | ticker.detach(); |
mfurukawa | 0:33eee66305ae | 52 | printf("terminated\r\n"); |
mfurukawa | 0:33eee66305ae | 53 | } |
mfurukawa | 0:33eee66305ae | 54 | } |
mfurukawa | 0:33eee66305ae | 55 | } |
mfurukawa | 0:33eee66305ae | 56 | |
mfurukawa | 0:33eee66305ae | 57 | |
mfurukawa | 0:33eee66305ae | 58 | } |