-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathAaosVhalSource.cpp
111 lines (102 loc) · 3.61 KB
/
AaosVhalSource.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
#include "AaosVhalSource.h"
#include "IDecoderManifest.h"
#include "LoggingModule.h"
#include "QueueTypes.h"
#include <cstddef>
#include <string>
#include <unordered_map>
#include <utility>
namespace Aws
{
namespace IoTFleetWise
{
AaosVhalSource::AaosVhalSource( InterfaceID interfaceId, SignalBufferDistributorPtr signalBufferDistributor )
: mInterfaceId( std::move( interfaceId ) )
, mSignalBufferDistributor{ std::move( signalBufferDistributor ) }
{
}
static bool
popU32FromString( std::string &decoder, uint32_t &val )
{
try
{
size_t pos{};
val = static_cast<uint32_t>( std::stoul( decoder, &pos, 0 ) );
pos++; // Skip over delimiter
decoder = ( pos < decoder.size() ) ? decoder.substr( pos ) : "";
}
catch ( ... )
{
return false;
}
return true;
}
void
AaosVhalSource::onChangeOfActiveDictionary( ConstDecoderDictionaryConstPtr &dictionary,
VehicleDataSourceProtocol networkProtocol )
{
if ( networkProtocol != VehicleDataSourceProtocol::CUSTOM_DECODING )
{
return;
}
std::lock_guard<std::mutex> lock( mDecoderDictionaryUpdateMutex );
mVehiclePropertyInfo.clear();
mSignalIdToSignalType.clear();
auto decoderDictionary = std::dynamic_pointer_cast<const CustomDecoderDictionary>( dictionary );
if ( decoderDictionary == nullptr )
{
FWE_LOG_TRACE( "Decoder dictionary removed" );
return;
}
auto decodersForInterface = decoderDictionary->customDecoderMethod.find( mInterfaceId );
if ( decodersForInterface == decoderDictionary->customDecoderMethod.end() )
{
FWE_LOG_TRACE( "Decoder dictionary does not contain interface ID " + mInterfaceId );
return;
}
for ( const auto &decoder : decodersForInterface->second )
{
auto decoderString = decoder.first;
auto signalId = decoder.second.mSignalID;
uint32_t vehiclePropertyId{};
uint32_t areaIndex{};
uint32_t resultIndex{};
if ( ( !popU32FromString( decoderString, vehiclePropertyId ) ) ||
( !popU32FromString( decoderString, areaIndex ) ) || ( !popU32FromString( decoderString, resultIndex ) ) )
{
FWE_LOG_ERROR( "Invalid decoder for signal ID " + std::to_string( signalId ) + ": " + decoder.first );
continue;
}
mVehiclePropertyInfo.push_back(
std::array<uint32_t, 4>{ vehiclePropertyId, areaIndex, resultIndex, signalId } );
mSignalIdToSignalType[signalId] = decoder.second.mSignalType;
}
FWE_LOG_TRACE( "Decoder dictionary updated" );
}
std::vector<std::array<uint32_t, 4>>
AaosVhalSource::getVehiclePropertyInfo()
{
std::lock_guard<std::mutex> lock( mDecoderDictionaryUpdateMutex );
return mVehiclePropertyInfo;
}
void
AaosVhalSource::setVehicleProperty( SignalID signalId, const DecodedSignalValue &value )
{
auto signalType = SignalType::DOUBLE;
{
std::lock_guard<std::mutex> lock( mDecoderDictionaryUpdateMutex );
auto it = mSignalIdToSignalType.find( signalId );
if ( it != mSignalIdToSignalType.end() )
{
signalType = it->second;
}
}
auto timestamp = mClock->systemTimeSinceEpochMs();
CollectedSignalsGroup collectedSignalsGroup;
collectedSignalsGroup.push_back( CollectedSignal::fromDecodedSignal( signalId, timestamp, value, signalType ) );
mSignalBufferDistributor->push( CollectedDataFrame( collectedSignalsGroup ) );
}
} // namespace IoTFleetWise
} // namespace Aws