public class Can
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
Can.CanMsg
Inner class to manage the CAN messages.
|
Modifier and Type | Field and Description |
---|---|
static int |
ABOVE_ERR_WARN |
static int |
ALL |
static int |
ARB_LOST |
static int |
BELOW_ERR_WARN |
static int |
BUS_ERROR |
static int |
BUS_OFF |
static int |
BUS_RECOVERED |
static int |
ERR_ACTIVE |
static int |
ERR_PASS |
static int |
HAS_CS |
static int |
MAX_FRAME_SIZE |
static int |
MAX_TIMEOUT |
static int |
MODE_LISTEN_ONLY |
static int |
MODE_NO_ACK |
static int |
MODE_NORMAL |
static int |
NO_CS |
static int |
NONE |
static int |
RECOVERY_IN_PROGRESS |
static int |
RX_NON_EMPTY |
static int |
RX_QUEUE_FULL |
static int |
SID_ACTIVE_EVENTS |
static int |
SID_ARB_LOST_COUNT |
static int |
SID_BUS_ERROR_COUNT |
static int |
SID_MSGS_TO_RX |
static int |
SID_MSGS_TO_TX |
static int |
SID_RX_ERROR_COUNTER |
static int |
SID_RX_MISSED_COUNT |
static int |
SID_STATE |
static int |
SID_TX_ERROR_COUNTER |
static int |
SID_TX_FAILED_COUNT |
static int |
STATE_BUS_OFF |
static int |
STATE_RECOVERING |
static int |
STATE_RUNNING |
static int |
STATE_STOPPED |
static int |
TX_FAILED |
static int |
TX_IDLE |
static int |
TX_SUCCESS |
Constructor and Description |
---|
Can(int canFrequency_kbps,
int canMode)
Creates a CAN interface at the specified frequency.
|
Modifier and Type | Method and Description |
---|---|
int |
enableEvent(int newenabled)
enableEvent( int newenabled )
Adapt the filter characteristics to send event (through onEvent() method)
|
int |
flushReceive()
flushReceive( )
flush the queue of received messages
|
int |
flushTransmit()
flushTransmit( )
flush the queue of messages to be transmitted.
|
Can.CanMsg |
getMessage(int timeout)
Read the first message from the CAN FIFO.
|
int |
getState(int sta_id)
getStateVal( int state_id )
Read the current state of the controller and update the corresponding class fields.
|
int |
recover()
recover( )
Try to recover the bus connection when state == STATE_BUS_OFF
|
int |
sendMessage(Can.CanMsg msg,
int timeout)
Send the given message to the CAN port
|
int |
setAcceptance(int code,
int mask,
byte single)
setAcceptance
Defines the filter for incoming messages (see mask above)
|
int |
setMode(int canMode)
setMode( int mode )
Enable the controller for both transmissin and reception
|
int |
start()
start()
Enable the controller for both transmissin and reception
|
int |
stop()
stop()
Enable the controller for both transmissin and reception
|
public static final int MAX_FRAME_SIZE
public static final int MAX_TIMEOUT
public static final int MODE_NORMAL
public static final int MODE_NO_ACK
public static final int MODE_LISTEN_ONLY
public static final int STATE_STOPPED
public static final int STATE_RUNNING
public static final int STATE_BUS_OFF
public static final int STATE_RECOVERING
public static final int SID_STATE
public static final int SID_MSGS_TO_RX
public static final int SID_MSGS_TO_TX
public static final int SID_TX_ERROR_COUNTER
public static final int SID_RX_ERROR_COUNTER
public static final int SID_TX_FAILED_COUNT
public static final int SID_RX_MISSED_COUNT
public static final int SID_ARB_LOST_COUNT
public static final int SID_BUS_ERROR_COUNT
public static final int SID_ACTIVE_EVENTS
public static final int NO_CS
public static final int HAS_CS
public static final int TX_IDLE
public static final int TX_SUCCESS
public static final int BELOW_ERR_WARN
public static final int ERR_ACTIVE
public static final int RECOVERY_IN_PROGRESS
public static final int BUS_RECOVERED
public static final int ARB_LOST
public static final int ABOVE_ERR_WARN
public static final int BUS_ERROR
public static final int TX_FAILED
public static final int RX_QUEUE_FULL
public static final int ERR_PASS
public static final int BUS_OFF
public static final int RX_NON_EMPTY
public static final int ALL
public static final int NONE
public Can(int canFrequency_kbps, int canMode)
canFrequency
- the frequency of the CAN (unit = kbit per second).canMode
- should 0 (Normal), 1 (no acknowledge) or 2 (listen only)public int setAcceptance(int code, int mask, byte single)
code
- bit sequence which a message�s ID, RTR, and possibly data bytes (for 11 bit id) must match to be received.mask
- bit sequence specifying which bits of the acceptance code can be ignoredsingle:
- 1: Single Filter Mode will use the acceptance code and mask to define a single filter
0: Dual Filter Mode will use code and mask to define two separate filters [only bits 13:28 are considered)public int start()
public int stop()
public int setMode(int canMode)
canMode
- should 0 (Normal), 1 (no acknowledge) or 2 (listen only)public int getState(int sta_id)
public int flushTransmit()
public int flushReceive()
public int recover()
public int enableEvent(int newenabled)
newenabled:
- bitfield to define the accepted events for notification.public Can.CanMsg getMessage(int timeout)
timeout
- in mspublic int sendMessage(Can.CanMsg msg, int timeout)
msg
- the message buffer to transmittimeout
- in ms