Python Forum
help coding for decode filtering
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help coding for decode filtering
#3
Thank you for your suggestion, however your code cannot be applied,
since input can be 1 line (original code) and can be 2 lines (need to modify code)
Please see below for original code

    def parse_mochad_line(self, line):
        """
        Parse a raw line of output from mochad
        """
        # bail out unless it's an incoming RFSEC message
        if line[15:23] == 'Rx RFSEC':

            # decode message. format is either:
            #   09/22 15:39:07 Rx RFSEC Addr: 21:26:80 Func: Contact_alert_min_DS10A
            #     ~ or ~
            #   09/22 15:39:07 Rx RFSEC Addr: 0x80 Func: Motion_alert_SP554A            
            line_list = line.split(' ')
            addr = line_list[5]
            func = line_list[7]

            func_dict = self.decode_func(func)

            return addr, {'func': func_dict}, 'security'

        elif line[15:20] == 'Rx RF':

            # decode RF message. format is:
            #   02/13 23:54:28 Rx RF HouseUnit: B1 Func: On
            line_list = line.split(' ')
            house_code = line_list[5];
            house_func = line_list[7]

            return house_code, {'func': house_func}, 'button'

        return '', ''
so I want to extend the code so that can accept 2 lines, something like below.
I think I will need to save variable filtered from #1 line input and
call that variable while #2 line input being processed.
But I have no idea how to do this???

        elif line[15:20] == 'Rx PL':

            # decode RF message. input has 2 lines, format is:
            #   02/13 23:54:28 Rx PL HouseUnit: A1
            #   02/13 23:54:28 Rx PL House: A Func: On
            line_list = line.split(' ')
            if line[21:27] == 'HouseU':   #filtering #1 line input for 'HouseUnit'=A1
                house_code = line_list[5]    
                #but this variable 'house_code' has to be saved somewhere
                #so that can be called when the next line input being processed
            elif line[21:27] == 'House:':   #filtering #2 line input for 'Func'=On
                house_func = line_list[7]
                house_code = ????   
                #here need to call variable 'HouseUnit'=A1 which already being saved
                #while filtering #1 line input
Reply


Messages In This Thread
help coding for decode filtering - by dony71 - Jun-29-2018, 01:05 AM
RE: help coding for decode filtering - by scidam - Jun-29-2018, 04:18 AM
RE: help coding for decode filtering - by dony71 - Jun-29-2018, 07:19 PM
RE: help coding for decode filtering - by volcano63 - Jun-29-2018, 08:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Decode string ? JohnnyCoffee 1 936 Jan-11-2023, 12:29 AM
Last Post: bowlofred
  how to encode and decode same value absolut 2 2,509 Sep-08-2020, 09:46 AM
Last Post: TomToad
  struct.decode() and '\0' deanhystad 1 3,421 Apr-09-2020, 04:13 PM
Last Post: TomToad
  Getting decode error. shankar 8 10,725 Sep-20-2019, 10:05 AM
Last Post: tinman
  how to decode UTF-8 in python 3 oco 3 37,673 Jun-05-2018, 11:05 AM
Last Post: wavic
  Ask help for utf-8 decode/encode forfan 12 11,314 Feb-25-2017, 02:04 AM
Last Post: forfan

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020