void DetectSCAB()
{
COMMAND_PACKET GPIO_State_returned;
GPIO_State_returned.command=0;
COMMAND_PACKET command_to_module;
command_to_module.command=0;
// set to drive high, pull low
command_to_module.command=34;
command_to_module.data[0]=4;
command_to_module.data[1]=0;
command_to_module.data[2]=8;
command_to_module.data_length=3;
send_packet(&command_to_module);
command_to_module.command=35;
command_to_module.data[0]=4;
command_to_module.data_length=1;
send_packet(&command_to_module);
command_to_module.command=35;
command_to_module.data[0]=4;
command_to_module.data_length=1;
send_packet(&command_to_module);
command_to_module.command=35;
command_to_module.data[0]=4;
command_to_module.data_length=1;
send_packet(&command_to_module);
fprintf(stdout,"Detecting SCAB\n");
int retries=0;
while(retries<=3)
{
if(check_for_packet(&GPIO_State_returned))
{
ShowReceivedPacket(&GPIO_State_returned);
if(GPIO_State_returned.command==0x63)
{
if((GPIO_State_returned.data[0]==4)&&(GPIO_State_returned.data[1]==0))
{
fprintf(stdout,"No SCAB Detected\n");
retries++;
}
else if((GPIO_State_returned.data[0]==4)&&(GPIO_State_returned.data[1]>0))
{
fprintf(stdout,"SCAB Detected\n");
command_to_module.command=34;
command_to_module.data[0]=4;
command_to_module.data[1]=0;
command_to_module.data[2]=7;
command_to_module.data_length=3;
send_packet(&command_to_module);
return;
}
}
}
else
check_for_packet(&GPIO_State_returned);
if((retries==3)&&(((GPIO_State_returned.data[0]==4)&&(GPIO_State_returned.data[1]==0))))
{
fprintf(stdout,"No SCAB Detected after 3 retries.\n");
exit(1);
}
Sleep(10);
}
return;
}