⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 samplesource.c

📁 基于J1939的汽车CAN通讯测试,简单上位机软件源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
  fprintf(stdout,"\n");

  if( fpDiskFile != NULL )
    fprintf(fpDiskFile,"\n");

  //
  // Disconnect from the data bus.
  // 

  if ( pRP1210_ClientDisconnect( nClientID ) != 0 ) 
    {
      PrintRP1210Error( "RP1210_ClientDisconnect", (short) nRetVal, stdout, fpDiskFile );
    }
  
  //
  // Free the RP1210 library that we used, and close the log file.
  // 

  FreeLibrary( hRP1210DLL );

  if( fpDiskFile != NULL )
    fclose( fpDiskFile );

  //  
  // Return SUCCESS to the operating system.
  //

  return 0;
}

// ----------------------------------------------------------------------
//  Function:  UnPackTwoByteIntegerLSB
// 
//  Purpose:   Unpack a two-byte integer that has been sent least 
//             significant byte first.  All J1939 variables are sent 
//             in this fashion.
// 
// ----------------------------------------------------------------------

/*FUNCTION*/  int UnPackTwoByteIntegerLSB( unsigned char *ucIntString )
{
  int iValue = 0;
  
  iValue = ( ucIntString[1] << 8 ) | ( ucIntString[0] );
  
  return iValue;
}

// ----------------------------------------------------------------------
//  Function:  UnPackTwoByteIntegerMSB
// 
//  Purpose:   Unpack a two-byte integer that has been sent most
//             significant byte first.  An 11-bit CANID comes from the
//             RP1210 adapter in this manner.
// 
// ----------------------------------------------------------------------

/*FUNCTION*/  int UnPackTwoByteIntegerMSB( unsigned char *ucIntString )
{
  int iValue = 0;
  
  iValue = ( ucIntString[0] << 8 ) | ( ucIntString[1] );
  
  return iValue;
}

// ----------------------------------------------------------------------
//  Function:  UnPackThreeByteIntegerLSB
// 
//  Purpose:   Unpack a three-byte integer that has been sent least 
//             significant byte first.  All J1939 variables are sent 
//             in this fashion.
// 
// ----------------------------------------------------------------------

/*FUNCTION*/  int UnPackThreeByteIntegerLSB( unsigned char *ucIntString )
{
  int iValue = 0;
  
  iValue = (ucIntString[2] << 16) | ( ucIntString[1] << 8 ) | ( ucIntString[0] );
  
  return iValue;
}

// ----------------------------------------------------------------------
//  Function:  UnPackThreeByteIntegerMSB
// 
//  Purpose:   Unpack a three-byte integer that has been sent most
//             significant byte first.  This function is currently 
//             unused.
// 
// ----------------------------------------------------------------------

/*FUNCTION*/  int UnPackThreeByteIntegerMSB( unsigned char *ucIntString )
{
  int iValue = 0;
  
  iValue = (ucIntString[0] << 16) | ( ucIntString[1] << 8 ) | ( ucIntString[2] );
  
  return iValue;
}

// ----------------------------------------------------------------------
//  Function:  UnPackFourByteIntegerLSB
// 
//  Purpose:   Unpack a four-byte integer that has been sent least 
//             significant byte first.  All J1939 variables are sent 
//             in this fashion.
// 
// ----------------------------------------------------------------------

/*FUNCTION*/  int UnPackFourByteIntegerLSB( unsigned char *ucIntString )
{
  int iValue = 0;
  
  iValue = (ucIntString[3] << 24) | (ucIntString[2] << 16) | ( ucIntString[1] << 8 ) | ( ucIntString[0] );
  
  return iValue;
}

// ----------------------------------------------------------------------------------------------------
//  Function:  UnPackFourByteIntegerMSB
// 
//  Purpose:   Unpack a four-byte integer that has been sent most significant
//             byte first.  This is used by RP1210 for message timestamps and
//             29-bit CANIDs come from the RP1210 API in this manner.
// 
// ----------------------------------------------------------------------------------------------------

/*FUNCTION*/  int UnPackFourByteIntegerMSB( unsigned char *ucIntString )
{
  int iValue = 0;
  
  iValue = (ucIntString[0] << 24 )|(ucIntString[1] << 16 )|(ucIntString[2] << 8  )|(ucIntString[3] );
  
  return iValue;
}

/*======================================================================
 * Name:          CreateFourByteIntegerLSB
 *
 * Description:   Given an integer, create a four byte unsigned char
 *                representation of the number.
 *
 *======================================================================*/

U8 *CreateFourByteIntegerLSB( int iVal, U8 *szBuffer )
{
  szBuffer[0] = BYTE0_OF_INT4( iVal );
  szBuffer[1] = BYTE1_OF_INT4( iVal );
  szBuffer[2] = BYTE2_OF_INT4( iVal );
  szBuffer[3] = BYTE3_OF_INT4( iVal );

  return ( &szBuffer[0] );
}

/*======================================================================
 * Name:          CreateThreeByteIntegerLSB
 *
 * Description:   Given an integer, create a three byte unsigned char
 *                representation of the number.
 *
 *======================================================================*/

U8 *CreateThreeByteIntegerLSB( int iVal, U8 *szBuffer )
{
  szBuffer[0] = BYTE0_OF_INT4( iVal );
  szBuffer[1] = BYTE1_OF_INT4( iVal );
  szBuffer[2] = BYTE2_OF_INT4( iVal );

  return ( &szBuffer[0] );
}

/*======================================================================
 * Name:          CreateTwoByteIntegerLSB
 *
 * Description:   Given an integer, create a two byte unsigned char
 *                representation of the number.
 *
 *======================================================================*/

U8 *CreateTwoByteIntegerLSB( int iVal, U8 *szBuffer )
{
  szBuffer[0] = BYTE0_OF_INT4( iVal );
  szBuffer[1] = BYTE1_OF_INT4( iVal );
  return ( &szBuffer[0] );
}

/*======================================================================
 * Name:          CreateFourByteIntegerMSB
 *
 * Description:   Given an integer, create a four byte unsigned char
 *                representation of the number.
 *
 *======================================================================*/

U8 *CreateFourByteIntegerMSB( int iVal, U8 *szBuffer )
{
  szBuffer[0] = BYTE3_OF_INT4( iVal );
  szBuffer[1] = BYTE2_OF_INT4( iVal );
  szBuffer[2] = BYTE1_OF_INT4( iVal );
  szBuffer[3] = BYTE0_OF_INT4( iVal );

  return ( &szBuffer[0] );
}

/*======================================================================
 * Name:          CreateThreeByteIntegerMSB
 *
 * Description:   Given an integer, create a three byte unsigned char
 *                representation of the number.
 *
 *======================================================================*/

U8 *CreateThreeByteIntegerMSB( int iVal, U8 *szBuffer )
{
  szBuffer[0] = BYTE2_OF_INT4( iVal );
  szBuffer[1] = BYTE1_OF_INT4( iVal );
  szBuffer[2] = BYTE0_OF_INT4( iVal );

  return ( &szBuffer[0] );
}

/*======================================================================
 * Name:          CreateTwoByteIntegerMSB
 *
 * Description:   Given an integer, create a two byte unsigned char
 *                representation of the number.
 *
 *======================================================================*/

U8 *CreateTwoByteIntegerMSB( int iVal, U8 *szBuffer )
{
  szBuffer[0] = BYTE1_OF_INT4( iVal );
  szBuffer[1] = BYTE0_OF_INT4( iVal );
  return ( &szBuffer[0] );
}

// ----------------------------------------------------------------------------------------------------
//  Procedure:     LoadRP1210LibraryAndFunctions
// 
//  Description:   This performs the loading of an RP1210 DLL and points
//                 the global function pointers to the RP1210 functions inside of
//                 the DLL.
// 
// *----------------------------------------------------------------------------------------------------

/*PROCEDURE*/ void LoadRP1210LibraryAndFunctions( char *szDLLName )
{
  
  FILE *fp1 = stderr;

  if ( ( hRP1210DLL = LoadLibrary( szDLLName ) ) == NULL )   
    {
      fprintf(fp1,"Error:  LoadLibrary( %s ) failed! \n", szDLLName );
      exit(1);
    }
  
  pRP1210_ClientConnect = (fxRP1210_ClientConnect)(
                                                   GetProcAddress( 
                                                                  hRP1210DLL, 
                                                                  "RP12

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -