コード例 #1
0
ファイル: main.py プロジェクト: teleofis/Locker
def executeCommand(command):
    global OUT1_STATE
    global OUT1_OFF_TIME
    global OUT2_STATE
    global OUT2_OFF_TIME
    ok = 0
    if(command.getCommand() == 'OUT1'):
        if(command.getParameter() == '0'):
            RX_API.setOUT1(0)
            OUT1_STATE = 0
            ok = 1
        if(command.getParameter() == '1'):
            RX_API.setOUT1(1)
            OUT1_STATE = 1
            OUT1_OFF_TIME = MOD.secCounter() + int(CFG.get('OUT1TIME'))
            ok = 1
        SER.send('Set OUT1 to %s\r' % (command.getParameter()))
    elif(command.getCommand() == 'OUT2'):
        if(command.getParameter() == '0'):
            RX_API.setOUT2(0)
            OUT2_STATE = 0
            ok = 1
        if(command.getParameter() == '1'):
            RX_API.setOUT2(1)
            OUT2_STATE = 1
            OUT2_OFF_TIME = MOD.secCounter() + int(CFG.get('OUT2TIME'))
            ok = 1
        SER.send('Set OUT2 to %s\r' % (command.getParameter()))
    elif(command.getCommand() == 'DEBUG'):
        CFG.set('DEBUG', command.getParameter())
        CFG.write()
        SER.send('DEBUG is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'REBOOTPERIOD'):
        CFG.set('REBOOTPERIOD', command.getParameter())
        CFG.write()
        SER.send('REBOOTPERIOD is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'ALIVESMS'):
        CFG.set('ALIVESMS', command.getParameter())
        CFG.write()
        SER.send('ALIVESMS is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'SAVEINPUTS'):
        CFG.set('SAVEINPUTS', command.getParameter())
        CFG.write()
        SER.send('SAVEINPUTS is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'ADC'):
        ADC_VALUE_NEW = RX_API.getADC() * 11
        SER.send('Current ADC value: %d\r' % (ADC_VALUE_NEW))
        return 'ADC=%d mV;' % (ADC_VALUE_NEW)
    elif(command.getCommand() == 'INPUTS'):
        ADC_VALUE = RX_API.getADC() * 11
        IN1_VALUE = RX_API.getSK1()
        IN2_VALUE = RX_API.getSK2()
        IN3_VALUE = RX_API.getCounter1()
        IN4_VALUE = RX_API.getCounter2()
        SER.send('Current IN1: %d, IN2: %d, IN3: %d, IN4: %d, ADC: %d\r' % (IN1_VALUE, IN2_VALUE, IN3_VALUE, IN4_VALUE, ADC_VALUE))
        return 'IN1=%d,IN2=%d,IN3=%d,IN4=%d,ADC=%d;' % (IN1_VALUE, IN2_VALUE, IN3_VALUE, IN4_VALUE, ADC_VALUE)
    elif(command.getCommand() == 'ADCTXTOVR'):
        CFG.set('ADCTXTOVR', command.getParameter())
        CFG.write()
        SER.send('ADCTXTOVR is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'ADCTXTUND'):
        CFG.set('ADCTXTUND', command.getParameter())
        CFG.write()
        SER.send('ADCTXTUND is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'ADCVAL'):
        CFG.set('ADCVAL', command.getParameter())
        CFG.write()
        SER.send('ADCVAL is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'ADCHYST'):
        CFG.set('ADCHYST', command.getParameter())
        CFG.write()
        SER.send('ADCHYST is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'ADCFRONT'):
        CFG.set('ADCFRONT', command.getParameter())
        CFG.write()
        SER.send('ADCFRONT is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'ADCDELAY'):
        CFG.set('ADCDELAY', command.getParameter())
        CFG.write()
        SER.send('ADCDELAY is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'PASS'):
        CFG.set('PASS', command.getParameter())
        CFG.write()
        SER.send('PASS is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'IN1ONTXT'):
        CFG.set('IN1ONTXT', command.getParameter())
        CFG.write()
        SER.send('IN1ONTXT is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'IN1OFFTXT'):
        CFG.set('IN1OFFTXT', command.getParameter())
        CFG.write()
        SER.send('IN1OFFTXT is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'IN2ONTXT'):
        CFG.set('IN2ONTXT', command.getParameter())
        CFG.write()
        SER.send('IN2ONTXT is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'IN2OFFTXT'):
        CFG.set('IN2OFFTXT', command.getParameter())
        CFG.write()
        SER.send('IN2OFFTXT is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'IN3ONTXT'):
        CFG.set('IN3ONTXT', command.getParameter())
        CFG.write()
        SER.send('IN3ONTXT is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'IN3OFFTXT'):
        CFG.set('IN3OFFTXT', command.getParameter())
        CFG.write()
        SER.send('IN3OFFTXT is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'IN4ONTXT'):
        CFG.set('IN4ONTXT', command.getParameter())
        CFG.write()
        SER.send('IN4ONTXT is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'IN4OFFTXT'):
        CFG.set('IN4OFFTXT', command.getParameter())
        CFG.write()
        SER.send('IN4OFFTXT is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'SMS_ACK'):
        CFG.set('SMS_ACK', command.getParameter())
        CFG.write()
        SER.send('SMS_ACK is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'IN1FRONT'):
        CFG.set('IN1FRONT', command.getParameter())
        CFG.write()
        SER.send('IN1FRONT is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'IN2FRONT'):
        CFG.set('IN2FRONT', command.getParameter())
        CFG.write()
        SER.send('IN2FRONT is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'IN3FRONT'):
        CFG.set('IN3FRONT', command.getParameter())
        CFG.write()
        SER.send('IN3FRONT is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'IN4FRONT'):
        CFG.set('IN4FRONT', command.getParameter())
        CFG.write()
        SER.send('IN4FRONT is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'IN1DELAY'):
        CFG.set('IN1DELAY', command.getParameter())
        CFG.write()
        SER.send('IN1DELAY is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'IN2DELAY'):
        CFG.set('IN2DELAY', command.getParameter())
        CFG.write()
        SER.send('IN2DELAY is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'IN3DELAY'):
        CFG.set('IN3DELAY', command.getParameter())
        CFG.write()
        SER.send('IN3DELAY is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'IN4DELAY'):
        CFG.set('IN4DELAY', command.getParameter())
        CFG.write()
        SER.send('IN4DELAY is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'OUT1TIME'):
        CFG.set('OUT1TIME', command.getParameter())
        CFG.write()
        SER.send('OUT1TIME is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'OUT2TIME'):
        CFG.set('OUT2TIME', command.getParameter())
        CFG.write()
        SER.send('OUT2TIME is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'WHITE'):
        CFG.set('WHITE', command.getParameter())
        CFG.write()
        SER.send('WHITE is set to: %s\r' % (command.getParameter()))
        ok = 1
    elif(command.getCommand() == 'ALERT'):
        CFG.set('ALERT', command.getParameter())
        CFG.write()
        SER.send('ALERT is set to: %s\r' % (command.getParameter()))
        ok = 1
    if(ok == 1):
        return 'CMD %s OK;' % (command.getCommand())
    else:
        return 'CMD %s ERR;' % (command.getCommand())