?? preform.c
字號:
printf("\nNon-Contiguous Write has failed\n");
break;
case NONCON_CONFFAL:
printf("\nNon-Contiguous Read/Write configuration has failed\n");
break;
case FILL_FAIL:
printf("\nFill Operation has failed\n");
break;
case READ_BLOCKFAIL:
printf("\nContiguous Block Read has failed\n");
break;
case WRITE_BLOCKFAIL:
printf("\nContiguous Block Write has failed\n");
break;
case SEARCH_FAIL:
printf("\nSearch Tag Operation failed\n");
break;
case PROTECT_VIOLATE:
printf("\nProtection violation\n");
break;
case NONCON_NOCONF:
printf("\nNon-Contiguous Read/Write attempt without pre-configuration\n");
break;
case INP_NOTMATCH:
printf("\nInput Command does not match pre-defined format\n");
break;
case COMM_FAIL:
printf("\nCommunication time out.\n");
break;
default:
printf("\nUnknown error %02XH\n",error_num);
break;
}
}
// ****************************************************************************
// Preform a Block Write.
//
// Input: Start and stop tag addresses of a tag.
// BOOLEAN - TRUE, using proteced mode block writes.
// - FALSE, normal block write.
// Return: NONE.
// Side effects: NONE.
static void do_Write(WORD start_add, WORD end_add, BYTE *data_ptr, BYTE prt_mode)
{
WORD now_start; // Starting address for the current block write.
WORD data_size; // Amount of data to be written.
WORD this_write; // Number of bytes in a given write block command.
WORD data_index; // Arrary index for the data buffer pointer..
BYTE status; // Mifare tag interface status value.
do
{
printf("\nSearching for tag.\n");
start_down(TAG_START); // This initialized finished.
now_start = start_add;
data_index = 0; // Start with the first data input.
data_size = end_add + 1 - start_add; // Count of tag data bytes.
while (down_count() AND NOT finished) // Note: Because Tag IO,
{ // mifare interface takes time the display down count is slower.
if ((data_size / max_data_pkt) NE 0) // Next packet of data MAX size?
this_write = max_data_pkt; // Use a maximum packet size for HMS827.
else // else send just what fits.
this_write = data_size % max_data_pkt;
if((status = Write_command
(now_start, this_write, data_ptr + data_index, prt_mode)) EQ OP_OK)
{
printf("Writing to tag"); // No new line, just overprint same string.
putch(CR);
now_start = now_start + this_write; // Updata date address for next read.
data_index = data_index + this_write; // Update data buffer array index.
if ((data_size = data_size - this_write) EQ 0) // If no more data
finished = TRUE; // then, must be finished.
} else if (status EQ PROTECT_VIOLATE)
{
print_code(status);
display_delay();
return; // Write violation, give up.
}
if (esc_entered())
return; // Yes, get out. Exit on ESC. Confused user.
}
if (finished)
printf("Writing is done. \n");
else
printf("Operation timed out.\n");
} while (ask_again()); // Repeat some command?
}
// ****************************************************************************
// Get (request) the data for a block write. Data entered through this routing
// is in number form not ASCII. This is for Hexadecimal, Decimal, and Binary.
// The make a function call to do the write command.
//
// Input: Start address to begin writing to a tag.
// Last valid address because of prosection or tag size.
// Return: The numbe of data bytes entered.
// Side effects: tag_io_buf[] is updated with the data entered.
static WORD data_for_write(WORD start_add, WORD end_add)
{
WORD data_size; // Amount of data to be written. Used as an array index.
WORD now_addr; // Current tag address a data byte is being entered for.
WORD hold_num; // Hold a WORD being input, for byte array.
BYTE imp_char; // Hold a character that is input. Like CR or ENTER.
data_size = 0; // Count of tag data bytes.
now_addr = start_add;
do
{
printf("%5u: ", now_addr);
switch (display_type)
{
case HEX:
hold_num = inp_hex(); // Enter a number in hexadecimal format.
break;
case DEC:
hold_num = inp_num(BYTE_VALUE); // Enter a number in decimal format.
break;
case BIN:
hold_num = inp_bin(); // Enter a number in binary format.
break;
default: // This will never happen.
break;
}
if (hold_num EQ TOO_BIG_VAL) // Was ESC entered?
return(0); // Yes, get out. Exit on ESC. Confused user.
if (hold_num NE ENTER_ALONE)
{
tag_io_buf[data_size] = hold_num;
data_size = data_size + 1; // Count one more byte to be written.
if ((now_addr = now_addr + 1) > end_add)
{
printf("Last write address data was just entered.\n");
printf("ENTER to begin the write, ESC to exit.\n");
now_addr = now_addr - 1; // No more data is to be entered.
do
if ((imp_char = getch_cont()) EQ ESC)
return (0); // The user is ESCaping out to quit.
while (imp_char NE CR);
hold_num = ENTER_ALONE; // Exit the loop and preform the operation.
}
}
} while (hold_num NE ENTER_ALONE);
return(data_size); // Was any data entered?
}
// ****************************************************************************
// Get (request) the data for a block write. This is to request an ASCII string.
// It is terminated with a carnage return. Only enough characters are entered
// that will fit in the tag. That is no more than string_length character entered.
// After this one should make a function call to do the write command.
//
// Input: Total number of bytes allwed to be written from that address.
// Return: Number of character entered into tag_io_buf[] for the write.
// Return value of zero (0) is no bytes, like ENTER_ALONE.
// if the user is ESCaping this function then TOO_BIG_VAL is returned.
// Side effects: tag_io_buf[] gets the input ASCII string.
static WORD get_ascii_data(WORD string_length)
{
BYTE inputting; // BOOLEAN, TRUE while entering digits.
BYTE imp_char; // Last character input.
WORD chr_pos; // The string position (index) of the next character.
WORD maxed_pos; // Number of character in the string, Maximum entered.
maxed_pos = chr_pos = 0; // No valid digits input yet.
inputting = TRUE;
memset(tag_io_buf, ' ', string_length); // Use SPACE as end of number.
while (inputting)
{
if ((imp_char = getch_cont()) EQ ESC) // This echos the character.
return(TOO_BIG_VAL); // Use is trying to ESCape out.
if (imp_char EQ ARROW_HI_BYTE)
{
if ((imp_char = getch_cont()) EQ LEFT_ARROW)
{
if (chr_pos AND (chr_pos % DISPLAY_WIDTH))
{ // Some digits have been input to back up over.
putch(BACK_SPACE); // Back up on the screen.
chr_pos = chr_pos - 1; // Backing up over a character.
}
continue; // Not an input character, but control.
} else if (imp_char EQ RIGHT_ARROW)
{
if ((chr_pos <= string_length) AND (chr_pos < maxed_pos))
putch(tag_io_buf[chr_pos++]); // Print again what is in the buffer.
continue; // Not an input character, but control.
}
}
if (imp_char EQ BACK_SPACE)
{
if (chr_pos AND (chr_pos % DISPLAY_WIDTH))
{ // Some digits have been input to back up over.
putch(imp_char); // Echo what was just input.
if (maxed_pos EQ chr_pos) // GWP. BACK space deletes the character.
maxed_pos = maxed_pos - 1; // GWP ??????????
chr_pos = chr_pos - 1; // Backing up over a character.
tag_io_buf[chr_pos] = ' '; // Last character is gone.
putch(' '); // Erase from screen last character.
putch(BACK_SPACE); // Backup over the ' ' just printed.
}
} else if (imp_char EQ CR)
{
inputting = FALSE; // Got a carriage return, thus done.
} else if (chr_pos < string_length)// Overflowing?
{ // NO, can take another character.
putch(imp_char); // Echo what was just input.
tag_io_buf[chr_pos++] = imp_char; // Got something, save it in input string.
if (chr_pos > maxed_pos)
maxed_pos = chr_pos; // Sting getting longer.
}
}
return(maxed_pos);
}
// ****************************************************************************
// Read in an eight (8) character file name, with no extension.
//
// Input: Pointer to a string to place the file name in.
// Return: BOOLEAN - TRUE, characters input.
// FALSE, ESE entered to exit.
// Side effects: None.
static BYTE input_filename(BYTE *file_name)
{
BYTE *inp_ptr; // Local filename string pointer
WORD ii; // Local loop counter.
WORD num_char_inp; // How many character where input.
printf("\nInput from one (1) to eight (8) characters for the file name.\n: ");
if ((num_char_inp = get_ascii_data(MAX_FILENAME)) NE TOO_BIG_VAL)
{
inp_ptr = tag_io_buf;
for (ii = 0; ii < num_char_inp; ii++)
if (*inp_ptr NE ' ')
*file_name++ = *inp_ptr++; // copy the input string.
else
inp_ptr++; // Skip the space character.
*file_name++ = '.'; // Put the .TXT extention on the file name.
*file_name++ = 'T';
*file_name++ = 'X';
*file_name++ = 'T';
*file_name++ = NULL; // Null terminate the string.
return(TRUE);
}
return(FALSE); // The user is trying to ESCape.
}
// ****************************************************************************
// Display data values in the current format.
//
// Input: Pointer to data to be printed.
// Number of bytes in the array pointed to.
// Address in the tag of the data being printed.
// Return: BOOLEAN - TRUE if ESCAPE was entered when for next page display.
// FALSE ESCAPE was not entered, all data displayed.
// Side effects: None.
WORD display_data(BYTE* data_ptr, WORD num_bytes, WORD data_adr)
{
WORD line_number = 0; // nothing printed yet.
while (num_bytes) // Until all data bytes have been printed.
{
if (num_bytes >= format_size())
{
print_data_line(data_ptr, format_size(), data_adr);
data_ptr = data_ptr + format_size(); // Point to next bytes to print.
data_adr = data_adr + format_size(); // Tag address of bytes to print.
num_bytes = num_bytes - format_size(); // Printed format_size() bytes.
} else // num_bytes must be < format_size
{
print_data_line(data_ptr, num_bytes, data_adr);
num_bytes = 0; // Last line of bytes printed. Exit loop.
}
line_number = line_number + 1; // Alother line printed.
if ((line_number >= DISPLAY_LINES) AND num_bytes)
{
printf("Enter for next page: ");
if (getch_cont() EQ ESC) // Use giving up and escaping out of this.
return (TRUE); // ESCAPE entered! EXIT!
putch(CR); // Be positive to be at the beginning of line.
line_number = 0; // nothing printed on the new screen.
}
}
return(FALSE); // Done displaying, no ESC entered.
}
// ****************************************************************************
// Print (display on standard out) an ASCII string of the current tag type
// that is expected to be attached to the reader.
// One leading space and enough spaces so all tag type strinngs are the same
// size.
//
// Input: NONE.
// Return: NONE.
// Side effects: Display updated. Output cursor moved..
void print_tag_type(void)
{
switch (mem_size)
{
case LRP_MEM_SIZE:
printf(" LRP ");
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -