firmware/DCC_Packet.c
uint8_t DCC_Packet_Get_Address(DCC_Packet_t *packet, uint16_t *address)
{
     *address = 0x0000;
    //first, is this an accessory decoder packet? If so, ignore it
    if ((packet->data[0] >> 6) == 0x02)
    {
        return DCC_ACCESSORY_ADDRESS;
    }
    //second, is this a broadcast packet?
    if ((packet->data[0] == 0xFF) || (packet->data[0] == 0x00)) //broadcast
    {
        if (DCC_consist_address & 0x7F) //if we are in a consist, use that address
            *address = DCC_consist_address;
        else
            *address = DCC_address; //force it to be us
        return DCC_address_kind;
    }
    //finally, is this a 2-digit or 4-digit address, or a broadcast packet?
    if ((packet->data[0] & 0xC0) == 0xC0) //bit mask to indicate extended address
    {
        if (packet->data[0] > 0xE7) //longest possible long address, any longer is in the reserverd range, or is an idle packet
        {
            return DCC_SHORT_ADDRESS; //used as an ignore indicator
        }
        *address = (uint16_t) (packet->data[0] & 0x3F) << 8;
        *address |= (uint16_t) (packet->data[1]);
        return DCC_LONG_ADDRESS;
    }
    else //short address
    {
        *address = packet->data[0];
        return DCC_SHORT_ADDRESS;
    }

    //should never get here
    return DCC_SHORT_ADDRESS;
}
//returns the address of a DCC operations mode packet
// returns 0 if it is for an accessory decoder, and should therefore be ignored
// returns 0xFF for broadcast packets of all kinds
//not valid on service mode packets; see service mode routines in DCC_Service.h
returns the address of a DCC operations mode packet
returns 0 if it is for an accessory decoder, and should therefore be ignored
returns 0xFF for broadcast packets of all kinds
not valid on service mode packets; see service mode routines in DCC_Service.h
returns the address of a DCC operations mode packet returns 0 if it is for an accessory decoder and should therefore be ignored returns 0xFF for broadcast packets of all kinds not valid on service mode packets ; see service mode routines in DCC_Service . h
uint8_t DCC_Packet_Get_Address(DCC_Packet_t *packet, uint16_t *address)
{
     *address = 0x0000;
    if ((packet->data[0] >> 6) == 0x02)
    {
        return DCC_ACCESSORY_ADDRESS;
    }
    if ((packet->data[0] == 0xFF) || (packet->data[0] == 0x00)) 
    {
        if (DCC_consist_address & 0x7F) 
            *address = DCC_consist_address;
        else
            *address = DCC_address; 
        return DCC_address_kind;
    }
    if ((packet->data[0] & 0xC0) == 0xC0) 
    {
        if (packet->data[0] > 0xE7) 
        {
            return DCC_SHORT_ADDRESS; 
        }
        *address = (uint16_t) (packet->data[0] & 0x3F) << 8;
        *address |= (uint16_t) (packet->data[1]);
        return DCC_LONG_ADDRESS;
    }
    else 
    {
        *address = packet->data[0];
        return DCC_SHORT_ADDRESS;
    }
    return DCC_SHORT_ADDRESS;
}
uint8_t DCC_Packet_Get_Address ( DCC_Packet_t * packet , uint16_t * address ) { * address = 0x0000 ; if ( ( packet -> data [ 0 ] >> 6 ) == 0x02 ) { return DCC_ACCESSORY_ADDRESS ; } if ( ( packet -> data [ 0 ] == 0xFF ) || ( packet -> data [ 0 ] == 0x00 ) ) { if ( DCC_consist_address & 0x7F ) * address = DCC_consist_address ; else * address = DCC_address ; return DCC_address_kind ; } if ( ( packet -> data [ 0 ] & 0xC0 ) == 0xC0 ) { if ( packet -> data [ 0 ] > 0xE7 ) { return DCC_SHORT_ADDRESS ; } * address = ( uint16_t ) ( packet -> data [ 0 ] & 0x3F ) << 8 ; * address |= ( uint16_t ) ( packet -> data [ 1 ] ) ; return DCC_LONG_ADDRESS ; } else { * address = packet -> data [ 0 ] ; return DCC_SHORT_ADDRESS ; } return DCC_SHORT_ADDRESS ; }
returns the address of a DCC operations mode packet
returns 0 if it is for an accessory decoder, and should therefore be ignored
returns 0xFF for broadcast packets of all kinds
not valid on service mode packets; see service mode routines in DCC_Service.h
returns the address of a DCC operations mode packet returns 0 if it is for an accessory decoder and should therefore be ignored returns 0xFF for broadcast packets of all kinds not valid on service mode packets ; see service mode routines in DCC_Service . h
//first, is this an accessory decoder packet? If so, ignore it //second, is this a broadcast packet? //broadcast //if we are in a consist, use that address //force it to be us //finally, is this a 2-digit or 4-digit address, or a broadcast packet? //bit mask to indicate extended address //longest possible long address, any longer is in the reserverd range, or is an idle packet //used as an ignore indicator //short address //should never get here