@@ -38,9 +38,7 @@ public class SdkConnection
38
38
private Dictionary < System . Type , Dictionary < object , iCallback > > _callbacks = new Dictionary < System . Type , Dictionary < object , iCallback > > ( ) ;
39
39
private List < Action > _inFlightActions = new List < Action > ( ) ;
40
40
private bool _open = false ;
41
- private byte _currentRobotId = byte . MaxValue ;
42
-
43
- public byte CurrentRobotId { get { return _currentRobotId ; } }
41
+ private bool _robotIsConnected = false ;
44
42
45
43
public SdkConnection ( string ip , int socket , bool verboseLogging = false )
46
44
{
@@ -62,7 +60,7 @@ public SdkConnection(string ip, int socket, bool verboseLogging = false)
62
60
_open = true ;
63
61
64
62
// wait for robot
65
- while ( _currentRobotId == byte . MaxValue )
63
+ while ( ! _robotIsConnected )
66
64
{
67
65
Thread . Sleep ( 5 ) ;
68
66
}
@@ -85,7 +83,7 @@ public void Close()
85
83
86
84
public Action SendAction < T > ( T state , int numRetries = 0 , bool inParallel = false )
87
85
{
88
- Action result = new Action ( this , _currentRobotId ) ;
86
+ Action result = new Action ( this ) ;
89
87
result . Initialize ( state , numRetries , inParallel ) ;
90
88
91
89
_inFlightActions . Add ( result ) ;
@@ -136,7 +134,6 @@ private void SendMessageInternal(SDKMessageOut messageOut)
136
134
private void ReceiveMessage ( SDKMessageIn messageIn )
137
135
{
138
136
var message = messageIn . Message ;
139
-
140
137
if ( _verboseLogging ) { System . Console . WriteLine ( "Recieved Message - " + message . GetTag ( ) ) ; }
141
138
142
139
// since the property to access individual message data in a CLAD message shares its name
@@ -154,13 +151,10 @@ private void ReceiveMessage(SDKMessageIn messageIn)
154
151
}
155
152
}
156
153
157
- // does this give us a robot id?
158
- string robotIDPropertyName = "robotID" ;
159
- if ( _currentRobotId == byte . MaxValue && messageData . GetType ( ) . GetProperty ( robotIDPropertyName ) != null )
154
+ if ( ! _robotIsConnected && message . GetTag ( ) == Anki . Cozmo . ExternalInterface . MessageEngineToGame . Tag . RobotState )
160
155
{
161
- uint robotId = ( uint ) messageData . GetType ( ) . GetProperty ( robotIDPropertyName ) . GetValue ( messageData , null ) ;
162
- _currentRobotId = ( byte ) robotId ;
163
- System . Console . WriteLine ( "Robot connected with id " + _currentRobotId . ToString ( ) ) ;
156
+ _robotIsConnected = true ;
157
+ System . Console . WriteLine ( "Robot connected!" ) ;
164
158
}
165
159
}
166
160
0 commit comments