Ejemplo n.º 1
0
uint32 atoui(char* input)
{
	if (input[0] == '0' && tolower(input[1]) == 'x')	// hex
		return atoui_hex(input + 2, strlen(input) - 2);
	else
		return atoui_dec(input, strlen(input));
}
Ejemplo n.º 2
0
void process_rx() {
	
	uns8 len,	// length of string
		 rec;	// received character
	uns8 first_char;
	
	rec = usb_cdc_getc();	// get the character from the fifo
	
	usb_cdc_putc(rec);	// print it out so we can see what we typed

	if (rec == '\r') {	// did we press return?
		first_char = serial_buffer[0];
		switch (first_char) {
			case 'a':
				do_task = 1;
				break;
		    case 'x':
				do_task = 2;
				break;
			case 'u':
				do_task = 3;
				break;
			case 'n':
				do_task = 4;
				break;
			default:
				// More complicated example
				// Let's set a variable based on input
				// You can type:
				// s05
				// And press enter, it will set "send_to" to this (in hex)
				if ((first_char == 's') && (strlen(serial_buffer)==3)) {
					send_to = atoui_hex(&serial_buffer[1]);
					usb_cdc_print_str(" Set send_to to ");
					usb_cdc_print_int(send_to);	// Of course, this could be anything
					usb_cdc_putc('\n');
				};
		}		
		serial_buffer[0] = '\0';	// clear the buffer
        usb_cdc_putc('\n');	// print new line
        usb_cdc_putc('>');	// print the prompt
	} else {
		len = strlen(serial_buffer);	// add the character to our line input
		serial_buffer[len] = rec;
		serial_buffer[len+1] = '\0';
	}

}
Ejemplo n.º 3
0
static void TaskSerialCmdProc(void) {

  uartInit();

  uint16_t uint16;

  while( true ) {

    Sys_WaitSemaphore(hSerial, 153);
    if( SysWaitTimedOut(hTaskSerialCmdProc) == false ) {

      // pkt is ready to parse
      rxPktCnt++;

      switch( buffer[0] ) {
        case SERCMD_LEDON:
          redOn();
          buffer[1] = '0';
          buffer[2] = '\n';
          break;
        case SERCMD_LEDOFF:
          redOff();
          buffer[1] = '0';
          buffer[2] = '\n';
          break;
        case SERCMD_CHKBUSY:
          buffer[1] = '0';
          buffer[2] = '0'+injIsBusy();
          buffer[3] = '\n';
          break;
        case SERCMD_GETCYCLES:
          buffer[1] = '0'+injGetCycles(&uint16);
          uitoa_hex(&buffer[2], uint16, 4);
          buffer[6] = '\n';
          break;
        case SERCMD_SETCYCLES:
          uint16 = atoui_hex(&buffer[1]);
          buffer[1] = '0'+injSetCycles(&uint16);
          buffer[2] = '\n';
          break;
        case SERCMD_GETACCCYCLES:
          buffer[1] = '0'+injGetAccumulatedCycles(&uint16);
          uitoa_hex(&buffer[2], uint16, 4);
          buffer[6] = '\n';
          break;
        case SERCMD_SETACCCYCLES:
          uint16 = atoui_hex(&buffer[1]);
          buffer[1] = '0'+injSetAccumulatedCycles(&uint16);
          buffer[2] = '\n';
          break;
        case SERCMD_START:
          buffer[1] = '0'+injStart();
          buffer[2] = '\n';
          break;
        case SERCMD_SETONWIDTH:
          uint16 = atoui_hex(&buffer[1]);
          buffer[1] = '0'+injSetOnWidth(&uint16);
          buffer[2] = '\n';
          break;
        case SERCMD_GETONWIDTH:
          buffer[1] = '0'+injGetOnWidth(&uint16);
          uitoa_hex(&buffer[2], uint16, 4);
          buffer[6] = '\n';
          break;
        case SERCMD_ABORT:
          buffer[1] = '0'+injAbort();
          buffer[2] = '\n';
          break;
        case SERCMD_GETOFFWIDTH:
          buffer[1] = '0'+injGetOffWidth(&uint16);
          uitoa_hex(&buffer[2], uint16, 4);
          buffer[6] = '\n';
          break;
        case SERCMD_SETFPPWM:
          uint16 = atoui_hex(&buffer[1]);
          buffer[1] = '0'+fpSet(&uint16);
          buffer[2] = '\n';
          break;
        case SERCMD_GETFPPWM:
          buffer[1] = '0'+fpGet(&uint16);
          uitoa_hex(&buffer[2], uint16, 4);
          buffer[6] = '\n';
          break;
        default:
          errors++;
          buffer[1] = 'F';
          buffer[2] = '\n';
          break;
      }

      // buffer already contains response, trigger
      // a send and wait for it to complete
      pie1.TXIE = true;       // goes straight to int and loads the first item
      Sys_WaitSemaphore(hSerial, 153);

      if( SysWaitTimedOut(hTaskSerialCmdProc) == false ) {
        txPktCnt++;
      } else {
        // tx never finished - got a timeout
        errors++;
      }

    }
  }
}