inline udp_sock udp_host(const std::string& serverport = SERVERPORT) { networking_init(); int sockfd; struct addrinfo hints, *servinfo, *p; int rv; memset(&hints, 0, sizeof hints); hints.ai_family = AF_INET; // set to AF_INET to force IPv4 hints.ai_socktype = SOCK_DGRAM; hints.ai_flags = AI_PASSIVE; // use my IP if ((rv = getaddrinfo(NULL, serverport.c_str(), &hints, &servinfo)) != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv)); exit(1); } // loop through all the results and bind to the first we can for(p = servinfo; p != NULL; p = p->ai_next) { if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) { perror("listener: socket"); continue; } if (bind(sockfd, p->ai_addr, p->ai_addrlen) == -1) { CLOSE(sockfd); perror("listener: bind"); continue; } break; } if (p == NULL) { fprintf(stderr, "listener: failed to bind socket\n"); udp_sock bad; bad.make_invalid(); return bad; } freeaddrinfo(servinfo); return udp_sock(sockfd); }
int main(void) { // Set the system clock to the full 120MHz uint32_t sysClkFreq = SysCtlClockFreqSet(SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480, 120000000); debug_init(sysClkFreq); status_led_init(); network_driver_init(sysClkFreq); networking_init(); telemetry_init(); transducer_init(); thermocouple_init(); solenoid_init(); debug_print("Initialization complete. starting main loop.\r\n"); // Set up the SysTick timer and its interrupts SysTickPeriodSet(6000); // 40 kHz SysTickIntRegister(sys_tick); SysTickIntEnable(); SysTickEnable(); uint32_t loopIterations = 0; uint32_t frame_start = systick_clock; while(1) { status_led_periodic(); network_driver_periodic(); telemetry_periodic(); solenoid_periodic(); // debug_print_u32(systick_clock); //count loop iterations per second loopIterations++; if(systick_clock - frame_start >= 1000) { loops_per_second = loopIterations; loopIterations = 0; frame_start = systick_clock; } } }