@@ -29,13 +29,22 @@ public class Nabaztag
29
29
public delegate void AsrEventHandler ( object sender , AsrEvent state ) ;
30
30
public event AsrEventHandler AsrEvent ;
31
31
32
+ /// <summary>
33
+ /// SStatistics on uptime, hardware, model
34
+ /// </summary>
35
+ public Statistics Statistics { get ; internal set ; }
36
+
37
+ /// <summary>
38
+ /// The state of the Nabaztag
39
+ /// </summary>
32
40
public NabState State { get ; internal set ; }
33
41
34
42
public Nabaztag ( ) : this ( "localhost" , DefaultTcpPortEmmit )
35
43
{ }
36
44
37
45
public Nabaztag ( string hostName , int tcpPort )
38
46
{
47
+ Statistics = new Statistics ( ) ;
39
48
_TcpClient = new TcpClient ( hostName , tcpPort ) ;
40
49
Task . Factory . StartNew ( ( ) => ProcessIncoming ( ) ) ;
41
50
}
@@ -261,6 +270,19 @@ private Response SendMessageProcessResponse(string toSend, Guid reqId, int cance
261
270
return _LastRequestId [ reqId . ToString ( ) ] ;
262
271
}
263
272
273
+ public Statistics GetStatistics ( )
274
+ {
275
+ Paquet paquet = new Paquet ( ) { Type = PaquetType . Statistics } ;
276
+ Guid reqId ;
277
+
278
+ reqId = Guid . NewGuid ( ) ;
279
+ _LastRequestId . Add ( reqId . ToString ( ) , null ) ;
280
+ paquet . RequestId = reqId . ToString ( ) ;
281
+
282
+ var res = SendMessageProcessResponse ( JsonConvert . SerializeObject ( paquet ) , reqId , 30 ) ;
283
+ return Statistics ;
284
+ }
285
+
264
286
private void ProcessIncoming ( )
265
287
{
266
288
// Listen to tcp
@@ -285,6 +307,7 @@ private void ProcessIncoming()
285
307
{
286
308
case PaquetType . State :
287
309
State = JsonConvert . DeserializeObject < NabState > ( result ) ;
310
+ Statistics . State = State . State ;
288
311
StateEvent ? . Invoke ( this , State ) ;
289
312
break ;
290
313
case PaquetType . EarsEvent :
@@ -298,16 +321,29 @@ private void ProcessIncoming()
298
321
break ;
299
322
case PaquetType . Response :
300
323
var response = JsonConvert . DeserializeObject < Response > ( result ) ;
301
- if ( response . RequestId ! = null )
324
+ if ( response . Status = = null )
302
325
{
303
- _LastRequestId [ response . RequestId ] = response ;
326
+ // We had a statistics in there
327
+ Statistics . Hardware = response . Hardware ;
328
+ Statistics . State = response . State ;
329
+ Statistics . Uptime = response . Uptime ;
330
+ Statistics . Connections = response . Connections ;
304
331
}
305
332
333
+ if ( response . RequestId != null )
334
+ {
335
+ // If the Response.Status is null then it's the answer to the statistics
336
+ _LastRequestId [ response . RequestId ] = response . Status == null ? new Response ( ) { Status = Status . Ok } : response ;
337
+ }
338
+
306
339
break ;
307
340
case PaquetType . AsrEvent :
308
341
var asrEvent = JsonConvert . DeserializeObject < AsrEvent > ( result ) ;
309
342
AsrEvent ? . Invoke ( this , asrEvent ) ;
310
343
break ;
344
+ case PaquetType . Statistics :
345
+ Statistics = JsonConvert . DeserializeObject < Statistics > ( result ) ;
346
+ break ;
311
347
default :
312
348
break ;
313
349
}
0 commit comments