📄 samplesource.c
字号:
#define ERR_INVALID_DEVICE 134
#define ERR_DEVICE_IN_USE 135
#define ERR_INVALID_PROTOCOL 136
#define ERR_TX_QUEUE_FULL 137
#define ERR_TX_QUEUE_CORRUPT 138
#define ERR_RX_QUEUE_FULL 139
#define ERR_RX_QUEUE_CORRUPT 140
#define ERR_MESSAGE_TOO_LONG 141
#define ERR_HARDWARE_NOT_RESPONDING 142
#define ERR_COMMAND_NOT_SUPPORTED 143
#define ERR_INVALID_COMMAND 144
#define ERR_TXMESSAGE_STATUS 145
#define ERR_ADDRESS_CLAIM_FAILED 146
#define ERR_CANNOT_SET_PRIORITY 147
#define ERR_CLIENT_DISCONNECTED 148
#define ERR_CONNECT_NOT_ALLOWED 149
#define ERR_CHANGE_MODE_FAILED 150
#define ERR_BUS_OFF 151
#define ERR_COULD_NOT_TX_ADDRESS_CLAIMED 152
#define ERR_ADDRESS_LOST 153
#define ERR_CODE_NOT_FOUND 154
#define ERR_BLOCK_NOT_ALLOWED 155
#define ERR_MULTIPLE_CLIENTS_CONNECTED 156
#define ERR_ADDRESS_NEVER_CLAIMED 157
#define ERR_WINDOW_HANDLE_REQUIRED 158
#define ERR_MESSAGE_NOT_SENT 159
#define ERR_MAX_NOTIFY_EXCEEDED 160
#define ERR_MAX_FILTERS_EXCEEDED 161
#define ERR_HARDWARE_STATUS_CHANGE 162
#define ERR_INI_FILE_NOT_IN_WIN_DIR 202
#define ERR_INI_SECTION_NOT_FOUND 204
#define ERR_INI_KEY_NOT_FOUND 205
#define ERR_INVALID_KEY_STRING 206
#define ERR_DEVICE_NOT_SUPPORTED 207
#define ERR_INVALID_PORT_PARAM 208
#define ERR_COMMAND_TIMED_OUT 213
#define ERR_OS_NOT_SUPPORTED 220
#define ERR_COMMAND_QUEUE_IS_FULL 222
#define ERR_CANNOT_SET_CAN_BAUDRATE 224
#define ERR_CANNOT_CLAIM_BROADCAST_ADDRESS 225
#define ERR_OUT_OF_ADDRESS_RESOURCES 226
#define ERR_ADDRESS_RELEASE_FAILED 227
#define ERR_COMM_DEVICE_IN_USE 230
#define ERR_DATA_LINK_CONFLICT 441
#define ERR_ADAPTER_NOT_RESPONDING 453
#define ERR_CAN_BAUD_SET_NONSTANDARD 454
#define ERR_MULTIPLE_CONNECTIONS_NOT_ALLOWED_NOW 455
#define ERR_J1708_BAUD_SET_NONSTANDARD 456
#define ERR_J1939_BAUD_SET_NONSTANDARD 457
#define ERR_ISO15765_BAUD_SET_NONSTANDARD 458
//-----------------------------------------------------------------------------------------------------
// Used to help in unpacking Motorola format numbers.
//-----------------------------------------------------------------------------------------------------
#define HIWORD_OF_INT4( x ) ( ( x >> 16 ) & 0xFFFF )
#define LOWORD_OF_INT4( x ) ( x & 0x0000FFFF )
#define HIBYTE_OF_WORD( x ) ( ( x >> 8 ) & 0xFF )
#define LOBYTE_OF_WORD( x ) ( x & 0x00FF )
#define HINIBBLE_OF_CHAR( x ) ( ( x & 0xF0 ) >> 4 )
#define LONIBBLE_OF_CHAR( x ) ( x & 0x0F )
#define BYTE0_OF_INT4( x ) LOBYTE_OF_WORD( LOWORD_OF_INT4( x ) )
#define BYTE1_OF_INT4( x ) HIBYTE_OF_WORD( LOWORD_OF_INT4( x ) )
#define BYTE2_OF_INT4( x ) LOBYTE_OF_WORD( HIWORD_OF_INT4( x ) )
#define BYTE3_OF_INT4( x ) HIBYTE_OF_WORD( HIWORD_OF_INT4( x ) )
//-----------------------------------------------------------------------------------------------------
// RP1210B Defined Function Prototypes
//-----------------------------------------------------------------------------------------------------
#define DLLEXPORT __declspec(dllexport)
#ifdef __cplusplus
extern "C" {
#endif
short DLLEXPORT WINAPI RP1210_ClientConnect (
HWND hwndClient,
short nDeviceId,
char *fpchProtocol,
long lSendBuffer,
long lReceiveBuffer,
short nIsAppPacketizingIncomingMsgs
);
short DLLEXPORT WINAPI RP1210_ClientDisconnect (
short nClientID
);
short DLLEXPORT WINAPI RP1210_SendMessage (
short nClientID,
char *fpchClientMessage,
short nMessageSize,
short nNotifyStatusOnTx,
short nBlockOnSend
);
short DLLEXPORT WINAPI RP1210_ReadMessage (
short nClientID,
char *fpchAPIMessage,
short nBufferSize,
short nBlockOnSend
);
short DLLEXPORT WINAPI RP1210_SendCommand (
short nCommandNumber,
short nClientID,
char *fpchClientCommand,
short nMessageSize
);
void DLLEXPORT WINAPI RP1210_ReadVersion (
char *fpchDLLMajorVersion,
char *fpchDLLMinorVersion,
char *fpchAPIMajorVersion,
char *fpchAPIMinorVersion
);
short DLLEXPORT WINAPI RP1210_ReadDetailedVersion (
short nClientID,
char *fpchAPIVersionInfo,
char *fpchDLLVersionInfo,
char *fpchFWVersionInfo
);
short DLLEXPORT WINAPI RP1210_GetHardwareStatus (
short nClientID,
char *fpchClientInfo,
short nInfoSize,
short nBlockOnRequest
);
#ifdef RP1210B
short DLLEXPORT WINAPI RP1210_GetErrorMsg (
short err_code,
char *fpchMessage,
short nClientID
);
#else
short DLLEXPORT WINAPI RP1210_GetErrorMsg (
short err_code,
char *fpchMessage
);
#endif
short DLLEXPORT WINAPI RP1210_GetLastErrorMsg (
short err_code,
int *SubErrorCode,
char *fpchMessage
);
#ifdef __cplusplus
}
#endif
//-----------------------------------------------------------------------------------------------------
// Local #define Definitions
//-----------------------------------------------------------------------------------------------------
#define J1939_GLOBAL_ADDRESS 255
#define J1939_OFFBOARD_DIAGNOSTICS_TOOL_1 249
#define J1587_OFFBOARD_DIAGNOSTICS_TOOL_1 172
//-----------------------------------------------------------------------------------------------------
// RP1210B Function Type Definitions
//-----------------------------------------------------------------------------------------------------
typedef short (WINAPI *fxRP1210_ClientConnect) ( HWND, short, char *, long, long, short );
typedef short (WINAPI *fxRP1210_ClientDisconnect) ( short );
typedef short (WINAPI *fxRP1210_SendMessage) ( short, char*, short, short, short );
typedef short (WINAPI *fxRP1210_ReadMessage) ( short, char*, short, short );
typedef short (WINAPI *fxRP1210_SendCommand) ( short, short, char*, short );
typedef short (WINAPI *fxRP1210_ReadVersion) ( char*, char*, char*, char* );
typedef short (WINAPI *fxRP1210_ReadDetailedVersion) ( short, char*, char*, char* );
typedef short (WINAPI *fxRP1210_GetHardwareStatus) ( short, char*, short, short );
typedef short (WINAPI *fxRP1210_GetLastErrorMsg) ( short, int *, char*, short );
#ifdef RP1210B
typedef short (WINAPI *fxRP1210_GetErrorMsg) ( short, char*, short);
#else
typedef short (WINAPI *fxRP1210_GetErrorMsg) ( short, char* );
#endif
//-----------------------------------------------------------------------------------------------------
// GLOBALVAR RP1210 Function Pointers using Function Type Definitions
//-----------------------------------------------------------------------------------------------------
fxRP1210_ClientConnect pRP1210_ClientConnect = NULL;
fxRP1210_ClientDisconnect pRP1210_ClientDisconnect = NULL;
fxRP1210_ReadMessage pRP1210_ReadMessage = NULL;
fxRP1210_SendMessage pRP1210_SendMessage = NULL;
fxRP1210_SendCommand pRP1210_SendCommand = NULL;
fxRP1210_ReadVersion pRP1210_ReadVersion = NULL;
fxRP1210_ReadDetailedVersion pRP1210_ReadDetailedVersion = NULL;
fxRP1210_GetErrorMsg pRP1210_GetErrorMsg = NULL;
fxRP1210_GetLastErrorMsg pRP1210_GetLastErrorMsg = NULL;
fxRP1210_GetHardwareStatus pRP1210_GetHardwareStatus = NULL;
//-----------------------------------------------------------------------------------------------------
// GLOBALVAR Global variables dealing with DLL, Client, Device, Protocol
//-----------------------------------------------------------------------------------------------------
HINSTANCE hRP1210DLL = NULL;
int iAdapter = -1;
int iUserDevice = -1;
int iProtocol = -1;
short nClientID = -1;
char szDLLName[81] = "";
char szProtocolName[81] = "";
unsigned char ucTxRxBuffer[6000] = "";
//-----------------------------------------------------------------------------------------------------
// GLOBALVAR Global variables dealing with J1939
//-----------------------------------------------------------------------------------------------------
unsigned char ucJ1939Address = J1939_OFFBOARD_DIAGNOSTICS_TOOL_1;
//-----------------------------------------------------------------------------------------------------
// GLOBALVAR Global variables dealing with J1708
//-----------------------------------------------------------------------------------------------------
unsigned char ucJ1587Address = J1587_OFFBOARD_DIAGNOSTICS_TOOL_1;
//-----------------------------------------------------------------------------------------------------
// RP1210-related functions
//-----------------------------------------------------------------------------------------------------
/*PROCEDURE*/ void PrintRP1210Error ( char *szInfo, short nErrorCode, FILE *fp1, FILE *fp2 );
/*PROCEDURE*/ void LoadRP1210LibraryAndFunctions ( char *szDLLName );
/*PROCEDURE*/ void SetAllFilterStatesToPass ( short nClientID, FILE *fp1, FILE *fp2 );
//-----------------------------------------------------------------------------------------------------
// Unpacking of character strings representing integers, and then converting them into integers
//-----------------------------------------------------------------------------------------------------
/*FUNCTION*/ int UnPackTwoByteIntegerLSB ( unsigned char *ucIntString );
/*FUNCTION*/ int UnPackTwoByteIntegerMSB ( unsigned char *ucIntString );
/*FUNCTION*/ int UnPackThreeByteIntegerLSB ( unsigned char *ucIntString );
/*FUNCTION*/ int UnPackThreeByteIntegerMSB ( unsigned char *ucIntString );
/*FUNCTION*/ int UnPackFourByteIntegerLSB ( unsigned char *ucIntString );
/*FUNCTION*/ int UnPackFourByteIntegerMSB ( unsigned char *ucIntString );
/*FUNCTION*/ unsigned char *CreateTwoByteIntegerLSB ( int iVal, unsigned char *ucIntString );
/*FUNCTION*/ unsigned char *CreateThreeByteIntegerLSB ( int iVal, unsigned char *ucIntString );
/*FUNCTION*/ unsigned char *CreateFourByteIntegerLSB ( int iVal, unsigned char *ucIntString );
/*FUNCTION*/ unsigned char *CreateTwoByteIntegerMSB ( int iVal, unsigned char *ucIntString );
/*FUNCTION*/ unsigned char *CreateThreeByteIntegerMSB ( int iVal, unsigned char *ucIntString );
/*FUNCTION*/ unsigned char *CreateFourByteIntegerMSB ( int iVal, unsigned char *ucIntString );
//-----------------------------------------------------------------------------------------------------
// J1939-related functions
//-----------------------------------------------------------------------------------------------------
/*PROCEDURE*/ void Process_J1939_Message (
short nClientID,
FILE *fp1,
FILE *fp2,
unsigned char *ucMessage,
short nLength,
short nEchoTXMsgs
);
/*PROCEDURE*/ void Print_J1939_Message (
short nClientID,
FILE *fp1,
FILE *fp2,
unsigned char *ucMessage,
short nLength,
short nEchoTXMsgs
);
/*PROCEDURE*/ void Print_Sent_J1939_Message (
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -