CT2KLib.h File Reference

CT2K NMEA2000 and J1939 Library. More...

#include <stdint.h>
#include <stddef.h>
#include <stdarg.h>
#include <stdbool.h>

Go to the source code of this file.

Data Structures

struct  CONFIGURATION_INFORMATION_STRING_T
 Defines the structure of strings used for transmitting and receiving PGN 1F016. More...
 
struct  CAN_FRAME_T
 CAN message structure. More...
 
struct  CAN_DRIVER_FUNCTIONS_T
 Structure used for the CAN Driver. More...
 
struct  PGNDesc
 PGN Description structure. More...
 
struct  PGNDOB
 Data object that contains information about a transmitted or received message. More...
 
struct  DEVICE_NAME_FIELDS
 Structure used for setting the Device Name. More...
 
struct  DEVNAME
 
struct  NETDEVICE
 Device information. More...
 
struct  CTLIB_PROD_INFO
 Product Information Structure. More...
 
struct  NMEA2000SpecVersion
 NMEA library version structure. More...
 
struct  INPUT_PARAMS_T
 Structure of Input Parameters. More...
 
struct  PORTS_CONFIG_T
 Structure Containing the Port Configuration the Library will use. More...
 
struct  NMEA_REQUEST_FAILED_FIELDS_T
 
struct  NAME_CHANGE_COMMAND_RESPONSE_T
 

Macros

#define PGN   int32_t
 Definitions of other types.
 
#define PGNGRPFUNC   uint8_t
 
#define INSTANCE   int8_t
 
#define PARAMETER   int16_t
 
#define CANBUF   int8_t
 
#define NETADDR   uint8_t
 
#define PGN_AddressClaim   60928
 NMEA2000 & J1939 PGN Required and used.
 
#define PGN_CommandedAddress   65240
 
#define PGN_Request   59904
 
#define PGN_Acknowledge   59392
 
#define PGN_NMEARequest   126208
 
#define PGN_Heartbeat   126993
 
#define PGN_ProductInformation   126996
 
#define PGN_ConfigurationInformation   126998
 
#define PGN_NMEAPGNList   126464
 
#define PGN_ISOConnectMgmt   60416
 Multi-Packet Specific PGNS.
 
#define PGN_ISODataTransport   60160
 
#define SINGLE_PKT_SIZE   8
 Packet Sizes.
 
#define FAST_PKT_SIZE   223
 
#define MULTI_PKT_SIZE   1785
 
#define PGN_CONFIGURATIONINFORMATION_SIZE   70
 PGN 1F016.
 
#define BYTES_IN_RAW_FRAME   8
 This is the max number of Bytes in a Raw CAN Frame.
 

Typedefs

typedef uint32_t __BIT
 Type definitions.
 
typedef uint32_t CAN_PORT_T
 
typedef void(* CT2KLibDiagnosticPrint_T) (const char *pFormatStr, va_list args, void *userData)
 Type define for CTKLib's driver level print to console function.
 
typedef int32_t(* CT2KLibCanOpen_T) (CAN_PORT_T canPort, void *userData)
 Type define for CT2KLib to Open the CAN Port.
 
typedef int32_t(* CT2KLibCanClose_T) (CAN_PORT_T canPort, void *userData)
 Type define for CT2KLib to Close the CAN Port.
 
typedef BUS_STATE_T(* CT2KLibGetBusState_T) (CAN_PORT_T canPort, void *userData)
 Type define for CT2KLib to get the current Bus State.
 
typedef int32_t(* CT2KLibTransmitFrame_T) (CAN_PORT_T canPort, CAN_FRAME_T *pFrame, void *userData)
 Type define for CT2KLib to transmit a frame.
 
typedef int32_t(* CT2KLibReceiveFrameWait_T) (CAN_PORT_T *pCanPorts, uint32_t LengthOf_pCanPorts, CAN_FRAME_T *pFrame, CAN_PORT_T *pFromPort, uint32_t timeoutMs, void *userData)
 Type define for CT2KLib to call to receive a Frame.
 
typedef int32_t(* CT2KLibBitRateSet_T) (CAN_PORT_T canPort, uint32_t bitRate, void *userData)
 Type define for CT2KLib to call to set the Bit Rate of the Bus.
 
typedef int(* RCVRCB) (PGNDOB *pDOB, uintptr_t userData)
 Type Definition for Received PGNs Callbacks.
 
typedef int(* ISOCallback_EA00) (PGNDOB *pDOB, uintptr_t userData)
 Type Definition for PGN Request Callbacks.
 
typedef int(* CTLIB_ADDRCLAIM_CB) (CAN_PORT_T i8Port, NETDEVICE *pNetDevice, uintptr_t userData)
 Type Definition for Address Claim Callback.
 
typedef void(* MLTIPCKTSENDCALLBACK) (uintptr_t userData)
 Type Definition for Multi-Packet Send Callback. Is executed after a Multi-Packet has been sent.
 
typedef bool(* COMMANDEDADDRESSCALLBACK) (DEVNAME *devName, NETADDR commandedAddress, uintptr_t userData)
 Type definition for Commanded address callback. Is executed after a commanded address message has been received (PGN 65240).
 
typedef void(* COMMANDCONFIGURATIONINFORMATIONCALLBACK) (const CAN_PORT_T i8Port, const CONFIGURATION_INFORMATION_STRING_T *pString1, GROUP_FUNCTION_PARAMETER_ERROR_CODE_T *pString1ErrCode, const CONFIGURATION_INFORMATION_STRING_T *pString2, GROUP_FUNCTION_PARAMETER_ERROR_CODE_T *pString2ErrCode, uintptr_t userData)
 Type definition for group function command (PGN 1ED00) Configuration information(PGN 1F016) .
 
typedef int(* NMEA2K_RQ_CMD) (PGNDOB *pDOB, uintptr_t userData)
 NMEA2000 Level A Request/Command/Acknowledge PGN Callbacks.
 
typedef NAME_CHANGE_COMMAND_RESPONSE_T(* CommandedNameChangeNotification) (CAN_PORT_T i8Port, DEVNAME commandedNameInformation, uintptr_t userData)
 Type Definition for Name Change Command Notification.
 
typedef GROUP_FUNCTION_TRANSMIT_INTERVAL_ERROR_CODE_T(* RequestedHeartbeatUpdateRateChangeNotification) (CAN_PORT_T i8Port, uint32_t requestedUpdateRate_ms, NETADDR sourceDevice, uintptr_t userData)
 Type definition for Heartbeat update rate notification.
 

Enumerations

enum  STRING_TYPE_T {
  STRING_TYPE_UNICODE = 0x00 ,
  STRING_TYPE_ASCII = 0x01 ,
  STRING_TYPE_UNKNOWN = 0xFF
}
 Defines string types used within PGN 1F016 for configuration information strings. More...
 
enum  BUS_STATE_T {
  BUS_STATE_OK = 0u ,
  BUS_STATE_WARNING = 1u ,
  BUS_STATE_ERROR = 2u
}
 Enum for Possible Bus States. More...
 
enum  CTCAN_STATUS {
  CTCR_OK ,
  CTCR_IDLE ,
  CTCR_UNKNOWN_PGN ,
  CTCR_TABLE_FULL ,
  CTCR_HEAP_ALLOC_FAIL ,
  CTCR_HEAP_DEALLOC_FAIL ,
  CTCR_NOT_FOUND ,
  CTCR_NEW_DATA ,
  CTCR_NO_DATA ,
  CTCR_INVALID_PORT ,
  CTCR_BUS_OFF ,
  CTCR_BUS_WARNING ,
  CTCR_LIB_BUSY ,
  CTCR_LIB_NOT_INIT ,
  CTCR_DRV_RX_FAILURE ,
  CTCR_DRV_TX_FAILURE ,
  CTCR_PGN_DUPLICATE ,
  CTCR_INVALID_CALL ,
  CTCR_COUNT
}
 Return codes that the Library uses. More...
 
enum  PROTOCOL {
  P_SINGLEPACKET = 0u ,
  P_FASTPACKET = 1u ,
  P_MULTIPACKET = 2u
}
 Supported Protocols. More...
 
enum  MULTIPKT_TYPE_T {
  MULTIPKT_TYPE_NONE = 0 ,
  MULTIPKT_TYPE_BAM = 1 ,
  MULTIPKT_TYPE_CMDT = 2
}
 Multi-packet types. More...
 
enum  DIRECTION {
  DIRECTION_TX_AND_RX = 0u ,
  DIRECTION_TX_ONLY = 1u ,
  DIRECTION_RX_ONLY = 2u
}
 Direction of the message. More...
 
enum  PGN_LIST_MODE_T {
  PGN_LIST_MODE_J1939 = 0 ,
  PGN_LIST_MODE_NMEA2000 = 10
}
 The list mode for the message. More...
 
enum  CTSTATE {
  CTSTATE_ONLINE ,
  CTSTATE_OFFLINE ,
  CTSTATE_CONFIGURING ,
  CTSTATE_END
}
 CT2KLibrary State. More...
 
enum  DBG_LVL_T {
  DBG_LVL_NORMAL = 0x01 ,
  DBG_LVL_NORMAL_TX = 0x02 ,
  DBG_LVL_NORMAL_RX = 0x04 ,
  DBG_LVL_VERBOSE = 0x08 ,
  DBG_LVL_INFO = 0x10 ,
  DBG_LVL_TEMPORARY_DEBUG = 0x20
}
 Debugging level. More...
 
enum  PORT_MODE_T {
  PORT_MODE_NMEA2000 = 10 ,
  PORT_MODE_J1939 = 20
}
 The mode of the port. More...
 
enum  NMEA_REQUEST_T {
  NMEA_REQUEST_REQUEST = 0 ,
  NMEA_REQUEST_COMMAND ,
  NMEA_REQUEST_ACKNOWLEDGE ,
  NMEA_REQUEST_READ_FIELDS ,
  NMEA_REQUEST_READ_FIELDS_REPLY ,
  NMEA_REQUEST_WRITE_FIELDS ,
  NMEA_REQUEST_WRITE_FIELDS_REPLY
}
 NMEA2000 Level A Request/Command/Acknowledge PGN values. More...
 
enum  GROUP_FUNCTION_PGN_ERROR_CODE_T {
  GROUP_FUNCTION_PGN_ERROR_CODE_NoError ,
  GROUP_FUNCTION_PGN_ERROR_CODE_PGNNotSupported ,
  GROUP_FUNCTION_PGN_ERROR_CODE_PGNTemporarilyNotAvailable ,
  GROUP_FUNCTION_PGN_ERROR_CODE_AccessDenied ,
  GROUP_FUNCTION_PGN_ERROR_CODE_RequestOrCommandNotSupported ,
  GROUP_FUNCTION_PGN_ERROR_CODE_DefinerTagNotSupported ,
  GROUP_FUNCTION_PGN_ERROR_CODE_ReadOrWriteNotSupported
}
 NMEA2000 ACK VALUES. More...
 
enum  GROUP_FUNCTION_TRANSMIT_INTERVAL_ERROR_CODE_T {
  GROUP_FUNCTION_TRANSMIT_INTERVAL_ERROR_CODE_NoError = 0 ,
  GROUP_FUNCTION_TRANSMIT_INTERVAL_ERROR_CODE_TransmitIntervalOrPriorityNotSupported ,
  GROUP_FUNCTION_TRANSMIT_INTERVAL_ERROR_CODE_TransmitIntervalIsLessThanMeasurementCalculationInterval ,
  GROUP_FUNCTION_TRANSMIT_INTERVAL_ERROR_CODE_AccessDenied ,
  GROUP_FUNCTION_TRANSMIT_INTERVAL_ERROR_CODE_RequestNotSupported
}
 
enum  GROUP_FUNCTION_PARAMETER_ERROR_CODE_T {
  GROUP_FUNCTION_PARAMETER_ERROR_CODE_NoError = 0 ,
  GROUP_FUNCTION_PARAMETER_ERROR_CODE_InvalidRequestOrCommandParmeterField ,
  GROUP_FUNCTION_PARAMETER_ERROR_CODE_TemporaryUnableToComply ,
  GROUP_FUNCTION_PARAMETER_ERROR_CODE_RequestOrCommandParameterOutOfRange ,
  GROUP_FUNCTION_PARAMETER_ERROR_CODE_AccessDenied ,
  GROUP_FUNCTION_PARAMETER_ERROR_CODE_RequestOrCommandIsNotSupported ,
  GROUP_FUNCTION_PARAMETER_ERROR_CODE_ReadOrWriteIsNotSupported
}
 

Functions

INPUT_PARAMS_T CT2KLibGetPGNTableRequiredMemorySize (const PGNDesc *pDesc, uint32_t tableSize, uint16_t numberOfPorts)
 Calculate the required size based on the provided PGNDesc Table.
 
void CT2KLibInitEx (INPUT_PARAMS_T *inputParams, PORTS_CONFIG_T *ports, uint32_t numberOfPorts, CAN_DRIVER_FUNCTIONS_T canDriverFunctions)
 Initialises the CT2K Library.
 
void CT2KLibDeinit (void)
 De-initialises the CT2K Library.
 
CTCAN_STATUS CT2KLibStart (void)
 Open the CAN Port and start the Library.
 
bool CT2KLibIsRunning (void)
 Query the State of the Library.
 
void CT2KLibStop (void)
 Stop the Library.
 
CTCAN_STATUS CT2KLibRestartCANPorts (PORTS_CONFIG_T *ports, uint32_t numberOfPorts)
 Restart the CAN Ports with a different configuration.
 
CTCAN_STATUS CT2KLibEnableDebug (uint32_t loggedMessagesBitmask, CT2KLibDiagnosticPrint_T printFunction, void *userData)
 Enable Debug Prints.
 
CTCAN_STATUS CT2KLibInstallPGNTable (CAN_PORT_T portNumber, const PGNDesc *pDesc, uint16_t tableSize)
 Install the PGN Table in the Library Duplicates are not allowed and will trigger an assert and a fail.
 
CTCAN_STATUS CT2KLibUninstallPGNTable (CAN_PORT_T portNumber, const PGNDesc *pDesc)
 Uninstall a PGN Table Installed using CT2KLibInstallPGNTable()
 
CTSTATE CT2KLibGetState (CAN_PORT_T i8Port)
 Get the Library status on the specified Port.
 
CTCAN_STATUS CT2KLibSetAppProductInfo (CAN_PORT_T i8Port, CTLIB_PROD_INFO *pProdInfo)
 Set and the Product Information via the NMEA2000 PGN.
 
CTCAN_STATUS CT2KLibSetConfigurationInformation_1F016 (CAN_PORT_T i8Port, const char *field1, size_t field1_Length, const char *field2, size_t field2_Length, const char *field3, size_t field3_Length)
 Set the information shared with other devices via the Configuration Information PGN (1F016).
 
CTCAN_STATUS CT2KLibSetConfigurationInformation_1F016_EX (CAN_PORT_T i8Port, const CONFIGURATION_INFORMATION_STRING_T *field1, const CONFIGURATION_INFORMATION_STRING_T *field2, const CONFIGURATION_INFORMATION_STRING_T *field3)
 Set the information shared with other devices via the Configuration Information PGN (1F016).
 
CTCAN_STATUS CT2KLibSetAddress (CAN_PORT_T i8Port, DEVNAME *pName, NETADDR u8SeedAddress)
 Assigns the name and address to the device.
 
CTCAN_STATUS CT2KLibAddValidAddressRange (CAN_PORT_T i8Port, uint8_t startAddress, uint8_t endAddress)
 Restricts the addressses that can be assigned to the device.
 
CTCAN_STATUS CT2KLibResetValidAddressRange (CAN_PORT_T i8Port)
 Resets the valid address range, cancelling the effect of any previous calls to CT2KLibAddValidAddressRange.
 
NETADDR CT2KLibGetMyAddress (CAN_PORT_T i8Port)
 Returns the devices CAN Address for the specified port.
 
void CT2KLibPackDeviceNameFields (const DEVICE_NAME_FIELDS *pFields, uint8_t *pPackedFields)
 Pack DEVICE_NAME_FIELDS struct into an 8 byte array.
 
void CT2KLibUnpackDeviceNameFields (const uint8_t *pPackedFields, DEVICE_NAME_FIELDS *pFields)
 Unpack 8 byte array into DEVICE_NAME_FIELDS struct.
 
const NMEA2000SpecVersion * CTLIBGetNMEA2KLibVersion (void)
 Get the NMEA2000 Database Version the library uses.
 
const char * CT2KGetLibVersion (void)
 Get the version number of CT2KLib.
 
CTCAN_STATUS CT2KLibSnoopNetwork (CAN_PORT_T i8Port)
 Sends Global Address Claim request using the Request PGN on the specified port.
 
CTCAN_STATUS CT2KSetPGNReceiveCallback (CAN_PORT_T i8Port, PGN i32PGN, RCVRCB rCB, uintptr_t userdata)
 Register a Callback function when a Message associated with the Specified PGN is received.
 
CTCAN_STATUS CT2KClearPGNReceiveCallback (CAN_PORT_T i8Port, PGN i32PGN)
 Deregister the Callback function that was registered with CT2KSetPGNReceiveCallback()
 
CTCAN_STATUS CT2KSetPGNISORequestReceivedCallback (CAN_PORT_T i8Port, PGN i32PGN, ISOCallback_EA00 regCB, uintptr_t userData)
 Register a Callback function when a Message associated with the Specified PGN is received.
 
CTCAN_STATUS CT2KLibAddrClaimReceiveCallback (CTLIB_ADDRCLAIM_CB AddrClaimCB, uintptr_t userData)
 Register a callback function that will be triggered when an address claim occurs.
 
CTCAN_STATUS CT2KLibSendPGN (CAN_PORT_T i8Port, NETADDR u8DestAddr, PGN i32PGN, void *pData, uint16_t u16DataLen)
 Send a Message using the specified PGN. Valid only for Single and Fast Packets.
 
CTCAN_STATUS CT2KLibSendPGNNow (CAN_PORT_T i8Port, NETADDR u8DestAddr, PGN i32PGN, void *pData, uint16_t u16DataLen)
 Functions the same as CT2KLibSendPGN Except allows you to mark a frame as to be sent immediately.
 
CTCAN_STATUS CT2KLibSendPGNMultiPkt (CAN_PORT_T i8Port, NETADDR u8DestAddr, PGN i32PGN, void *pData, uint16_t u16DataLen, MLTIPCKTSENDCALLBACK multiPktClbk, uintptr_t userdata, bool isBAM)
 Send a Message using the specified PGN.
 
CTCAN_STATUS CT2KSetGroupFunctionCallback (CAN_PORT_T i8Port, PGN i32PGN, NMEA2K_RQ_CMD regCB, uintptr_t userData)
 NMEA 2000 Level A - Request, Command, Acknowledge PGN Functions.
 
CTCAN_STATUS CT2KNMEA2KSendAcknowledge (CAN_PORT_T i8Port, PGN i32PGN, NETADDR u8DestAddr, MULTIPKT_TYPE_T transmitMethod, GROUP_FUNCTION_PGN_ERROR_CODE_T pgnErrorCode, GROUP_FUNCTION_TRANSMIT_INTERVAL_ERROR_CODE_T transmissionErrorCode, uint8_t numberOfRequestedParams, NMEA_REQUEST_FAILED_FIELDS_T *failedFields, uint8_t length)
 Send a NMEA2K Acknowledge Message (PGN 126208)
 
CTCAN_STATUS CT2KRegisterCallbackOnCommandedNameChange (CAN_PORT_T i8Port, CommandedNameChangeNotification callBack, uintptr_t userData)
 NMEA 2000 Level A - Commanded Name (0xEE00) Functionality.
 
CTCAN_STATUS CT2KRegisterCallbackOnRequestedHeartbeatRateChange (CAN_PORT_T i8Port, RequestedHeartbeatUpdateRateChangeNotification callback, uintptr_t userData)
 This allows you to register for a callback from the library if we receive a request to change the update rate of the heartbeat message.
 
CTCAN_STATUS CT2KSetHeartbeatUpdateRate (CAN_PORT_T i8Port, uint32_t updateRate_ms)
 This allows you to set the update rate of the NMEA2000 heartbeat message.
 
CTCAN_STATUS CT2KLibRegisterCommandedAddressCallback (CAN_PORT_T i8Port, COMMANDEDADDRESSCALLBACK callback, uintptr_t userData)
 This allows registration of a callback to check whether or not the device should change to the specified address on receipt of the CommandedAddress PGN.
 
CTCAN_STATUS CT2KLibRegisterCommandedConfigurationInformationCallback (COMMANDCONFIGURATIONINFORMATIONCALLBACK callback, uintptr_t userData)
 This allows registration of a callback to check whether or not the device should change it's configuration information to the specified strings on receipt of the Configuration Information PGN change command.
 

Detailed Description

CT2K NMEA2000 and J1939 Library.

Author
Copyright (c) 2016 CANtronik Ltd. All rights reserved.
Version
5.0.2.0
Date
2017 Revision History : Added NMEA2000 update to database 2.1 (Level A Support)

Definition in file CT2KLib.h.