Skip to content

Add indexed CAN map transmit API to avoid burst messages#50

Merged
jsphuebner merged 1 commit intojsphuebner:masterfrom
Modellfan:send-can-map-by-index
Apr 28, 2026
Merged

Add indexed CAN map transmit API to avoid burst messages#50
jsphuebner merged 1 commit intojsphuebner:masterfrom
Modellfan:send-can-map-by-index

Conversation

@Modellfan
Copy link
Copy Markdown
Contributor

@Modellfan Modellfan commented Apr 27, 2026

Summary

Adds CanMap::SendByIndex(uint8_t ididx) so applications can transmit one configured CAN map TX message at a time instead of always sending the full mapped TX set via SendAll().

The existing SendAll() behavior is preserved, but its frame-packing implementation now reuses a private Send(CANIDMAP*) helper.

Motivation

Some applications schedule mapped CAN TX messages periodically, for example from a 10 ms or 100 ms task. Calling SendAll() there sends every mapped TX message in one scheduler slice, which can create a burst of up to MAX_MESSAGES frames.

With SendByIndex(), application code can spread mapped messages across smaller scheduler slices.

Example downstream usage from src/main.cpp in Zombie-Slave, not included in this libopeninv PR:

static uint8_t canMapTxSlot;

static void Ms10Task(void)
{
   // Spread 100ms mapped CAN messages over ten 10ms scheduler slices.
   if (Param::GetInt(Param::canperiod) == CAN_PERIOD_100MS)
   {
      canMap->SendByIndex(canMapTxSlot);
      canMapTxSlot = (canMapTxSlot + 1) % MAX_MESSAGES;
   }
}

static void Ms1Task(void)
{
   // Spread 10ms mapped CAN messages over ten 1ms scheduler slices.
   if (Param::GetInt(Param::canperiod) == CAN_PERIOD_10MS)
   {
      canMap->SendByIndex(canMapTxSlot);
      canMapTxSlot = (canMapTxSlot + 1) % MAX_MESSAGES;
   }
}

This keeps the existing period setting semantics while avoiding bursts of all mapped TX frames in a single scheduler slice.

Backward compatibility
This is additive and keeps existing behavior intact.

CanMap::SendAll() remains public and keeps sending all configured TX map messages in one call. Existing applications that call SendAll() do not need changes.

Existing CAN map storage, SDO mapping, terminal mapping commands, and frame encoding behavior are unchanged. The new API only exposes indexed transmission for applications that want finer scheduling control.

SendByIndex() returns false for an out-of-range index, an unused TX map slot, or if transmission is skipped while CAN map flash saving is active. It returns true when the indexed message is sent.

Validation
Built and ran the libopeninv host tests.

Added a regression test covering:

sending only the selected mapped TX message;
preserving existing DLC behavior;
returning false for an unused slot;
returning false for MAX_MESSAGES.

@jsphuebner jsphuebner merged commit c076e19 into jsphuebner:master Apr 28, 2026
1 check passed
@jsphuebner
Copy link
Copy Markdown
Owner

Looks legit, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants