int send_command(int instance, char * command_ptr, int byteCountBuff, int wait_time,char * response,int recieve_size){ PRINTF("\r\nInside send command\r\n"); int i =0, x; for(x=0;x<200;x++) response[x]=0; UART_DRV_SendDataBlocking(instance, command_ptr, byteCountBuff, wait_time); printf("Sent\r\n"); printf("Size of response1 %d\r\n",sizeof(response)); returnValue = UART_DRV_ReceiveDataBlocking (instance,response,recieve_size,wait_time);//Buffer size in bytes to accept all of the me printf("Size of response2 %d\r\n",sizeof(response)); if(returnValue == kStatus_UART_Success){ PRINTF("Fn Recieved:\r\n"); while(response[i] != '\0') { PRINTF("%c",response[i]); i++; } PRINTF("\r\n"); if(strstr(*response,"OK") || strstr(*response,">") || strstr(*response,"+CMSG:") == 0){ printf("Response matches\r\n"); return 0; } //return -2; } }
/** * send data packet * @param pHostInterface_packet [description] */ static void HostInterface_FlushPacket(hostInterface_packet_t * pHostInterface_packet) { osa_status_t status = OSA_MutexLock(&uartTxAccessMutex, OSA_WAIT_FOREVER ); if ( kStatus_OSA_Success == status ) { #if defined( SEND_VIA_UART_INT ) GPIO_DRV_TogglePinOutput( PROBE_PIN ); UART_DRV_SendDataBlocking( gHostInterface_instance, (uint8_t*)pHostInterface_packet, pHostInterface_packet->length + gHostInterface_headerSize + 1, 10 ); #elif defined( SEND_VIA_UART_DMA ) UART_DRV_EdmaSendDataBlocking( gHostInterface_instance, (uint8_t*)pHostInterface_packet, pHostInterface_packet->length + gHostInterface_headerSize + 1, 100 ); #endif #if defined( HEXIWEAR_DEBUG ) UART_DRV_SendDataBlocking( HEXIWEAR_DEBUG_INSTANCE, (uint8_t*)pHostInterface_packet, pHostInterface_packet->length + gHostInterface_headerSize + 1, 100 ); } #endif OSA_MutexUnlock(&uartTxAccessMutex); }
static int nio_serial_write(void *dev_context, void *fp_context, const void *buf, size_t nbytes) { NIO_SERIAL_DEV_CONTEXT_STRUCT *serial_dev_context = (NIO_SERIAL_DEV_CONTEXT_STRUCT *)dev_context; #if PLATFORM_LPUART_ENABLED if (kStatus_UART_Success != LPUART_DRV_SendDataBlocking(serial_dev_context->instance, buf, nbytes, OSA_WAIT_FOREVER)) #else if (kStatus_UART_Success != UART_DRV_SendDataBlocking(serial_dev_context->instance, buf, nbytes, OSA_WAIT_FOREVER)) #endif { errno = EIO; } return (nbytes - serial_dev_context->uart_state.txSize); }
/** * send data packet * @param pHostInterface_packet [description] */ static void HostInterface_FlushPacket(hostInterface_packet_t * pHostInterface_packet) { osa_status_t status = OSA_MutexLock(&uartTxAccessMutex, OSA_WAIT_FOREVER ); if ( kStatus_OSA_Success == status ) { #if defined( SEND_PACKETS_VIA_UART_INT ) UART_DRV_SendDataBlocking( gHostInterface_instance, (uint8_t*)pHostInterface_packet, pHostInterface_packet->length + gHostInterface_headerSize + 1, UART_TIMEOUT ); #elif defined( SEND_PACKETS_VIA_UART_DMA ) UART_DRV_EdmaSendDataBlocking( gHostInterface_instance, (uint8_t*)pHostInterface_packet, pHostInterface_packet->length + gHostInterface_headerSize + 1, UART_TIMEOUT ); #endif #if defined( HEXIWEAR_DEBUG ) // UART_DRV_SendDataBlocking( HEXIWEAR_DEBUG_UART_INSTANCE, (uint8_t*)pHostInterface_packet, pHostInterface_packet->length + gHostInterface_headerSize + 1, UART_TIMEOUT ); #endif } OSA_MutexUnlock(&uartTxAccessMutex); }
int main (void) { /*************************************************************************** * RX buffers **************************************************************************/ /*! @param receiveBuff Buffer used to hold received data */ uint8_t receiveBuff[19] = {0}; /* Initialize standard SDK demo application pins */ hardware_init(); /* Configure the UART TX/RX pins */ configure_uart_pins(BOARD_DEBUG_UART_INSTANCE); #ifdef USE_STDIO_FUNCTIONS /* Call this function to initialize the console UART. This function enables the use of STDIO functions (printf, scanf, etc.) */ dbg_uart_init(); /* Print the initial banner */ printf("\r\nHello World!\n\n\r"); while(1) { /******************************************** * Main routine that simply echoes received * characters forever *********************************************/ /* First, get character. */ receiveBuff[0] = getchar(); /* Now echo the received character */ putchar(receiveBuff[0]); } #else /*************************************************************************** * UART configuration and state structures **************************************************************************/ /*! @param uartConfig UART configuration structure */ /*! @param uartState UARt state structure which is used internally by the*/ /*! by the UART driver to keep track of the UART states */ uart_user_config_t uartConfig; uart_state_t uartState; /*************************************************************************** * TX buffers **************************************************************************/ /*! @param sourceBuff Buffer used to hold the string to be transmitted */ uint8_t sourceBuff[19] = {"\r\nHello World!\n\n\r"}; /* Configure the UART for 115200, 8 data bits, No parity, and one stop bit*/ uartConfig.baudRate = 115200; uartConfig.bitCountPerChar = kUart8BitsPerChar; uartConfig.parityMode = kUartParityDisabled; uartConfig.stopBitCount = kUartOneStopBit; /* Must call the OSA Init function to use Communication drivers */ OSA_Init(); /* Initialize the UART module */ UART_DRV_Init(BOARD_DEBUG_UART_INSTANCE, &uartState, &uartConfig); /* Print the initial banner */ UART_DRV_SendDataBlocking(BOARD_DEBUG_UART_INSTANCE, sourceBuff, 17, 200); while(1) { /******************************************** * Main routine that simply echoes received * characters forever *********************************************/ /* First, get character. */ UART_DRV_ReceiveDataBlocking(BOARD_DEBUG_UART_INSTANCE, receiveBuff, 1, OSA_WAIT_FOREVER); /* Now, stuff the buffer for the TX side and send the character*/ sourceBuff[0] = receiveBuff[0]; /* Now echo the received character */ UART_DRV_SendDataBlocking(BOARD_DEBUG_UART_INSTANCE, sourceBuff, 1, 200); } #endif }