Skip to content
Snippets Groups Projects
Commit a46d1377 authored by Jonas Gesenhues's avatar Jonas Gesenhues
Browse files

Added endianness conversion feature.

Removed bugfix in receive handling loops.
parent 4626248f
No related branches found
No related tags found
No related merge requests found
...@@ -26,6 +26,7 @@ void JsonModelDescription::Load(std::string resourceDir) ...@@ -26,6 +26,7 @@ void JsonModelDescription::Load(std::string resourceDir)
Channels.push_back(SocketChannel( Channels.push_back(SocketChannel(
channel.second.get<std::string>("Name"), channel.second.get<std::string>("Name"),
channel.second.get<unsigned int>("ValueRef"), channel.second.get<unsigned int>("ValueRef"),
channel.second.get<bool>("IsSender"))); channel.second.get<bool>("IsSender"),
channel.second.get<bool>("ReverseEndianness")));
} }
} }
...@@ -6,8 +6,8 @@ SocketChannel::SocketChannel() ...@@ -6,8 +6,8 @@ SocketChannel::SocketChannel()
} }
SocketChannel::SocketChannel(std::string name, unsigned int valueRef, bool settable) : SocketChannel::SocketChannel(std::string name, unsigned int valueRef, bool settable, bool reverseEndianness) :
_name(name), _valueRef(valueRef), _isSender(settable), _value(0) _name(name), _valueRef(valueRef), _isSender(settable), _reverseEndianness(reverseEndianness), _value(0)
{ {
} }
...@@ -39,3 +39,8 @@ bool SocketChannel::IsSender() const ...@@ -39,3 +39,8 @@ bool SocketChannel::IsSender() const
{ {
return _isSender; return _isSender;
} }
bool SocketChannel::ReverseEndianness() const
{
return _reverseEndianness;
}
...@@ -6,10 +6,11 @@ private: ...@@ -6,10 +6,11 @@ private:
std::string _name; std::string _name;
unsigned int _valueRef; unsigned int _valueRef;
bool _isSender; bool _isSender;
bool _reverseEndianness;
double _value; double _value;
SocketChannel(); SocketChannel();
public: public:
SocketChannel(std::string name, unsigned int valueRef, bool settable); SocketChannel(std::string name, unsigned int valueRef, bool settable, bool reverseEndianness);
~SocketChannel(); ~SocketChannel();
std::string GetName(); std::string GetName();
...@@ -17,5 +18,6 @@ public: ...@@ -17,5 +18,6 @@ public:
double GetValue() const; double GetValue() const;
void SetValue(double value); void SetValue(double value);
bool IsSender() const; bool IsSender() const;
bool ReverseEndianness() const;
}; };
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "TcpConnection.h" #include "TcpConnection.h"
#include "UdpConnection.h" #include "UdpConnection.h"
#include "JsonModelDescription.h" #include "JsonModelDescription.h"
#include "EndianConverter.h"
SocketFmiComponent::SocketFmiComponent() SocketFmiComponent::SocketFmiComponent()
{ {
...@@ -84,15 +85,22 @@ void SocketFmiComponent::valuesReceivedCallback(std::shared_ptr<std::vector<doub ...@@ -84,15 +85,22 @@ void SocketFmiComponent::valuesReceivedCallback(std::shared_ptr<std::vector<doub
size_t channel = 0; size_t channel = 0;
_mutex.lock(); _mutex.lock();
// received values and channels are sorted by valueRef // received values and channels are sorted by valueRef
//Log(fmi2Status::fmi2Error, std::string("receivedValues size ") + std::to_string(receivedValues->size()) + std::string(" _channels.size() ") + std::to_string(_channels.size()));
while (receivedValue < receivedValues->size() && channel < _channels.size()) while (receivedValue < receivedValues->size() && channel < _channels.size())
{ {
while (channel < _channels.size()) bool foundRightChannel = false;
while (!foundRightChannel && channel < _channels.size())
{ {
// Break condition if found -> setvalue // Break condition if found -> setvalue
if (!_channels[channel].IsSender()) if (!_channels[channel].IsSender())
{ {
if (_channels[channel].ReverseEndianness())
{
EndianConverter::ReverseEndianness((*receivedValues)[receivedValue]);
}
_channels[channel].SetValue((*receivedValues)[receivedValue]); _channels[channel].SetValue((*receivedValues)[receivedValue]);
break; foundRightChannel = true;
} }
channel++; channel++;
} }
...@@ -112,7 +120,12 @@ void SocketFmiComponent::DoStep(fmi2Real currentCommunicationPoint, fmi2Real ste ...@@ -112,7 +120,12 @@ void SocketFmiComponent::DoStep(fmi2Real currentCommunicationPoint, fmi2Real ste
{ {
if (channel.IsSender()) if (channel.IsSender())
{ {
buff.push_back(channel.GetValue()); double val = channel.GetValue();
if (channel.ReverseEndianness())
{
EndianConverter::ReverseEndianness(val);
}
buff.push_back(val);
} }
} }
_mutex.unlock(); _mutex.unlock();
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
private uint _valueRef; private uint _valueRef;
private string _displayedUnit; private string _displayedUnit;
private bool _isSender; private bool _isSender;
private bool _reverseEndianness;
/// <summary> /// <summary>
/// Displayed name of the channel /// Displayed name of the channel
...@@ -61,6 +62,22 @@ ...@@ -61,6 +62,22 @@
} }
} }
/// <summary>
/// Whether the channel value's endianness should be reversed
/// </summary>
public bool ReverseEndianness
{
get
{
return _reverseEndianness;
}
set
{
Set(ref _reverseEndianness, value);
}
}
public SocketChannel() public SocketChannel()
{ {
} }
......
...@@ -40,6 +40,10 @@ ...@@ -40,6 +40,10 @@
Binding="{Binding ValueRef}" Binding="{Binding ValueRef}"
Header="ValueRef" Header="ValueRef"
IsReadOnly="True" /> IsReadOnly="True" />
<DataGridCheckBoxColumn
Width="Auto"
Binding="{Binding ReverseEndianness}"
Header="Reverse Endianess" />
</DataGrid.Columns> </DataGrid.Columns>
</DataGrid> </DataGrid>
<StackPanel <StackPanel
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment