Beispiel #1
0
    def resolution(self):
        """
        step1: Decode the binary data to a tuple
        step2: Split each element by the JTT808 protocol
        step3: Recognize the message id ,and then checking Dicts!
        something like {'(1,0)':'ter_reg_req'}
        :return: None
        """
        self.request_data = tongue.Decode(self.request)
        self.client_tuple_data = self.request_data.dst  # Don't forget get dst attribute
        if self.client_tuple_data[3] == 254:
            self.client_tuple_data = tuple(self.client_tuple_data)
            self.split_instance = MainSplit(self.client_tuple_data)
            self.request_dict = self.split_instance.result

            #Error request special processing
            if self.split_instance.flag:
                self.request_dict['client_msg_id'] = (9, )

            if self.split_instance.debug:
                self.request_dict['GET'] = self.conn
                self.msg_key = str(self.request_dict['client_msg_id'])
            else:
                warning('No Split instance !')
                self.PUB = False
        else:
            warning('Not a command package')
            self.PUB = False
Beispiel #2
0
    def resolution(self):
        """
        step1: Decode the binary data to a tuple
        step2: Split each element by the JTT808 protocol
        step3: Recognize the message id ,and then checking Dicts!
        something like {'(1,0)':'ter_reg_req'}
        :return: None
        """
        self.request_data = tongue.Decode(self.request)
        self.client_tuple_data = self.request_data.dst  # Don't forget get dst attribute
        self.client_tuple_data = tuple(self.client_tuple_data)
        self.split_instance = MainSplit(self.client_tuple_data)
        self.request_dict = self.split_instance.result
        self.request_dict[
            'client_check_code_msg'] = self.client_tuple_data[:-7]
        print self.client_tuple_data
        print self.request_dict

        #pi time
        time_pi = time.time()
        time_pi2 = time.localtime(time_pi)
        time_pi3 = time.strftime('%Y%m%d%H%M%S', time_pi2)[2:]
        self.request_dict['time_pi'] = (time_pi, )

        #Error request special processing
        if self.split_instance.debug:
            self.request_dict['GET'] = self.conn
            str_msg_key = ''
            for item in self.request_dict['client_msg_id']:
                str_msg_key = str_msg_key + str(item)
            self.msg_key = str(self.request_dict['client_main_com'])
        else:
            warning('No Split instance !')
            self.PUB = False
Beispiel #3
0
    def resolution(self):
        """
        step1: Decode the binary data to a tuple
        step2: Split each element by the JTT808 protocol
        step3: Recognize the message id ,and then checking Dicts!
        something like {'(1,0)':'ter_reg_req'}
        :return: None
        """
        # 把数据转为10进制的元组
        self.request_data = tongue.Decode(self.request)
        self.client_tuple_data = self.request_data.dst

        # 判断数据判断第4字节,或者第2字节是否符合协议
        if self.client_tuple_data[3] == 254 or self.client_tuple_data[3] == 1:
            # 把接收到的数据转化的元组,根据协议分成一个带有多个数据块的字典
            self.client_tuple_data = tuple(self.client_tuple_data)
            self.split_instance = MainSplit(self.client_tuple_data)
            self.request_dict = self.split_instance.result

            # 如果数据无效,就把消息的id变成09返回
            if self.split_instance.flag:
                self.request_dict['client_msg_id'] = (9, )

            # 把链接加入到数据块字典中, 后续使用这个链接对象,应答数据
            if self.split_instance.debug:
                self.request_dict['GET'] = self.conn
                self.msg_key = str(self.request_dict['client_msg_id'])
            else:
                warning('No Split instance !')
                self.PUB = False
        else:
            warning('Not a command package')
            self.PUB = False
Beispiel #4
0
 def resolution(self):
     """
     step1: Decode the binary data to a tuple
     step2: Split each element by the JTT808 protocol
     step3: Recognize the message id ,and then checking Dicts!
     something like {'(1,0)':'ter_reg_req'}
     :return: None
     """
     self.request_data = tongue.Decode(self.request)
     self.client_tuple_data = self.request_data.dst  # Don't forget get dst attribute
     self.client_tuple_data = tuple(self.client_tuple_data)
     self.split_instance = MainSplit(self.client_tuple_data)
     self.request_dict = self.split_instance.result
     '''
     #pi time
     time_pi = time.time()
     time_pi2 = time.localtime(time_pi)
     time_pi3 = time.strftime('%Y%m%d%H%M%S', time_pi2)[2:]
     self.request_dict['time_pi'] = (time_pi,)
     try:
         #terminal time
         for item in time_tuple:
             item = int(item)
             if item/10 == 0:
                 item = '0'+str(item)
             else:
                 item = str(item)
             str_ter_time = str_ter_time +item
         str_ter_time = '20'+str_ter_time
         ter_time = time.mktime(time.strptime(str_ter_time,'%Y%m%d%H%M%S'))
         #time interval result
         interval_time = time_pi - ter_time
         self.request_dict['interval_time'] = (str(interval_time),)
         self.request_dict['time_ter'] = (ter_time,)
     except:
         self.request_dict['interval_time'] = ('0',)
     ''' 
     #Error request special processing
     if self.split_instance.debug:
         self.request_dict['GET'] = self.conn
         self.msg_key = str(self.request_dict['client_msg_flag'] + self.request_dict['client_aid'])
     else:
         warning('No Split instance !')
         self.PUB = False
Beispiel #5
0
    def resolution(self):
        """
        step1: Decode the binary data to a tuple
        step2: Split each element by the JTT808 protocol
        step3: Recognize the message id ,and then checking Dicts!
        something like {'(1,0)':'ter_reg_req'}
        :return: None
        """
        self.request_data = tongue.Decode(self.request)
        self.client_tuple_data = self.request_data.dst  # Don't forget get dst attribute
        self.split_instance = MainSplit(self.client_tuple_data)
        self.request_dict = self.split_instance.result

        if self.split_instance.debug:
            self.request_dict['GET'] = self.conn
            self.msg_key = str(self.request_dict['client_msg_id'])
        else:
            warning('No Split instance !')
            self.PUB = False
Beispiel #6
0
    def resolution(self):
        """
        step1: Decode the binary data to a tuple
        step2: Split each element by the JTT808 protocol
        step3: Recognize the message id ,and then checking Dicts!
        something like {'(1,0)':'ter_reg_req'}
        :return: None
        """
        self.request_data = tongue.Decode(self.request)
        self.client_tuple_data = self.request_data.dst  # Don't forget get dst attribute

        #convert data
        self.client_tuple_data = list(self.client_tuple_data)
        num = len(self.client_tuple_data)
        i = 0
        while i < num - 2:
            i = i + 1
            if self.client_tuple_data[i] == 125:
                if self.client_tuple_data[i + 1] == 1:
                    del self.client_tuple_data[i + 1]
                    num = num - 1
                if self.client_tuple_data[i + 1] == 2:
                    del self.client_tuple_data[i + 1]
                    self.client_tuple_data[i] = 126
                    num = num - 1
                else:
                    continue
        self.client_tuple_data = tuple(self.client_tuple_data)

        self.split_instance = MainSplit(self.client_tuple_data)
        self.request_dict = self.split_instance.result

        if self.split_instance.debug:
            self.request_dict['GET'] = self.conn
            self.msg_key = str(self.request_dict['client_msg_id'])
        else:
            warning('No Split instance !')
            self.PUB = False
info(info_self)
sock.bind(server_address)

# Calling listen() puts the socket into server mode,
# and accept() waits for an incoming connection
# Listen for incoming connection
sock.listen(1)

while True:
    # Wait for a connection
    info('waiting for a connection')
    connection, client_address = sock.accept()
    try:
        info_one = 'connection from ' + str(client_address)
        info(info_one)
        # Receive the data in small chunks and retransmit it
        while True:
            data = connection.recv(1024)
            if data:
                # dispatch_sample(data.strip('\n'), connection)
                Dispatch(data, connection)
                pass

            else:
                warn_one = 'no more data from %s' + str(client_address)
                warning(warn_one)
                break
    finally:
        # clean up the connection
        connection.close()
Beispiel #8
0
    def resolution(self):
        """
        step1: Decode the binary data to a tuple
        step2: Split each element by the JTT808 protocol
        step3: Recognize the message id ,and then checking Dicts!
        something like {'(1,0)':'ter_reg_req'}
        :return: None
        """
        self.request_data = tongue.Decode(self.request)
        self.client_tuple_data = self.request_data.dst  # Don't forget get dst attribute
        #print self.client_tuple_data
        if self.client_tuple_data[3] == 254 or self.client_tuple_data[3] == 1:
            self.client_tuple_data = tuple(self.client_tuple_data)
            self.split_instance = MainSplit(self.client_tuple_data)
            self.request_dict = self.split_instance.result
            #print self.request_dict['client_msg_content']
            #Real-time reporting time judgment
            str_ter_time = ''
            time_tuple = self.request_dict['client_msg_content'][0:6]
            #pi time
            time_pi = time.time()
            time_pi2 = time.localtime(time_pi)
            time_pi3 = time.strftime('%Y%m%d%H%M%S', time_pi2)[2:]
            self.request_dict['time_pi'] = (time_pi, )

            if 'client_msg_vin' in self.request_dict:
                vin_str = ''
                for item in self.request_dict['client_msg_vin']:
                    item = chr(item)
                    vin_str = vin_str + item
                self.request_dict['client_msg_vin_save'] = vin_str

            try:
                #terminal time
                for item in time_tuple:
                    item = int(item)
                    if item / 10 == 0:
                        item = '0' + str(item)
                    else:
                        item = str(item)
                    str_ter_time = str_ter_time + item
                str_ter_time = '20' + str_ter_time
                ter_time = time.mktime(
                    time.strptime(str_ter_time, '%Y%m%d%H%M%S'))
                #time interval result
                interval_time = time_pi - ter_time
                self.request_dict['time_interval'] = (str(interval_time), )
                self.request_dict['time_ter'] = (ter_time, )
            except:
                self.request_dict['interval_time'] = ('0', )

            #Error request special processing
            if self.split_instance.flag:
                self.request_dict['client_msg_id'] = (9, )

            if self.split_instance.debug:
                self.request_dict['GET'] = self.conn
                self.msg_key = str(self.request_dict['client_msg_id'])
            else:
                warning('No Split instance !')
                self.PUB = False
        else:
            warning('Not a command package')
            self.PUB = False