Tod - just for reference, this is some of my handling subroutine for data so far:
void soft_handler(void)
{
volatile unsigned int i; // counting index variable
WORD buff_size = GetDataSize(); // Stores the size of the Data Buffer in "buff_size"
PBYTE data_pointer = GetDataBuffer(); // points "data_pointer" to the (address) start of the data buffer
unsigned int data_byte = *data_pointer; // derefrencess the data pointer to get data it's pointing towards
// Check machine ID - although the machine is defined by IP address, a failsafe is needed.
i=0;
if (machine_ID != data_byte) // first byte of the payload is machine ID - verify machine ID
{
// send back an error message that says "incorrect machine ID"
return;
}
else
{
data_pointer++; // increment data_pointer so that the next value points to the first instruction.
}
while (i < buff_size) // function operates as long as i < total number of bytes in the buffer
{
switch (data_byte) // switch-case routine for manipulating data
{
case ONOFF: // enable system
data_pointer++; //increments the data pointer to point to the instruction data byte
if (data_byte == ON)
{
// GPIO write 1 to enable system
data_pointer++; //increments the data pointer to point to the next instruction
i+=2; // increment i by 2 - one for instruction, one for data associated with instruction
}
else
{
// GPIO write 0 to inhibit system
data_pointer++; //increments the data pointer to point to the next instruction
i+=2; // increment i by 2 - one for instruction, one for data associated with instruction
}
break;
case temp_check:
data_pointer++; // increment the data pointer to point to the instruction data byte
// send temperature:
// -get value from ADC
// -scale value to proper temperature range
// -put value in output array
data_pointer++; //increments the data pointer to point to the next instruction
i+=2; // increment i by 2 - one for instruction, one for data associated with instruction
break;
case fan_speed:
data_pointer++; // increment the data pointer to point to the instruction data byte
// send fan speed
// -read fan speed?
// -convert data to proper speed value
// -put value into output array
data_pointer++; //increments the data pointer to point to the next instruction
i+=2; // increment i by 2 - one for instruction, one for data associated with instruction
break;
case chk_faults:
data_pointer++; // increment the data pointer to point to the instruction data byte
// send fault information
// -check system faults
// -put data into output array
data_pointer++; //increments the data pointer to point to the next instruction
i+=2; // increment i by 2 - one for instruction, one for data associated with instruction
break;
case chk_intrlcks:
data_pointer++; // increment the data pointer to point to the instruction data byte
// check interlock status
// -check system interlocks
// -put data into output array
data_pointer++; //increments the data pointer to point to the next instruction
i+=2; // increment i by 2 - one for instruction, one for data associated with instruction
break;
case preset_mode:
data_pointer++; // increment the data pointer to point to the instruction data byte
// enter preset mode
// -check if live adjust or not
// -adjust voltage and current
// -read program DACs to be sure
// -put status, output (if live) and DAC readings into output array
data_pointer++; //increments the data pointer to point to the next instruction
i+=2; // increment i by 2 - one for instruction, one for data associated with instruction
break;
case adj_volts:
data_pointer++; // increment the data pointer to point to the instruction data byte
// Adjust voltage (fine-small increments during run operation)
// -convert data_i value to 12 bit value for DAC
// -load value into voltage DAC
// -place DAC value, output, and status into output array
data_pointer++; //increments the data pointer to point to the next instruction
i+=2; // increment i by 2 - one for instruction, one for data associated with instruction
break;
case adj_amps:
data_pointer++; //increments the data pointer to point to the next instruction
// adjust current (fine-small increments during run operation)
// -convert data_i value to 12 bit value for DAC
// -load value into voltage DAC
// -place DAC value, output value, and status into output array
data_pointer++; //increments the data pointer to point to the next instruction
i+=2; // increment i by 2 - one for instruction, one for data associated with instruction
break;
/* case get_log:
// retrieve data log and send to host - might eliminate
i++; // increment to next array position
break;
*/
default:
// no instruction match, send "instruction mismatch" error
// -load "resend instruction" byte into output array
return;
if (i == buff_size)
{
// once every command has been processed, what do we do?
// all data is collected and ready to go - create UDP packet, add data, append to packet, allow to send back
}
}
}
return; // go back to calling function which will send data array back to the host system. Total time in subroutine should be no longer than the total time it takes to read all ADCs and program all DACs (~8us each -1 second total time maximum)
}
MOD54415 file handling
Re: MOD54415 file handling
When you de-reference a pointer it gets the value of the pointer at that point in time. If I were you I would rewrite this method to take a pointer to the buffer and the buffer length (actually I would write it to take a vector but that's going off topic), and then you can easily write some test code and pass in some data and make sure it does what you want, because right now it doesn't.
-
- Posts: 192
- Joined: Mon Dec 17, 2012 6:24 am
Re: MOD54415 file handling
So if I de-reference the pointer in each case separately, would that make a difference? I'm a little unsure how to go about accomplishing what you're suggesting... should I write a method to put the data into an array instead? I'm not sure how time sensitive the data in the buffer is.
-
- Posts: 192
- Joined: Mon Dec 17, 2012 6:24 am
Re: MOD54415 file handling
Tod - will this work? I see no reason why it shouldn't. Sorry if the comments are out of alignment in this text, can't seem to figure out how to space them properly...
volatile unsigned int i; // counting index variable
i = 0; // initialize
PBYTE data_pointer = GetDataBuffer(); // points "data_pointer" to the (address) start of the data buffer
WORD buff_size = GetDataSize(); // Stores the size of the Data Buffer in "buff_size"
volatile unsigned int data[buff_size]; // data stored into this array
while (i <= buff_size)
{
unsigned int data_byte = *data_pointer; // Dereferences the data pointer to get data it's pointing towards
data = data_byte; // Data is stored in array location
i++; // increment
data_pointer++; // Next data location
}
volatile unsigned int i; // counting index variable
i = 0; // initialize
PBYTE data_pointer = GetDataBuffer(); // points "data_pointer" to the (address) start of the data buffer
WORD buff_size = GetDataSize(); // Stores the size of the Data Buffer in "buff_size"
volatile unsigned int data[buff_size]; // data stored into this array
while (i <= buff_size)
{
unsigned int data_byte = *data_pointer; // Dereferences the data pointer to get data it's pointing towards
data = data_byte; // Data is stored in array location
i++; // increment
data_pointer++; // Next data location
}