8 BotSense Unit Test Script 73 msgId = BsProxyMsgIdDevCmd
75 print >>sys.stderr,
"error: %s missing argument(s)" % cmdName
79 if whichfoot
not in [
'bpfoot_left',
'bpfoot_right']:
80 print >>sys.stderr,
"error: %s %s: whichfoot foot?" % (cmdName, args[0])
82 handle = BsClientHandles.get(whichfoot)
84 print >>sys.stderr,
"error: %s: proxied device not found" % whichfoot
86 if footcmd ==
'getids':
87 devCmdId = BsProxyBPFootCmdIdGetIds
88 cmd = BsPacker.PackMsg(msgId,
89 [ {
'fval':handle,
'ftype':
'u8'},
90 {
'fval':devCmdId,
'ftype':
'u8'},
92 sendCmd(BsClientSock, cmd)
93 rsp = recvRsp(BsClientSock)
95 vals = BsPacker.UnpackMsg(rsp, msgId,
96 [ {
'fname':
'devId',
'ftype':
'u16'},
97 {
'fname':
'version',
'ftype':
'u8'}
99 if vals[
'_rc'] ==
'ok':
100 print "%s %s device_id=0x%04x version=0x%02x" % \
101 (whichfoot, cmdName, vals[
'devId'], vals[
'version'])
103 print "error:", vals[
'_error_msg']
104 elif footcmd ==
'getraw':
105 devCmdId = BsProxyBPFootCmdIdGetRaw
106 cmd = BsPacker.PackMsg(msgId,
107 [ {
'fval':handle,
'ftype':
'u8'},
108 {
'fval':devCmdId,
'ftype':
'u8'},
110 sendCmd(BsClientSock, cmd)
111 rsp = recvRsp(BsClientSock)
113 vals = BsPacker.UnpackMsg(rsp, msgId,
114 [{
'fname':
'press_raw',
'ftype':
'u16',
'fcount':8}])
115 if vals[
'_rc'] ==
'ok':
116 print "%s pressure_raw" % (whichfoot),
117 for press
in vals[
'press_raw']:
121 print "error:", vals[
'_error_msg']
122 elif footcmd ==
'getcooked':
123 devCmdId = BsProxyBPFootCmdIdGetCooked
124 cmd = BsPacker.PackMsg(msgId,
125 [ {
'fval':handle,
'ftype':
'u8'},
126 {
'fval':devCmdId,
'ftype':
'u8'},
128 sendCmd(BsClientSock, cmd)
129 rsp = recvRsp(BsClientSock)
131 vals = BsPacker.UnpackMsg(rsp, msgId,
132 [{
'fname':
'press_cal',
'ftype':
'u16',
'fcount':8}])
133 if vals[
'_rc'] ==
'ok':
134 print "%s pressure_cal" % (whichfoot),
135 for press
in vals[
'press_cal']:
139 print "error:", vals[
'_error_msg']
141 print >>sys.stderr,
"error: %s: unknown device command" % args[1]
144 def CmdDevOpen(args):
146 msgId = BsProxyMsgIdDevOpen
148 print >>sys.stderr,
"error: %s: missing argument(s)" % cmdName
150 devTypeName = args[0]
151 if devTypeName ==
'i2c':
152 devType = BsProxyDevTypeI2C
153 elif devTypeName ==
'bpfoot_left' or devType ==
'bpfoot_right':
154 devType = BsProxyDevTypeBPFoot
155 elif devTypeName ==
'bpimu':
156 devType = BsProxyDevTypeBPImu
158 print >>sys.stderr,
"error: 0x%02x: unknown type" % devTypeName
160 i2cAddr = str2int(args[1])
166 devName =
'/dev/null' 167 cmd = BsPacker.PackMsg(msgId,
168 [ {
'fval':devType,
'ftype':
'u8'},
169 {
'fval':i2cAddr,
'ftype':
'u8'},
170 {
'fval':devName,
'ftype':
'zstr'}
172 sendCmd(BsClientSock, cmd)
173 rsp = recvRsp(BsClientSock)
175 vals = BsPacker.UnpackMsg(rsp, msgId,
176 [{
'fname':
'handle',
'ftype':
'u8'}],
177 BsPacker.GetLastTid())
178 if vals[
'_rc'] ==
'ok':
179 print "proxied device %s's handle is %d" % (devTypeName, vals[
'handle'])
180 BsClientHandles[devTypeName] = vals[
'handle']
182 print "error:", vals[
'_error_msg']
185 def CmdDevClose(args):
187 msgId = BsProxyMsgIdDevClose
189 print >>sys.stderr,
"error: %s missing argument(s)" % cmdName
191 handle = str2int(args[0])
194 cmd = BsPacker.PackMsg(msgId, [{
'fval':handle,
'ftype':
'u8'}])
195 sendCmd(BsClientSock, cmd)
196 rsp = recvRsp(BsClientSock)
198 vals = BsPacker.UnpackMsg(rsp, msgId, [{
'fname':
'handle',
'ftype':
'u8'}])
199 if vals[
'_rc'] ==
'ok':
200 for k,v
in BsClientHandles.iteritems():
202 del BsClientHandles[k]
205 print "error:", vals[
'_error_msg']
215 port = str2int(args[1])
220 rc = BsClientSock.connect_ex((addr, port))
222 print "Failed to connect, rc=%d (%s)" % \
223 (rc, errno.errorcode.get(rc,
'UNKNOWN'))
225 BsClientHandles.clear()
226 print "Connected to bsproxy @ %s:%d" % (addr, port)
232 BsClientHandles.clear()
235 def CmdLoopback(args):
237 msgId = BsProxyMsgIdLoopback
239 max = str2int(args[0])
248 loopmsg =
"loopback "+str(cnt)+
" "+s+
"\n" 249 cmd = BsPacker.PackMsg(msgId, [{
'fval':loopmsg,
'ftype':
'zstr'}])
250 sendCmd(BsClientSock, cmd)
251 rsp = recvRsp(BsClientSock)
253 vals = BsPacker.UnpackMsg(rsp, msgId,
254 [{
'fname':
'loopmsg',
'ftype':
'zstr'}],
255 BsPacker.GetLastTid())
256 if vals[
'_rc'] ==
'ok':
257 print vals[
'loopmsg'],
259 print "error:", vals[
'_error_msg']
261 if max
is not None and cnt > max:
268 msgId = BsProxyMsgIdVersion
269 cmd = BsPacker.PackMsg(msgId, [])
270 sendCmd(BsClientSock, cmd)
271 rsp = recvRsp(BsClientSock)
273 vals = BsPacker.UnpackMsg(rsp, msgId, [{
'fname':
'version',
'ftype':
'zstr'}])
274 if vals[
'_rc'] ==
'ok':
275 print 'BotSense Server Version: %s' % vals[
'version']
277 print "error:", vals[
'_error_msg']
282 msgId = BsProxyMsgIdProxyInfo
283 cmd = BsPacker.PackMsg(msgId, [])
284 sendCmd(BsClientSock, cmd)
285 rsp = recvRsp(BsClientSock)
287 vals = BsPacker.UnpackMsg(rsp, msgId, [])
288 if vals[
'_rc'] ==
'ok':
289 print 'Server proxied devices:',
293 print '0x%02x' % ord(rsp[k]),
298 print "error:", vals[
'_error_msg']
303 msgId = BsProxyMsgIdLog
305 print >>sys.stderr,
"error: %s: missing argument(s)" % cmdName
307 level = str2int(args[0])
310 cmd = BsPacker.PackMsg(msgId, [{
'fval':level,
'ftype':
'u8'}])
311 sendCmd(BsClientSock, cmd)
312 rsp = recvRsp(BsClientSock)
314 vals = BsPacker.UnpackMsg(rsp, msgId, [{
'fname':
'level',
'ftype':
'u8'}])
315 if vals[
'_rc'] ==
'ok':
316 print 'Server logging level: %d' % vals[
'level']
318 print "error:", vals[
'_error_msg']
321 def CmdI2CScan(args):
323 msgId = BsProxyMsgIdDevScan
325 print >>sys.stderr,
"error: %s: missing argument(s)" % cmdName
327 handle = str2int(args[0])
330 cmd = BsPacker.PackMsg(msgId, [{
'fval':handle,
'ftype':
'u8'}])
331 sendCmd(BsClientSock, cmd)
332 rsp = recvRsp(BsClientSock)
334 vals = BsPacker.UnpackMsg(rsp, msgId, [{
'fname':
'nScanned',
'ftype':
'u8'}])
335 if vals[
'_rc'] ==
'ok':
336 nScanned = vals[
'nScanned']
337 print "Scanned %d I2C devices" % nScanned
341 print "0x%02x" % ord(byte),
344 print "error:", vals[
'_error_msg']
351 The bsUnitTest python application is being rewritten to fit into BotSense 3.0. 355 cmd = raw_input(
"bsclient$ ")
359 elif args[0] ==
'quit':
361 elif args[0] ==
'open':
363 elif args[0] ==
'close':
365 elif args[0] ==
'loopback':
366 CmdLoopback(args[1:])
367 elif args[0] ==
'version':
369 elif args[0] ==
'info':
371 elif args[0] ==
'log':
373 elif args[0] ==
'i2cscan':
375 elif args[0] ==
'devopen':
376 handle = CmdDevOpen(args[1:])
377 elif args[0] ==
'devclose':
378 CmdDevClose(args[1:])
379 elif args[0] ==
'bpfoot_left' or args[0] ==
'bpfoot_right':
381 elif args[0] ==
'help':
382 print >>sys.stderr,
"""\ 383 BotSense Server UnitTest Help 384 ----------------------------- 386 *BrainPack Foot Commands 387 Two BP Feet (left and right) are supported. Use command 'devadd' to add each 388 foot to the bsproxy proxied devices. 390 General Foot Command Format: 391 bpfoot_left footcmd [byte...] 392 bpfoot_right footcmd [byte...] 393 footcmd - Foot-specific command. 394 byte... - Foot-specific command bytes, if any. 396 Specific Foot Commands: 397 ... getids - Get BrainPack foot identifiers. 398 ... getraw - Get foot raw sensor data. 399 ... getcooked - Get foot cooked sensor data. 402 *BotSense Proxy Connection Commands 403 Opens, closes, and tests bsproxy connection. 406 open [addr [port]] - Open connection on IP address and port. 407 addr - IP address. Default: 127.0.0.1 408 port - IP port. Default: 9195 409 close - Close connection. 410 loopback [cnt] - Loopback cnt times. 411 cnt - Number of loops. Default is forever. 412 version - Server version. 413 info - List of server supported proxied device types. 414 log - Set server log level. 415 i2cscan handle - Scan the I2C Bus for available I2C attached devices. 416 handle - allocated proxied device handle 419 *Proxied Device General Commands 420 Opens, closes, and lists client's proxied devices. 423 devopen type i2caddr [devname] 424 - Open proxied device. 425 type - One of: i2c bpfoot_left bpfoot_right bpimu. 426 i2caddr - I2C address [0x01 - 0x7f]. 427 devname - device name. Default: /dev/null 428 devclose handle - Close proxied device. 429 handle - allocated proxied device handle 432 *BotSense UnitTest Commands 433 help - Print this help. 434 quit - Quit UnitTest shell. 437 print >>sys.stderr,
"Error:", args[0],
"; unknown command"