int main(int argc, char **argv) { Stopif(argc < 2, "Supply bignum value in argv[1]!\n"); slre_cap SlreCaps[3]; u8 InputBuffer[128]; i32 MatchedStringLength = slre_match("((\\d|[a-f])*)", argv[1], strlen(argv[1]), SlreCaps, ARRAY_LENGTH(SlreCaps), SLRE_IGNORE_CASE); if (MatchedStringLength > 0) { Stopif(SlreCaps[0].len % 2, "Invalid hex digit match!\n"); HexStringToByteArray(InputBuffer, (char *)SlreCaps[0].ptr, SlreCaps[0].len); u32 InputBuffLengthBytes = MatchedStringLength/2; ByteSwap(InputBuffer, InputBuffLengthBytes); for (u32 ArrayIndex = 0; ArrayIndex < InputBuffLengthBytes; ++ArrayIndex) { printf("0x%02x, ", InputBuffer[ArrayIndex]); } printf("\n"); } }
/****************************************************************************** Function Name: ProcessUartData ******************************************************************************* Summary: Parses the commands received through the UART and initiates actions based on the command. For example, this function initiates connection to a peer device upon receiving the connect command. Parameters: None. Return: None. ******************************************************************************/ void ProcessUartData(void) { uint32 data; uint32 length; uint32 i; CYBLE_GAP_BD_ADDR_T peerAddr; if(UART_DEB_SpiUartGetRxBufferSize() < MIN_UART_BYTES) {return;} data = UART_DEB_UartGetChar(); if(data == 0){return;} if(data == CMD_CONNECT) { length = UART_DEB_UartGetChar(); /* length */ if(length == 0){return;} i = 0; do { data = UART_DEB_UartGetChar(); if(data != 0x00) { tagData[i++] = data; } }while(data != 0x0D); if(length != CONNECT_DATA_LENGTH) { printf("PSoC: Length is not equal to %d \r\n", CONNECT_DATA_LENGTH); return; } else { printf("PSoC: CONNECT command is Received. \r\n"); tagData[length] = (uint8)'\r'; tagData[length + 1] = (uint8)'\n'; tagData[length + 2] = 0; printf("%s", tagData); } /* Convert Hex string into byte array */ HexStringToByteArray(tagData, length); for(i = 0; i < CYBLE_GAP_BD_ADDR_SIZE; i++) { peerAddr.bdAddr[i] = tagData[i]; } peerAddr.type = tagData[i]; for(i = 0; i < SECURITY_KEY_LENGTH; i++) { securityKey[i] = tagData[CYBLE_GAP_BD_ADDR_SIZE + 1 + i]; } printf("PSoC: Connection initiated to device address: "); for(i = 0; i < CYBLE_GAP_BD_ADDR_SIZE; i++) { printf("%2.2x", peerAddr.bdAddr[CYBLE_GAP_BD_ADDR_SIZE - i - 1]); } printf("\r\n"); /* Initiate Connection */ apiResult = CyBle_GapcConnectDevice(&peerAddr); if(apiResult != CYBLE_ERROR_OK) { printf("PSoC: Error in Connection Inititation \r\n"); } } }