void udp_init ( UdpCommStruct *commStruct ) { UbloxModemUdpStruct *pUbloxModemUdpStruct = (UbloxModemUdpStruct *) &ubloxModemUdpStruct; //For now, making this so that it is single instance implementation. //TODO: Make more generic this wrapper in future commStruct->udpSocketDataPtr = pUbloxModemUdpStruct; commStruct->socketIP.port = atoi(commStruct->port); pUbloxModemUdpStruct->hostname = commStruct->hostname; pUbloxModemUdpStruct->port = atoi(commStruct->port); ublox_init(pUbloxModemUdpStruct); //Handles server connections if (commStruct->actAsServer) { //Server //Bind connection //Read POSIX socket to populate Generic IP Address //commStruct->socketIP.address = 0; commStruct->socketIP.address = 0x7f000001; //127.0.0.1 //TO DO: Add more server stuff here } else { //Client //Resolve the name of the server //Read POSIX socket to populate Generic IP Address ublox_blocked_namelookup(pUbloxModemUdpStruct, commStruct->hostname, (int *) &commStruct->socketIP.address); pUbloxModemUdpStruct->hostnameIp = commStruct->socketIP.address; } }
void vmisc_tasks() { uint8_t time_count,time_200ms; portTickType ticks_now,ticks_old = 0; uint16_t time_elapsed = 0; modem_config(); ublox_init(); // debug_config(); //configure debug serial port /* * data from external sensors initialized, version M21 * can disable it by commenting here and changing dataFromInternalSensors from 0 to 1 * check externalPackets.h for more information */ if (!(dataFromInternalSensors)) /* initialize external sensors data UART3, debug port and this can't be enabled together */ externalDataPortInit(); RPM_config(); ADC_config(); ADC_SoftwareStartConv(ADC1); ADC_3_config(); ADC_SoftwareStartConv(ADC3); PWM_out_config(); for(;;) { if(WDT_status == 1) { IWDG_ReloadCounter(); WDT_status = 0; //clear it so that it can be set again if all is OK } if(xbee_tx_count>0) //enable TX interrupts if transmit data is present USART_ITConfig(USART1, USART_IT_TXE, ENABLE); if(gps_tx.count >0) //enable TX interrupts if transmit data is present USART_ITConfig(USART2, USART_IT_TXE, ENABLE); if(debug_tx_count >0) //enable TX interrupts if transmit data is present USART_ITConfig(USART3, USART_IT_TXE, ENABLE); parse_gps_data(); if(xbee_rx_count) parse_modem_data(); if(xbee_fresh_data) //if received fresh data { calculate_xbee(); //call appropriate function based on received data xbee_fresh_data = 0; } if(log_init_flag) { if(write_buff_to_card == 1) //if one buffer is full { res = f_open(&fil, file_name, FA_OPEN_ALWAYS | FA_WRITE |FA_READ); f_lseek(&fil, cursor_pos); if(log_buff_status == 1) { f_write(&fil, SD_buffer2.BUFFER, SD_buffer2.write_count, &bw); cursor_pos += SD_buffer2.write_count; } else if(log_buff_status == 2) { f_write(&fil, SD_buffer1.BUFFER, SD_buffer1.write_count, &bw); cursor_pos += SD_buffer1.write_count; } write_buff_to_card = 0; f_close(&fil); GPIOF->ODR ^= GPIO_Pin_12; } } ticks_now = xTaskGetTickCount()*2; if((ticks_now - ticks_old) >=100) //do the following every 100ms { time_elapsed = ticks_now - ticks_old; rpm = pulse_cnt*2*60/MOTOR_POLES*(1000/time_elapsed); pulse_cnt = 0; ticks_old = ticks_now; air_speed_indicator(); send_status(); if(link_count >= 5 ) //no data from more than 500ms { modem_link_active = 0; //indicate absence of GIB link_count = 0; } else link_count++; if(time_200ms == 2) //do the following every 200ms { send_gps_data(); time_200ms = 0; } else time_200ms++; if(time_count == 5) //do the following every 500ms { queue_data(); //append debug data for transmission update_battery(); update_RPM(); send_press_temp(); send_defections(); send_power_propulsion(); time_count = 0; } else time_count++; } } }