Пример #1
0
    def enroll(self, customer_Mid = 0, customer_Did = 0):
        """ enroll device """

        ser_num = SPC.dev_serial(int(self.serial))
        #print SPC.hexdump(ser_num)

        rssi = '\x32'
        tx_power = '\x01'
        association_request_data = '\x00'
        #attached_device_information = '\x01'+self.type+'\x03\x14\x03\x00\x00'
        attached_device_information = '\x00'+self.type+'\x01\x14\x03\x00\x00'
        #Counting customer id
        manufacturing_information = chr(customer_Mid) + chr(customer_Did % 256) + chr(customer_Did / 256)
        rf_module_information = '\x00\x70\x09\x28\x03\x08\x01' 
        host_protocol_message = SPC.make_host_packet( 0x41, ser_num + rssi + tx_power
            + association_request_data + '\x00' + SPC.str_len_plus_str(attached_device_information)
            + '\x01' + SPC.str_len_plus_str(manufacturing_information) + '\x02'
            + SPC.str_len_plus_str(rf_module_information) )
        enroll_packet = '\x01' + host_protocol_message

        packet_f2 = SPC.make_packet( 0xF2, 13, enroll_packet ) # F2 protocol packet

        StrLog = '(enroll): {0}'.format( SPC.hexdump(packet_f2) )
        print StrLog
        logging.debug( StrLog )

        Cmd = SPC.packet( 11 )
        self.SerPort.wait(Cmd, 'Start')
        #self.SerPort.ser.write(packet_f2)
        self.SendPacketTo_PortOrFile( packet_f2, 'enroll' )
        self.SerPort.wait(Cmd, 'Check', 5)

        #print 'ShortID {0}, DevTypeNum {1}, DevNum {2}'.format( Cmd.ShortID, Cmd.DevTypeNum, Cmd.DevNum )

        if Cmd.ShortID == -1: raise enroll_failed()
        self.short_id = Cmd.ShortID

        if   Cmd.DevTypeNum == 0:      self.DevType = 'RP'
        elif Cmd.DevTypeNum == 1:      self.DevType = 'K'   # KEYPAD_2WAY_TYPE
        elif Cmd.DevTypeNum == 2:      self.DevType = 'SR'
        elif Cmd.DevTypeNum == 3:      self.DevType = 'Z'
        elif Cmd.DevTypeNum == 4:      self.DevType = 'K'   # KEYPAD_1WAY_TYPE
        elif Cmd.DevTypeNum == 5:      self.DevType = 'F'   # KEYFOB_TYPE
        else:            self.DevType = 'Unknown'

        self.DevNum  = '%02d' % Cmd.DevNum
        if self.DevType == 'RP': self.DevNum  = '%d' % Cmd.DevNum
        print 'After wait cmd #11. short_id: {0}, DevType: {1}, DevNum: {2}'.format( self.short_id, self.DevType, self.DevNum )

        return
Пример #2
0
    def SendPacketTo_PortOrFile(self, Packet, StrForLog):
        """ ... and print in console and log file """

        StrLog = '({0}): {1}'.format( StrForLog, SPC.hexdump(Packet) )
        print StrLog
        logging.debug( StrLog )

        #if self.SerPort.ser == None:
        #    print 'The port is not open'
        #    return

        if (self.SerPort != None): self.SerPort.ser.write(Packet)
        else:
            print 'The port is not open. Saving to file.'
            f = open(CurrDir+ SEPARATOR +'Tmp'+ SEPARATOR +'packet_for_run.txt', "w", 0)
            f.write( SPC.hexdump2(Packet) )
            f.close()