Example #1
0
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)
Example #2
0
def _SubscribeToSharedVar(name, subscriptionType, reportType):

    r = BB.SendAndWait(
        Command(
            'suscribe_var',
            name + ' suscribe=' + subscriptionType + ' report=' + reportType),
        2000, 2)
    return (r and r.successful)
Example #3
0
def _ReadSharedVar(name):

    r = BB.SendAndWait(Command('read_var', name), 2000)

    if not (r and r.successful):
        return None

    return r.data
Example #4
0
    def _Execute(self):

        response = None

        currentAttempt = 0

        self._attemptsLock.acquire()
        att = self._attempts
        self._attemptsLock.release()

        while not response and (att == 0 or currentAttempt < att):
            currentAttempt += 1
            response = BB.SendAndWait(self._command, self._timeout)

            self._attemptsLock.acquire()
            att = self._attempts
            self._attemptsLock.release()

        self._setResponse(response)
        self._setSending(False)
Example #5
0
def _CreateSharedVar(svType, name):
    r = BB.SendAndWait(Command('create_var', svType + ' ' + name), 2000, 2)

    return (r and r.successful)