Exemplo n.º 1
0
byte processSwitchSensorMessage( lnMsg *LnPacket )
{
	word	Address ;
	byte 	Direction ;
	byte  Output ;
	byte  ConsumedFlag = 1 ;

	Address = (LnPacket->srq.sw1 | ( ( LnPacket->srq.sw2 & 0x0F ) << 7 )) ;
	if( LnPacket->sr.command != OPC_INPUT_REP )
		Address++;
		
	switch( LnPacket->sr.command )
	{
	case OPC_INPUT_REP:
		Address <<= 1 ;
		Address += ( LnPacket->ir.in2 & OPC_INPUT_REP_SW ) ? 2 : 1 ;
			
		notifySensor( Address, LnPacket->ir.in2 & OPC_INPUT_REP_HI ) ;
		break ;

	case OPC_SW_REQ:
		notifySwitchRequest( Address, LnPacket->srq.sw2 & OPC_SW_REQ_OUT, LnPacket->srq.sw2 & OPC_SW_REQ_DIR ) ;
		break ;

	case OPC_SW_REP:
		notifySwitchReport( Address, LnPacket->srp.sn2 & OPC_SW_REP_HI, LnPacket->srp.sn2 & OPC_SW_REP_SW ) ;
		break ;

	case OPC_SW_STATE:
		Direction = LnPacket->srq.sw2 & OPC_SW_REQ_DIR ;
		Output = LnPacket->srq.sw2 & OPC_SW_REQ_OUT ;

		notifySwitchState( Address, Output, Direction ) ;
		break;
		
	case OPC_SW_ACK:
		break ;

  case OPC_LONG_ACK:
    if( LnPacket->lack.opcode == (OPC_SW_STATE & 0x7F ) )
    {
      Direction = LnPacket->lack.ack1 & 0x01 ;
    }
		else
			ConsumedFlag = 0 ;
		break;
		
	default:
		ConsumedFlag = 0 ;
	}
	
	return ConsumedFlag ;
}
Exemplo n.º 2
-1
uint8_t LocoNetClass::processSwitchSensorMessage( lnMsg *LnPacket )
{
  uint16_t Address ;
  uint8_t  Direction ;
  uint8_t  Output ;
  uint8_t  ConsumedFlag = 1 ;

  Address = (LnPacket->srq.sw1 | ( ( LnPacket->srq.sw2 & 0x0F ) << 7 )) ;
  if( LnPacket->sr.command != OPC_INPUT_REP )
    Address++;

  switch( LnPacket->sr.command )
  {
  case OPC_INPUT_REP:
    Address <<= 1 ;
    Address += ( LnPacket->ir.in2 & OPC_INPUT_REP_SW ) ? 2 : 1 ;

    if(notifySensor)
      notifySensor( Address, LnPacket->ir.in2 & OPC_INPUT_REP_HI ) ;
    break ;

  case OPC_GPON:
    if(notifyPower)
      notifyPower( 1 );
    break ;

  case OPC_GPOFF:
    if(notifyPower)
      notifyPower( 0 );
    break ;

  case OPC_SW_REQ:
    if(notifySwitchRequest)
      notifySwitchRequest( Address, LnPacket->srq.sw2 & OPC_SW_REQ_OUT, LnPacket->srq.sw2 & OPC_SW_REQ_DIR ) ;
    break ;

  case OPC_SW_REP:
    if(notifySwitchReport)
      notifySwitchReport( Address, LnPacket->srp.sn2 & OPC_SW_REP_HI, LnPacket->srp.sn2 & OPC_SW_REP_SW ) ;
    break ;

  case OPC_SW_STATE:
    Direction = LnPacket->srq.sw2 & OPC_SW_REQ_DIR ;
    Output = LnPacket->srq.sw2 & OPC_SW_REQ_OUT ;

    if(notifySwitchState)
      notifySwitchState( Address, Output, Direction ) ;
    break;

  case OPC_SW_ACK:
    break ;

  case OPC_LONG_ACK:
    if( LnPacket->lack.opcode == (OPC_SW_STATE & 0x7F ) )
    {
      Direction = LnPacket->lack.ack1 & 0x01 ;
    }
    else
      ConsumedFlag = 0 ;
    break;

  default:
    ConsumedFlag = 0 ;
  }

  return ConsumedFlag ;
}