void usb_serial_flush_input(void) { int16_t i; int16_t bufsize = CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface); for(i=0; i<bufsize; i++) CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface); }
/** Main program entry point. This routine contains the overall program flow, including initial * setup of all components and the main program loop. */ int main(void) { SetupHardware(); uint16_t bytesAvailable, currentByte; CDC_Device_CreateStream(&tpad_CDC_Interface, &USBSerialStream); sei(); for (;;) { // // Read pressures from 16 buttons // ButtonStates(); // // Handle incoming bytes // bytesAvailable = CDC_Device_BytesReceived(&tpad_CDC_Interface); while (bytesAvailable--) { currentByte = CDC_Device_ReceiveByte(&tpad_CDC_Interface); // TODO: implement led updates from host } CDC_Device_USBTask(&tpad_CDC_Interface); USB_USBTask(); } }
static int CDC_Device_getchar(FILE* Stream) { if (!(CDC_Device_BytesReceived((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream)))) return _FDEV_EOF; return CDC_Device_ReceiveByte((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream)); }
void VCOM_echo(void) { if(CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface)) { in_buff[0] = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface); CDC_Device_SendData(&VirtualSerial_CDC_Interface, (char *)in_buff, 1); Endpoint_ClearIN(); } }
uint8_t uart_isdata(void) { if (usb_rxpacket_leftb) { Endpoint_SelectEndpoint(CDC_RX_EPNUM); return usb_rxpacket_leftb; } usb_process(); usb_rxpacket_leftb = CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface); return usb_rxpacket_leftb; }
static int CDC_Device_getchar_Blocking(FILE* Stream) { while (!(CDC_Device_BytesReceived((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream)))) { if (USB_DeviceState == DEVICE_STATE_Unattached) return _FDEV_EOF; CDC_Device_USBTask((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream)); USB_USBTask(); } return CDC_Device_ReceiveByte((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream)); }
/** Main program entry point. This routine contains the overall program flow, including initial * setup of all components and the main program loop. */ int main(void) { SetupHardware(); LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); for (;;) { CheckJoystickMovement(); /* Discard all received data on the first CDC interface */ while (CDC_Device_BytesReceived(&VirtualSerial1_CDC_Interface)) CDC_Device_ReceiveByte(&VirtualSerial1_CDC_Interface); /* Echo all received data on the second CDC interface */ while (CDC_Device_BytesReceived(&VirtualSerial2_CDC_Interface)) CDC_Device_SendByte(&VirtualSerial2_CDC_Interface, CDC_Device_ReceiveByte(&VirtualSerial2_CDC_Interface)); CDC_Device_USBTask(&VirtualSerial1_CDC_Interface); CDC_Device_USBTask(&VirtualSerial2_CDC_Interface); USB_USBTask(); } }
void CDC_Arduino_In_Task() { uint16_t bytes = CDC_Device_BytesReceived(&VirtualSerial_CDC0_Interface); while(bytes--){ /* Read bytes from the USB OUT endpoint and store it for the Arduino Serial Class */ if ( ringbuf_elements(&serialRx_Buffer) < ringbuf_size(&serialRx_Buffer)-2 ) { int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC0_Interface); if ( !(ReceivedByte < 0) ) ringbuf_put(&serialRx_Buffer, ReceivedByte); } else{ return; } } // end while }
/* This function checks number of bytes received from the USB host. */ uint16_t USBVC001_BytesReceived(void) { uint16_t Bytes = 0; /* Check if bytes are received from host */ NVIC_DisableIRQ(USB0_0_IRQn); Bytes = CDC_Device_BytesReceived(&USBVC001_CDCInterface); if(Bytes == 0) { Endpoint_ClearOUT(); } NVIC_EnableIRQ(USB0_0_IRQn); return Bytes; }
void VCOM_bridge(void) { uint32_t recv_count; recv_count = CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface); while(recv_count--) { out_buff[0] = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface); uart_send_byte(out_buff[0]); } recv_count = uart_get_data(in_buff); if(recv_count) { CDC_Device_SendData(&VirtualSerial_CDC_Interface, (char *)in_buff, recv_count); Endpoint_ClearIN(); } }
uint8_t uart_recv(void) { do { if (usb_rxpacket_leftb) { uint8_t d; Endpoint_SelectEndpoint(CDC_RX_EPNUM); d = Endpoint_Read_Byte(); usb_rxpacket_leftb--; if (!usb_rxpacket_leftb) Endpoint_ClearOUT(); return d; } usb_process(); usb_rxpacket_leftb = CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface); if ((!usb_rxpacket_leftb)&&(usb_txpacket_leftb)) { Endpoint_SelectEndpoint(CDC_TX_EPNUM); Endpoint_ClearIN(); /* Go data, GO. */ usb_txpacket_leftb = 0; } } while (1); }
/** Main program entry point. This routine contains the overall program flow, including initial * setup of all components and the main program loop. */ int main(void) { SetupHardware(); RingBuffer_InitBuffer(&USARTtoUSB_Buffer, USARTtoUSB_Buffer_Data, sizeof(USARTtoUSB_Buffer_Data)); sei(); for (;;) { /* Echo bytes from the host to the target via the hardware USART */ if ((UCSR1A & (1 << UDRE1)) && CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface)) { UDR1 = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface); LEDs_TurnOnLEDs(LEDMASK_TX); PulseMSRemaining.TxLEDPulse = TX_RX_LED_PULSE_MS; } /* Check if the millisecond timer has elapsed */ if (TIFR0 & (1 << OCF0A)) { /* Clear flush timer expiry flag */ TIFR0 |= (1 << TOV0); /* Check if the reset pulse period has elapsed, if so tristate the target reset line */ if (PulseMSRemaining.ResetPulse && !(--PulseMSRemaining.ResetPulse)) { LEDs_TurnOffLEDs(LEDMASK_BUSY); AVR_RESET_LINE_DDR &= ~AVR_RESET_LINE_MASK; } /* Check if the LEDs should be ping-ponging (during enumeration) */ if (PulseMSRemaining.PingPongLEDPulse && !(--PulseMSRemaining.PingPongLEDPulse)) { LEDs_ToggleLEDs(LEDMASK_TX | LEDMASK_RX); PulseMSRemaining.PingPongLEDPulse = PING_PONG_LED_PULSE_MS; } /* Turn off TX LED(s) once the TX pulse period has elapsed */ if (PulseMSRemaining.TxLEDPulse && !(--PulseMSRemaining.TxLEDPulse)) LEDs_TurnOffLEDs(LEDMASK_TX); /* Turn off RX LED(s) once the RX pulse period has elapsed */ if (PulseMSRemaining.RxLEDPulse && !(--PulseMSRemaining.RxLEDPulse)) LEDs_TurnOffLEDs(LEDMASK_RX); /* Check if the receive buffer flush period has expired */ uint16_t BufferCount = RingBuffer_GetCount(&USARTtoUSB_Buffer); if (!(--FlushPeriodRemaining) || (BufferCount > 200)) { FlushPeriodRemaining = RECEIVE_BUFFER_FLUSH_MS; /* Start RX LED indicator pulse */ if (BufferCount) { LEDs_TurnOnLEDs(LEDMASK_RX); PulseMSRemaining.RxLEDPulse = TX_RX_LED_PULSE_MS; } /* Echo bytes from the target to the host via the virtual serial port */ while (BufferCount--) { /* Try to send the next byte of data to the host, abort if there is an error without dequeuing */ if (CDC_Device_SendByte(&VirtualSerial_CDC_Interface, RingBuffer_Peek(&USARTtoUSB_Buffer)) != ENDPOINT_READYWAIT_NoError) { break; } /* Dequeue the already sent byte from the buffer now we have confirmed that no transmission error occurred */ RingBuffer_Remove(&USARTtoUSB_Buffer); } } } CDC_Device_USBTask(&VirtualSerial_CDC_Interface); USB_USBTask(); } }
static void vUserInput(void) { TickType_t xLastWakeTime; const TickType_t xFrequency = 100; // Initialise the xLastWakeTime variable with the current time. xLastWakeTime = xTaskGetTickCount(); vTaskSuspendAll(); CDC_Device_SendString(&USB_Interface, "enter command: "); xTaskResumeAll(); for (;;) { int count = 0; buffer[0] = 0; /* read bytes from USB interface */ vTaskSuspendAll(); BytesAvailable = CDC_Device_BytesReceived(&USB_Interface); for (count = 0; count < BytesAvailable; count++) { buffer[count] = CDC_Device_ReceiveByte(&USB_Interface); } xTaskResumeAll(); /* Null terminate buffer*/ buffer[count] = 0; /* Buffer is not empty */ if (buffer[0] != 0) { /* echo user input back */ vTaskSuspendAll(); CDC_Device_SendString(&USB_Interface, buffer); xTaskResumeAll(); /* combine into buffer */ strncat(end_buffer, buffer, 1); if (buffer[0] == '\r') { strncat(end_buffer, '\0', 1); handle_input(end_buffer); /* 'reset' end_buffer */ end_buffer[0] = '\0'; vTaskSuspendAll(); CDC_Device_SendString(&USB_Interface, "enter command: "); xTaskResumeAll(); } } vTaskDelayUntil(&xLastWakeTime, xFrequency); } }
uint16_t usb_serial_available(void) { return CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface); }
int16_t usb_serial_get_nb_received(){ return CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface); }
void process_bytes(){ uint16_t nb_received = CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface); uint8_t c; for( uint16_t i = 0; i < nb_received ; i++ ){ c = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface); switch (c){ //case 'h': //println("AirBoxLab serial firmware - for tests only"); //println("Commands:"); //println("h : this help"); //println("l : run LED test cycle"); //println("m : toggle motor"); //println("k : print humidity and temperature"); //println("t : print tilt sensor"); // //println("w : test CC3000..."); // //println("c : toggle charge test (disabled JTAG temporarily)"); //println("b : print battery voltage"); //println("g : print MQ-135 voltage (sensor board needs to be ON)"); //println("d : print GP2Y voltage"); //println("J : WARNING toggles JTAG interface (automatically disabled for CHARGING, not for WIFI_CONNECT)"); //println("i : print iAQengine (sensor board needs to be ON)"); //println("k : print humidity and temperature (sensor board needs to be ON)"); //break; case '7':{ uint8_t is_on; sensor_board_heater_is_on(&is_on); fprintf(&USBSerialStream, "Sensor board ON : %u\r\n", is_on); sensor_board_heater_on(1); sensor_board_heater_is_on(&is_on); fprintf(&USBSerialStream, "Sensor board ON : %u\r\n", is_on); }break; case '8':{ uint16_t val; sensor_board_get_mq135(&val); fprintf(&USBSerialStream, "MQ135 : %u\r\n", val); }break;/* case 't':{ int16_t acc_x, acc_y, acc_z; mma8435q_getAccXYZ(&acc_x, &acc_y, &acc_z, 1); double norm = sqrt((double)acc_x*(double)acc_x+ (double)acc_y*(double)acc_y + (double)acc_z*(double)acc_z)/255.0; fprintf(&USBSerialStream, "Accel: %d, %d, %d (%f)\r\n", acc_x, acc_y, acc_z, norm ); }break; case 'y': if (cc3000_connectToAP("linksys", "", 0)){ wlan_ioctl_set_connection_policy(0, 0, 0); // TODO add wlan_ioctl_set_connection_policy(0, 0, 0); and reset the CC3000 println("Connected to wifi"); } else { println("Couldn't connect to wifi"); } while(!cc3000_checkDHCP()){ Delay_MS(100); print("."); } uint32_t retip, netmask, gateway, dhcpserv, dnsserv; cc3000_getIPAddress(&retip, &netmask, &gateway, &dhcpserv, &dnsserv); fprintf(&USBSerialStream, "IP: %d.%d.%d.%d\r\n", (uint8_t)(retip>>24), (uint8_t)(retip>>16), (uint8_t)(retip>>8), (uint8_t)(retip)); fprintf(&USBSerialStream, "Netmask: %d.%d.%d.%d\r\n", (uint8_t)(netmask>>24), (uint8_t)(netmask>>16), (uint8_t)(netmask>>8), (uint8_t)(netmask)); fprintf(&USBSerialStream, "Gateway: %d.%d.%d.%d\r\n", (uint8_t)(gateway>>24), (uint8_t)(gateway>>16), (uint8_t)(gateway>>8), (uint8_t)(gateway)); fprintf(&USBSerialStream, "DHCPServ: %d.%d.%d.%d\r\n", (uint8_t)(dhcpserv>>24), (uint8_t)(dhcpserv>>16), (uint8_t)(dhcpserv>>8), (uint8_t)(dhcpserv)); fprintf(&USBSerialStream, "DNSServ: %d.%d.%d.%d\r\n", (uint8_t)(dnsserv>>24), (uint8_t)(dnsserv>>16), (uint8_t)(dnsserv>>8), (uint8_t)(dnsserv)); if (cc3000_checkDHCP()){ println("Got IP from DHCP"); } else { println("Couldn't get DHCP lease"); } if (cc3000_ping(cc3000_IP2U32(192,168,1,1), 3, 500, 32)){ println("pinged 192.168.1.1 successfully"); } else { println("192.168.1.1 not pinged"); } break; //case 'l': //// LED test : cycle each led up and down then all 3 at the same time //println("starting LED test cycle"); //println("Red (0 to 255 in 2.55s)..."); //CDC_Device_USBTask(&VirtualSerial_CDC_Interface); //USB_USBTask(); //for (uint8_t x = 0; x < 255; x++){ //led_set(x,0,0); //Delay_MS(10); //} //println("Green (0 to 255 in 2.55s)..."); //CDC_Device_USBTask(&VirtualSerial_CDC_Interface); //USB_USBTask(); //for (uint8_t x = 0; x < 255; x++){ //led_set(0,x,0); //Delay_MS(10); //} //println("Blue (0 to 255 in 2.55s)..."); //CDC_Device_USBTask(&VirtualSerial_CDC_Interface); //USB_USBTask(); //for (uint8_t x = 0; x < 255; x++){ //led_set(0,0,x); //Delay_MS(10); //} //println("All at once (0 to 255 in 2.55s)..."); //CDC_Device_USBTask(&VirtualSerial_CDC_Interface); //USB_USBTask(); //for (uint8_t x = 0; x < 255; x++){ //led_set(x,x,x); //Delay_MS(10); //} //println("All at 255 blinking 3 times..."); //CDC_Device_USBTask(&VirtualSerial_CDC_Interface); //USB_USBTask(); //led_clear(); //Delay_MS(200); //led_set(255, 255, 255); //Delay_MS(200); //led_clear(); //Delay_MS(200); //led_set(255, 255, 255); //Delay_MS(200); //led_clear(); //Delay_MS(200); //led_set(255, 255, 255); //Delay_MS(200); //led_clear(); //println("LED test finished"); //break; //case 'm': //switch (motor_get()){ //case 0: //println("Motor ON (PWM @255)"); //motor_set(255); //break; //case 255: //println("Motor ON (PWM @100)"); //motor_set(100); //break; //case 100: //println("Motor OFF"); //motor_set(0); //break; //} //break; //case 'c': //do_charge_test = !do_charge_test; //if (do_charge_test){ ////disable JTAG //MCUCR = (1<<JTD); //MCUCR = (1<<JTD); //println("Start charge test: RED pulse = charging, GREEN pulse = not charging..."); //} else { ////enable JTAG //MCUCR = MCUCR_old; //println("End of charge test"); //led_clear(); //} //break; //case 'b': //fprintf(&USBSerialStream, "Battery voltage: %d mV\r\n", power_battery_get_voltage() ); //break; //case 'g': ////fprintf(&USBSerialStream, "MQ-135 voltage: %d mV\r\n", mq135_get_voltage() ); //break; //case 'd': //fprintf(&USBSerialStream, "GP2Y voltage: %d mV\r\n", gp2y_get_voltage() ); //break; // //case 'J': //if (bit_is_clear(MCUCR, JTD)){ //MCUCR = (1<<JTD); //MCUCR = (1<<JTD); //println("JTAG interface DISABLED"); //} else { //MCUCR = 0; //MCUCR = 0; //println("JTAG interface ENABLED"); //} //break; //case 'i': //fprintf(&USBSerialStream, "iAQengine: %d\r\n", iaqengine_get_ppm()); //break; case 'k': fprintf(&USBSerialStream, "humidity: %f %%\r\n", cc2dxx_get_humidity()); Delay_MS(100); fprintf(&USBSerialStream, "temp: %f deg C\r\n", cc2dxx_get_temperature()); break; case 'w':{ printf("Testing CC3000..."); CDC_Device_USBTask(&VirtualSerial_CDC_Interface); USB_USBTask(); Delay_MS(500); uint8_t major, minor; if (cc3000_getFirmwareVersion(&major, &minor)){ fprintf(&USBSerialStream, "V%d.%d\r\n", major,minor); } else { println("Could not get version"); } uint8_t mac[6]; if (cc3000_getMacAddress(mac)){ fprintf(&USBSerialStream, "MAC:%02X%02X%02X%02X%02X%02X\r\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); } else { println("Could not get MAC"); } }break; */ default: println("press h for help"); break; } } }
int main(void) { uint8_t byte; // Initalize the system init(); // Load the saved registers applySavedRegisters(); MRF_reset(); // Get the default boot state mode = getBootState(); // Loop here forever while (true) { // Process menu actions as long as we're in the menu or test modes // New packets received while in menu mode are ignored if (mode == MENU || mode == TEST_ALT || mode == TEST_ZERO || mode == TEST_ONE || mode == CAPTURE || mode == TEST_PING ) { // Handle any new bytes from the USB system // These functions can be assumed to return immediately. if (CDC_Device_BytesReceived(&CDC_interface) > 0) { byte = CDC_Device_ReceiveByte(&CDC_interface); menuHandleByte(byte); } // Test for a new packet MRF_packet_t *rx_packet = MRF_receive_packet(); // Was the packet correctly received? if (rx_packet != NULL) { switch (mode) { case TEST_PING: MRF_transmit_packet(rx_packet); sendStringP(pingString); printPacket(rx_packet); break; case CAPTURE: printPacket(rx_packet); break; default: // Other menu modes would end up here, ignore the packet break; } } } // These modes are responsible for actually using the RF interface else { switch (mode) { case PACKET: case PACKET_ECC: packetMainLoop(); break; case SERIAL: case SERIAL_ECC: serialMainLoop(); break; case USB_SERIAL: usbSerialMainLoop(); break; default: // This would catch any weird modes sendStringP(invalidModeString); print_dec(mode); CDC_Device_Flush(&CDC_interface); mode = MENU; break; } } } }
void process_bytes(){ uint16_t nb_received = CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface); uint8_t c; for( uint16_t i = 0; i < nb_received ; i++ ){ c = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface); switch (c){ case 'l': CDC_Device_USBTask(&VirtualSerial_CDC_Interface); USB_USBTask(); for (uint8_t x = 0; x < 255; x++){ led_set(255,20,x); Delay_MS(10); } led_clear(); println("LED test finished"); break; #ifdef ONBOARD_STUFF case 'm':{ switch (motor_get()){ case 0: // TODO use ranges instead of exact values println("Motor ON (PWM @255)"); motor_set(255); break; case 255: println("Motor ON (PWM @100)"); motor_set(100); break; case 100: println("Motor OFF"); motor_set(0); break; } }break; case 'd':{ fprintf(&USBSerialStream, "GP2Y PM: %.1f ug/m3\r\n", gp2y_get_pm() ); }break; case 'k': fprintf(&USBSerialStream, "humidity: %.0f %%\r\n", cc2dxx_get_humidity()); Delay_MS(100); fprintf(&USBSerialStream, "temp: %.2f deg C\r\n", cc2dxx_get_temperature()); break; #endif #ifdef SENSORBOARD case 'i': fprintf(&USBSerialStream, "TCOV: %d\r\n", iaqengine_get_ppm()); break; #endif #ifdef WIFI case 'w': wifi_print_MAC(); wifi_print_ip(); break; case 'y': wifi_config_set_dev(); wifi_connect_to_ap(wifi_ap_ssid, wifi_ap_password, wifi_ap_encrypt_mode); wifi_print_ip(); wifi_ping(192,168,1,1); break; case 's': wifi_resolve_backend_ip(); break; /*case 'e': fprintf(&USBSerialStream, "is set? %u\r\n", wifi_config_is_set()); fprintf(&USBSerialStream, "set dev %u\r\n", wifi_config_set_dev()); fprintf(&USBSerialStream, "is set? %u\r\n", wifi_config_is_set()); fprintf(&USBSerialStream, "save %u\r\n", wifi_config_save()); fprintf(&USBSerialStream, "%s %s %u\r\n", wifi_ap_ssid, wifi_ap_password, wifi_ap_encrypt_mode); fprintf(&USBSerialStream, "set lol %u\r\n", wifi_config_set("lol", "lolilol", 2)); fprintf(&USBSerialStream, "%s %s %u\r\n", wifi_ap_ssid, wifi_ap_password, wifi_ap_encrypt_mode); fprintf(&USBSerialStream, "load %u\r\n", wifi_config_load()); fprintf(&USBSerialStream, "%s %s %u\r\n", wifi_ap_ssid, wifi_ap_password, wifi_ap_encrypt_mode); wifi_config_mem_clear(); fprintf(&USBSerialStream, "clear then load %u\r\n", wifi_config_load()); break;*/ case 'p':{ println("Trying to POST"); CDC_Device_USBTask(&VirtualSerial_CDC_Interface); USB_USBTask(); wifi_config_set_dev(); /* // There is a problem with that, it hangs sometimes >< if (!wifi_config_is_set()){ if (!wifi_config_load()){ #ifdef DEV printf("setting up DEV config"); wifi_config_set_dev(); #else printf("No config anywhere!"); return; // TODO what do we do if it's not configured? #endif } }*/ fprintf(&USBSerialStream, "%s %s %u\r\n", wifi_ap_ssid, wifi_ap_password, wifi_ap_encrypt_mode); CDC_Device_USBTask(&VirtualSerial_CDC_Interface); USB_USBTask(); // TODO check if the SSID is available before trying to connect or it might hang... :/ if( !wifi_connect_to_ap(wifi_ap_ssid, wifi_ap_password, wifi_ap_encrypt_mode) == WERR_OK){ println("AP NOK"); } else { println("AP OK"); wifi_print_ip(); uint32_t backend_ip; uint16_t backend_port = 80; //backend_ip = cc3000_IP2U32(54,221,218,154); //backend_ip = cc3000_IP2U32(67,215,65,132); //backend_ip = cc3000_IP2U32(192,168,1,11); //backend_ip = cc3000_IP2U32(192,168,42,102); backend_ip = wifi_resolve_backend_ip(); print_ip_helper("backend", backend_ip); CDC_Device_USBTask(&VirtualSerial_CDC_Interface); USB_USBTask(); if (cc3000_ping(backend_ip, 3, 500, 32)){ fprintf(&USBSerialStream, "ping OK\r\n"); } else { fprintf(&USBSerialStream, "ping timeout\r\n"); } CDC_Device_USBTask(&VirtualSerial_CDC_Interface); USB_USBTask(); void* sock = cc3000_connectTCP(backend_ip, backend_port); if (cc3000_cli_connected(sock)){ println("cli connected"); CDC_Device_USBTask(&VirtualSerial_CDC_Interface); USB_USBTask(); uint16_t res = 0; res += cc3000_cli_fastrprint(sock, "POST /v1/airboxlab/ HTTP/1.1\n"); res += cc3000_cli_fastrprint(sock, "User-Agent: abl1.0\n"); res += cc3000_cli_fastrprint(sock, "Host: api.airboxlab.com\n"); res += cc3000_cli_fastrprint(sock, "Accept: */*\n"); //res += cc3000_cli_fastrprint(sock, "Content-Type: application/json\n"); res += cc3000_cli_fastrprint(sock, "Content-Length: 35\n\n"); res += cc3000_cli_fastrprint(sock, "5040f3bd20c8,20.7,53.9,1255,11.1,78\n"); fprintf(&USBSerialStream, "written: %u / %u\r\n", res, 171); CDC_Device_USBTask(&VirtualSerial_CDC_Interface); USB_USBTask(); Delay_MS(1000); uint8_t nb_available = cc3000_cli_available(sock); fprintf(&USBSerialStream, "Returned %u\r\n", nb_available); CDC_Device_USBTask(&VirtualSerial_CDC_Interface); USB_USBTask(); for (int i = 0; i<cc3000_cli_available(sock); i++){ fprintf(&USBSerialStream, "%c" ,cc3000_cli_read(sock)); } println(""); cc3000_cli_close(sock); println("closed"); } else { println("cli not connected"); } } }break;/* case 'W':{ // setup wifi int nb_returned; println("SSID?"); println("password?"); println("encryption mode number?[0:none, 1:WEP, 2:WPA, 3:WPA2]"); uint16_t _mode; CDC_Device_USBTask(&VirtualSerial_CDC_Interface); USB_USBTask(); while(1){ // TODO timeout? opt-out? _mode = fgetc(&USBSerialStream); printf("read: %i", _mode); if(_mode <= 3){ wifi_ap_encrypt_mode = _mode; fprintf(&USBSerialStream, "Mode = %u\r\n", _mode); break; } else { fprintf(&USBSerialStream, "Not a valid mode. Please choose number between [0:none, 1:WEP, 2:WPA, 3:WPA2]\r\n"); CDC_Device_USBTask(&VirtualSerial_CDC_Interface); USB_USBTask(); } } }break;*/ #endif default: println("Airboxlab serial mode: press 'l' key to test LEDs"); break; } } }