spartanracingelectric / VCU

HY TTC 50 VCU code for SRE-2 to SRE-5. HY TTC 60 VCU code for SRE-6, SR-14, SR-15.
4 stars 6 forks source link

CAN Message Update Frequency #17

Closed RustyPedrosa closed 1 year ago

RustyPedrosa commented 8 years ago

Only send CAN messages if there has been an update or a certain amount of time has passed since the last message was sent.

Make this limitation easy to apply to all CAN messages.

(Use a universal CAN object for all messages? Pass this CAN object through a CAN sending function that applies this limitation and tosses superfluous messages out while passing messages with new data to the FIFO queue?)

RustyPedrosa commented 8 years ago

Develop an outgoing CAN handling system. Whenever a system attempts to transmit a CAN message, it should:

RustyPedrosa commented 8 years ago

Alternatively, develop a way to send messages only when needed (see subpoints in previous comment).

This doesn't seem to be the right solution. Go with the CAN handling system in the previous comment.

RustyPedrosa commented 8 years ago
CanManager* CanManager_new(canHandle0, canHandle1, defaultMinSendDelay, defaultMaxSendDelay);
//create can history data structure (AVL tree?)
//do other can init stuff

CanManager_setupMessage(ubyte2 messageID, ubyte4 timeBetweenMessages_Min, ubyte4 timeBetweenMessages_Max)
//add the parameters to can history datastructure

IO_ErrBlaBla CanManager_send(ubyte1 canHandle, IO_CAN_DATA_FRAME[] canMessages, ubyte? canMessageCount, bool force);
//Check if message data has changed
//Check if it's time to send message yet
  //If so, send message and update tree / linked list
//ToDo? write function to re-send message automatically if timebetweenMessages_Max has elapsed? (only applies to rinehart keepalive message)

//Helper functions
ubyte4 CanManager_timeSinceLastTransmit(IO_CAN_DATA_FRAME* canMessage)  //Overflows/resets at 74 min
bool CanManager_enoughTimeSinceLastTransmit(IO_CAN_DATA_FRAME* canMessage) // timesincelast > timeBetweenMessages_Min
bool CanManager_dataChangedSinceLastTransmit(IO_CAN_DATA_FRAME* canMessage) //bitwise comparison for all data bytes

//Keep track of CAN message IDs, their data, and when they were last sent.
typedef struct canMessageControls
{
  ubyte2 canMessageID;
  ubyte4 timeBetweenMessages_Min;
  ubyte4 timeBetweenMessages_Max;
  ubyte1 lastMessage_data[8];
  ubyte4 lastMessage_timeStamp;
  canHistoryNode* left;
  canHistoryNode* right;
}
RustyPedrosa commented 8 years ago

CanManager sends messages without delaying in case of repeat / too soon