mirror of
				https://gitea.farpn.net/w1cdn/mwtchahrd.git
				synced 2025-11-03 21:46:35 -06:00 
			
		
		
		
	Cache locations shared in packets.
This commit is contained in:
		
							
								
								
									
										51
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										51
									
								
								src/main.rs
									
									
									
									
									
								
							@@ -378,7 +378,7 @@ impl BufferManager {
 | 
				
			|||||||
/// - Filters out frames destined for "NODES" and frames with an XID payload.
 | 
					/// - Filters out frames destined for "NODES" and frames with an XID payload.
 | 
				
			||||||
/// - Optionally filters to only UI frames if requested.
 | 
					/// - Optionally filters to only UI frames if requested.
 | 
				
			||||||
/// - Buffers multi-line frames and prints a formatted session line.
 | 
					/// - Buffers multi-line frames and prints a formatted session line.
 | 
				
			||||||
fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager) {
 | 
					fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager, loc_store: &mut HashMap<String, Vec<String>>) {
 | 
				
			||||||
    let hdr = &frame.header;
 | 
					    let hdr = &frame.header;
 | 
				
			||||||
    // Process only frames on the specified channel.
 | 
					    // Process only frames on the specified channel.
 | 
				
			||||||
    if hdr.port != cli.channel as i32 {
 | 
					    if hdr.port != cli.channel as i32 {
 | 
				
			||||||
@@ -411,9 +411,26 @@ fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager) {
 | 
				
			|||||||
    
 | 
					    
 | 
				
			||||||
    // Extract location from APRS format
 | 
					    // Extract location from APRS format
 | 
				
			||||||
    let (lat, lon) = aprs_loc(&text);
 | 
					    let (lat, lon) = aprs_loc(&text);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					   // Store the location
 | 
				
			||||||
 | 
					   // Only update location store if there is a real location
 | 
				
			||||||
 | 
					    if lat > -9999.0_f64 && lon > -9999.0_f64 {
 | 
				
			||||||
 | 
					        let loc = vec![lat.to_string(), lon.to_string()];
 | 
				
			||||||
 | 
					        loc_store.insert(source.clone(), loc);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					    // Look up a stored location
 | 
				
			||||||
 | 
					    // If it doesn't exist, set to empty
 | 
				
			||||||
 | 
					    let stored_loc = match loc_store.get(&source) {
 | 
				
			||||||
 | 
					        Some(loc_value) => loc_value,
 | 
				
			||||||
 | 
					        None => &vec!["".to_string(), "".to_string()],
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    // Only send good locations on
 | 
					    // Only send good locations on
 | 
				
			||||||
    let json_lat = if lat > -9999.0_f64 && lon > -9999.0_f64 { lat.to_string() } else { "".to_string() }; // send nothing
 | 
					    let json_lat = stored_loc[0].clone() ; 
 | 
				
			||||||
    let json_lon = if lat > -9999.0_f64 && lon > -9999.0_f64 { lon.to_string() } else { "".to_string() }; // send nothing
 | 
					    let json_lon = stored_loc[1].clone() ; 
 | 
				
			||||||
 | 
					    //let json_lat = if lat > -9999.0_f64 && lon > -9999.0_f64 { lat.to_string() } else { old_loc[0].clone() }; 
 | 
				
			||||||
 | 
					    //let json_lon = if lat > -9999.0_f64 && lon > -9999.0_f64 { lon.to_string() } else { old_loc[1].clone() }; 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Ignore frames where the basic destination contains "NODES" (case‑insensitive).
 | 
					    // Ignore frames where the basic destination contains "NODES" (case‑insensitive).
 | 
				
			||||||
    if basic_destination.to_uppercase().contains("NODES") {
 | 
					    if basic_destination.to_uppercase().contains("NODES") {
 | 
				
			||||||
@@ -440,6 +457,18 @@ fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager) {
 | 
				
			|||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    // In non-debug mode, print the session line and any additional lines.
 | 
				
			||||||
 | 
					    if !cli.debug {
 | 
				
			||||||
 | 
					        print_session_line(×tamp, &source, &final_destination, &summary);
 | 
				
			||||||
 | 
					        if lines.len() > 1 {
 | 
				
			||||||
 | 
					            for line in &lines[1..] {
 | 
				
			||||||
 | 
					                println!("{}", line);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    println!("Stored location: {} {}", stored_loc[0].clone(), stored_loc[1].clone());
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    // If Spothole is enabled
 | 
					    // If Spothole is enabled
 | 
				
			||||||
    if summary == "UI" && cli.spothole {
 | 
					    if summary == "UI" && cli.spothole {
 | 
				
			||||||
    // POST JSON
 | 
					    // POST JSON
 | 
				
			||||||
@@ -486,16 +515,6 @@ fn handle_frame(frame: &AgwFrame, cli: &Cli, buffers: &mut BufferManager) {
 | 
				
			|||||||
        });
 | 
					        });
 | 
				
			||||||
        let _ = socket.expect("REASON").send_to(packet.to_string().as_bytes(), uaddr);
 | 
					        let _ = socket.expect("REASON").send_to(packet.to_string().as_bytes(), uaddr);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    // In non-debug mode, print the session line and any additional lines.
 | 
					 | 
				
			||||||
    if !cli.debug {
 | 
					 | 
				
			||||||
        print_session_line(×tamp, &source, &final_destination, &summary);
 | 
					 | 
				
			||||||
        if lines.len() > 1 {
 | 
					 | 
				
			||||||
            for line in &lines[1..] {
 | 
					 | 
				
			||||||
                println!("{}", line);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -554,6 +573,10 @@ fn main() -> Result<()> {
 | 
				
			|||||||
    let uaddr = format!("{}:{}", cli.uip, cli.uport);
 | 
					    let uaddr = format!("{}:{}", cli.uip, cli.uport);
 | 
				
			||||||
    let reconnect_delay_ms = 5000;
 | 
					    let reconnect_delay_ms = 5000;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    // Set up the location store
 | 
				
			||||||
 | 
					    //let mut loc_store = HashMap:: new();
 | 
				
			||||||
 | 
					    let mut loc_store: HashMap<String, Vec<String>> = HashMap::new();
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    if cli.uport != 55555 {
 | 
					    if cli.uport != 55555 {
 | 
				
			||||||
        // Bind the client socket to any available address and port
 | 
					        // Bind the client socket to any available address and port
 | 
				
			||||||
        let socket = UdpSocket::bind("0.0.0.0:0")?;
 | 
					        let socket = UdpSocket::bind("0.0.0.0:0")?;
 | 
				
			||||||
@@ -601,7 +624,7 @@ fn main() -> Result<()> {
 | 
				
			|||||||
                            while buffer.len() >= 36 {
 | 
					                            while buffer.len() >= 36 {
 | 
				
			||||||
                                match parse_frame(&buffer, cli.debug) {
 | 
					                                match parse_frame(&buffer, cli.debug) {
 | 
				
			||||||
                                    Ok((consumed, frame)) => {
 | 
					                                    Ok((consumed, frame)) => {
 | 
				
			||||||
                                        handle_frame(&frame, &cli, &mut buffers);
 | 
					                                        handle_frame(&frame, &cli, &mut buffers, &mut loc_store);
 | 
				
			||||||
                                        // Remove the processed frame from the buffer.
 | 
					                                        // Remove the processed frame from the buffer.
 | 
				
			||||||
                                        buffer.drain(0..consumed);
 | 
					                                        buffer.drain(0..consumed);
 | 
				
			||||||
                                    }
 | 
					                                    }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user