我正在使用xilinx Spartan6板和微控制器,我使用微控制器加速度计来控制我的Spartan6上的一个移动块。
我现在打印
xil_printf("%c",XUartLite_RecvByte(XPAR_UARTLITE_1_BASEADDR));我在我的终端机返回
$SWITCH 0
$ENC___ 13
$ACC___ -205 -317 860
$ACCRAW 796 812 1134
$SWITCH 0
$ENC___ 13我只是不想要我的$ACCRAW数据,你知道如何做到这一点并存储它来控制我的movingBlock吗?
发布于 2014-04-24 20:30:15
你需要一个parser。
在您的示例中,这将是一个简单的状态机,已识别的字符串\n$ACCRAW的每个字母对应一个状态,即
State 0 (uninteresting data):
'\n' -> go to state 1
otherwise -> go to state 0
State 1 (beginning of line):
'$' -> go to state 2
'\n' -> go to state 1
otherwise -> go to state 0
State 2 (after dollar sign):
'A' -> go to state 3
'\n' -> go to state 1
otherwise -> go to state 0
[...]
State 8 (after "$ACCRAW"):
' ' -> clear x, go to state 9
'\n' -> go to state 1
otherwise -> go to state 0State 9 (read X value):
'0'-'9' -> multiply x by 10, add current digit
' ' -> clear y, go to state 10
'\n' -> go to state 1
otherwise -> go to state 0
[...]
State 11 (read Z value):
'0'-'9' -> multiply z by 10, add current digit
'\n' -> start processing of data, go to state 1
otherwise -> go to state 0您可以在状态0或1中启动状态机。
https://stackoverflow.com/questions/23245655
复制相似问题