📄 contread.c
字号:
// state of the continuous Block Read data response.
//
// Input: NONE.
// Return: NONE.
// Side effects: NONE.
static void terminate_byte(void)
{
BYTE got_byte; // Hold what should be the header byte.
if (NOT interbyte_toolong())
if (comm_avail())
{
init_time(); // Start timing fresh for the next byte.
if (NOT com_rec_buf(&got_byte, ONE_BYTE, SOMETHING))
return; // This cannot happen, but check anyway.
if (got_byte EQ 0xFF) // Got the header byte.
{ // Got expected BYTE value.
if (ContRead_file NE NULL)
fprintf(ContRead_file, "\n");
else
printf("\n"); // Finial Carrage Return at packet end.
cur_col = 0; // Start next packet on a new display line.
} else
{ // Display what ever it is and
if (ContRead_file NE NULL)
fprintf(ContRead_file, " [Invalid terminator]\n");
else
printf(" [Invalid terminator]\n");
cur_col = 0;
print_the_byte(got_byte); // Display what ever was received.
}
#if TEST_MUX32
Cont_read_rsp = precede; // Start fresh looking for data response.
#else
Cont_read_rsp = header_byte; // Start fresh looking for data response.
#endif
}
}
//*****************************************************************************
// Leading zero in ABx standard state of the continuous Block Read data response.
//
// Input: NONE.
// Return: NONE.
// Side effects: NONE.
static void zero_cont_data(void)
{
BYTE got_byte; // Hold what should be the header byte.
if (NOT interbyte_toolong())
if (comm_avail())
{
init_time(); // Start timing fresh for the next byte.
if (NOT com_rec_buf(&got_byte, ONE_BYTE, SOMETHING))
return; // This cannot happen, but check anyway.
if (got_byte EQ 0x00) // Got the header byte.
Cont_read_rsp = cont_data_read; // Got expected BYTE value (00).
else if (got_byte EQ 0xFF) // First byte of terminator?
Cont_read_rsp = terminate_byte; // Look for the second termination byte.
else
{ // Display what ever it is and
#if DEBUG_DUMP
if (ContRead_file NE NULL)
fprintf(ContRead_file, "\n [Invalid value]");
else
printf("\n [Invalid value]");
#endif
cur_col = 0;
print_the_byte(got_byte); // Display what ever was received.
#if TEST_MUX32
Cont_read_rsp = precede; // Start fresh looking for data response.
#else
Cont_read_rsp = header_byte; // Start fresh looking for data response.
#endif
}
}
}
//*****************************************************************************
// Command echo state of the continuous Block Read data response.
//
// Input: NONE.
// Return: NONE.
// Side effects: NONE.
static void cmd_echo(void)
{
BYTE cmd_byte; // Hold what should be the header byte.
time_t hold_time; // To get the current time, in seconds;
if (NOT interbyte_toolong())
if (comm_avail())
{
init_time(); // Start timing fresh for the next byte.
if (NOT com_rec_buf(&cmd_byte, ONE_BYTE, SOMETHING))
return; // This cannot happen, but check anyway.
if (cmd_byte EQ CONT_READ) // Got the header byte.
{ // Got expected BYTE value.
if (ContRead_file NE NULL)
{
time(&hold_time);
fprintf(ContRead_file,
"\n\n-------> Continual Read data response on %s\n",
asctime(localtime(&hold_time)));
}
#if TEST_MUX32
if (ContRead_file NE NULL)
fprintf(ContRead_file, "MUX: %2d:", Mux_address);
else
printf("MUX: %2d :", Mux_address);
cur_col = cur_col + 9;
if (display_type EQ DEC)
{
if (ContRead_file NE NULL)
fprintf(ContRead_file, " ");
else
printf(" ");
cur_col = cur_col + 3;
}
#endif
Cont_read_rsp = zero_cont_data; // Now get the Command echo.
} else // Else not command echo!
{ // Display what ever it is and
print_the_byte(MSG_BEGIN); // Display header byte received.
print_the_byte(cmd_byte); // Display what ever was received.
#if TEST_MUX32
Cont_read_rsp = precede; // Start fresh looking for data response.
#else
Cont_read_rsp = header_byte; // Start fresh looking for data response.
#endif
}
}
}
//*****************************************************************************
// State to handle the continuous Block Read data response packet header byte.
//
// Input: NONE.
// Return: NONE.
// Side effects: NONE.
static void header_byte(void)
{
BYTE head_byte; // Hold what should be the header byte.
if (comm_avail()) // Have received somthing. Is the continual read response?
{
if (NOT com_rec_buf(&head_byte, ONE_BYTE, SOMETHING))
return; // This cannot happen, but check anyway.
if (head_byte EQ MSG_BEGIN) // Got the header byte.
{
init_time(); // Start timing fresh for the next byte.
Cont_read_rsp = cmd_echo; // Now get the Command echo.
} else
print_the_byte(head_byte); // Display what ever was received.
}
}
#if TEST_MUX32
//*****************************************************************************
// State to handle the MUX32 format type preceding byte.
//
// Input: NONE.
// Return: NONE.
// Side effects: NONE.
static void mux_addr(void)
{
if (NOT interbyte_toolong())
if (comm_avail()) // Have received somthing. Is the continual read response?
{
if (NOT com_rec_buf(&Mux_address, ONE_BYTE, SOMETHING))
return; // This cannot happen, but check anyway.
Cont_read_rsp = header_byte; // Now get the mux Address.
} // Because this is coming form an MM80 (with a message) no time
} // verification on the next byte is necessary, but could be done.
//*****************************************************************************
// State to handle the MUX32 format type preceding byte.
//
// Input: NONE.
// Return: NONE.
// Side effects: NONE.
static void precede(void)
{
BYTE fmt_type; // Hold what should be the format type byte.
if (comm_avail()) // Have received somthing. Is the continual read response?
{
if (NOT com_rec_buf(&fmt_type, ONE_BYTE, SOMETHING))
return; // This cannot happen, but check anyway.
if (fmt_type EQ THESE_MSG_HEAD) // Got the header byte.
{
init_time(); // Start timing fresh for the next byte.
Cont_read_rsp = mux_addr; // Now get the mux Address.
} else
print_the_byte(fmt_type); // Display what ever was received.
}
}
#endif
//*****************************************************************************
// Initialize the continuous Block Read mode state machine. This routine must
// be called BEFORE cont_read_mode() is called the fist time.
//
// Input: NONE.
// Return: NONE.
// Side effects: Initialize the state machine.
void init_cont_read(void)
{
cur_col = 0;
ContRead_file = NULL; // Be positive nothing is pointed to.
#if TEST_MUX32
Cont_read_rsp = precede; // Start fresh looking for data response.
#else
Cont_read_rsp = header_byte; // Start fresh looking for data response.
#endif
}
//*****************************************************************************
// Main entry point for this file. This is the driver for the Continuous Block
// Read mode. The appropriate state subroutine is called from here.
//
// Input: NONE.
// Return: NONE.
// Side effects: NONE.
void cont_read_mode(void)
{
(*Cont_read_rsp)(); // Handle any Contiguous Block Read data response.
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -