Corrections regarding Outputaddressing

OutputAddress must be a signed variable
This commit is contained in:
MicroBahner
2018-04-22 10:03:48 +02:00
parent 86caca5bfb
commit 4ee7430d7c
2 changed files with 20 additions and 14 deletions

View File

@@ -39,7 +39,7 @@
#endif #endif
// Uncomment to print DEBUG messages // Uncomment to print DEBUG messages
// #define DEBUG_PRINT #define DEBUG_PRINT
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// DCC Receive Routine // DCC Receive Routine
@@ -1048,8 +1048,8 @@ void execDccProcessor( DCC_MSG * pDccMsg )
{ {
if( DccProcState.Flags & FLAGS_DCC_ACCESSORY_DECODER ) if( DccProcState.Flags & FLAGS_DCC_ACCESSORY_DECODER )
{ {
uint16_t BoardAddress ; int16_t BoardAddress ;
uint16_t OutputAddress ; int16_t OutputAddress ;
uint8_t TurnoutPairIndex ; uint8_t TurnoutPairIndex ;
#ifdef DEBUG_PRINT #ifdef DEBUG_PRINT
@@ -1057,7 +1057,9 @@ void execDccProcessor( DCC_MSG * pDccMsg )
#endif #endif
BoardAddress = ( ( (~pDccMsg->Data[1]) & 0b01110000 ) << 2 ) | ( pDccMsg->Data[0] & 0b00111111 ) ; BoardAddress = ( ( (~pDccMsg->Data[1]) & 0b01110000 ) << 2 ) | ( pDccMsg->Data[0] & 0b00111111 ) ;
DB_PRINT("execDccProcessor: Board Addr: %d", BoardAddress); TurnoutPairIndex = (pDccMsg->Data[1] & 0b00000110) >> 1;
DB_PRINT("execDccProcessor: Board Addr: %d, Index: %d", BoardAddress, TurnoutPairIndex);
// First check for Legacy Accessory Decoder Configuration Variable Access Instruction // First check for Legacy Accessory Decoder Configuration Variable Access Instruction
// as it's got a different format to the others // as it's got a different format to the others
if((pDccMsg->Size == 5) && ((pDccMsg->Data[1] & 0b10001100) == 0b00001100)) if((pDccMsg->Size == 5) && ((pDccMsg->Data[1] & 0b10001100) == 0b00001100))
@@ -1078,10 +1080,10 @@ void execDccProcessor( DCC_MSG * pDccMsg )
return; return;
} }
TurnoutPairIndex = (pDccMsg->Data[1] & 0b00000110) >> 1;
OutputAddress = (((BoardAddress - 1) << 2 ) | TurnoutPairIndex) + 1 ; //decoder output addresses start with 1, packet address range starts with 0 OutputAddress = (((BoardAddress - 1) << 2 ) | TurnoutPairIndex) + 1 ; //decoder output addresses start with 1, packet address range starts with 0
// ( according to NMRA 9.2.2 ) // ( according to NMRA 9.2.2 )
DB_PRINT("execDccProcessor: Output Addr: %d", OutputAddress);
if( DccProcState.inAccDecDCCAddrNextReceivedMode) if( DccProcState.inAccDecDCCAddrNextReceivedMode)
{ {
@@ -1111,15 +1113,22 @@ void execDccProcessor( DCC_MSG * pDccMsg )
// If we're filtering addresses, does the address match our address or is it a broadcast address? If NOT then return // If we're filtering addresses, does the address match our address or is it a broadcast address? If NOT then return
if( DccProcState.Flags & FLAGS_MY_ADDRESS_ONLY ) if( DccProcState.Flags & FLAGS_MY_ADDRESS_ONLY )
{ {
if( ( DccProcState.Flags & FLAGS_OUTPUT_ADDRESS_MODE ) && ( OutputAddress != getMyAddr() ) && ( OutputAddress < 2045 ) ) if( DccProcState.Flags & FLAGS_OUTPUT_ADDRESS_MODE ) {
return; DB_PRINT(" AddrCheck: OutputAddr: %d, BoardAddr: %d, myAddr: %d OutChk=%d", OutputAddress, BoardAddress, getMyAddr(), OutputAddress != getMyAddr() );
if ( OutputAddress != getMyAddr() && OutputAddress < 2045 ) {
else if( ( BoardAddress != getMyAddr() ) && ( BoardAddress < 511 ) ) DB_PRINT(" eDP: OutputAddress: %d, myAddress: %d - no match", OutputAddress, getMyAddr() );
return; return;
}
} else {
if( ( BoardAddress != getMyAddr() ) && ( BoardAddress < 511 ) ) {
DB_PRINT(" eDP: BoardAddress: %d, myAddress: %d - no match", BoardAddress, getMyAddr() );
return;
}
}
DB_PRINT("execDccProcessor: Address Matched"); DB_PRINT("execDccProcessor: Address Matched");
} }
if((pDccMsg->Size == 4) && ((pDccMsg->Data[1] & 0b10001001) == 1)) // Extended Accessory Decoder Control Packet Format if((pDccMsg->Size == 4) && ((pDccMsg->Data[1] & 0b10001001) == 1)) // Extended Accessory Decoder Control Packet Format
{ {
uint8_t state = pDccMsg->Data[2] ;// & 0b00011111; uint8_t state = pDccMsg->Data[2] ;// & 0b00011111;

View File

@@ -676,9 +676,6 @@ extern void notifyServiceMode(bool) __attribute__ ((weak));
// Deprecated, only for backward compatibility with version 1.4.2. Don't use in new designs // Deprecated, only for backward compatibility with version 1.4.2. Don't use in new designs
extern void notifyDccAccState( uint16_t Addr, uint16_t BoardAddr, uint8_t OutputAddr, uint8_t State ) __attribute__ ((weak)); extern void notifyDccAccState( uint16_t Addr, uint16_t BoardAddr, uint8_t OutputAddr, uint8_t State ) __attribute__ ((weak));
// Deprecated, only for backward compatibility with version 1.4.2. Don't use in new designs
extern void notifyDccAccState( uint16_t Addr, uint16_t BoardAddr, uint8_t OutputAddr, uint8_t State ) __attribute__ ((weak));
#if defined (__cplusplus) #if defined (__cplusplus)
} }
#endif #endif