19 #ifndef _CANGENPLUGINIMPL_H_
20 #define _CANGENPLUGINIMPL_H_
25 #include <libwebsockets.h>
29 #include <canobserver.h>
31 #include <ambpluginimpl.h>
32 #include "websockets.h"
76 static const char* CANSimPluginUUID =
"3f43e231-11ec-4782-9b5a-3dbcc5221eeb";
96 const std::string
uuid()
const {
return "becbbef9-6cc8-4b9e-8cd7-2fbe37b9b52a"; }
176 void printFrame(
const can_frame& frame)
const;
183 void parseMappingTable(
const std::string& json);
194 void getValue(lws* socket,
const std::string&
property,
int zone,
const std::string&
uuid);
207 void setValue(lws* socket,
const std::string&
property,
const std::string&
value,
int zone,
const std::string& interface,
const std::string& transactionId);
233 MappingTable(
const MappingTable& other) =
delete;
234 MappingTable& operator=(
const MappingTable& other) =
delete;
235 MappingTable(MappingTable&& other) =
default;
236 MappingTable& operator=(MappingTable&& other) =
default;
238 void addProperty(
const std::string& source, json_object* signal)
240 json_object* canIdObj = json_object_object_get(signal,
"can_id");
241 json_object* nameObj = json_object_object_get(signal,
"name");
242 if(!canIdObj || !nameObj)
244 Zone::Type
zone(Zone::None);
245 json_object* zoneObj = json_object_object_get(signal,
"zone");
247 zone = json_object_get_int(zoneObj);
249 auto& zp = mapping[source];
250 auto& prop = zp[Zone::Type(
zone)];
251 std::string
name(json_object_get_string(nameObj));
252 int can_id = json_object_get_int(canIdObj);
256 int getCanId(
const std::string& source,
const Zone::Type&
zone,
const VehicleProperty::Property&
name)
const
259 auto sourceIt = mapping.find(source);
260 if(sourceIt == mapping.end())
262 auto zoneIt = sourceIt->second.find(zone);
263 if(zoneIt == sourceIt->second.end())
265 auto propIt = zoneIt->second.find(name);
266 if(propIt == zoneIt->second.end())
269 return propIt->second;
278 typedef std::map< Zone::Type, std::map<VehicleProperty::Property, canid_t> > ZonedProperty;
279 std::map<std::string, ZonedProperty> mapping;
290 MappingTable mappingTable;
296 std::map<std::string, std::shared_ptr<CANBus> > interfaces;
302 std::unique_ptr<WebSockets> ws;
308 interprocess_recursive_mutex mutex;
318 #endif // _CANGENPLUGINIMPL_H_