@@ -56,7 +56,7 @@ def setReconnectRCId(self, rc_id: str):
5656 self .reconnect_RC_id = rc_id
5757 self .reconnect_enabled = True
5858 self .reconnect_keep_alive_ms = 0
59- def validateConnection (self ):
59+ def validateConnection (self ) -> bool :
6060 #print("validateConnection")
6161 need_reconnect = False
6262 if self .last_keep_alive_ms > 0 :
@@ -87,6 +87,7 @@ def validateConnection(self):
8787 #_ConnectVersion = _ConnectVersion + 1;
8888 self .reconnect_keep_alive_ms = 0
8989 self .last_keep_alive_ms = time .ticks_ms ()
90+ return not need_reconnect
9091 def isReconnecting (self ) -> bool :
9192 return self .reconnecting ;
9293
@@ -146,9 +147,11 @@ def release(self):
146147 self ._connected = False
147148 self ._connected_iop = None
148149
149- def toggleDebugLed (self ):
150- pass
151- def switchDebugLed (self , on ):
150+ # def toggleDebugLed(self):
151+ # pass
152+ # def switchDebugLed(self, on):
153+ # pass
154+ def onDetectedDisconnect (self ):
152155 pass
153156 def onSendCommandException (self , error ):
154157 pass
@@ -184,7 +187,7 @@ def _connect(self):
184187 if self ._connected :
185188 return
186189
187- self .switchDebugLed (True )
190+ # self.switchDebugLed(True)
188191 self ._io .preconnect ()
189192
190193 # > ddhello and < ddhello
@@ -194,7 +197,7 @@ def _connect(self):
194197 now = time .ticks_ms ()
195198 if now > next_time :
196199 iop .print ('ddhello\n ' )
197- self .toggleDebugLed ()
200+ # self.toggleDebugLed()
198201 next_time = now + _HS_GAP
199202 if iop .available ():
200203 data = iop .read ()
@@ -211,7 +214,7 @@ def _connect(self):
211214 now = time .ticks_ms ()
212215 if now > next_time :
213216 iop .print ('>init>:' + _DD_SID + '\n ' )
214- self .toggleDebugLed ()
217+ # self.toggleDebugLed()
215218 next_time = now + _HS_GAP
216219 if iop .available ():
217220 data = iop .read ()
@@ -225,12 +228,12 @@ def _connect(self):
225228
226229 self ._connected = True
227230 self ._compatibility = compatibility
228- self .switchDebugLed (False )
231+ # self.switchDebugLed(False)
229232 #print('connected:' + str(compatibility))
230233
231234 def _sendSpecial (self , special_type : str , special_id : str , special_command : str , special_data : str ):
232235 ##print("lt:" + str(special_command) + ":" + str(special_data))#####
233- self .switchDebugLed (True )
236+ # self.switchDebugLed(True)
234237 self ._io .print ('%%>' )
235238 self ._io .print (special_type )
236239 self ._io .print ('.' )
@@ -242,10 +245,10 @@ def _sendSpecial(self, special_type: str, special_id: str, special_command: str,
242245 if special_data != None :
243246 self ._io .print (special_data )
244247 self ._io .print ('\n ' )
245- self .switchDebugLed (False )
248+ # self.switchDebugLed(False)
246249 def _sendCommand (self , layer_id : str , command : str , * params ):
247250 self ._checkForFeedback ()
248- self .switchDebugLed (True )
251+ # self.switchDebugLed(True)
249252 try :
250253 if layer_id != None :
251254 self ._io .print (layer_id )
@@ -323,7 +326,8 @@ def _checkForFeedback(self):
323326 except :
324327 pass
325328 def _readFeedback (self ) -> str :
326- self ._validateConnection ()
329+ if not self ._validateConnection ():
330+ self .onDetectedDisconnect ()
327331 if not self ._connected_iop .available ():
328332 return None
329333 feedback = self ._connected_iop .read ()
@@ -338,8 +342,11 @@ def _validateConnection(self):
338342 now = time .ticks_ms ()
339343 diff_ms = now - self .last_validate_ms
340344 if diff_ms >= validate_gap :
341- self ._connected_iop .validateConnection ()
345+ res = self ._connected_iop .validateConnection ()
342346 self .last_validate_ms = now
347+ else :
348+ res = True
349+ return res
343350 def _setReconnectRCId (self , rc_id : str ):
344351 if self ._connected_iop :
345352 self ._connected_iop .setReconnectRCId (rc_id )
0 commit comments