예제 #1
0
파일: procedures.py 프로젝트: AlexKano/pmax
    def request_configuration_data(self, short_id, long_id, parameter):
        if (not self.is_AUTO_port_ready()): return
        final_hop_info = '\x00\x00\x00\x00\x80\x00\x84\x00\x00\x00\x00'
        repeater_hop_info = '\x00' * 12
        dpr_seq = prutils.generate_seq('dpr')
        hpr_seq = prutils.generate_seq('hpr')
        if parameter == 0x46:
            data = chr(short_id) + chr(hpr_seq) + chr(0xF8) + final_hop_info  + repeater_hop_info\
                + prutils.str_l('\x64\x00' + chr(dpr_seq) + prutils.num_to_chars(long_id, 3, 0) + "\x02\x02" + chr(parameter) + '\x00')
        else:    
            data = chr(short_id) + chr(hpr_seq) + chr(0x30) + final_hop_info  + repeater_hop_info\
                + prutils.str_l('\x64\x00' + chr(dpr_seq) + prutils.num_to_chars(long_id, 3, 0) + "\x02\x02" + chr(parameter) + '\x00')

        packet = prutils.make_host_packet(0x30, data) 
        self._Communicator.send(packet)
예제 #2
0
    def request_configuration_data(self, short_id, long_id, parameter):
        if (not self.is_AUTO_port_ready()): return
        final_hop_info = '\x00\x00\x00\x00\x80\x00\x84\x00\x00\x00\x00'
        repeater_hop_info = '\x00' * 12
        dpr_seq = prutils.generate_seq('dpr')
        hpr_seq = prutils.generate_seq('hpr')
        if parameter == 0x46:
            data = chr(short_id) + chr(hpr_seq) + chr(0xF8) + final_hop_info  + repeater_hop_info\
                + prutils.str_l('\x64\x00' + chr(dpr_seq) + prutils.num_to_chars(long_id, 3, 0) + "\x02\x02" + chr(parameter) + '\x00')
        else:
            data = chr(short_id) + chr(hpr_seq) + chr(0x30) + final_hop_info  + repeater_hop_info\
                + prutils.str_l('\x64\x00' + chr(dpr_seq) + prutils.num_to_chars(long_id, 3, 0) + "\x02\x02" + chr(parameter) + '\x00')

        packet = prutils.make_host_packet(0x30, data)
        self._Communicator.send(packet)
예제 #3
0
파일: procedures.py 프로젝트: AlexKano/pmax
    def send_response(self, long_id, short_id, dpr_seq, mcode=0x06, state=0, notification_period=0):
        #log.write('RESPONSE')
        # state: 0 - OK, 1 .. see device protocol
        # prepare device protocol
        # mcode = 0x06
        #print type(state)
        state = chr(state)
        seq = prutils.generate_seq("hpr")
        ser_num = prutils.convert_longid(int(long_id))[:3]
        mdata_value = chr(mcode) + chr(len(state)) + state
        device_packet = '\x14\x00' + chr(dpr_seq) + ser_num + mdata_value

        # prepare host protocol
        #final_hop_info = '\x00' * 11
        final_hop_info = '\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00'
        relaying_repeater_ID = 0
        repeater_hop_info = '\x00' * 11
        data = chr(short_id) + chr(seq) + chr(0x30 + notification_period) + final_hop_info + chr(relaying_repeater_ID)\
         + repeater_hop_info + prutils.str_l(device_packet)
        cmd = 0x30
        data = chr(cmd) + data
        cmd_l = 2 + len(data)
        data = chr(cmd_l) + data
        host_protocol_message = data + prutils.crc16(data)[0] + '\x0A'
     
        packet = prutils._make_f2_packet( host_protocol_message )

        #self._Procedures._Communicator.add_to_queue(packet, 0, 5)
        self._Communicator.send(packet)
예제 #4
0
    def send_hello(self, seq=0xFF, notification_period=0):
        log.write('** hello from [%d:%d] **' % (self._short_id, self._long_id))

        self._Procedures.hello(self._long_id, self._short_id, 0, notification_period)
        return 
        ser_num = prutils.convert_longid(int(self._long_id))[:3]
        mcode = 5
        mdata_type = 64
        mdata_value = chr(0)
        if seq == 0xFF:
            seq = self._dpr_seq.next()
        mdata = chr(mcode) + prutils.str_l( chr(mdata_type) + prutils.str_l(mdata_value) )
        device_packet = '\xE4\x00' + chr(seq) + ser_num + mdata

        # prepare host protocol
        #final_hop_info = '\x00' * 11
        final_hop_info = '\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00'
        relaying_repeater_ID = 0
        repeater_hop_info = '\x00' * 11
        #data = chr(short_id) + '\x01\xF8' + final_hop_info + chr(relaying_repeater_ID) + repeater_hop_info + str_l(device_packet)
        data = chr(self._short_id) + chr(prutils.generate_seq('hpr')) + chr(0x30 + notification_period) + final_hop_info + chr(relaying_repeater_ID) + repeater_hop_info + prutils.str_l(device_packet)
        cmd = 0x30
        data = chr(cmd) + data
        cmd_l = 2 + len(data)
        data = chr(cmd_l) + data
        host_protocol_message = data + prutils.crc16(data)[0] + '\x0A'
        #TODO: Use "make_host_packet" function to create device packet
        #host_protocol_message = make_host_packet( 0x30,  data)

        #preparing packet to send
        #print hexdump(host_protocol_message)
        packet = host_protocol_message
        packet = prutils._make_f2_packet( host_protocol_message )
        # self.prepare_transmitter()
        self._Procedures._Communicator.send(packet, 9)
예제 #5
0
    def send_response(self,
                      long_id,
                      short_id,
                      dpr_seq,
                      mcode=0x06,
                      state=0,
                      notification_period=0):
        #log.write('RESPONSE')
        # state: 0 - OK, 1 .. see device protocol
        # prepare device protocol
        # mcode = 0x06
        #print type(state)
        state = chr(state)
        seq = prutils.generate_seq("hpr")
        ser_num = prutils.convert_longid(int(long_id))[:3]
        mdata_value = chr(mcode) + chr(len(state)) + state
        device_packet = '\x14\x00' + chr(dpr_seq) + ser_num + mdata_value

        # prepare host protocol
        #final_hop_info = '\x00' * 11
        final_hop_info = '\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00'
        relaying_repeater_ID = 0
        repeater_hop_info = '\x00' * 11
        data = chr(short_id) + chr(seq) + chr(0x30 + notification_period) + final_hop_info + chr(relaying_repeater_ID)\
         + repeater_hop_info + prutils.str_l(device_packet)
        cmd = 0x30
        data = chr(cmd) + data
        cmd_l = 2 + len(data)
        data = chr(cmd_l) + data
        host_protocol_message = data + prutils.crc16(data)[0] + '\x0A'

        packet = prutils._make_f2_packet(host_protocol_message)

        #self._Procedures._Communicator.add_to_queue(packet, 0, 5)
        self._Communicator.send(packet)
예제 #6
0
    def send_response(self, mcode, seq=0xFF, amount=1, notification_period=0, state=0, return_packet=False):
        if(mcode == 0x06):
            log.write('** response from [%d:%d] **' % (self._short_id, self._long_id))
        elif(mcode == 0x07):
            log.write('** confirm from [%d:%d] **' % (self._short_id, self._long_id))
        if amount > 1:
            log.write("--multiply--: %d" % amount)
        # state: 0 - OK, 1 .. see device protocol
        # prepare device protocol
        #print type(state)
        state = chr(state)
        if seq == 0xFF:
            seq = self._dpr_seq.next()
        ser_num = prutils.convert_longid(int(self._long_id))[:3]
        mdata_value = ''
        # mdata_value = chr(mcode) + chr(len(state)) + state
        for i in range(amount):
            mdata_value += chr(len(state)) + state
        mdata_value = chr(mcode) + mdata_value

        device_packet = '\x14\x00' + chr(seq) + ser_num + mdata_value

        # prepare host protocol
        #final_hop_info = '\x00' * 11
        final_hop_info = '\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00'
        relaying_repeater_ID = 0
        repeater_hop_info = '\x00' * 11
        data = chr(self._short_id) + chr(prutils.generate_seq("hpr")) + chr(0x30 + notification_period) + final_hop_info + chr(relaying_repeater_ID)\
         + repeater_hop_info + prutils.str_l(device_packet)
        cmd = 0x30
        data = chr(cmd) + data
        cmd_l = 2 + len(data)
        data = chr(cmd_l) + data
        host_protocol_message = data + prutils.crc16(data)[0] + '\x0A'
     
        packet = prutils._make_f2_packet( host_protocol_message )

        #self._Procedures._Communicator.add_to_queue(packet, 0, 5)
        if return_packet == False:
            # self.prepare_transmitter()
            self._Procedures._Communicator.send(packet)
        else:
            return packet
예제 #7
0
 def _send_ka_message(self):
     if (self._Procedures.keepalive(self._short_id, self._long_id, prutils.generate_seq("hpr")) != False):
         log.write(strftime("%H:%M:%S", time.localtime()) +  " ** KA from [" + str(self._short_id) + ";" + str(self._long_id) + "] **" )