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_task(void *pvParameter){
	adc_data_t in_raw;
	uint8_t outbuf_raw[13];
	udp_sensor_data_t in;
	uint8_t outbuf[6];
	uint8_t msg_id = 0x00;
	for(;;){
		if(xQueuePeek( globalPtrs->udp_tx_q, &in_raw, pdMS_TO_TICKS(5000))) {
			if((xEventGroupGetBits(globalPtrs->wifi_event_group ) & UDP_ENABLED )) {
				if((xEventGroupGetBits(globalPtrs->system_event_group ) & SEND_RAW_DATA_ONLY ) > 0) {
					int ii = 0, ii_0 = 0;
					int data_pnt_offset = 0;
					xQueueReceive( globalPtrs->udp_tx_q, &in_raw, 0);
					outbuf_raw[ii++] = 0x53;			
					outbuf_raw[ii++] = 9; 				
					outbuf_raw[ii++] = in_raw.nodeid;	
					outbuf_raw[ii++] = in_raw.counter;	
					ii_0 = ii;
					for (; ii < (ii_0 + sizeof(in_raw.data)); ii++){
						outbuf_raw[ii] = *((uint8_t *)in_raw.data + data_pnt_offset);
						data_pnt_offset++;
					}
					outbuf_raw[12] = getCRC8(&outbuf_raw[0], sizeof(outbuf_raw));
					sendto(udpParams.udpConnection[0].socket, outbuf_raw, sizeof(outbuf_raw), 0, (struct sockaddr * ) &udpParams.udpConnection[0].udpRemote, sizeof(udpParams.udpConnection[0].udpRemote));
					udpParams.idlecount = 0;
				}
				else if((xEventGroupGetBits(globalPtrs->system_event_group ) & SEND_RAW_DATA_ONLY ) == 0) {
					xQueueReceive( globalPtrs->udp_tx_q, &in, 0);
					outbuf[0] = 0x53;				
					outbuf[1] =	2;					
					outbuf[2] = in.nodeid + msg_id;	
					outbuf[3] = in.counter;			
					outbuf[4] = in.data;			
					outbuf_raw[5] = getCRC8(&outbuf_raw[0], sizeof(outbuf_raw));
					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_task ( void * pvParameter ) { adc_data_t in_raw ; uint8_t outbuf_raw [ 13 ] ; udp_sensor_data_t in ; uint8_t outbuf [ 6 ] ; uint8_t msg_id = 0x00 ; for ( ; ; ) { if ( xQueuePeek ( globalPtrs -> udp_tx_q , & in_raw , pdMS_TO_TICKS ( 5000 ) ) ) { if ( ( xEventGroupGetBits ( globalPtrs -> wifi_event_group ) & UDP_ENABLED ) ) { if ( ( xEventGroupGetBits ( globalPtrs -> system_event_group ) & SEND_RAW_DATA_ONLY ) > 0 ) { int ii = 0 , ii_0 = 0 ; int data_pnt_offset = 0 ; xQueueReceive ( globalPtrs -> udp_tx_q , & in_raw , 0 ) ; outbuf_raw [ ii ++ ] = 0x53 ; outbuf_raw [ ii ++ ] = 9 ; outbuf_raw [ ii ++ ] = in_raw . nodeid ; outbuf_raw [ ii ++ ] = in_raw . counter ; ii_0 = ii ; for ( ; ii < ( ii_0 + sizeof ( in_raw . data ) ) ; ii ++ ) { outbuf_raw [ ii ] = * ( ( uint8_t * ) in_raw . data + data_pnt_offset ) ; data_pnt_offset ++ ; } outbuf_raw [ 12 ] = getCRC8 ( & outbuf_raw [ 0 ] , sizeof ( outbuf_raw ) ) ; sendto ( udpParams . udpConnection [ 0 ] . socket , outbuf_raw , sizeof ( outbuf_raw ) , 0 , ( struct sockaddr * ) & udpParams . udpConnection [ 0 ] . udpRemote , sizeof ( udpParams . udpConnection [ 0 ] . udpRemote ) ) ; udpParams . idlecount = 0 ; } else if ( ( xEventGroupGetBits ( globalPtrs -> system_event_group ) & SEND_RAW_DATA_ONLY ) == 0 ) { xQueueReceive ( globalPtrs -> udp_tx_q , & in , 0 ) ; outbuf [ 0 ] = 0x53 ; outbuf [ 1 ] = 2 ; outbuf [ 2 ] = in . nodeid + msg_id ; outbuf [ 3 ] = in . counter ; outbuf [ 4 ] = in . data ; outbuf_raw [ 5 ] = getCRC8 ( & outbuf_raw [ 0 ] , sizeof ( outbuf_raw ) ) ; 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
//receive raw sensor data //start byte //length //node id //counter //					outbuf_raw[12] = getChecksum(&outbuf_raw[0], sizeof(outbuf_raw)); //receive calibrated sensor data //start byte //length //msg_id //counter //data //					outbuf[5] = getChecksum(&outbuf[0], sizeof(outbuf)); //keep the wifi connection alive, send a packet every 120 seconds (@ 1000hz tick rate) //send a zero integer