int main(void) { // Configure cpu and mandatory peripherals systemInit(); // Check if projectconfig.h is properly configured for this example #if !defined CFG_CHIBI #error "CFG_CHIBI must be enabled in projectconfig.h for this example" #endif #if CFG_CHIBI_PROMISCUOUS == 0 #error "CFG_CHIBI_PROMISCUOUS must set to 1 in projectconfig.h for this example" #endif #if !defined CFG_PRINTF_UART #error "CFG_PRINTF_UART must be enabled in projectconfig.h for this example" #endif #if defined CFG_INTERFACE #error "CFG_INTERFACE must be disabled in projectconfig.h for this example" #endif #if defined CFG_CHIBI && CFG_CHIBI_PROMISCUOUS != 0 // Get a reference to the Chibi peripheral control block chb_pcb_t *pcb = chb_get_pcb(); // Wait for incoming frames and transmit the raw data over uart while(1) { // Check for incoming messages while (pcb->data_rcv) { // get the length of the data rx_data.len = chb_read(&rx_data); // make sure the length is nonzero if (rx_data.len) { // Enable LED to indicate message reception gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON); // Send raw data to UART for processing on // the PC (requires WSBridge - www.freaklabs.org) uint8_t i; for (i=0; i<rx_data.len; i++) { // Send output to UART uartSendByte(rx_data.data[i]); } // Disable LED gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF); } } } #endif return 0; }
int main(void) { // Configure cpu and mandatory peripherals systemInit(); // Make sure that projectconfig.h is properly configured for this example #if !defined CFG_CHIBI #error "CFG_CHIBI must be enabled in projectconfig.h for this example" #endif #if CFG_CHIBI_PROMISCUOUS != 0 #error "CFG_CHIBI_PROMISCUOUS must be set to 0 in projectconfig.h for this example" #endif // Get a reference to the Chibi peripheral control block chb_pcb_t *pcb = chb_get_pcb(); while(1) { // Check for incoming messages while (pcb->data_rcv) { // Enable LED to indicate message reception gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON); // get the length of the data rx_data.len = chb_read(&rx_data); // make sure the length is nonzero if (rx_data.len) { int dbm = edToDBM(pcb->ed); printf("Message received from node %02X: %s, len=%d, dBm=%d.%s", rx_data.src_addr, rx_data.data, rx_data.len, dbm, CFG_PRINTF_NEWLINE); } // Disable LED gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF); } } return 0; }
int main(void) { // Configure cpu and mandatory peripherals systemInit(); // Check if projectconfig.h is properly configured for this example #if !defined CFG_CHIBI #error "CFG_CHIBI must be enabled in projectconfig.h for this example" #endif #if CFG_CHIBI_PROMISCUOUS == 0 #error "CFG_CHIBI_PROMISCUOUS must set to 1 in projectconfig.h for this example" #endif #if !defined CFG_SDCARD #error "CFG_SDCARD must be enabled in projectconfig.h for this example" #endif #if defined CFG_CHIBI && defined CFG_SDCARD && CFG_CHIBI_PROMISCUOUS != 0 // Get a reference to the Chibi peripheral control block chb_pcb_t *pcb = chb_get_pcb(); // Create a binary file to store captured data libpcap_error_t error; error = libpcapInit("/capture.cap"); if (error) { // Something happened trying to create the file or access the SD card switch (error) { case LIBPCAP_ERROR_FATFS_NODISK: printf("No Disk\r\n"); break; case LIBPCAP_ERROR_FATFS_INITFAILED: printf("Init Failed\r\n"); break; case LIBPCAP_ERROR_FATFS_FAILEDTOMOUNTDRIVE: printf("Failed to mount drive\r\n"); break; case LIBPCAP_ERROR_FATFS_UNABLETOCREATEFILE: printf("Unable to create file\r\n"); break; } // Quit the program return -1; } // Wait for incoming frames and log them to disk in libpcap format. while(1) { // Check for incoming messages while (pcb->data_rcv) { // get the length of the data rx_data.len = chb_read(&rx_data); // make sure the length is non-zero if (rx_data.len) { // Enable LED to indicate message reception gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON); // Write frame content to disk libpcapWriteFrame(rx_data.data, rx_data.len); // Disable LED gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF); } } } #endif return 0; }
int main(void) { // Configure cpu and mandatory peripherals systemInit(); // Check if projectconfig.h is properly configured for this example #if !defined CFG_CHIBI #error "CFG_CHIBI must be enabled in projectconfig.h for this example" #endif #if CFG_CHIBI_PROMISCUOUS == 0 #error "CFG_CHIBI_PROMISCUOUS must set to 1 in projectconfig.h for this example" #endif #if defined CFG_INTERFACE #error "CFG_INTERFACE must be disabled in projectconfig.h for this example" #endif #if defined CFG_CHIBI && CFG_CHIBI_PROMISCUOUS != 0 // Get a reference to the Chibi peripheral control block chb_pcb_t *pcb = chb_get_pcb(); // Wait for incoming frames and transmit the raw data over uart while(1) { // Check for incoming messages while (pcb->data_rcv) { // get the length of the data rx_data.len = chb_read(&rx_data); // make sure the length is nonzero if (rx_data.len) { // Enable LED to indicate message reception gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON); // Send raw data the to PC for processing using wsbridge uint8_t i; for (i=0; i<rx_data.len; i++) { #ifdef CFG_PRINTF_UART uartSendByte(rx_data.data[i]); #endif #ifdef CFG_PRINTF_USBCDC // ToDo: This really needs to be refactored! if (USB_Configuration) { cdcBufferWrite(rx_data.data[i]); // Check if we can flush the buffer now or if we need to wait unsigned int currentTick = systickGetTicks(); if (currentTick != lastTick) { uint8_t frame[64]; uint32_t bytesRead = 0; while (cdcBufferDataPending()) { // Read 64 byte chunks until end of data bytesRead = cdcBufferReadLen(frame, 64); // debug_printf("%d,", bytesRead); USB_WriteEP (CDC_DEP_IN, frame, bytesRead); systickDelay(1); } lastTick = currentTick; } } #endif } // Disable LED gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF); } } } #endif return 0; }