2024-06-06 10:01 PM - last edited on 2024-06-07 05:56 AM by Tesla DeLorean
I am trying to understand what I am doing wrong here. The following image was captured during a debug session to show strange behaviour.
In the If statement ap->enable and ap->active are both true, but ap->relay_map is 0, as shown on the right, so this should evaluate to false. So why does the processor execute the statement within the brackets (shown by the green highlight) since the If fails? It actually crashes the processor because the index evaluates to -1 which is out of bounds of the relays array.
Solved! Go to Solution.
2024-06-17 03:37 AM
I have managed to prove that although the debugger actually looks like it steps to that line under these particular circumstances, in fact it does not execute the statement it steps to.
I put a line in between to turn on the LED. It steps to that line 10 below, but doesn't execute it, the LED does not turn on.
So apologies for wasting everyone's time. This is just an artefact of the debugger operation and not real.
for(ai=0;ai<(sizeof(Alarms)/sizeof(AlarmType *));ai++)
{
//this process effectively does an OR, so multiple alarms can share one relay
ap=Alarms[ai];
if(ap->enable == true)
if(ap->active == true)
{
if(ap->relay_map > 0)
{
HAL_GPIO_WritePin(GPIOC, LED_USER2_Pin, GPIO_PIN_RESET); //Turn Alarm LED on
relays[ap->relay_map-1].relay_state=true;
}
}
}