@@ -50,14 +50,26 @@ public static ExitCodes SetVcpBaudRate(
5050 return ExitCodes . E8002 ;
5151 }
5252
53+ Console . ForegroundColor = ConsoleColor . White ;
54+
5355 // launch silink
56+ if ( verbosity >= VerbosityLevel . Detailed )
57+ {
58+ Console . WriteLine ( "Launching silink..." ) ;
59+ }
60+
5461 var silinkCli = RunSilinkCLI ( Path . Combine ( probeId ) ) ;
5562
5663 var silinkSocket = new Socket ( AddressFamily . InterNetwork , SocketType . Stream , ProtocolType . Tcp ) ;
5764 IPEndPoint silinkEndPoint = new ( IPAddress . Parse ( "127.0.0.1" ) , SilinkAdminPort ) ;
5865
5966 try
6067 {
68+ if ( verbosity >= VerbosityLevel . Diagnostic )
69+ {
70+ Console . WriteLine ( "Connecting to admin console..." ) ;
71+ }
72+
6173 silinkSocket . Connect ( silinkEndPoint ) ;
6274
6375 Thread . Sleep ( 250 ) ;
@@ -66,13 +78,23 @@ public static ExitCodes SetVcpBaudRate(
6678 byte [ ] buffer = Encoding . Default . GetBytes ( "serial vcom\r " ) ;
6779 silinkSocket . Send ( buffer ) ;
6880
81+ if ( verbosity >= VerbosityLevel . Diagnostic )
82+ {
83+ Console . WriteLine ( "Querying current config..." ) ;
84+ }
85+
6986 Thread . Sleep ( 250 ) ;
7087
7188 buffer = new byte [ 1024 ] ;
7289 int receiveCount = silinkSocket . Receive ( buffer , 0 , buffer . Length , 0 ) ;
7390
7491 var currentConfig = Encoding . Default . GetString ( buffer , 0 , receiveCount ) ;
7592
93+ if ( verbosity >= VerbosityLevel . Diagnostic )
94+ {
95+ Console . WriteLine ( $ "{ currentConfig } ") ;
96+ }
97+
7698 if ( ! string . IsNullOrEmpty ( currentConfig ) )
7799 {
78100 // interpret reply
@@ -86,21 +108,30 @@ public static ExitCodes SetVcpBaudRate(
86108 // verify current setting
87109 if ( int . TryParse ( currentBaud . Groups [ "baudrate" ] . Value , out int baudRate ) && baudRate == TargetBaudRate )
88110 {
111+ if ( verbosity >= VerbosityLevel . Detailed )
112+ {
113+ Console . WriteLine ( "VCP baud rate it's correct! Nothing to do here." ) ;
114+ }
115+
89116 return ExitCodes . OK ;
90117 }
91118 }
92119
93120 // need to set baud rate because it's different
94121
95- if ( verbosity > = VerbosityLevel . Normal )
122+ if ( verbosity = = VerbosityLevel . Normal )
96123 {
97- Console . Write ( "Setting VCP baud rate..." ) ;
124+ Console . Write ( "Trying to set VCP baud rate..." ) ;
125+ }
126+ else if ( verbosity > VerbosityLevel . Normal )
127+ {
128+ Console . WriteLine ( "Trying to set VCP baud rate..." ) ;
98129 }
99130
100131 Thread . Sleep ( 250 ) ;
101132
102133 // compose command
103- buffer = Encoding . Default . GetBytes ( "serial vcom config speed {TargetBaudRate}\r " ) ;
134+ buffer = Encoding . Default . GetBytes ( $ "serial vcom config speed { TargetBaudRate } \r ") ;
104135 silinkSocket . Send ( buffer ) ;
105136
106137 Thread . Sleep ( 250 ) ;
@@ -110,9 +141,14 @@ public static ExitCodes SetVcpBaudRate(
110141
111142 var opResult = Encoding . Default . GetString ( buffer , 0 , receiveCount ) ;
112143
113- if ( opResult . Contains ( "Baudrate set to 921600 bps" ) )
144+ if ( verbosity >= VerbosityLevel . Diagnostic )
114145 {
115- if ( verbosity >= VerbosityLevel . Normal )
146+ Console . WriteLine ( $ "{ opResult } ") ;
147+ }
148+
149+ if ( opResult . Contains ( $ "Baudrate set to { TargetBaudRate } bps") )
150+ {
151+ if ( verbosity == VerbosityLevel . Normal )
116152 {
117153 Console . ForegroundColor = ConsoleColor . Green ;
118154 Console . WriteLine ( " OK" ) ;
@@ -121,12 +157,16 @@ public static ExitCodes SetVcpBaudRate(
121157
122158 Console . ForegroundColor = ConsoleColor . White ;
123159 }
160+ else if ( verbosity > VerbosityLevel . Normal )
161+ {
162+ Console . WriteLine ( "Success!" ) ;
163+ }
124164
125165 return ExitCodes . OK ;
126166 }
127167 else
128168 {
129- if ( verbosity > = VerbosityLevel . Normal )
169+ if ( verbosity = = VerbosityLevel . Normal )
130170 {
131171 Console . ForegroundColor = ConsoleColor . Red ;
132172 Console . WriteLine ( "FAILED!" ) ;
@@ -139,6 +179,13 @@ public static ExitCodes SetVcpBaudRate(
139179 Console . ForegroundColor = ConsoleColor . White ;
140180 Console . WriteLine ( "" ) ;
141181 }
182+ else if ( verbosity > VerbosityLevel . Normal )
183+ {
184+ Console . ForegroundColor = ConsoleColor . Red ;
185+ Console . WriteLine ( "FAILED!" ) ;
186+ Console . ForegroundColor = ConsoleColor . White ;
187+ Console . WriteLine ( "" ) ;
188+ }
142189
143190 return ExitCodes . E8002 ;
144191 }
@@ -149,7 +196,7 @@ public static ExitCodes SetVcpBaudRate(
149196 Console . WriteLine ( "" ) ;
150197 Console . ForegroundColor = ConsoleColor . Red ;
151198
152- Console . WriteLine ( $ "Error occurred: { ex . Message } ") ;
199+ Console . WriteLine ( $ "Exception occurred: { ex . Message } ") ;
153200
154201 Console . ForegroundColor = ConsoleColor . White ;
155202 Console . WriteLine ( "" ) ;
0 commit comments