?? preform.c
字號:
break;
case HMS_MEM_SIZE:
printf(" HMS ");
break;
default:
printf("ERROR");
break;
}
}
#define SOME_DATA 5 // Try to read this many bytes for antenna and tag detect.
#define READ_SOMEPLACE 0x00 // Try to read from this address in antenna detect.
// ****************************************************************************
// Display if the current antenna type antenna is attached.
//
// Input: Optional, comport to be used.
// Return: None.
// Side effects: None.
void ant_attached(void)
{
BYTE ant_att; // Local BOOLEAN flags for if antenna attatched
BYTE tag_pres; // and if a TAG is present.
time_t start_time; // Hold second count for display and tag read time.
for ( ; ; ) // Loop forever, until user enters ESC.
{
ant_att = FALSE; // Assume that no antenna with
tag_pres = FALSE; // Assume no tag present.
// Search for a tag to see if antenna responds with anything.
SearchTx(MIF_SEARCH_TI); // Try to communicate with the mifare chip.
time(&start_time);
while ((NOT comm_avail()) AND
(ANT_CHK_TIME > (time((long *)NULL) - start_time)))
{
if (esc_entered()) // Keep checking for an ESC key.
return; // Yes, get out. Exit on ESC. Confused user.
}
if (comm_avail()) // Get any response from the antenna?
{
ant_att = TRUE; // It is TRUE to have an antenna attached.
if (SearchRx() EQ OP_OK)
tag_pres = TRUE; // TRUE to have a tag present.
}
clrscr();
printf("Controller for");
print_tag_type(); // Print tag type for these commands.
printf("\n");
if (ant_att)
{
printf(" attached.\n"); // Yes, got something, it must be there.
if (tag_pres)
printf("With Tag present.");
printf("\n");
} else
printf("NOT attached.\n\n");
time(&start_time); // Get current second count form the runtime.
do // Check for ESC entered, while waiting for antanna.
if (esc_entered())
return; // ESC entered, exit this function.
while (BETWEEN_CHECK > (time((long *)NULL) - start_time));
}
}
// ****************************************************************************
// Continuously read
// Infinite loop and increment block read
//
// Input: NONE.
// Return: NONE.
// Side effects: NONE.
void ContinueRead(void)
{
WORD data_size; // Number of bytes for these reads.
WORD disp_start; // Tag starting address for the current read display line.
WORD now_start; // Tag starting addres for the current block read.
WORD this_disp; // Number of bytes in a given display line.
WORD left_disp; // Number of bytes left to read for this_display.
WORD this_read; // Number of bytes in a given read.
BYTE *rx_data; // Where to place the received tag data for a given read.
WORD duration; // Duration of continual read.
time_t time_left; // Remaining time for this continual read.
time_t now_last_time; // Value returned by time() last time.
time_t old_last_time; // Hole the last time value for calculations.
BYTE ii; // Tempory varriable.
printf("\nDuration in seconds. Less then 32,767. ENTER for a minute:\n");
if ((duration = inp_num(LARGEST_DEC)) EQ ENTER_ALONE)
duration = 60;
else if (duration EQ TOO_BIG_VAL) // Was ESC entered?
return; // Yes, get out. Exit on ESC. Confused user.
disp_start = 0; // Begin at addres zero (0).
data_size = mem_size; // Display the entire tag..
do // Do while the user keeps requesting more.
{
time_left = duration;
time(&now_last_time);
clrscr();
printf("\nSearching for tag.\n");
while (time_left > 0) // For the duration entered to read.
{
old_last_time = now_last_time; // Use as working varriable.
time_left = time_left - (time(&now_last_time) - old_last_time);
// The time left value used to be printed out, so it is calculated.
if ((data_size / format_size()) NE 0) // Next packet of data MAX size?
this_disp = format_size(); // Use a maximum display for this format..
else // else just what fits.
this_disp = data_size;
rx_data = tag_io_buf; // Use the global working tag data buffer.
now_start = disp_start; // Line of data starts at this tag address.
left_disp = this_disp; // Have read no bytes for this display.
start_down(TAG_CONTINUAL); // This initialized finished.
do // Do reads for one line of display.
{
while (down_count() AND NOT finished) // Note: Because BLReadTx and
{ // BLReadRx take time the display down count is slower.
if (left_disp <= max_data_pkt) // One display line be read with
this_read = left_disp; // one read command.
else // OR,
this_read = max_data_pkt; // many reads at maximum size.
if (Read_command(now_start, this_read, rx_data) EQ OP_OK)
{
rx_data = rx_data + this_read; // For next read of this display.
now_start = now_start + this_read;// Got this_read more tag data.
if ((left_disp = left_disp - this_read) EQ 0)// Read bytes.
finished = TRUE; // This display bytes have been read.
}
if (kbhit())
{
if ((ii = getch_cont()) EQ ESC)
return;
if (ii EQ CR)
{
printf("\nENTER to repeat.\n");
do
{
if ((ii = getch_cont()) EQ ESC)
return; // User is giving up.
} while (ii NE CR); // CR is ENTER to repeate.
printf("\nSearching for tag.\n");
time_left = duration; // Start fresh display time.
time(&now_last_time);
}
}
}
} while (left_disp AND down_count());
if (finished)
{ //print out receiving data
display_data(tag_io_buf, this_disp, disp_start);
data_size = data_size - this_disp;
if ((disp_start = disp_start + this_disp) >= mem_size)
{
disp_start = 0; // Loop back to the begining.
data_size = mem_size; // Display the entire tag..
}
}
}
} while (ask_again()); // Repeat some command?
}
// ****************************************************************************
// Preform a Non-contiguous write. The address must have been setup in the last
// command, using read_write_conf().
//
// Input: NONE.
// Return: NONE.
// Side effects: NONE.
void write_notcont(void)
{
BYTE status; // Status of write command.
WORD num_write; // Number of write address input.
WORD num_ASCII; // Number of ASCII data bytes entere on a given line.
BYTE data_buf[OUT_LIMIT]; // build the command in this buffer.
num_write = 0;
address_ptr = data_buf;
do
{
printf("Input data byte number %d (ENTER when finished): ", num_write + 1);
switch (display_type)
{
case HEX:
address_value = inp_hex(); // Enter a number in hexadecimal format.
break;
case DEC:
address_value = inp_num(BYTE_VALUE); // Enter a number in decimal format.
break;
case BIN:
address_value = inp_bin(); // Enter a number in binary format.
break;
case ASCII:
num_ASCII = get_ascii_data(1); // Get a byte of ASCII data, a character.
if (num_ASCII EQ TOO_BIG_VAL)
address_value = TOO_BIG_VAL; // User trying to ESCape out of this command.
else if (num_ASCII EQ 0)
address_value = ENTER_ALONE; // Done entering the characters.
else
address_value = tag_io_buf[0]; // from a common buffer (return parameter).
printf("\n"); // Output a carriage return.
break;
default: // This will never happen.
address_value = TOO_BIG_VAL; // ERROR, this should never happen.
break;
}
if (address_value EQ TOO_BIG_VAL)
return; // User trying to ESCape out of this command.
if (address_value NE ENTER_ALONE)
num_write++; // Data for another address was input, count it.
*address_ptr++ = (BYTE) address_value & 0xFF; // and low byte also.
} while (address_value NE ENTER_ALONE); // And point past data.
// Prefrom the Non-contiguous write, with write time + some more for big write commands.
NCWriteTx(MIF_WRITE_TI + (num_write * 10), data_buf, num_write);
status = NCWriteRx();
if(status EQ OP_OK)
printf("\nNon-contiguous write is done. \n");
else //error code is RX
print_code(status);
printf("\nPress any key to go back to menu. \n");
getche_cont();
}
// ****************************************************************************
// Preform a Non-contiguous read. The address must have been setup in the last
// command, using read_write_conf().
//
// Input: NONE.
// Return: NONE.
// Side effects: NONE.
void read_notcont(void)
{
WORD ii;
BYTE *rx_buf;
BYTE status;
printf("\nReading data from tag. Please wait...\n\n");
NCReadTx(MIFARE_TIME_OUT);
rx_buf = (BYTE*) malloc(nc_read_size);
status = NCReadRx(rx_buf, nc_read_size);
printf("\n");
if( (status EQ OP_OK) )
{ //print out receiving data.
for(ii = 0; ii < nc_read_size; ii++)
{
print_byte(rx_buf[ii]);
if (display_type EQ ASCII) // If displaying in ASCII, then
printf(" "); // have a space between characters.
if (((ii + 1) MOD format_size()) EQ 0) // If handled a display line of data,
printf("\n"); // then output a carriage return.
}
} else //receive error message
print_code(status);
free(rx_buf);
printf("\nPress any key to go back to menu. \n");
getche_cont();
}
// ****************************************************************************
// Set up for a Read/Write Configuration Command. This is to configure the
// tag for non-Contiguour Read/Write
//
// Input: NONE.
// Return: NONE.
// Side effects: NONE.
void read_write_conf(void)
{
BYTE *write_addr; // Point to the input write addresses.
BYTE status; // Status of write command.
WORD num_write; // Number of write address input.
address_ptr = tag_io_buf;
nc_read_size = 0; // To remember How many bytes read.
do
{
printf("Input read addresses number %d (ENTER when finished): ", nc_read_size + 1);
if ((address_value = inp_num(mem_size)) EQ TOO_BIG_VAL)
return; // User trying to ESCape out of this command.
if (address_value NE ENTER_ALONE)
nc_read_size++; // Another address was input, count it.
*address_ptr++ = address_value >> 8; // Get the high byte
*address_ptr++ = (BYTE) address_value & 0xFF; // and low byte also.
} while (address_value NE ENTER_ALONE); // And point past data.
write_addr = address_ptr;
num_write = 0;
do
{
printf("Input write addresses number %d (ENTER when finished): ", num_write + 1);
if ((address_value = inp_num(mem_size)) EQ TOO_BIG_VAL)
return; // User trying to ESCape out of this command.
if (address_value NE ENTER_ALONE)
{
num_write++
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -