upb_lib/message.py
def encode_message(ctl, addr, src_id, msg_code, data=""):
    """Encode a message for the PIM, assumes data formatted"""
    ctl = create_control_word(addr.is_link) if ctl == -1 else ctl
    length = 7 + len(data)
    ctl = ctl | (length << 8)
    msg = bytearray(length)
    msg[0:2] = ctl.to_bytes(2, byteorder="big")
    msg[2] = addr.network_id
    msg[3] = addr.upb_id
    msg[4] = src_id
    msg[5] = msg_code
    if data:
        msg[6 : len(data) + 6] = data
    msg[-1] = (256 - reduce(lambda x, y: x + y, msg)) % 256  # Checksum
    return msg.hex().upper()
Encode a message for the PIM, assumes data formatted
Encode a message for the PIM, assumes data formatted
Encode a message for the PIM assumes data formatted
def encode_message(ctl, addr, src_id, msg_code, data=""):
    ctl = create_control_word(addr.is_link) if ctl == -1 else ctl
    length = 7 + len(data)
    ctl = ctl | (length << 8)
    msg = bytearray(length)
    msg[0:2] = ctl.to_bytes(2, byteorder="big")
    msg[2] = addr.network_id
    msg[3] = addr.upb_id
    msg[4] = src_id
    msg[5] = msg_code
    if data:
        msg[6 : len(data) + 6] = data
    msg[-1] = (256 - reduce(lambda x, y: x + y, msg)) % 256  
    return msg.hex().upper()
def encode_message ( ctl , addr , src_id , msg_code , data = "" ) : ctl = create_control_word ( addr . is_link ) if ctl == - 1 else ctl length = 7 + len ( data ) ctl = ctl | ( length << 8 ) msg = bytearray ( length ) msg [ 0 : 2 ] = ctl . to_bytes ( 2 , byteorder = "big" ) msg [ 2 ] = addr . network_id msg [ 3 ] = addr . upb_id msg [ 4 ] = src_id msg [ 5 ] = msg_code if data : msg [ 6 : len ( data ) + 6 ] = data msg [ - 1 ] = ( 256 - reduce ( lambda x , y : x + y , msg ) ) % 256 return msg . hex ( ) . upper ( )
Encode a message for the PIM, assumes data formatted
Encode a message for the PIM assumes data formatted
"""Encode a message for the PIM, assumes data formatted""" # Checksum
ctl
addr
src_id
msg_code
data