Skip to content

Commit

Permalink
SKA-265: added enumeration parameters setting by name in configuratio…
Browse files Browse the repository at this point in the history
…n file

Also added some unit tests
Updated CHANGELOG and README

Continuous improvement on line wrapping and indentation
  • Loading branch information
VJean-ThomasMasse authored and GitHub Enterprise committed May 16, 2024
1 parent f7d1568 commit a8ca214
Show file tree
Hide file tree
Showing 26 changed files with 693 additions and 436 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to the Vector SIL Kit FMU Importer project shall be document

The format is based on `Keep a Changelog (http://keepachangelog.com/en/1.0.0/) <http://keepachangelog.com/en/1.0.0/>`.

## [1.3.0] - TBD

### Changed

* If the value of an enumeration-typed variable is set, strings are now considered referring to an enumerator's name, whereas integers refer to an enumerators' value.

## [1.2.0] - 2024-03-28

### Added
Expand Down
1 change: 1 addition & 0 deletions FmuImporter/Common/CommonHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ internal static class Helpers
{
stringBuilder.AppendLine(".");
}

return new Tuple<bool, StringBuilder?>(true, stringBuilder);
}
}
Expand Down
50 changes: 10 additions & 40 deletions FmuImporter/FmiBridge/Binding/Fmi2Binding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,42 +270,24 @@ internal override void SetValue(Variable mdVar, byte[] data)
}

SetReal(
new[]
{
mdVar.ValueReference
},
new[]
{
value
});
new[] { mdVar.ValueReference },
new[] { value });
return;
}
case VariableTypes.Int32:
{
var value = BitConverter.ToInt32(data);
SetInteger(
new[]
{
mdVar.ValueReference
},
new[]
{
value
});
new[] { mdVar.ValueReference },
new[] { value });
return;
}
case VariableTypes.Boolean:
{
var value = BitConverter.ToBoolean(data);
SetBoolean(
new[]
{
mdVar.ValueReference
},
new[]
{
value
});
new[] { mdVar.ValueReference },
new[] { value });
return;
}
case VariableTypes.String:
Expand All @@ -314,29 +296,17 @@ internal override void SetValue(Variable mdVar, byte[] data)
// offset = 4 byte -> 32 bit
var value = Encoding.UTF8.GetString(data, 4, byteLength);
SetString(
new[]
{
mdVar.ValueReference
},
new[]
{
value
});
new[] { mdVar.ValueReference },
new[] { value });
return;
}
case VariableTypes.EnumFmi2:
{
var value = BitConverter.ToInt32(data);

SetInteger(
new[]
{
mdVar.ValueReference
},
new[]
{
value
});
new[] { mdVar.ValueReference },
new[] { value });
return;
}
default:
Expand Down
125 changes: 25 additions & 100 deletions FmuImporter/FmiBridge/Binding/Fmi3Binding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,7 @@ internal override void SetValue(Variable mdVar, byte[] data)
if (isScalar)
{
var value = BitConverter.ToSingle(data);
values = new[]
{
value
};
values = new[] { value };
}
else
{
Expand Down Expand Up @@ -470,10 +467,7 @@ internal override void SetValue(Variable mdVar, byte[] data)
}

SetFloat32(
new[]
{
mdVar.ValueReference
},
new[] { mdVar.ValueReference },
values);
return;
}
Expand All @@ -484,10 +478,7 @@ internal override void SetValue(Variable mdVar, byte[] data)
if (isScalar)
{
var value = BitConverter.ToDouble(data);
values = new[]
{
value
};
values = new[] { value };
}
else
{
Expand Down Expand Up @@ -518,10 +509,7 @@ internal override void SetValue(Variable mdVar, byte[] data)
}

SetFloat64(
new[]
{
mdVar.ValueReference
},
new[] { mdVar.ValueReference },
values);
return;
}
Expand All @@ -539,14 +527,8 @@ internal override void SetValue(Variable mdVar, byte[] data)
Buffer.BlockCopy(data, 0, values, 0, data.Length);

SetInt8(
new[]
{
mdVar.ValueReference
},
new[]
{
(sbyte)data[0]
});
new[] { mdVar.ValueReference },
new[] { (sbyte)data[0] });
return;
}
case VariableTypes.Int16:
Expand All @@ -556,21 +538,15 @@ internal override void SetValue(Variable mdVar, byte[] data)
if (isScalar)
{
var value = BitConverter.ToInt16(data);
values = new[]
{
value
};
values = new[] { value };
}
else
{
Buffer.BlockCopy(data, 0, values, 0, data.Length);
}

SetInt16(
new[]
{
mdVar.ValueReference
},
new[] { mdVar.ValueReference },
values);
return;
}
Expand All @@ -581,21 +557,15 @@ internal override void SetValue(Variable mdVar, byte[] data)
if (isScalar)
{
var value = BitConverter.ToInt32(data);
values = new[]
{
value
};
values = new[] { value };
}
else
{
Buffer.BlockCopy(data, 0, values, 0, data.Length);
}

SetInt32(
new[]
{
mdVar.ValueReference
},
new[] { mdVar.ValueReference },
values);
return;
}
Expand All @@ -606,21 +576,15 @@ internal override void SetValue(Variable mdVar, byte[] data)
if (isScalar)
{
var value = BitConverter.ToInt64(data);
values = new[]
{
value
};
values = new[] { value };
}
else
{
Buffer.BlockCopy(data, 0, values, 0, data.Length);
}

SetInt64(
new[]
{
mdVar.ValueReference
},
new[] { mdVar.ValueReference },
values);
return;
}
Expand All @@ -635,10 +599,7 @@ internal override void SetValue(Variable mdVar, byte[] data)
}

SetUInt8(
new[]
{
mdVar.ValueReference
},
new[] { mdVar.ValueReference },
data);
return;
}
Expand All @@ -649,21 +610,15 @@ internal override void SetValue(Variable mdVar, byte[] data)
if (isScalar)
{
var value = BitConverter.ToUInt16(data);
values = new[]
{
value
};
values = new[] { value };
}
else
{
Buffer.BlockCopy(data, 0, values, 0, data.Length);
}

SetUInt16(
new[]
{
mdVar.ValueReference
},
new[] { mdVar.ValueReference },
values);
return;
}
Expand All @@ -674,21 +629,15 @@ internal override void SetValue(Variable mdVar, byte[] data)
if (isScalar)
{
var value = BitConverter.ToUInt32(data);
values = new[]
{
value
};
values = new[] { value };
}
else
{
Buffer.BlockCopy(data, 0, values, 0, data.Length);
}

SetUInt32(
new[]
{
mdVar.ValueReference
},
new[] { mdVar.ValueReference },
values);
return;
}
Expand All @@ -699,21 +648,15 @@ internal override void SetValue(Variable mdVar, byte[] data)
if (isScalar)
{
var value = BitConverter.ToUInt64(data);
values = new[]
{
value
};
values = new[] { value };
}
else
{
Buffer.BlockCopy(data, 0, values, 0, data.Length);
}

SetUInt64(
new[]
{
mdVar.ValueReference
},
new[] { mdVar.ValueReference },
values);
return;
}
Expand All @@ -724,21 +667,15 @@ internal override void SetValue(Variable mdVar, byte[] data)
if (isScalar)
{
var value = BitConverter.ToBoolean(data);
values = new[]
{
value
};
values = new[] { value };
}
else
{
Buffer.BlockCopy(data, 0, values, 0, data.Length);
}

SetBoolean(
new[]
{
mdVar.ValueReference
},
new[] { mdVar.ValueReference },
values);
return;
}
Expand All @@ -759,10 +696,7 @@ internal override void SetValue(Variable mdVar, byte[] data)
}

SetString(
new[]
{
mdVar.ValueReference
},
new[] { mdVar.ValueReference },
values);
return;
}
Expand All @@ -777,21 +711,15 @@ internal override void SetValue(Variable mdVar, byte[] data)
if (isScalar)
{
var value = BitConverter.ToInt64(data);
values = new[]
{
value
};
values = new[] { value };
}
else
{
Buffer.BlockCopy(data, 0, values, 0, data.Length);
}

SetInt64(
new[]
{
mdVar.ValueReference
},
new[] { mdVar.ValueReference },
values);
return;
}
Expand Down Expand Up @@ -844,10 +772,7 @@ public override void SetValue(uint valueRef, byte[] data, int[] binSizes)
}

SetBinary(
new[]
{
valueRef
},
new[] { valueRef },
Array.ConvertAll(binSizes, b => (IntPtr)b),
values);

Expand Down
Loading

0 comments on commit a8ca214

Please sign in to comment.