The basic idea of the test is:
For a certain message length=M do:
- reset MCU
- cpu puts random message of length M and a single char ID (key1)
- mcu constinuously checks for a new ID, if it finds a new ID, it puts the message back to the cpu (key2)
- cpu checks (after a couple of seconds) if it gets the message it had sent.
- if YES: repeat (max 200 times for now)
- if NO: failure and decrease M
Results get written in a file.
To rule out timing issues I put quite some delays in the process (2 second wait on the cpu side, 2*250ms on the mcu side).
The result is imho quite amazing (not all lengths tested for now):
msg_length=60 FAILURE after 21 messages
msg_length=55 FAILURE after 21 messages
msg_length=50 FAILURE after 21 messages
msg_length=45 FAILURE after 21 messages
msg_length=40 FAILURE after 21 messages
msg_length=35 FAILURE after 21 messages
msg_length=30 FAILURE after 21 messages
msg_length=25 SUCCES 199 messages
msg_length=20 SUCCES 199 messages
msg_length=15 SUCCES 199 messages
Note that the buffer size on the mcu side is identical for each message length.
So all message lengths above or equal to 30 seem to fail, and surprisingly each time after 21 message exchanges??
Below that length no failures were detected.
Code:
#include "Bridge.h" void setup() { Bridge.begin(); } void loop() { unsigned int len; char buffer[64]; char prevID='-'; while(true) { Bridge.get("key",buffer,64); if(buffer[0]!=prevID) { // new message delay(250); Bridge.put("key2",&buffer[1]); prevID=buffer[0]; } delay(250); } }and
#!/usr/bin/python import sys import time import string import random def rand_generator(size=6, chars=string.ascii_uppercase + string.digits): return ''.join(random.choice(chars) for x in range(size)) sys.path.insert(0, '/usr/lib/python2.7/bridge/') from bridgeclient import BridgeClient as bridgeclient bc = bridgeclient() from subprocess import call f=open('test_result.txt','w') cnt4=0 msg_id='a' n_loops=200 for msg_length in range(60,10,-5): print "msg_length set to ",msg_length #reset mcu print "resetting mcu now" call(["reset-mcu"]) time.sleep(5) for loop in range(1,n_loops): time.sleep(2) if cnt4==0: msg_id='a' cnt4=1 elif cnt4==1: msg_id='b' cnt4=2 elif cnt4==2: msg_id='c' cnt4=3 else: msg_id='d' cnt4=0 msg=rand_generator(msg_length) toput=msg_id+msg print "put",toput bc.put('key',toput) # wait for identical returned value trial=1 while trial<4: time.sleep(1) r = bc.get('key2') print "get ",r if r is None: print " No answer key found yet" else: if r==msg: print " OK after",trial," trials" break else: print " FAIL" trial=trial+1 if trial>=4: f.write("msg_length=") f.write(str(msg_length)) f.write(" ") f.write("FAILURE after ") f.write(str(loop)) f.write(" messages\n") break elif loop==n_loops-1: f.write("msg_length=") f.write(str(msg_length)) f.write(" ") f.write("SUCCES ") f.write(str(loop)) f.write(" messages\n") f.close()
also available on http://forum.arduino.cc/index.php?topic=201484.msg1484792#msg1484792
No comments:
Post a Comment