@@ -54,8 +54,6 @@ ProcedureStatus MultipleSharedHandler::validateSignalContexts(const std::vector<
5454
5555 static const std::set<SampleType> allowedSampleTypes{SampleType::Float64,
5656 SampleType::Float32,
57- SampleType::Float32,
58- SampleType::Float64,
5957 SampleType::UInt8,
6058 SampleType::Int8,
6159 SampleType::UInt16,
@@ -70,43 +68,54 @@ ProcedureStatus MultipleSharedHandler::validateSignalContexts(const std::vector<
7068 auto signal = sigCtx.inputPort .getSignal ();
7169 if (!signal.assigned ())
7270 continue ;
73- if (!signal.getDomainSignal ().assigned ())
71+ const auto dSignal = signal.getDomainSignal ();
72+ if (!dSignal.assigned ())
7473 {
75- status.messages .emplace_back (fmt::format (" Connected signal \" {}\" doesn't contain a domain signal. This is not allowed." ,
76- sigCtx.inputPort .getSignal ().getGlobalId ()));
77- status.success = false ;
74+ status.addError (fmt::format (" Connected signal \" {}\" doesn't contain a domain signal. This is not allowed." ,
75+ sigCtx.inputPort .getSignal ().getGlobalId ()));
7876 }
79- if (!signal. getDomainSignal (). getDescriptor ().assigned ())
77+ else if (const auto dSignalDesc = dSignal. getDescriptor (); !dSignalDesc .assigned ())
8078 {
81- status.messages .emplace_back (
82- fmt::format (" Connected signal \" {}\" doesn't contain a descroptor for a domain signal. This is not allowed." ,
83- sigCtx.inputPort .getSignal ().getGlobalId ()));
84- status.success = false ;
79+ status.addError (fmt::format (" Connected signal \" {}\" doesn't contain a descroptor for a domain signal. This is not allowed." ,
80+ sigCtx.inputPort .getSignal ().getGlobalId ()));
8581 }
86- if ( auto domainDataRule = signal. getDomainSignal (). getDescriptor (). getRule (); domainDataRule. getType () != DataRuleType::Linear)
82+ else
8783 {
88- status.messages .emplace_back (fmt::format (" Connected signal \" {}\" has an incompatible data rule for its domain signal." ,
89- sigCtx.inputPort .getSignal ().getGlobalId ()));
90- status.success = false ;
84+ if (auto domainDataRule = signal.getDomainSignal ().getDescriptor ().getRule (); domainDataRule.getType () != DataRuleType::Linear)
85+ {
86+ status.addError (fmt::format (" Connected signal \" {}\" has an incompatible data rule for its domain signal." ,
87+ sigCtx.inputPort .getSignal ().getGlobalId ()));
88+ }
89+ if (signal.getDomainSignal ().getDescriptor ().getSampleType () != SampleType::UInt64 &&
90+ signal.getDomainSignal ().getDescriptor ().getSampleType () != SampleType::Int64)
91+ {
92+ status.addError (fmt::format (" Connected signal \" {}\" has an incompatible sample type for its domain signal. "
93+ " Only SampleType::UInt64 and SampleType::Int64 are allowed." ,
94+ sigCtx.inputPort .getSignal ().getGlobalId ()));
95+ }
96+ if (auto unit = signal.getDomainSignal ().getDescriptor ().getUnit (); !unit.assigned () || unit.getSymbol () != " s" )
97+ {
98+ status.addError (fmt::format (" Connected signal \" {}\" has an incompatible unit for its domain signal. "
99+ " Only 's' (seconds) is allowed." ,
100+ sigCtx.inputPort .getSignal ().getGlobalId ()));
101+ }
91102 }
103+
92104 if (!signal.getDescriptor ().assigned ())
93105 {
94- status.messages .emplace_back (fmt::format (" Connected signal \" {}\" doesn't contain a descroptor. This is not allowed." ,
95- sigCtx.inputPort .getSignal ().getGlobalId ()));
96- status.success = false ;
106+ status.addError (fmt::format (" Connected signal \" {}\" doesn't contain a descroptor. This is not allowed." ,
107+ sigCtx.inputPort .getSignal ().getGlobalId ()));
97108 }
98109 if (auto demensions = signal.getDescriptor ().getDimensions (); demensions.assigned () && demensions.getCount () > 0 )
99110 {
100- status.messages .emplace_back (fmt::format (" Connected signal \" {}\" has more then 1 demention. This is not allowed." ,
101- sigCtx.inputPort .getSignal ().getGlobalId ()));
102- status.success = false ;
111+ status.addError (fmt::format (" Connected signal \" {}\" has more then 1 demention. This is not allowed." ,
112+ sigCtx.inputPort .getSignal ().getGlobalId ()));
103113 }
104114 if (auto sampleType = signal.getDescriptor ().getSampleType (); allowedSampleTypes.find (sampleType) == allowedSampleTypes.cend ())
105115 {
106- status.messages .emplace_back (fmt::format (" Connected signal \" {}\" has an incompatible sample type ({})." ,
107- sigCtx.inputPort .getSignal ().getGlobalId (),
108- convertSampleTypeToString (sampleType)));
109- status.success = false ;
116+ status.addError (fmt::format (" Connected signal \" {}\" has an incompatible sample type ({})." ,
117+ sigCtx.inputPort .getSignal ().getGlobalId (),
118+ convertSampleTypeToString (sampleType)));
110119 }
111120 }
112121
@@ -131,8 +140,7 @@ ProcedureStatus MultipleSharedHandler::validateSignalContexts(const std::vector<
131140
132141 if (error)
133142 {
134- status.messages .emplace_back (fmt::format (" Connected signals have incompatible sample rates. This is not allowed." ));
135- status.success = false ;
143+ status.addError (fmt::format (" Connected signals have incompatible sample rates. This is not allowed." ));
136144 }
137145 return status;
138146}
@@ -142,14 +150,13 @@ TimestampTickStruct MultipleSharedHandler::domainToTs(const MultiReaderStatusPtr
142150 TimestampTickStruct res;
143151 const auto descriptor =
144152 status.getMainDescriptor ().getParameters ().get (event_packet_param::DOMAIN_DATA_DESCRIPTOR).asPtr <IDataDescriptor>();
145- const auto [ratioNum, ratioDen] = calculateRatio (descriptor);
146153 const uint64_t offset = status.getOffset ().getValue <uint64_t >(0 );
147154 const uint64_t start = descriptor.getRule ().getParameters ().get (" start" ).getValue <uint64_t >(0 );
148155 const uint64_t refOffset = descriptor.getReferenceDomainInfo ().getReferenceDomainOffset ().getValue <uint64_t >(0 );
149156
150157 res.firstTick = offset + start + refOffset;
151- res.ratioNum = ratioNum ;
152- res.ratioDen = ratioDen ;
158+ res.ratioNum = descriptor. getTickResolution (). simplify (). getNumerator () ;
159+ res.ratioDen = descriptor. getTickResolution (). getDenominator () ;
153160 res.multiplier = 1'000'000 ; // amount of us in a second
154161 res.delta = descriptor.getRule ().getParameters ().get (" delta" ).getValue <uint64_t >(0 );
155162 return res;
@@ -168,14 +175,28 @@ std::string MultipleSharedHandler::toString(const SampleType sampleType, const s
168175 {
169176 case SampleType::Float64:
170177 return fmt::format (" \" {}\" : {}" , valueFieldName, std::to_string (*(static_cast <SampleTypeToType<SampleType::Float64>::Type*>(data) + offset)));
178+ case SampleType::Float32:
179+ return fmt::format (" \" {}\" : {}" , valueFieldName, std::to_string (*(static_cast <SampleTypeToType<SampleType::Float32>::Type*>(data) + offset)));
171180 case SampleType::UInt64:
172181 return fmt::format (" \" {}\" : {}" , valueFieldName, std::to_string (*(static_cast <SampleTypeToType<SampleType::UInt64>::Type*>(data) + offset)));
173182 case SampleType::Int64:
174183 return fmt::format (" \" {}\" : {}" , valueFieldName, std::to_string (*(static_cast <SampleTypeToType<SampleType::Int64>::Type*>(data) + offset)));
184+ case SampleType::UInt32:
185+ return fmt::format (" \" {}\" : {}" , valueFieldName, std::to_string (*(static_cast <SampleTypeToType<SampleType::UInt32>::Type*>(data) + offset)));
186+ case SampleType::Int32:
187+ return fmt::format (" \" {}\" : {}" , valueFieldName, std::to_string (*(static_cast <SampleTypeToType<SampleType::Int32>::Type*>(data) + offset)));
188+ case SampleType::UInt16:
189+ return fmt::format (" \" {}\" : {}" , valueFieldName, std::to_string (*(static_cast <SampleTypeToType<SampleType::UInt16>::Type*>(data) + offset)));
190+ case SampleType::Int16:
191+ return fmt::format (" \" {}\" : {}" , valueFieldName, std::to_string (*(static_cast <SampleTypeToType<SampleType::Int16>::Type*>(data) + offset)));
192+ case SampleType::UInt8:
193+ return fmt::format (" \" {}\" : {}" , valueFieldName, std::to_string (*(static_cast <SampleTypeToType<SampleType::UInt8>::Type*>(data) + offset)));
194+ case SampleType::Int8:
195+ return fmt::format (" \" {}\" : {}" , valueFieldName, std::to_string (*(static_cast <SampleTypeToType<SampleType::Int8>::Type*>(data) + offset)));
175196 default :
176197 break ;
177198 }
178- return " " ;
199+ return " unsupported " ;
179200}
180201
181202template <typename T>
@@ -187,6 +208,9 @@ std::string MultipleSharedHandler::toString(const std::string& valueFieldName, v
187208std::string MultipleSharedHandler::tsToString (TimestampTickStruct tsStruct, SizeT offset)
188209{
189210 // const uint64_t epochTime = (firstTick + delta * offset) * ratioNum * US_IN_S / ratioDen; // us
211+ const uint64_t g = std::gcd (tsStruct.multiplier , tsStruct.ratioDen );
212+ tsStruct.multiplier /= g;
213+ tsStruct.ratioDen /= g;
190214 return fmt::format (" \" timestamp\" : {}" ,
191215 std::to_string (((tsStruct.firstTick + tsStruct.delta * offset) * tsStruct.ratioNum * tsStruct.multiplier ) /
192216 tsStruct.ratioDen ));
0 commit comments