⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 preform.c

📁 LP830 无线识别卡 读写程序demo
💻 C
📖 第 1 页 / 共 5 页
字号:
{
   WORD incom_value;     // Build the value being input here.
   BYTE ascii_number[MAX_BIN_DIG + 2];  // Hold digits being input + CR, terminator.
   BYTE *digit_ptr;      // Point to where the next digit goes.
   WORD ii;              // Local loop counter, for all eight digits.

   incom_value = 0;
   printf("........\10\10\10\10\10\10\10\10"); // Dots to become binary digits.
   if (NOT inp_digstring(ascii_number, MAX_BIN_DIG, BIN, '.'))
       return(TOO_BIG_VAL); // Use is trying to ESCAPE out.
   digit_ptr = ascii_number;        // Point at the character just input.
   if (*digit_ptr EQ CR)       // No digits, only the ENTER key.
      return(ENTER_ALONE);     // Return to caller for a try again, or default.
   for (ii = MAX_BIN_DIG; ii; ii--)
      incom_value = (incom_value << 1) + *digit_ptr++ - '0'; // Add in new value.
   return(incom_value);   // Done imputing, return the input value.
}

// ****************************************************************************
// Input a decimal number, character by character, for a tag range.
// sscanf() would be used, but that waits for a CR.  ESC must be detected, to exit.
// A NULL entry (Enter alone with no digits) must be detected to indicate entire tag.
//
// Input:        The tags valid staring Address. HS tags can not write to address 0.
//               Last valid tag address for this range.  Protected and/or tag type.
// Return:       Number input, 
//               or TOO_BIG_VAL to exit,
//               or ENTER_ALONE if no digits entered, but the ENTER key was pressed.
// Side effects: NONE.
static WORD inp_tag_range(WORD tag_start, WORD tag_end) 
{
   BYTE  ascii_number[MAX_DEC_DIGITS + 2];  // Hold digits being input.
   WORD  this_value;          // Build the value being input here.
   
   this_value = 0;            // Initialize working variables.
   if (NOT inp_decimal(ascii_number, tag_start, tag_end))
       return(TOO_BIG_VAL);   // Use is trying to ESCape out.
   printf("\n");              // Echo the terminating carriage return.
   if (ascii_number[0] EQ CR) // No digits, only the ENTER key.
      return(ENTER_ALONE);    // Thus, done with entering data.
   if (dec_word_val(ascii_number, &this_value))
      return(this_value);     // Valid decimal number entered. Return it!
   return(0);                 // Should never get here, but be safe.
}

// ****************************************************************************
// Delay while something is being displayed.
//
// Input:        None.
// Return:       None.
// Side effects: None.
static void do_delay(time_t delay_time) 
{
   time_t start_time, now_time; // Hold second count for display.

   time(&start_time);       // Get current second count form the runtime.
   time(&now_time);
   while ((start_time + delay_time) >= now_time)
      time(&now_time);      // Get new second value.
}

// ****************************************************************************
// Delay while something is being displayed.
//
// Input:        None.
// Return:       None.
// Side effects: None.
static void display_delay(void) 
{
   do_delay(DISPLAY_TIME);  // Do the display delay 
}

// ****************************************************************************
// Delay while something is being displayed.
//
// Input:        None.
// Return:       None.
// Side effects: None.
void display_delay_sht(void) 
{
   do_delay(SHORT_DELAY);  // Do the display delay 
}

// ****************************************************************************
// Request and save the beginning (lower) and ending (upper) bound of tag data
// to be read. The upper bound is gotten from taking the staring Address and
// adding the length that the user specified.  A length that would exceed
// the end of tag is not taken, and it will be requested again.
//
// Input:        Pointer to start and stop tag addresses to be updated.
//               The tags valid staring Address. HS tags can not write to address 0.
//               The tags valid higher bound. For protected writing.
// Return:       BOOLEAN - TRUE, got a valid range.
//                       - FALSE, Not a valid range, the user gave up.
// Side effects: None.
static BYTE req_tag_range(WORD* lower, WORD* upper, WORD tag_start, WORD high_bound)
{
   WORD length;  // Length (number of bytes) for the tag range.
     
   if (tag_start EQ mem_size)      // Entire tag protected?
   {
      printf("Nothing between\n%u and %u.\n", tag_start, mem_size - 1);
      display_delay();
      return (FALSE);
   }
   printf("Starting address (%u to %u),\nor ENTER for entire %u to %u: ", 
      tag_start, high_bound, tag_start, high_bound);
   if ((*lower = inp_tag_range(tag_start, high_bound)) EQ TOO_BIG_VAL)
      return(FALSE);          // So return to exit this function.
   if (*lower EQ ENTER_ALONE) // Requesting entire tag?
   {
      *lower = tag_start;     // From the first valid tag address.
      *upper = high_bound;    // To the end of the tag.
   } else
   {
      printf("\nNumber of bytes?\nENTER for rest of tag, (1 to %u): ",
         high_bound + 1  - *lower);
      if ((length = inp_tag_range(1, high_bound + 1  - *lower)) EQ TOO_BIG_VAL)
         return(FALSE);          // So return to exit this function.
      else if (length EQ ENTER_ALONE) // Requesting to the end of tag?
         *upper = high_bound;  // To the end of the tag.
      else 
         *upper = *lower + length - 1;
   }
   return(TRUE);      // Got a valid and desired address range.
}

// ****************************************************************************
// Get the line length for the current display format. 
//
// Input:        Implied, display_type.
// Return:       None.
// Side effects: None.
static BYTE format_size(void) 
{
   switch (display_type)
   {
   case HEX:
      return(HMS_HEX_LINES);

   case DEC:
      return(HMS_DEC_LINES);

   case ASCII:
      return(HMS_ASCII_LNS);

   case BIN:
      return(HMS_BIN_LINES);
   }
   return(0);  // Never get here, this is just to make the compiler happy..
}


// ****************************************************************************
// Print, on the console, the current data byte.  Display in it the format
// chosen from the display options menu.
//
// Input:        BYTE to be printed.
// Return:       NONE.
// Side effects: NONE.
static void print_byte(BYTE disp_data) 
{
WORD ii;      // Local loop counter.

   switch (display_type)
   {
   case HEX:
      printf(" %02X", disp_data);
      break;

   case DEC:
      printf(" %3d", disp_data);
      break;

   case ASCII:
      printf("%c", disp_data);
      break;

   case BIN:
      printf(" ");  // Space between numbers.
      for (ii = 0x80; ii; ii = ii >> 1)
         if (ii & disp_data)
            putch('1');
         else
            putch('0');
      break;
   }
}


// ****************************************************************************
// Print the data for a line being dsplayed, in the current format.
// The tag address leader is also printed from this routines.
//
// 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:       None.
// Side effects: None.
static void print_data_line(BYTE* data_ptr, WORD num_bytes, WORD data_adr) 
{
   WORD ii;              // Local loop counter.
   
   putch(CR);  // Be positive to be at the beginning of line.
   printf("A%3d:", data_adr);
   if (display_type EQ ASCII)      // If displaying ASCII, then put a 
      putch(' ');                  // space after the :. Because no spaces later.
   for(ii = num_bytes; ii; ii--)   // for data_adr bytes.
      print_byte(*data_ptr++);
   printf("\n");                  // final CR behind last data.
}

// ****************************************************************************
// Initialize the Display a down counter number. This is for down_count()
//
// Input:        Implied - set_doun() has been called to Initialization.
// Return:       BOOLEAN - TRUE, still down counting Borlands second counter
//                         FALSE, Done waiting.
// Side effects: NONE, outside down count.
//               finished is Initialized to FALSE.
static void start_down(WORD start_value) 
{
   
   display_val = start_value;  // Begin display time.
   time(&last_time);
   finished = FALSE;           // The mikron interface not finished.
}

// ****************************************************************************
// Display a down counter number:
// Do not print new line but back up so the next thing printed prints over
// the number just displayed. It is intended to have the cursor at a location
// and then repetitively call this routine while waiting.
// It looks for a 'change' in the runtime time_t routine and decrements display
// counter.
//
// Input:        Implied - set_doun() has been called to initialization.
// Return:       BOOLEAN - TRUE, still down counting Borlands second couter
//                         FALSE, Done waiting.
// Side effects: NONE, outside .
static BYTE down_count(void) 
{
   time_t now_time;
   time(&now_time);       // Get current second count form the runtime.

   if ((display_val = display_val - (now_time - last_time)) < 0)
      display_val = 0;    // NO underflow.
   last_time = now_time;  // Remember when here last
#if DOWN_DISPLAY
   printf("%4d", display_val);
   putch(BACK_SPACE);
   putch(BACK_SPACE);
   putch(BACK_SPACE);
   putch(BACK_SPACE);
#endif
   return(display_val);
}

// ****************************************************************************
// Ask the user if the current command should be executing again.
//
// Input:        NONE.
// Return:       BOOLEAN - TRUE, YES, the ESCAPE key has just been pressed.
//                         FALSE, NO, the eSCAPE key has NOT been pressed.
// Side effects: NONE.
static BYTE esc_entered(void) 
{
   if (kbhit())
      if (getch_cont() EQ ESC)
         return(TRUE);     // Escape key enterd for the user to giving up.
   return(FALSE);          // Escape key not pressed.
}               

// ****************************************************************************
// Ask the user if the current command should be executing again.
//
// Input:        NONE.
// Return:       BOOLEAN - TRUE, YES, the user desires to do it again.
//                         FALSE, NO, the user is finished.
// Side effects: NONE.
static BYTE ask_again(void) 
{
   printf("\nENTER to repeat.\n");
   return(getch_cont() EQ CR);
}

// ****************************************************************************
// Print the text string for the Error codes in the Reader/Writer manual.
//
// Input:        NONE.
// Return:       BOOLEAN - TRUE,  characters input for a number.
//                         FALSE, ESE entered to exit.
// Side effects: number length BYTES at the ASCII string might be altered.
void print_code(BYTE error_num) 
{
   switch (error_num)
   {
   case NONCON_READFAIL:
      printf("\nNon-Contiguous Read has failed\n");
      break;
   case NONCON_WRITEFAIL:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -