Updating variables from comunications

I am working on a project where I am using several Arduinos connected by CAN bus to distribute various computation and sensing tasks. I want to use the CAN bus to essentially update global variables across the various nodes.

I have variables using several different data types. My CAN header will contain the data type and information to identify the variable. I am sure (haven't actually written the code yet) I can use nested if statements but I have to believe there is a simpler or cleaner way, especially when I get more than a few variables. Any suggestions on how to approach this problem? Or ideas on what concept I should do more research on, a search keyword?

Thanks for any advice you can provide

I am working on a project where I am using several Arduinos connected by CAN bus to distribute various computation and sensing tasks.

But I'm not going to show you any code.

I have variables using several different data types.

But, I'm not going to tell you what they are.

Any suggestions on how to approach this problem?

I'd suggest that you put your hands in your pockets while talking. The handwaving adds nothing since we can't see it. Details, man!

But I'm not going to show you any code.

Because as I was taught to write code you prepare a flow chart first, I can't figure out this one block of my flow chart, and have not written the code yet, as depending on how I approach this problem will impact some of the code before. I can put together some psueo code from my flow chart.

On interrupt (caused by message reception interrupt on CAN control chip (MCP 2515) {
   Byte Variable= GetCANVariable();
   Byte DataType=GetCANDataType();
   
   If Datatype ==
      byte value=GetCANByte();
      if Variable==1
        variable1=value;
      else if Variable==2
        variable2=value

...Repeat for each data type and varaiable

But, I'm not going to tell you what they are.

Right now I have 35 different variables (why I want to not use if statements, or even switch statements if I can avoid it). I have floats, Booleans, ints, Unsigned ints, bytes, and unsigned longs.

I'd suggest that you put your hands in your pockets while talking. The handwaving adds nothing since we can't see it. Details, man!

Sorry for asking a question without having lost of details worked out, I have applied the principals of preliminary design, which I use all the time at my job, to this hobby project. I am not a programmer by trade and apparently approach projects from a different perspective.

I am not a programmer by trade and apparently approach projects from a different perspective.

OK. Fair enough. The more you can describe, the better you'll be able, with our help, to translate that into code.

Is the data being sent as ASCII data, or binary data? Do you have control over what is sent? Start and end markers? Delimiters?

I can't grasp the highest level operation of the system you are trying to describe.

Perhaps a master is reading data from several slaves and then consolidating all the answers into a single set of data for onward transmission to something else (what, how)?

Perhaps the master is generating data to be sent to several slaves? is it sending the data one slave at a time, or is it sending all the data at once and each slave has to identify the piece that is meant for it?

Or something else entirely? Please clarify.

A general description of the sort of data and the quantity of data in each transmission would also be useful.

...R

The system is a control system for making beer, that is my highest level objective (yes I know people have done similar things already in far simpler ways, but that is not how you learn new things)

The system consists of several nodes, using the CAN bus each node is a peer (no masters). Sensor readings and output values are needed by several of the nodes. So when a value is updated it is broadcast across the network. The nodes which need to know that value will receive the value and update it in the Arduino/nodes memory. Filtering of which values are needed is done by the CAN controller.

The actual data transmission is pretty quick, the data gets held in the CAN controller. When a message comes, and has been verified, in it generates an interrupt, which triggers my routine. The actual message consists of a message header, which gets stored in 2 bytes. The header identifies which variable the message contains, as well as the data type.
The message it self is stored as individual bytes in the CAN controller buffer. I am reading the individual bytes and assembling them into the appropriate data type. I am getting the data from the CAN controller using the SPI library. Each transmission contains only one variable. I have successfully read the header information, as well as get the message and process it into the appropriate data type.

The variables contain data like temperature, volume (gallons), and output power (byte sent to PWM).

I have complete control over what gets sent. I have chosen to let the CAN controller deal with the specifics of the communications. I think I have a pretty good handle on how to get the actual communications, and have been able to get data out of the CAN controller.

Once I have the actual value (which could be any one of 6 data types) and have an ID for which variable it is (byte), is there some data structure I can use to store that value into memory without having to check each of the possible variables if the ID's match. I have used a Python dictionary to do something similar in the past.

I should add part of my motivation is to avoid occupying the processor for too long. I am running 7 segment displays on most of the nodes, which are being driven with the Sparkfun 7 segment library. I learned with another project that if the processor gets tied up for to long there is a noticeable flash in the display. By the time I finish checking 30+ if statements I fully expect to see a flash, that and the code gets hard to read (at least for me).

Does that make it easier to understand?

If I read it 7 or 8 times and think hard I'm sure I would make some progress.

My major stumbling block are the statements

using the CAN bus each node is a peer (no masters)

and

The actual data transmission is pretty quick, the data gets held in the CAN controller

Doesn't that make the CAN controller the master? Is this implemented in an Arduino device?

Where does the CAN controller get its data from?

Can you explain this

When a message comes, and has been verified, in it generates an interrupt, which triggers my routine.

Can you provide some samples of typical data (actual byte values) with an explanation.

...R