Beispiel #1
0
                  def manageIOSTATUS(self, arg):
                     astr=struct.unpack('<'+str(len(arg))+'B', arg)
                     baseboard_type=struct.unpack('<H', arg[2:4])[0]
                     msg_fwtype=struct.unpack('<B', arg[0])[0]
               
                     # For compatibility with pre-5 firmware
                     o=oldb.OldBoards()
                     if host in o.get_boardlist():
                        log.info("OLDBOARD DETECTED FOR IP "+str(host))
                        msg_fwtype=0x02
                        baseboard_type=0x0001

                     if msg_fwtype==C.FWTYPE_RELAYMASTER:
                        rawio=list("".join(
                           ["".join(revlist(list(bin(x).replace("0b", "").zfill(8)))) for x in iter(astr[5:9])]))

                        # For compatibility with pre-5 firmware
                        if host in o.get_boardlist():
                           rawio=list("".join(
                              ["".join(revlist(list(bin(x).replace("0b", "").zfill(8)))) for x in iter(astr[0:4])]))

                        rawrel=rawio[0:12]
                        rawinp=rawio[16:28]
                        if baseboard_type==C.BOARD_WORKER_12R12I_v3:
                           self.core.setAnalogStatus(src, host, port, ptype, 1,
                              struct.unpack('<h', struct.pack('<2B', *astr[9:11]))[0])
                           self.core.setAnalogStatus(src, host, port, ptype, 2,
                              struct.unpack('<h', struct.pack('<2B', *astr[11:13]))[0])

                           rawamp=astr[13:25]
                        else:
                           rawamp=[0]*12

                        #map(lambda x,y: self.core.setRelayStatus(src, host, x, y, rawamp[x-1]), 
                        #   xrange(1,13) , iter(rawrel))
                        map(lambda x,y: reactor.callLater(0.01, 
                           self.core.setRelayStatus, src, host, port, ptype, x, y, rawamp[x-1]),
                           xrange(1,13), iter(rawrel))

                        #map(lambda x,y: self.core.setInputStatus(src, host, x, str(int(y))), 
                        #   xrange(1,13), iter(rawinp))
                        map(lambda x,y: reactor.callLater(0.05,
                           self.core.setInputStatus, src, host, port, ptype, x, str(int(y))),
                           xrange(1, 13), iter(rawinp))

                        larg=len(arg)
                     
                        self.core.updateBoardLastStatus(host, port, ptype, src)

                     if msg_fwtype==C.FWTYPE_RELAYMASTERANA:
                        rawio=list("".join(
                           ["".join(revlist(list(bin(x).replace("0b", "").zfill(8)))) for x in iter(astr[5:9])]))

                        # For compatibility with pre-5 firmware
                        if host in o.get_boardlist():
                           rawio=list("".join(
                              ["".join(revlist(list(bin(x).replace("0b", "").zfill(8)))) for x in iter(astr[0:4])]))

                        rawrel=rawio[0:6]
                        rawinp=rawio[16:28]
                        if baseboard_type==C.BOARD_WORKER_12R12I_v3:
                           anab=9
                           for an in xrange(1, 9):
                              self.core.setAnalogStatus(src, host, port, ptype, an,
                                 struct.unpack('<h', struct.pack('<2B', *astr[anab:anab+2]))[0])
                              anab+=2

                        rawamp=dst[13:19]

                        map(lambda x,y: reactor.callLater(0.01,
                           self.core.setRelayStatus, src, host, port, ptype, x, y, rawamp[x-1]),
                           xrange(1,7), iter(rawrel))

                        map(lambda x,y: reactor.callLater(0.05,
                           self.core.setInputStatus, src, host, port, ptype, x, str(int(y))),
                           xrange(1, 13), iter(rawinp))

                        larg=len(arg)

                        self.core.updateBoardLastStatus(host, port, ptype, src)
Beispiel #2
0
                  webport=80
                  if len(arg)>26:
                     webport=struct.unpack('<H', arg[26:28])[0]
                  
                  self.core.updateWebPort(src, host, webport, port, ptype)
                  arg="\n\tIP: "+".".join([str(x) for x in astr[0:4]])
                  arg+="\n\tNETMASK: "+".".join([str(x) for x in astr[4:8]])
                  arg+="\n\tGW: "+".".join([str(x) for x in astr[8:12]])
                  arg+="\n\tDNS1: "+".".join([str(x) for x in astr[12:16]])
                  arg+="\n\tDNS2: "+".".join([str(x) for x in astr[16:20]])
                  arg+="\n\tMAC: "+":".join([hex(x)[2:].zfill(2) for x in astr[20:26]])
                  arg+="\n\tWEBPORT: "+str(webport)

               elif dst.startswith("IOSTATUS.DEF"):
                  astr=struct.unpack('<'+str(len(arg))+'B', arg)
                  rel=list("".join(["".join(revlist(list(bin(x).replace("b", "").zfill(8)))) for x in astr[0:3]]))
                  rel=map(lambda x,y: "REL%d:%s" % (x,"ON" if int(y) else "OFF"), xrange(1,13) , rel[0:12])
                  for r in rel:
                     arg+="\n\t"+r

               elif dst.startswith("IOSTATUS.NOW") and self.checkTimeLimits(self.ikahdr.epoch):
                  def manageIOSTATUS(self, arg):
                     astr=struct.unpack('<'+str(len(arg))+'B', arg)
                     baseboard_type=struct.unpack('<H', arg[2:4])[0]
                     msg_fwtype=struct.unpack('<B', arg[0])[0]
               
                     # For compatibility with pre-5 firmware
                     o=oldb.OldBoards()
                     if host in o.get_boardlist():
                        log.info("OLDBOARD DETECTED FOR IP "+str(host))
                        msg_fwtype=0x02