if I am better off using Structures or Array's to store and present the data. Currently I am using array's but it is getting to be a pain to keep track
of everything. It basically acts a monitor circuit and certain events trip as they occur.
I am not that great of a programmer, but I am trying to broaden my horizons as my job is requiring me to learn a lot more
Basically my pseudocode is the following:
Code: Select all
Get Battery1 Voltage
Get Battery1 Current
Get Battery1 Status
Get Battery1 ...N
...
Get BatteryN Voltage
Basically it would fill an array/matrix ~16x20
Process the data (Better for structs or arrays)
Output the data linearly like this
Code: Select all
Output[0] = Value1
Output[1] = Value2
...
Output[35] = Battery1 Voltage
Output[240] = Battery16 N
Currently I have array's loop through saving in each individual part of the array after I convert them to the appropriate data type. So something like this:
Code: Select all
for(i = 0; i< TotalBatteryNumber; i++)
// Loop through each battery
{
GetVoltage(BatteryNumber)
// Function gets the battery voltage
{
BatteryArray[i][0] = Voltage;
// Inside the function basically does this
}
}
Then I do the same thing for the Current, Status, etc.
I would then process the data and then output it on my Output loop using similar for loops. I was wondering if a structure like this is more efficient and easier to read:
Code: Select all
struct Batterys{
int Voltage;
int Current;
int Status;
int ...
} Battery1, Battery2, Battery3, BatteryN;
Or would it be better like this:
Code: Select all
struct Voltage{
int Battery
} Battery1, Battery2, Battery3, BatteryN;
struct Current{
int Battery
} Battery1, Battery2, Battery3, BatteryN;
Or if someone has a better idea to collect, organize and process the data for output. The other thing is my Output data can only send 16 bytes at a time through the serial bus
it interfaces with so I was trying to use a counter for that.
The only thing I am not that comfortable with is pointers and references. I have been trying to get a grasp on it, but it is taking me a while.
This is for a DSP embedded solution with actual hardware. I am just trying to get some opinions on how to best organize the data.
Thanks for the help.