static ICACHE_FLASH_ATTR int configure(void) { char ch; int ret; static struct station_config st_config; wifi_station_get_config(&st_config); do { printf("\r\nConfiguration:\r\n"); printf("1: Wifi SSID [%s]\r\n", st_config.ssid); printf("2: Wifi Password [%s]\r\n", st_config.password); printf("3: HTTP host[%s]\r\n", user_config.host); printf("4: HTTP port[%d]\r\n", user_config.port); printf("5: HTTP path/query [%s]\r\n", user_config.get_cmd); printf("0: Exit configuration\r\n"); // ch = uart_getchar(); xQueueReceive(xUARTQueue, &ch, -1); switch (ch) { case '1': printf("Enter Wifi SSID: "); uart_gets(&xUARTQueue, st_config.ssid, 32); break; case '2': printf("Enter Wifi Password: "******"Enter HTTP host: "); uart_gets(&xUARTQueue, user_config.host, HOST_LEN+1); break; case '4': printf("Enter HTTP port: "); char buf[6]; uart_gets(&xUARTQueue, buf, 6); user_config.port = atoi(buf); break; case '5': printf("Enter HTTP path and query string: "); uart_gets(&xUARTQueue, user_config.get_cmd, GET_LEN+1); break; case '0': DBG("setting config [%s] [%s]\n", st_config.ssid, st_config.password); wifi_station_set_config(&st_config); save_user_config(&user_config); break; default: printf("Invalid choice\r\n"); } } while (ch != '0'); printf("System will now restart\r\n"); system_restart(); }
/* * uart_getnum * * Read a number in from the specified channel. Accepts base * decorators (like 0x) to distinguish hexadecimal numbers from * decimal ones. See aton for the list. */ uint32_t uart_getnum(int chan) { char buf[48]; uart_gets(chan, buf, 48); return aton(buf); }
int main() { int i; clock_init(); uart_init(); __asm__ __volatile__( "mrs r0,cpsr\n" "mov %0,r0\n" :"=&r"(i) : :"r0" ); uart_printf("%s cpsr.M %x\n",__FUNCTION__,i&0x1f); __asm__ __volatile__( "nop\n" ".word 0x77777777\n" "nop\n" ); while(1){ uart_puts(uart_gets()); } }
int16_t main(void) { init_clock(); init_uart(); printf("Hello World!\n"); printf("What is your name? "); uart_gets(&uart1, string, 40); printf("Hello %s!\n", string); printf("Type something at the prompt.\n"); while (1) { printf(">> "); uart_gets(&uart1, string, 40); printf("You typed '%s'\n", string); } }
int uart_get_int(void) { char buffer[80]; uart_gets(buffer); int num = 0; int i = 0; int sign = 1; if (buffer[0] == '-') { ++i; sign = -1; } for (; buffer[i] != '\0'; ++i) { if (!(buffer[i] >= '0' && buffer[i] <= '9')) return 0; num = num * 10 + buffer[i] - '0'; } return sign * num; }
void rx_task(void * ignore) { int cnt = 0; while (1) { if (uart_gets(buf) <= 0) continue; PORTB ^= _BV(PB0); if (!strncmp(buf, "+BTINQ: ", 8)) { char * x = strchr(&buf[8], ','); if (x == NULL) continue; *(x+1) = 0; //strcpy(ptr[cnt], &buf[8]); uart_puts("AT+BTSDP="); uart_puts(&buf[8]); uart_puts("2\r"); posTaskSleep(MS(500)); PORTB ^= _BV(PB0); posTaskSleep(MS(500)); PORTB ^= _BV(PB0); posTaskSleep(MS(500)); PORTB ^= _BV(PB0); } } }
sc_string sMRIfaceUART_getData() { return uart_gets(); }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ int count = 0; char temp[100]; printf("STM32> "); HAL_Delay(200); count = uart_gets((uint8_t*)input, BUFFSIZE); //read input //printf("Read %d chars:%s\r\n", count, input); char cmd[100]; int addr,data,paramNum; sscanf(input, "%s", cmd); if(strcmp(cmd,"peek")==0){ paramNum = sscanf(input,"%s %x %s",cmd,&addr,temp); if(paramNum==2){ printf("peek: 0x%x in addr 0x%x\r\n",*(int*)addr,addr); }else{ printf("Usage:peek addr\r\n"); } }else if(strcmp(cmd,"poke")==0){ paramNum = sscanf(input,"%s %x %x %s",cmd,&addr,&data,temp); if(paramNum==3){ *((int*)addr) = data; printf("poke: change addr 0x%x to 0x%x\r\n",addr,data); }else{ printf("Usage:poke addr data\r\n"); } }else if(strcmp(cmd,"tempaddr")==0){ printf("temp array's addr is 0x%x, length:%d\r\n",(int)temp,100); }else{ printf("invalid cmd!\r\n"); } } /* USER CODE END 3 */ }
int main(void) { //uart_set_FrameFormat(USART_8BIT_DATA|USART_1STOP_BIT|USART_NO_PARITY|USART_ASYNC_MODE); // default settings uart_init(BAUD_CALC(115200)); // 8n1 transmission is set as default stdout = &uart0_io; // attach uart stream to stdout & stdin stdin = &uart0_io; // uart0_in if no TX and uart0_out if no RX (depends on config macros) sei(); // enable interrupts, library wouldn't work without this uart_puts("hello from usart 0\r\n"); // write const string to usart buffer // C++ restriction, in C its the same as uart_putstr() //uart_puts("hello world\r\n"); // write const string to usart buffer // C++ restriction, in C its the same as uart_putstr() // if you do not have enough SRAM memory space to keep all strings, try to use puts_P instead uart_puts_P("hello from flashed, usart\r\n"); // write string to usart buffer from flash memory // string is parsed by PSTR() macro _delay_ms(5000); uart_puts_p(foo_string); char buffer[25]; uart_gets(buffer, 25); // read at most 24 bytes from buffer (CR,LF will not be cut) int a; uart_puts("gimmie a number: "); a = uart_getint(); uart_puts("numba a: "); uart_putint(a); uart_puts("\r\n"); while(1) { uart_puts("bytes waiting in receiver buffer : "); uart_putint(uart_AvailableBytes()); // ask for bytes waiting in receiver buffer //uart_getsln(buffer, 25); // read 24 bytes or one line from usart buffer if (!strcmp(buffer, "people who annoy you")) { uart_putc('>'); _delay_ms(5000); uart_puts_P(" naggers"); } uart_puts("\r\n"); /* uart_putfloat(0.1337f); uart_puts("\r\n"); uart_putstr(buffer); // write array string to usart buffer uart_puts("\r\n"); printf("Say my name: "); scanf("%s", buffer); printf("So it's %s, You are damn' right.\n", buffer); _delay_ms(5000); */ } }
int uart_geti() // Get Integer from UART, Require uart_gets(),s2i() { char s[7]; uart_gets(s); return s2i(s); }