Listing 1—The command reply from the switch module is assembled in the send_buffer[] array and is sent before the actual
RPC code is executed. A valid command reply always begins with the incoming command plus 0x10.
case 0x14:
send_buffer[0] = 0x24;
data_buffer[1] = bgetc();
data_buffer[2] = bgetc();
send_buffer[1] = data_buffer[1];
send_buffer[2] = data_buffer[2];
if(data_buffer[1] == 0x30 && data_buffer[2] == 0x31)
{
for(i=0;i<3;++i)
putc(send_buffer[i]);
rf_ON;
rf_serial_data_H;
}
if(data_buffer[1] == 0x30 && data_buffer[2] == 0x32)
{
for(i=0;i<3;++i)
putc(send_buffer[i]);
rf_OFF;
rf_serial_data_L;
}
if(data_buffer[1] == 0x30 && data_buffer[2] == 0x33)
{
for(i=0;i<3;++i)
putc(send_buffer[i]);
++station_id;
if(station_id > 0x07)
station_id = 0x00;
status_byte |= SW1_STATUS_BIT;
for (i=0;i<7;++i)
{
Get_The_Temp();
// Send burst of three messages with this station ID times (takes approximately 400 ms)
Transmit_Data(STATION_ID_MSG); // Transmit message with this station ID
delay_ms(100); // Wait 100 ms
Transmit_Data(STATION_ID_MSG); // Transmit message with this station ID
delay_ms(100); // Wait 100 ms
Transmit_Data(STATION_ID_MSG); // Transmit message with this station ID
delay_ms(100); // Wait 100 ms
}
}
if(data_buffer[1] == 0x30 && data_buffer[2] == 0x34)
{
for(i=0;i<3;++i)
putc(send_buffer[i]);
Get_The_Temp();
old_temperature_deg_C = temperature_deg_C;
old_status_byte = status_byte;
// Transmit data
Transmit_Data(NORMAL_MSG);
delay_ms(20);
Transmit_Data(NORMAL_MSG);
delay_ms(20);
Transmit_Data(NORMAL_MSG);
delay_ms(5);
}
break;