main/ims_udp.c
/*
 * Send data over udp only to primary remote
 */
Send data over udp only to primary remote
Send data over udp only to primary remote
void udp_tx_rawdata_task(void *pvParameter){
	adc_data_t in;
	uint8_t outbuf[sizeof(in.nodeid) + sizeof(in.counter) + sizeof(in.data) + 3];
	for(;;){
		if(xQueueReceive( globalPtrs->udp_tx_q, &in, pdMS_TO_TICKS(5000))) {
			if((xEventGroupGetBits(globalPtrs->wifi_event_group ) & UDP_ENABLED)) {
				outbuf[1] =	in.nodeid;
				outbuf[2] = in.counter;
				outbuf[3] = in.counter >> 8;
				outbuf[4] = in.counter >> 16;
				outbuf[5] = in.counter >> 24;
				for (int ii = 0; ii < sizeof(in.data); ii++){
					outbuf[6 + ii] = *((uint8_t *)in.data + ii);
				}
				outbuf[14] = getCRC8(&outbuf[0], sizeof(outbuf));
				sendto(udpParams.udpConnection[0].socket, outbuf, sizeof(outbuf), 0, (struct sockaddr * ) &udpParams.udpConnection[0].udpRemote, sizeof(udpParams.udpConnection[0].udpRemote));
				udpParams.idlecount = 0;
			}
		}
		udpParams.idlecount++;
		if(udpParams.idlecount >= 24){
			ESP_LOGI(TAG, "wifi keep-alive");
			udpParams.idlecount = 0;
			if(xEventGroupGetBits( globalPtrs->wifi_event_group ) & (UDP_ENABLED)) {
				sendto(udpParams.udpConnection[0].socket, &udpParams.idlecount, sizeof(int), 0, (struct sockaddr * ) &udpParams.udpConnection[0].udpRemote, sizeof(udpParams.udpConnection[0].udpRemote));
			}
		}
	}
}
void udp_tx_rawdata_task ( void * pvParameter ) { adc_data_t in ; uint8_t outbuf [ sizeof ( in . nodeid ) + sizeof ( in . counter ) + sizeof ( in . data ) + 3 ] ; for ( ; ; ) { if ( xQueueReceive ( globalPtrs -> udp_tx_q , & in , pdMS_TO_TICKS ( 5000 ) ) ) { if ( ( xEventGroupGetBits ( globalPtrs -> wifi_event_group ) & UDP_ENABLED ) ) { outbuf [ 1 ] = in . nodeid ; outbuf [ 2 ] = in . counter ; outbuf [ 3 ] = in . counter >> 8 ; outbuf [ 4 ] = in . counter >> 16 ; outbuf [ 5 ] = in . counter >> 24 ; for ( int ii = 0 ; ii < sizeof ( in . data ) ; ii ++ ) { outbuf [ 6 + ii ] = * ( ( uint8_t * ) in . data + ii ) ; } outbuf [ 14 ] = getCRC8 ( & outbuf [ 0 ] , sizeof ( outbuf ) ) ; sendto ( udpParams . udpConnection [ 0 ] . socket , outbuf , sizeof ( outbuf ) , 0 , ( struct sockaddr * ) & udpParams . udpConnection [ 0 ] . udpRemote , sizeof ( udpParams . udpConnection [ 0 ] . udpRemote ) ) ; udpParams . idlecount = 0 ; } } udpParams . idlecount ++ ; if ( udpParams . idlecount >= 24 ) { ESP_LOGI ( TAG , " " ) ; udpParams . idlecount = 0 ; if ( xEventGroupGetBits ( globalPtrs -> wifi_event_group ) & ( UDP_ENABLED ) ) { sendto ( udpParams . udpConnection [ 0 ] . socket , & udpParams . idlecount , sizeof ( int ) , 0 , ( struct sockaddr * ) & udpParams . udpConnection [ 0 ] . udpRemote , sizeof ( udpParams . udpConnection [ 0 ] . udpRemote ) ) ; } } } }
Send data over udp only to primary remote
Send data over udp only to primary remote
//normal running, send data over UDP //keep the wifi connection alive, send a packet every 120 seconds (@ 1000hz tick rate) //send a zero integer