-
-
Save oryjkov/3d7b0a6402b85cad6db9d14b2078b560 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import serial | |
import struct | |
s = serial.Serial('/dev/ttyACM1', 460800, timeout=1.0) | |
print('Opened port %s', s) | |
s.write(b'1') | |
ok = 0 | |
while True: | |
buf = s.read(1) | |
(msgLen, ) = struct.unpack('B', buf) | |
buf = s.read(msgLen) | |
sm = 0 | |
for c in buf[:-1]: | |
sm = (sm + c) % 256 | |
if sm != buf[-1]: | |
print("wrong sum", sm, buf[-1]) | |
else: | |
ok += 1 | |
if ok % 10 == 1: | |
print("ok", ok) | |
s.write(buf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mbed.h" | |
BufferedSerial com(USBTX, USBRX, 460800); | |
void check(BufferedSerial *com) { | |
uint8_t u; | |
com->read(&u, 1); | |
uint8_t buf[256]; | |
while(1) { | |
uint8_t len = rand() % 254 + 1; | |
uint8_t sum = 0; | |
for (int i = 0; i < len; i++) { | |
buf[i] = rand() % 256; | |
sum = (sum + buf[i]) % 256; | |
} | |
buf[len] = sum; | |
len += 1; | |
com->write(&len, 1); | |
com->write(buf, len); | |
int rd = 0; | |
while (rd < len) { | |
int x = com->read(&buf, len); | |
rd += x; | |
} | |
sum = 0; | |
for (int i = 0; i < len-1; i++) { | |
sum = (sum + buf[i]) % 256; | |
} | |
if (sum != buf[len-1]) { | |
while(1) {} | |
} | |
} | |
} | |
int main() { | |
check(&com); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"requires": ["bare-metal"], | |
"target_overrides": { | |
"*": { | |
"target.c_lib": "small" | |
}, | |
"K64F": { | |
"platform.stdio-baud-rate": 9600 | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"target_overrides": { | |
"*": { | |
"target.c_lib": "small" | |
}, | |
"K64F": { | |
"platform.stdio-baud-rate": 9600 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment