def _WriteSharedVar(sharedVarType, name, data): w = str(data) if sharedVarType == SharedVarTypes.BYTE_ARRAY: w = '0x' + ''.join(["%02X" % x for x in data]) elif sharedVarType in [SharedVarTypes.INT, SharedVarTypes.LONG]: w = str(int(data)) elif sharedVarType == SharedVarTypes.DOUBLE: w = str(float(data)) elif sharedVarType in [ SharedVarTypes.INT_ARRAY, SharedVarTypes.LONG_ARRAY ]: w = ' '.join([str(int(x)) for x in data]) elif sharedVarType == SharedVarTypes.DOUBLE_ARRAY: w = ' '.join([str(float(x)) for x in data]) elif sharedVarType == SharedVarTypes.STRING: w = Message._SerializeString(data) elif sharedVarType == SharedVarTypes.MATRIX: w = SharedVar._SerializeMatrix(data) elif sharedVarType == SharedVarTypes.RECOGNIZED_SPEECH: w = SharedVar._SerializeRecognizedSpeech(data) else: print 'pyRobotics - ERROR: Unhandled shared var type' return False r = BB.SendAndWait( Command('write_var', sharedVarType + ' ' + name + ' ' + w), 2000, 2) return (r and r.successful)
def _WriteSharedVar(sharedVarType, name, data): w = str(data) if sharedVarType == SharedVarTypes.BYTE_ARRAY: w = '0x' + ''.join([ "%02X" % x for x in data ]) elif sharedVarType in [SharedVarTypes.INT, SharedVarTypes.LONG]: w = str(int(data)) elif sharedVarType == SharedVarTypes.DOUBLE: w = str(float(data)) elif sharedVarType in [SharedVarTypes.INT_ARRAY, SharedVarTypes.LONG_ARRAY]: w = ' '.join([str(int(x)) for x in data]) elif sharedVarType == SharedVarTypes.DOUBLE_ARRAY: w = ' '.join([str(float(x)) for x in data]) elif sharedVarType == SharedVarTypes.STRING: w = Message._SerializeString(data) elif sharedVarType == SharedVarTypes.MATRIX: w = SharedVar._SerializeMatrix(data) elif sharedVarType == SharedVarTypes.RECOGNIZED_SPEECH: w = SharedVar._SerializeRecognizedSpeech(data) else: print 'pyRobotics - ERROR: Unhandled shared var type' return False r = BB.SendAndWait(Command('write_var', sharedVarType + ' ' + name + ' ' + w), 2000, 2) return (r and r.successful)
def _SerializeRecognizedSpeech(cls, data): if not data: return None txt = StringIO() txt.write('{ ' + str(len(data)) + ' ') for t in data: txt.write(Message._SerializeString(t[0]) + ' ' + str(t[1]) + ' ') txt.write('}') return txt.getvalue()