@@ -22,7 +22,6 @@ use parking_lot::Mutex;
2222use serde:: { Deserialize , Serialize } ;
2323use serialport:: FlowControl ;
2424
25- use crate :: connection:: Connection ;
2625use crate :: constants:: {
2726 APPLICATION_NAME , APPLICATION_ORGANIZATION , APPLICATION_QUALIFIER , CONNECTION_HISTORY_FILENAME ,
2827 DEFAULT_LOG_DIRECTORY , MAX_CONNECTION_HISTORY , MPS ,
@@ -38,6 +37,7 @@ use crate::update_tab::UpdateTabUpdate;
3837use crate :: utils:: send_conn_state;
3938use crate :: watch:: { WatchReceiver , Watched } ;
4039use crate :: { client_sender:: BoxedClientSender , main_tab:: logging_stats_thread} ;
40+ use crate :: { common_constants:: ConnectionType , connection:: Connection } ;
4141use crate :: {
4242 common_constants:: { self as cc, SbpLogging } ,
4343 status_bar:: Heartbeat ,
@@ -147,6 +147,9 @@ impl SharedState {
147147 pub fn serial_history ( & self ) -> IndexMap < String , SerialConfig > {
148148 self . lock ( ) . connection_history . serial_configs ( )
149149 }
150+ pub fn connection_type_history ( & self ) -> ConnectionType {
151+ self . lock ( ) . connection_history . last_connection_type . clone ( )
152+ }
150153 pub fn update_folder_history ( & self , folder : PathBuf ) {
151154 let folder = String :: from ( folder. to_str ( ) . expect ( CONVERT_TO_STR_FAILURE ) ) ;
152155 self . lock ( ) . connection_history . record_folder ( folder) ;
@@ -713,6 +716,17 @@ pub struct ConnectionHistory {
713716 files : IndexSet < String > ,
714717 folders : IndexSet < String > ,
715718 serial_configs : IndexMap < String , SerialConfig > ,
719+ #[ serde( with = "ConnectionTypeDef" ) ]
720+ last_connection_type : ConnectionType ,
721+ }
722+
723+ // https://serde.rs/remote-derive.html
724+ #[ derive( Serialize , Deserialize ) ]
725+ #[ serde( remote = "ConnectionType" ) ]
726+ enum ConnectionTypeDef {
727+ Tcp ,
728+ File ,
729+ Serial ,
716730}
717731
718732impl Default for ConnectionHistory {
@@ -739,6 +753,7 @@ impl ConnectionHistory {
739753 files : IndexSet :: new ( ) ,
740754 folders,
741755 serial_configs : IndexMap :: new ( ) ,
756+ last_connection_type : ConnectionType :: Serial ,
742757 }
743758 }
744759 /// Return the filename of the saved connection history file.
@@ -772,6 +787,7 @@ impl ConnectionHistory {
772787 self . addresses . insert ( address) ;
773788 let diff = i32:: max ( 0 , self . addresses . len ( ) as i32 - MAX_CONNECTION_HISTORY ) ;
774789 self . addresses = self . addresses . split_off ( diff as usize ) ;
790+ self . last_connection_type = ConnectionType :: Tcp ;
775791
776792 if let Err ( e) = self . save ( ) {
777793 error ! ( "Unable to save connection history, {}." , e) ;
@@ -786,6 +802,7 @@ impl ConnectionHistory {
786802 self . files . insert ( filename) ;
787803 let diff = i32:: max ( 0 , self . files . len ( ) as i32 - MAX_CONNECTION_HISTORY ) ;
788804 self . files = self . files . split_off ( diff as usize ) ;
805+ self . last_connection_type = ConnectionType :: File ;
789806
790807 if let Err ( e) = self . save ( ) {
791808 error ! ( "Unable to save connection history, {}." , e) ;
@@ -818,6 +835,7 @@ impl ConnectionHistory {
818835 self . serial_configs . insert ( device, serial) ;
819836 let diff = i32:: max ( 0 , self . serial_configs . len ( ) as i32 - MAX_CONNECTION_HISTORY ) ;
820837 self . serial_configs = self . serial_configs . split_off ( diff as usize ) ;
838+ self . last_connection_type = ConnectionType :: Serial ;
821839
822840 if let Err ( e) = self . save ( ) {
823841 error ! ( "Unable to save connection history, {}." , e) ;
@@ -943,6 +961,7 @@ mod tests {
943961 let first_addy = addresses. first ( ) . unwrap ( ) ;
944962 assert_eq ! ( host1, first_addy. host) ;
945963 assert_eq ! ( port, first_addy. port) ;
964+ assert_eq ! ( ConnectionType :: Tcp , conn_history. last_connection_type) ;
946965
947966 conn_history. record_address ( host2. clone ( ) , port) ;
948967 let addresses = conn_history. addresses ( ) ;
@@ -972,6 +991,7 @@ mod tests {
972991 let files = conn_history. files ( ) ;
973992 assert_eq ! ( filename1, files[ 1 ] ) ;
974993 assert_eq ! ( filename2, files[ 0 ] ) ;
994+ assert_eq ! ( ConnectionType :: File , conn_history. last_connection_type) ;
975995
976996 for ele in 0 ..MAX_CONNECTION_HISTORY {
977997 conn_history. record_file ( ele. to_string ( ) ) ;
@@ -987,13 +1007,16 @@ mod tests {
9871007 backup_file ( bfilename. clone ( ) ) ;
9881008
9891009 let mut conn_history = ConnectionHistory :: new ( ) ;
1010+ assert_eq ! ( ConnectionType :: Serial , conn_history. last_connection_type) ;
9901011
9911012 let configs = conn_history. serial_configs ( ) ;
9921013 assert_eq ! ( configs. keys( ) . len( ) , 0 ) ;
9931014
9941015 conn_history. record_serial ( "/dev/ttyUSB0" . to_string ( ) , 115200 , FlowControl :: Software ) ;
9951016 conn_history. record_serial ( "/dev/ttyUSB0" . to_string ( ) , 115200 , FlowControl :: None ) ;
9961017
1018+ assert_eq ! ( ConnectionType :: Serial , conn_history. last_connection_type) ;
1019+
9971020 let configs = conn_history. serial_configs ( ) ;
9981021
9991022 // Should only store one serial record despite the settings changing
0 commit comments