@@ -323,19 +323,78 @@ private async void BUT_graphmavlog_Click(object sender, EventArgs e)
323323
324324 // Form selectform;
325325
326- private static string ReplaceLastOccurrence ( string Source , string Find , string Replace )
327- {
328- int place = Source . LastIndexOf ( Find ) ;
329-
330- if ( place == - 1 )
326+ private static string ReplaceLastOccurrence ( string Source , string Find , string Replace )
327+ {
328+ int place = Source . LastIndexOf ( Find ) ;
329+
330+ if ( place == - 1 )
331331 return Source ;
332332
333- string result = Source . Remove ( place , Find . Length ) . Insert ( place , Replace ) ;
334- return result ;
335- }
336-
337- private async Task < List < string > > GetLogFileValidFields ( string logfile )
338- {
333+ string result = Source . Remove ( place , Find . Length ) . Insert ( place , Replace ) ;
334+ return result ;
335+ }
336+
337+ private static bool IsGraphableNumericType ( Type type )
338+ {
339+ switch ( Type . GetTypeCode ( type ) )
340+ {
341+ case TypeCode . Single :
342+ case TypeCode . Int16 :
343+ case TypeCode . UInt16 :
344+ case TypeCode . Byte :
345+ case TypeCode . SByte :
346+ case TypeCode . Int32 :
347+ case TypeCode . UInt32 :
348+ case TypeCode . Int64 :
349+ case TypeCode . UInt64 :
350+ case TypeCode . Double :
351+ return true ;
352+ default :
353+ return false ;
354+ }
355+ }
356+
357+ private static bool TryAddGraphValue ( PointPairList list , XDate time , object value )
358+ {
359+ switch ( Type . GetTypeCode ( value . GetType ( ) ) )
360+ {
361+ case TypeCode . Single :
362+ list . Add ( time , ( Single ) value ) ;
363+ return true ;
364+ case TypeCode . Int16 :
365+ list . Add ( time , ( short ) value ) ;
366+ return true ;
367+ case TypeCode . UInt16 :
368+ list . Add ( time , ( ushort ) value ) ;
369+ return true ;
370+ case TypeCode . Byte :
371+ list . Add ( time , ( byte ) value ) ;
372+ return true ;
373+ case TypeCode . SByte :
374+ list . Add ( time , ( sbyte ) value ) ;
375+ return true ;
376+ case TypeCode . Int32 :
377+ list . Add ( time , ( Int32 ) value ) ;
378+ return true ;
379+ case TypeCode . UInt32 :
380+ list . Add ( time , ( UInt32 ) value ) ;
381+ return true ;
382+ case TypeCode . UInt64 :
383+ list . Add ( time , ( ulong ) value ) ;
384+ return true ;
385+ case TypeCode . Int64 :
386+ list . Add ( time , ( long ) value ) ;
387+ return true ;
388+ case TypeCode . Double :
389+ list . Add ( time , ( double ) value ) ;
390+ return true ;
391+ default :
392+ return false ;
393+ }
394+ }
395+
396+ private async Task < List < string > > GetLogFileValidFields ( string logfile )
397+ {
339398 // if (selectform != null && !selectform.IsDisposed)
340399 // selectform.Close();
341400
@@ -431,82 +490,64 @@ private async Task<List<string>> GetLogFileValidFields(string logfile)
431490 }
432491
433492 foreach ( var field in test . GetFields ( ) )
434- {
435- // field.Name has the field's name.
436-
437- object fieldValue = field . GetValue ( data ) ; // Get value
438-
439- if ( field . FieldType . IsArray )
440- {
441- }
442- else
443- {
444- if ( ! seenIt . ContainsKey ( field . DeclaringType . Name + "." + field . Name ) )
445- {
493+ {
494+ // field.Name has the field's name.
495+
496+ object fieldValue = field . GetValue ( data ) ; // Get value
497+ XDate time = new XDate ( mine . lastlogread ) ;
498+
499+ if ( field . FieldType . IsArray )
500+ {
501+ var elementType = field . FieldType . GetElementType ( ) ;
502+
503+ if ( elementType == null || ! IsGraphableNumericType ( elementType ) || ! ( fieldValue is IEnumerable values ) )
504+ continue ;
505+
506+ int index = 0 ;
507+ foreach ( var subValue in values )
508+ {
509+ string indexedFieldName = field . Name + "[" + index + "]" ;
510+ string optionName = field . DeclaringType . Name + "." + indexedFieldName ;
511+ string dataKey = indexedFieldName + " " + field . DeclaringType . Name ;
512+
513+ if ( ! seenIt . ContainsKey ( optionName ) )
514+ {
515+ seenIt [ optionName ] = 1 ;
516+ options . Add ( optionName ) ;
517+ }
518+
519+ if ( ! this . datappl . ContainsKey ( dataKey ) )
520+ this . datappl [ dataKey ] = new PointPairList ( ) ;
521+
522+ if ( ! TryAddGraphValue ( ( PointPairList ) this . datappl [ dataKey ] , time , subValue ) )
523+ {
524+ Console . WriteLine ( "Unknown data type" ) ;
525+ }
526+
527+ index ++ ;
528+ }
529+ }
530+ else
531+ {
532+ if ( ! seenIt . ContainsKey ( field . DeclaringType . Name + "." + field . Name ) )
533+ {
446534 seenIt [ field . DeclaringType . Name + "." + field . Name ] = 1 ;
447535 //AddDataOption(selectform, field.Name + " " + field.DeclaringType.Name);
448536 options . Add ( field . DeclaringType . Name + "." + field . Name ) ;
449537 }
450538
451539 if ( ! this . datappl . ContainsKey ( field . Name + " " + field . DeclaringType . Name ) )
452540 this . datappl [ field . Name + " " + field . DeclaringType . Name ] = new PointPairList ( ) ;
453-
454- PointPairList list =
455- ( ( PointPairList ) this . datappl [ field . Name + " " + field . DeclaringType . Name ] ) ;
456-
457- object value = fieldValue ;
458- // seconds scale
459- //double time = (MavlinkInterface.lastlogread - startlogtime).TotalMilliseconds / 1000.0;
460-
461- XDate time = new XDate ( mine . lastlogread ) ;
462-
463- if ( value . GetType ( ) == typeof ( Single ) )
464- {
465- list . Add ( time , ( Single ) field . GetValue ( data ) ) ;
466- }
467- else if ( value . GetType ( ) == typeof ( short ) )
468- {
469- list . Add ( time , ( short ) field . GetValue ( data ) ) ;
470- }
471- else if ( value . GetType ( ) == typeof ( ushort ) )
472- {
473- list . Add ( time , ( ushort ) field . GetValue ( data ) ) ;
474- }
475- else if ( value . GetType ( ) == typeof ( byte ) )
476- {
477- list . Add ( time , ( byte ) field . GetValue ( data ) ) ;
478- }
479- else if ( value . GetType ( ) == typeof ( sbyte ) )
480- {
481- list . Add ( time , ( sbyte ) field . GetValue ( data ) ) ;
482- }
483- else if ( value . GetType ( ) == typeof ( Int32 ) )
484- {
485- list . Add ( time , ( Int32 ) field . GetValue ( data ) ) ;
486- }
487- else if ( value . GetType ( ) == typeof ( UInt32 ) )
488- {
489- list . Add ( time , ( UInt32 ) field . GetValue ( data ) ) ;
490- }
491- else if ( value . GetType ( ) == typeof ( ulong ) )
492- {
493- list . Add ( time , ( ulong ) field . GetValue ( data ) ) ;
494- }
495- else if ( value . GetType ( ) == typeof ( long ) )
496- {
497- list . Add ( time , ( long ) field . GetValue ( data ) ) ;
498- }
499- else if ( value . GetType ( ) == typeof ( double ) )
500- {
501- list . Add ( time , ( double ) field . GetValue ( data ) ) ;
502- }
503-
504- else
505- {
506- Console . WriteLine ( "Unknown data type" ) ;
507- }
508- }
509- }
541+
542+ PointPairList list =
543+ ( ( PointPairList ) this . datappl [ field . Name + " " + field . DeclaringType . Name ] ) ;
544+
545+ if ( ! TryAddGraphValue ( list , time , fieldValue ) )
546+ {
547+ Console . WriteLine ( "Unknown data type" ) ;
548+ }
549+ }
550+ }
510551 }
511552
512553 mine . logreadmode = false ;
@@ -859,12 +900,13 @@ void chk_box_CheckedChanged(object sender, EventArgs e)
859900 ( PointPairList ) datappl [ ( ( CheckBox ) sender ) . Name ] ,
860901 Color . FromArgb ( unchecked ( colorvalue + ( int ) 0xff000000 ) ) , SymbolType . None ) ;
861902
862- var split = ( ( CheckBox ) sender ) . Name . Split ( ' ' ) ;
863-
864- if ( split . Length == 2 )
865- {
866- var unit = MAVLink . GetUnit ( split [ 0 ] ,
867- name : split [ 1 ] . Replace ( "mavlink_" , "" ) . RemoveFromEnd ( "_t" ) . ToUpper ( ) ) ;
903+ var split = ( ( CheckBox ) sender ) . Name . Split ( ' ' ) ;
904+
905+ if ( split . Length == 2 )
906+ {
907+ var fieldName = split [ 0 ] . Split ( '[' ) [ 0 ] ;
908+ var unit = MAVLink . GetUnit ( fieldName ,
909+ name : split [ 1 ] . Replace ( "mavlink_" , "" ) . RemoveFromEnd ( "_t" ) . ToUpper ( ) ) ;
868910
869911 var index = zg1 . GraphPane . YAxisList . IndexOf ( unit ) ;
870912
@@ -1473,4 +1515,4 @@ private async void but_cs_Click(object sender, EventArgs e)
14731515 }
14741516 }
14751517 }
1476- }
1518+ }
0 commit comments