/* 
 * File:   can.h
 * Author: hamilton
 *
 * Created on February 6, 2015, 10:53 AM
 */

#ifndef CAN_H
#define	CAN_H




/* ECAN message type identifiers */
#define CAN_MSG_DATA 0x01
#define CAN_MSG_RTR 0x02
#define CAN_FRAME_EXT 0x03
#define CAN_FRAME_STD 0x04
#define CAN_BUF_FULL 0x05
#define CAN_BUF_EMPTY 0x06

/* message structure in RAM */
typedef struct{
/* Keep track of the buffer status */
unsigned char buffer_status;
/* RTR message or data message */
unsigned char message_type;
/* Frame type extended or standard */
unsigned char frame_type;
/* 29 bit ID max of 0x1FFF FFFF */
/* 11 bit ID max of 0x7FF */
unsigned long id;
unsigned char data[8];
unsigned char data_length;
} CANmsg;

void AssembleMessageData_TwoFloats(CANmsg *message, float float1, float float2);
void AssembleMessageData_FourInts(CANmsg *message, int int1, int int2, int int3, int int4);
void AssembleMessageData_EightBytes(CANmsg *message, char byte1, char byte2, char byte3, char byte4, char byte5, char byte6, char byte7,char byte8);

unsigned long Assemble_packetID(unsigned int src, unsigned int dataID, unsigned int seq_num);
int AssembleCAN_Packet(int bufnum, CANmsg *message);
void DisAssembleCAN_Packet(int bufnum, CANmsg *message);

#endif	/* CAN_H */

