Ejemplo n.º 1
0
//----------------------------------------------------------------------
// Enter a hex string and convert it to an unsigned long
// (1-8) characters
//
int EnterHex(char *msg, int numchars, ulong *value)
{
   int tmp,cnt;
   int ch;

   // prompt
   printf("%s (enter hex, up to %d chars):",msg,numchars);

   *value = 0;

   cnt = 0;
   do
   {
      ch = getkeystroke();

      if (ch == 0x08)
      {
         printf("%c %c",ch,ch);
         if (cnt)
            cnt--;
      }
      else if (ch == 0x1B)
      {
         printf("  Aborted\n\n");
         return FALSE;
      }
      // caraige return
      else if (ch == 0x0A)
      {
         printf("\n");
         return TRUE;
      }
      else
      {
         tmp = ToHex((char)ch);
         if (tmp)
         {
            printf("%c",ch);
            *value <<= 4;
            *value |= tmp;
            cnt++;
         }
      }
   }
   while (cnt < numchars);

   printf("\n");

   return TRUE;
}
Ejemplo n.º 2
0
//----------------------------------------------------------------------
// Enter a string
// Leave the same if no characters entered
//
int EnterString(char *msg, char *buf, int min, int max)
{
   int len,deflen;
   char ch,defbuf[80];

   // check for abort
   if (key_abort())
      return -1;

   // remember the start length
   deflen = strlen(buf);
   if (deflen < 80)
      sprintf(defbuf,"%s",buf); /* rma: fixed format warning */
   else
      defbuf[0] = 0;

   // prompt
   if (deflen < 30)
      printf("%s (%s): ",msg,buf);
   else
      printf("%s (%s):\n",msg,buf);


   // loop to get the file
   len = 0;
   for (;;)
   {
      // get a key
      ch = (char)getkeystroke();
 
      // check for abort
      if (key_abort())
         return -1;

      // check the backspace key
      if (ch == 0x08)
      {
         if (len > 0)
         {
            // got a valid backspace
            len--;
            printf("\x008 \x008");
         }
      }
      // escape key
      else if (ch == 0x1B)
      {
         printf("\n");
         return -1;
      }
      // caraige return
      if (ch == 0x0A)
      {
         // check for special case (keep default)
         if ((len == 0) && (deflen > min))
         {
            sprintf(buf,"%s",defbuf);
            printf("\n");
            return deflen;
         }
         else if (len < min)
            continue;
         else
         {
            printf("\n");
            return len;
         }
      }
      // valid key
      else if (len < max)
      {
         printf("%c",ch);
         // record the char
         buf[len++] = ch;
      }
   }
}
Ejemplo n.º 3
0
//----------------------------------------------------------------------
// Enter a decimal string and convert it to an unsigned long
// Prompt again if not within min/max inclusive.
//
int EnterNum(char *msg, int numchars, long *value, long min, long max)
{
   short tmp,cnt,isneg=FALSE;
   char ch;

   // check for abort
   if (key_abort())
      return FALSE;

   // loop while not in correct range
   do
   {
      printf("%s (%ld): ",msg,*value);

      // loop for each character read
      cnt = 0;
      for (;;)
      {
         ch = (char)getkeystroke();

         // check for abort
         if (key_abort())
            return FALSE;

         // negative flag
         if (ch == '-')
         {
            if (!isneg)
            {
               isneg = TRUE;
               printf("-");
               cnt++;
            }
         }
         // backspace
         if (ch == 0x08)
         {
            if (cnt)
            {
               if (isneg && (cnt == 1))
                  isneg = FALSE;
               else
                  *value /= 10;
               printf("%c %c",ch,ch);
               cnt--;
            }
         }
         // escape
         if (ch == 0x1B)
         {
            printf("  Aborted\n\n");
            return FALSE;
         }
         // enter
         if (ch == 0x0A)
         {
            printf("\n");
            break;
         }
         // number
         else if ((ch >= '0') && (ch <= '9'))
         {
            if (cnt == 0)
               *value = 0;

            if (cnt < numchars)
            {
               printf("%c",ch);
               tmp = ch - 0x30;
               *value *= 10;
               *value += tmp;
               cnt++;
            }
         }
      }

      if (isneg)
         *value = -*value;
   }
   while ((*value < min) || (*value > max));

   return TRUE;
}
Ejemplo n.º 4
0
//--------------------------------------------------------------------------
// This is the begining of the program that tests the different Channels
int main() //short argc, char **argv)
{
   char return_msg[128];           //returned message from 1-wire operations
   int i,j,k,n;                    //loop counters
   short test=0;                   //info byte data
   short clear=0;                  //used to clear the button
   SwitchProps sw;                 //used to set Channel A and B
   uchar SwitchSN[MAXDEVICES][8];  //the serial numbers for the devices
   int num;                        //for the number of devices present
   int ch;                         //inputed character from user
   char out[140];                  //used for output of the info byte data
   int portnum=0;

   //----------------------------------------
   // Introduction header
   printf("\n/---------------------------------------------\n");
   printf("  swtest - V2.00\n"
          "  The following is a test to excersize the\n"
          "  different channels on the DS2406.\n");
   printf("  Press any CTRL-C to stop this program.\n\n");

   // check for required port name
   if (argc != 2)
   {
      printf("1-Wire Net name required on command line!\n"
             " (example: \"COM1\" (Win32 DS2480),\"/dev/cua0\" "
             "(Linux DS2480),\"1\" (Win32 TMEX)\n");
      exit(1);
   }

   // attempt to acquire the 1-Wire Net
   if (!owAcquire(portnum, argv[1], return_msg))
   {  
      printf("%s",return_msg);
      exit(1);
   }

   // success
   printf("%s",return_msg);
   
   // this is to get the number of the devices and the serial numbers
   num = FindDevices(portnum, &SwitchSN[0], SWITCH_FAMILY, MAXDEVICES);

   // setting up the first print out for the frist device
   owSerialNum(portnum, SwitchSN[0], FALSE);
   
   j=1;
   n=0;
   do
   {
      // This is for after the different combinations of channels
      // have been tested to reset to a different device to be tested.
      if( ((test & 0x40) && (j==5)) ||
         ((!(test & 0x40)) && (j==3)) )
      {
         printf("\n\n");
         for(k=0; k < num; k++)
         {
            printf("%d  ", k+1);
            for(i=7; i>=0; i--)
            {
               printf("%02X", SwitchSN[k][i]);
            }
            printf("\n");
         }
         printf("%d To quit or any other key.\n", k+1);

         printf("\n");
         printf("Pick a device\n");

         ch = getkeystroke();
         n = 0;
         n = (10*n + (ch - '0')) - 1;

         if( (n>num-1) || (n<0) )
         {
            n = 0;        //used to finish off the loop
            break;
         }

         owSerialNum(portnum, SwitchSN[n], FALSE);
         j = 1;
      }
      printf("\n");
      
      test = ReadSwitch12(portnum,clear);

      // This looks at the info byte to determine if it is a
      // two or one channel device.
      if(test & 0x40)
      {

         switch(j)
         {
            case 1: 
               sw.Chan_A = 0;
               sw.Chan_B = 0;
               break;
            case 2:
               sw.Chan_A = 0;
               sw.Chan_B = 1;
               break;
            case 3:
               sw.Chan_A = 1;
               sw.Chan_B = 0;
               break;
            case 4:
               sw.Chan_A = 1;
               sw.Chan_B = 1;
               break;
            default:
               sw.Chan_A = 1;
               sw.Chan_B = 1;
               j=0;
               break;
            }
      }
      else
      {
         switch(j)
         {
            case 1:
               sw.Chan_B = 0;
               sw.Chan_A = 0;
               break;
            case 2:
               sw.Chan_B = 0;
               sw.Chan_A = 1;
               break;
            default:
               sw.Chan_B = 0;
               sw.Chan_A = 1;
               j = 0;
               break;
         }
      }

      if(!SetSwitch12(portnum, SwitchSN[n], &sw))
      {
         msDelay(50);
         if(SetSwitch12(portnum, SwitchSN[n], &sw))
            msDelay(50);
         else
            printf("Switch not set\n");
      }

      test = ReadSwitch12(portnum,clear);

      printf("\n");

      for(i=7; i>=0; i--)
      {
         printf("%02X", SwitchSN[n][i]);
      }
      printf("\n");

      SwitchStateToString12(test, out);
      printf("%s", out);

      j++;

   }
   while(1);

   // release the 1-Wire Net
   owRelease(portnum,return_msg);
   printf("%s",return_msg);
   exit(0);

   return 0;
}