📄 demo.c
字号:
// ****************************************************************************
//
// File Name: demo.c
//
// Description: Main demonstration program.
// Used to give an HMS serial commands.
//
//
// ORIGINATOR: Escort Memory Systems
//
// HISTORY
// who when what
// -------- --------- ----------------------------------------------------
// Geof 09/13/99 From HMS820 ABx standard demonstration program V1.4B.
//
// ****************************************************************************
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h> // Lower case conversion and toupper.
#include <time.h>
#include <dos.h>
#include "typedef.h" // General typedef and defines.
#include "handheld.h" // MUX enabled and MUX address defines.
#include "comm.h"
#include "hms800.h"
#include "preform.h"
#include "contread.h"
#define TOO_MANY_ERRORS 10 // Too many read errors on this tag.
#define LRP_ID_SIZE 8 // Number of bytes in an LRP tag ID.
#define MY_LIMIT 256 // Array size define.
#define INP_BUF_SIZE 100 // Input buffer size.
#define OUT_LIMIT (255 * 4) // Outut buffer array size.
// Below working variables for non-contiguous I/O routines.
static BYTE *address_ptr; // Index the output buffer to build command packet.
static WORD address_value; // Hold the input address.
static WORD nc_read_size; // Number of bytes in for Non_contiguous Read.
static WORD cont_start_add = 0; // Continual read mode start address
static BYTE out_buf[OUT_LIMIT];
static int serial_port; // Remember the port number being used, to change baud rates.
static BYTE cur_value; // The current value being written to each byte in the tag.
static BYTE hold_resp; // Hold the input character while the screen is cleared.
static BYTE UART_control; // Copy of the current UART control register value.
// ****************************************************************************
// Open the Serial port, to actualy receive data from the COM port.
//
// Input: COM port number (1 or 2)
// Baud rate setting.
// Return: BOOLEAN - TRUE if open OK.
// - FALSE if open error, like invalid parameter.
// Side effects: Receive buffer and pointer are updated.
// UART_contrl is updated.
BYTE open_comport(WORD portid, long unsigned int speed)
{
BYTE status;
status = comm_open(portid, speed, UART_control = WORD_EIGHT);
if (status)
comm_flush();
return(status);
}
// ****************************************************************************
// Open the Serial port again, with a new baud rate.
// NOTE: It is assumed that open_cmoport() has been called to initilize
// UART_control.
//
// Input: COM port number (1 or 2)
// Baud rate setting.
// Return: BOOLEAN - TRUE if open OK.
// - FALSE if open error, like invalid parameter.
// Side effects: Receive buffer and pointer are updated.
BYTE reopen_comport(WORD portid, long unsigned int speed)
{
BYTE status;
status = comm_open(portid, speed, UART_control);
if (status)
comm_flush();
return(status);
}
// ****************************************************************************
// Initial initialize serial port
//
// Input: NONE, implied global value passed in serial_port.
// Return: NONE.
// Side effects: Initilizes the COM port specified by serial_port..
static void InitCom (void)
{
if (NOT open_comport(serial_port, 9600))
printf("COM%1d open error\n", serial_port);
comm_flush(); // Clear out any residue from the command.
}
//*****************************************************************************
// Change the host serialal baud rate. Because the LRP does not support
// the change baud rage command, no command is sent.
//
// Input: NONE.
// Return: NONE.
// Side effects: Alters this machine's baud rate.
static void ChangeBaud(void)
{
WORD baud_value; // Hold the desired baud rate value.
clrscr();
do
{
printf("\n\nSet PC baud rate to:\n");
printf(" 0: 1200 \n");
printf(" 1: 2400\n");
printf(" 2: 4800\n");
printf(" 3: 9600\n");
printf(" 4: 19200\n");
printf(" 5: 38400\n");
switch (getch_cont())
{
case '0':
baud_value = 12; // Set the baud rate value for dobaud(), in comm.c.
break;
case '1':
baud_value = 24; // Set the baud rate value for dobaud(), in comm.c.
break;
case '2':
baud_value = 48; // Set the baud rate value for dobaud(), in comm.c.
break;
case '3':
baud_value = 96; // Set the baud rate value for dobaud(), in comm.c.
break;
case '4':
baud_value = 192; // Set the baud rate value for dobaud(), in comm.c.
break;
case '5':
baud_value = 384; // Set the baud rate value for dobaud(), in comm.c.
break;
case ESC:
return;
default:
printf("NO! \7 Enter a number in the list (dummy).\n");
baud_value = 0; // No valid entry, thus no baud rate value.
break;
;
}
} while (NOT baud_value); // Keep requesting new baud rate until entered.
reopen_comport(serial_port, (long )baud_value * 100);
comm_flush();
delay(100); // Wait for the transmit buffer setup to take effect.
printf("\n\n Baud rate in port %1d is changed to ", serial_port);
if (baud_value EQ 1152)
printf("115200.\n");
else
printf("%6u.\n", baud_value * 100);
printf("\n Enter a key to continue\n");
getch_cont(); // Wait with baud rate change displayed.
}
//*****************************************************************************
// Choose a command for the antenna.
//
// Input: NONE.
// Return: NONE.
// Side effects: NONE.
static void req_HMScommand(void)
{
for(;;)
{
printf("\nCommand for");
print_tag_type(); // Print tag type for these commands.
printf("\n");
#if TEST_MUX32
printf(" ---------> Using MUX32 address %d <---------\n", now_mux_addr);
#endif
printf(" 0. Issue repetitive Block Read commands.\n");
printf(" 1. Block Read.\n");
printf(" 2. Block Write.\n");
printf(" 3. Search Tag.\n");
printf(" 4. Read tag ID.\n");
printf(" 5. Clear Tag.\n");
printf(" 6. Fill Tag.\n");
printf(" 7. Check antenna.\n");
printf(" 8. Copy from a tag.\n");
if ((start_adr NE TOO_BIG_VAL) AND (stop_adr NE TOO_BIG_VAL))
{
printf(" 9. Write copied tag.\n");
printf(" A. View copied data.\n");
}
printf("Selection ........\n");
hold_resp = getch_cont();
clrscr();
switch(toupper(hold_resp))
{
case '0':
ContinueRead();
break;
case '1':
BlockRead();
break;
case '2':
pro_BlockWrite(FALSE);
break;
case '3':
SearchTag();
break;
case '4':
Get_tag_ID(LRP_ID_SIZE);
break;
case '5':
ClearTag();
break;
case '6':
FillTag();
break;
case '7':
ant_attached();
break;
case '8':
copy_from_tag();
break;
case '9':
if ((start_adr NE TOO_BIG_VAL) AND (stop_adr NE TOO_BIG_VAL))
copy_to_tag();
break;
case 'A':
if ((start_adr NE TOO_BIG_VAL) AND (stop_adr NE TOO_BIG_VAL))
disp_copied();
break;
case ESC:
return;
default:
;
}
clrscr();
}
}
// ****************************************************************************
// The main routine. Choose an antanna type.
//
// Input: Command line options, like the COM port number.
// Return: NONE.
// Side effects: NONE.
void main(argc, argv)
int argc; // Agetc returns an integer not a char
char **argv;
{
#if TEST_MUX32
WORD hold_adr; // Hold the input MUX32 address, to verify it is not an ESC.
#endif
if(argc <= 1) // Always have at least one parameter?
serial_port = 1; // Default comport is port one.
else
serial_port = atoi(argv[1]); // Setup implied parameter.
if ((serial_port < MIN_COM) OR ((serial_port > MAX_COM)))
{
printf("Use comport between\n%u and %u only.\n", MIN_COM, MAX_COM);
exit(1);
}
printf("\n");
#if PRINT_CMDS
printf("DEBUG ");
#endif
printf("LRP820 demonstration program using ");
#if TEST_MUX32
printf("MUX32.\n");
#else
printf("RS232.\n");
#endif
printf("Version %s, using COM%1d at 9600 baud, with ABx Standard.\n\n",
VERSION_STR, serial_port);
InitCom();
init_cont_read(); // Initilize contiguous Block Read state machine.
cur_value = 0; // For write to entire tag test. Start with a value.
max_data_pkt = LRP_MEM_SIZE;
mem_size = LRP_MEM_SIZE;
antenna_type = HMS_FAMILY;
for(;;) // Loop forever, use exit command.
{
#if TEST_MUX32
printf("Using MUX32 address %d \n\n", now_mux_addr);
#endif
printf("Data display format:\n");
printf(" 0. Hexadecimal\n");
printf(" 1. Decimal\n");
printf(" 2. ASCII\n");
printf(" 3. Binary\n");
printf(" 4. Change host's baud rate.\n");
#if TEST_MUX32
printf(" 5: Set MUX32 address.\n");
#endif
printf(" X: Exit \n\n");
printf("Select data display format: ");
while(NOT kbhit())
cont_read_mode(); // Handle any Contiguous Block Read data response.
clrscr();
switch(toupper(getch_cont()))
{
case '0':
display_type = HEX;
req_HMScommand();
break;
case '1':
display_type = DEC;
req_HMScommand();
break;
case '2':
display_type = ASCII;
req_HMScommand();
break;
case '3':
display_type = BIN;
req_HMScommand();
break;
case '4':
ChangeBaud();
break;
#if TEST_MUX32
case '5':
printf("Input new MUX32 address: ");
hold_adr = inp_num(BYTE_VALUE); // Get BYTE value input for address.
if ((hold_adr NE ENTER_ALONE) AND (hold_adr NE TOO_BIG_VAL))
now_mux_addr = hold_adr;
break;
#endif
case 'X':
if (ContRead_file NE NULL)// Was Continiuous Block Read response file open?
{ // Yes, so close it.
fprintf(ContRead_file, "\n"); // Final new line.
fclose(ContRead_file); // Close the debug dump file.
}
comm_close();
exit(0);
default:
;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -