/** Print a string from PROGMEM
 *
 * This function simply prints the nul terminated string from PROGMEM to the
 * serial port.
 *
 * @param cszString pointer to a character array in PROGMEM.
 */
void uartPrintP(const char *cszString) {
  uint8_t ch;
  while((ch = pgm_read_byte_near(cszString))!='\0') {
    uartSend(ch);
    cszString++;
    }
  }
/** Print an unsigned 16 bit value in decimal
 *
 * Print the given value in decimal format to the UART.
 *
 * @param value the value to print.
 */
void uartInt(uint16_t value) {
  bool emit = false;
  // Special case for 0
  if(value==0) {
    uartSend('0');
    return;
    }
  // Emit the value, skip leading zeros
  for(uint16_t divisor = 10000; divisor > 0; divisor = divisor / 10) {
    uint8_t digit = value / divisor;
    value = value % divisor;
    if((digit>0)||emit) {
      uartSend('0' + digit);
      emit = true;
      }
    }
  }
Beispiel #3
0
void GSM_send_data(char *command, uint8_t uartport) {
    //printf("%s", command);
    uint8_t data_length = strlen(command);

    uartSend(command, data_length, uartport);

    GSM_get_data(3000);
}
pn532_error_t pn532_bus_Wakeup(void)
{
  size_t szLen;
  byte_t abtWakeUp[] = { 0x55,0x55,0x00,0x00,0x00,0x00,0x00,0xff,0x03,0xfd,0xd4,0x14,0x01,0x17,0x00,0x00,0xff,0x03,0xfd,0xd4,0x14,0x01,0x17,0x00 };

  pn532_pcb_t *pn532 = pn532GetPCB();

  #ifdef PN532_DEBUGMODE
  PN532_DEBUG("Sending Wakeup Sequence%s", CFG_PRINTF_NEWLINE);
  #endif
  uartSend(abtWakeUp,sizeof(abtWakeUp));
  delay(100);

  byte_t response[32];
  pn532_bus_ReadResponse(response, &szLen);

  // Todo: Check for error ... currently throws a checksum error
  // that isn't really an error

  pn532->state = PN532_STATE_READY;
  return PN532_ERROR_NONE;
}
Beispiel #5
0
void proto_frame_and_send(const char *buffer, int length) {
	afproto_serialize_payload(buffer, length, _proto_buff);

	uartSend(_proto_buff, length+4);
}
/** Print a string from RAM
 *
 * This function simply prints the nul terminated string from RAM to the
 * serial port.
 *
 * @param cszString pointer to a character array in RAM.
 */
void uartPrint(const char *cszString) {
  while(*cszString) {
    uartSend(*cszString);
    cszString++;
    }
  }
Beispiel #7
0
void __putchar(const char c)
{
   uartSend(c);
}
pn532_error_t pn532_bus_SendCommand(const byte_t * pbtData, const size_t szData)
{
  pn532_pcb_t *pn532 = pn532GetPCB();

  // Check if we're busy
  if (pn532->state == PN532_STATE_BUSY)
  {
    return PN532_ERROR_BUSY;
  }

  // Flag the stack as busy
  pn532->state = PN532_STATE_BUSY;

  // Every packet must start with "00 00 ff"
  byte_t  abtFrame[PN532_BUFFER_LEN] = { 0x00, 0x00, 0xff };
  size_t szFrame = 0;

  // Build the frame
  pn532_bus_BuildFrame (abtFrame, &szFrame, pbtData, szData);

  // Keep track of the last command that was sent
  pn532->lastCommand = pbtData[0];

  // Output the frame data for debugging if requested
  #ifdef PN532_DEBUGMODE
  PN532_DEBUG("Sending  (%02d): ", szFrame);
  pn532PrintHex(abtFrame, szFrame);
  #endif

  // Send data to the PN532
  uartSend (abtFrame, szFrame);

  // Wait for ACK
  byte_t abtRxBuf[6];
  uart_pcb_t *uart = uartGetPCB();
  delay(10);   // FIXME: How long should we wait for ACK?
  if (uart->rxfifo.len < 6)
  {
    // Unable to read ACK
    #ifdef PN532_DEBUGMODE
    PN532_DEBUG ("Unable to read ACK%s", CFG_PRINTF_NEWLINE);
    #endif
    pn532->state = PN532_STATE_READY;
    return PN532_ERROR_NOACK;
  }

  // Read ACK ... this will also remove it from the buffer
  const byte_t abtAck[6] = { 0x00, 0x00, 0xff, 0x00, 0xff, 0x00 };
  abtRxBuf[0] = uartRxBufferRead();
  abtRxBuf[1] = uartRxBufferRead();
  abtRxBuf[2] = uartRxBufferRead();
  abtRxBuf[3] = uartRxBufferRead();
  abtRxBuf[4] = uartRxBufferRead();
  abtRxBuf[5] = uartRxBufferRead();

  // Make sure the received ACK matches the prototype
  if (0 != (memcmp (abtRxBuf, abtAck, 6)))
  {
    #ifdef PN532_DEBUGMODE
    PN532_DEBUG ("Invalid ACK: ");
    pn532PrintHex(abtRxBuf, 6);
    PN532_DEBUG("%s", CFG_PRINTF_NEWLINE);
    #endif
    pn532->state = PN532_STATE_READY;
    return PN532_ERROR_INVALIDACK;
  }

  pn532->state = PN532_STATE_READY;
  return PN532_ERROR_NONE;
}