Roll Call and Aggregate Library - UWCubeSat/DubSat1 GitHub Wiki
David's Roll Call Library
First, it is probably a good idea to include the library itself:
#include "interfaces/rollcall.h"
Now it's time to get to work!
First, we should declare the functions which will populate the rollcall packets. These functions should take a canPacket to fill, and return nothing.
FILE_STATIC void rcPopulate1(CANPacket *out);
FILE_STATIC void rcPopulate2(CANPacket *out);
FILE_STATIC void rcPopulate3(CANPacket *out);
Here's what a function would kind of look like.
void rcPopulate1(CANPacket *out)
{
rc_adcs_sp_1 rc;
rc.rc_adcs_sp_1_reset_count = bspGetResetCount();
rc.rc_adcs_sp_1_sysrstiv = SYSRSTIV;
rc.rc_adcs_sp_1_temp_avg = 2732+((uint16_t)(10*aggVec_avg_f(&rc_temp)));
rc.rc_adcs_sp_1_temp_max = 2732+((uint16_t)(10*aggVec_max_f(&rc_temp)));
rc.rc_adcs_sp_1_temp_min = 2732+((uint16_t)(10*aggVec_min_f(&rc_temp)));
aggVec_reset((aggVec *) &rc_temp);
encoderc_adcs_sp_1(&rc, out);
}
Then we create an array which contains these functions
FILE_STATIC const rollcall_fn rollcallFunctions[] =
{
rcPopulate1, rcPopulate2, rcPopulate3
};
Initialize the rollcall library with the array of functions, and the number of functions contained.
rollcallInit(rollcallFunctions, sizeof(rollcallFunctions) / sizeof(rollcall_fn));
Then in order to actually send all those packets you want to send.
rollcallUpdate();
rollcallUpdate
returns the number of packets that are not yet sent. It's likely that not all rollcall packets will be sent in one call to rollcallUpdate
. Keep calling rollcallUpdate
in your while loop (and not in the CAN callback) to eventually send all the packets.
MOST IMPORTANTLY
Don't forget this in your can callback!!
if(packet->id == CAN_ID_CMD_ROLLCALL)
{
rollcallStart();
}
Emory's Agglib
THE CAPACITY OF AN AGGLIB VECTOR IS 65535. IT WILL NOT PUSH VALUES TO THE AGGREGATE VECTOR AFTER THAT AND YOU MUST RESET.
First include the library.
#include "core/agglib.h"
create our aggregate struct.
FILE_STATIC aggVec_f rc_temp;
ALWAYS INIT BEFORE PUSHING AND MAKE SURE YOU GET YOUR TYPES RIGHT!!!!
for doubles : aggVec_init_d
for floats : aggVec_init_f
for ints : aggVec_init_i
intialize the struct
aggVec_init_f(&rc_temp);
Add something to the aggregate struct
aggVec_push_f(&rc_temp, (hseg.inttemp + 273.15f) * 10);
And then we can get the average, maximum and minimum
aggVec_avg_f(&rc_temp);
aggVec_max_f(&rc_temp);
aggVec_min_f(&rc_temp);
After getting all the aggregates, you may want to reset them all with
aggVec_reset((aggVec *) &rc_temp);
Note this requires a cast to aggVec*
.
You can also selectively reset specific aggregates using the aggVec_as_reset
(resets average and sum), aggVec_max_reset
, and aggVec_min_reset
functions.