예제 #1
0
  TracLight_c::SendMessage_e TracLight_c::sendLightingData()
  { // there is no need to check for address claim in tractor mode because this is already done in the timeEvent
    // function of base class BaseCommon_c
    CanPkgExt_c pkg;

    // precondition checks for sending as implement
    if (!mb_cmdWait4Response) return MessageNotSent;

    if( ( ! getIdentItem() ) || ( ! getIdentItem()->isClaimedAddress() ) ) {
      return MessageNotSent;
    }

    pkg.setIsoPgn(LIGHTING_DATA_PGN);
    //reset flag because msg will now be send
    mb_cmdWait4Response = false;

    pkg.setIsoPri(6);

    uint16_t ui16_temp = 0;
    ui16_temp =
      (mt_cmd.implOEMOpt2          <<  0) +
      (mt_cmd.implOEMOpt1          <<  2) +
      (mt_cmd.implRightForwardWork <<  4) +
      (mt_cmd.implLeftForwardWork  <<  6) +
      (0                          <<  8) +    //reserved field in lighting data
      (mt_cmd.implRightFacingWork  << 10) +
      (mt_cmd.implLeftFacingWork   << 12) +
      (mt_cmd.implRearWork         << 14);
    pkg.setUint16Data(6, ui16_temp);

    return helpSendMessage( pkg );
  }
  bool ProprietaryMessageA_c::sendWithPrio( unsigned prio, const IsoName_c& a_overwrite_remote ) {

    isoaglib_assert( prio <= 7 );
    isoaglib_assert(m_ident);
    // do not allow overwrite to a different target if m_remote is specified
    isoaglib_assert(!m_remote.isSpecified() || a_overwrite_remote.isUnspecified() || (a_overwrite_remote == m_remote));

    const uint32_t pgn = ( uint32_t( m_dp ) << 16) | PROPRIETARY_A_PGN;
    if (getDataSend().getLen() <= 8)
    {
      CanPkgExt_c pkg;

      pkg.setIsoPri( static_cast<uint8_t>( prio ) );
      pkg.setIsoPgn( pgn );
      pkg.setISONameForDA( a_overwrite_remote.isSpecified() ? a_overwrite_remote : m_remote );
      pkg.setMonitorItemForSA( m_ident->getIsoItem() );
      pkg.setDataFromString ( getDataSend().getDataStream(), static_cast<uint8_t>( getDataSend().getLen() ) );
      getIsoBusInstance( m_ident->getMultitonInst() ) << pkg;
      return true;
    }
    else
    { /** multi-packet */
      /** variable should be evaluated */
      // const bool cb_couldStartMultiSend =
      // we could catch the information if the sending succeeded, but what to do with it anyway?
      return getMultiSendInstance( m_ident->getMultitonInst() ).sendIsoTarget(
         m_ident->isoName(),
         a_overwrite_remote.isSpecified() ? a_overwrite_remote : m_remote,
         getDataSend().getDataStream(0),
         getDataSend().getLen(),
         pgn,
         this );
    }
  }
  bool ProprietaryMessageB_c::send( uint8_t ps ) {

    isoaglib_assert(m_ident);

    const uint32_t pgn = ( uint32_t( m_dp ) << 16) | PROPRIETARY_B_PGN | ps;
    if (getDataSend().getLen() <= 8)
    {
      CanPkgExt_c pkg;

      pkg.setIsoPri( 6 );
      pkg.setIsoPgn( pgn );
      pkg.setMonitorItemForSA( m_ident->getIsoItem() );
      pkg.setDataFromString ( getDataSend().getDataStream(), static_cast<uint8_t>( getDataSend().getLen() ) );
      getIsoBusInstance( m_ident->getMultitonInst() ) << pkg;
      return true;
    }
    else
    { /** multi-packet */
      /** variable should be evaluated */
      // const bool cb_couldStartMultiSend =
      // we could catch the information if the sending succeeded, but what to do with it anyway?
      return getMultiSendInstance( m_ident->getMultitonInst() ).sendIsoTarget(
         m_ident->isoName(),
         m_remote,
         getDataSend().getDataStream(0),
         getDataSend().getLen(),
         pgn,
         this );
    }
  }
예제 #4
0
/** send a PGN request */
bool BaseCommon_c::sendPgnRequest(uint32_t ui32_requestedPGN)
{
  if( ( ! getIdentItem() ) || ( ! getIdentItem()->isClaimedAddress() ) )
    return false;

  IsoItem_c *dest = getSelectedDataSourceISONameConst().isSpecified()
    ? getIsoMonitorInstance( getIdentItem()->getMultitonInst() ).item( getSelectedDataSourceISONameConst(), true )
    : NULL; // --> ask to global

  CanPkgExt_c pkg;
  pkg.setIsoPri(6);
  pkg.setIsoPgn(REQUEST_PGN_MSG_PGN);
  pkg.setMonitorItemForSA( getIdentItem()->getIsoItem() );
  pkg.setMonitorItemForDA( dest );
  pkg.setLen( 3 );
  pkg.setUint32Data( 0 , ui32_requestedPGN );
  getIsoBusInstance( getIdentItem()->getMultitonInst() ) << pkg;
  return true;
}
예제 #5
0
  TracLight_c::SendMessage_e TracLight_c::sendLightingCommand()
  {
    const ecutime_t ci32_now = System_c::getTime();

    CanPkgExt_c pkg;

    // tractor mode
    if ( ( ci32_now - marr_timeStamp[m_index] ) <= 1000 )
    { // WE ARE NOT ALLOWED TO SEND - EVEN IF REQUESTED
      return MessageNotSent;
    }
    else if ( (!mb_changeNeedBeSend) && ( (ci32_now - marr_timeStamp[(m_index+9)%10]) < 900 ) ) // (m_index+9)%10 -> youngest entry in array marr_timeStamp[];
    { // to send requested (i.e. no change occured) or not yet time to repeat last command
      return MessageNotSent;
    }
    mb_changeNeedBeSend = false;
    // now it's evident, that we have to send a command
    pkg.setIsoPgn(LIGHTING_COMMAND_PGN);
    setSelectedDataSourceISOName( getIdentItem()->isoName() );

    pkg.setIsoPri(3);
    uint16_t ui16_temp = 0;
    ui16_temp =
      (mt_cmd.implOEMOpt2          <<  0) +
      (mt_cmd.implOEMOpt1          <<  2) +
      (mt_cmd.implRightForwardWork <<  4) +
      (mt_cmd.implLeftForwardWork  <<  6) +
      (mt_cmd.dataMsgReq           <<  8) +
      (mt_cmd.implRightFacingWork  << 10) +
      (mt_cmd.implLeftFacingWork   << 12) +
      (mt_cmd.implRearWork         << 14);
    pkg.setUint16Data(6, ui16_temp);
    //overwrite the eldest time event with latest time event
    marr_timeStamp[m_index] = ci32_now;

    //set m_index to the eldest time event
    m_index = (m_index + 1) % 10;

    return helpSendMessage( pkg );
  }
예제 #6
0
  /** send facilities data
      @see  TracFacilities_c::processMsgRequestPGN
      @see  CanIo_c::operator<<
    */
  void TracFacilities_c::sendFacilities( )
  {// there is no need to check for address claim because this is already done in the processMsgRequestPGN;
   // this function is only be called on request!!
    isoaglib_assert( getIdentItem() );

    IsoBus_c& c_can = getIsoBusInstance4Comm();

    CanPkgExt_c pkg;
    pkg.setMonitorItemForSA( getIdentItem()->getIsoItem() );
    setSelectedDataSourceISOName( getIdentItem()->isoName() );
    pkg.setIsoPri(3);
    pkg.setLen(8);

    pkg.setIsoPgn(TRACTOR_FACILITIES_PGN);

    for (uint8_t ui8_counter = 0;ui8_counter<sizeof(arrui8_facilitiesBitData)/sizeof(uint8_t);++ui8_counter)
      pkg.setUint8Data(ui8_counter,arrui8_facilitiesBitData[ui8_counter]);

    // CanIo_c::operator<< retreives the information with the help of CanPkg_c::getData
    // then it sends the data
    c_can << pkg;
  }