@@ -77,12 +77,6 @@ const char* V2VCommManager::TOPIC_NAME_IVS = "ivs";
77
77
/* MQTT subtopic name for Platoon Length. */
78
78
const char * V2VCommManager::TOPIC_NAME_PLATOON_LENGTH = " length" ;
79
79
80
- /* * Buffer size for JSON serialization of heartbeat messages. */
81
- static const uint32_t JSON_HEARTBEAT_MAX_SIZE = 128U ;
82
-
83
- /* * Default size of the JSON Document for parsing. */
84
- static const uint32_t JSON_DOC_DEFAULT_SIZE = 512U ;
85
-
86
80
/* *****************************************************************************
87
81
* Public Methods
88
82
*****************************************************************************/
@@ -302,8 +296,8 @@ bool V2VCommManager::sendIVS(const int32_t ivs) const
302
296
V2VEventType type = V2V_EVENT_IVS;
303
297
304
298
/* Create JSON document. */
305
- StaticJsonDocument<JSON_DOC_DEFAULT_SIZE> jsonPayload;
306
- String payload;
299
+ JsonDocument jsonPayload;
300
+ String payload;
307
301
308
302
jsonPayload[" ivs" ] = ivs;
309
303
@@ -375,29 +369,29 @@ int32_t V2VCommManager::getPlatoonLength() const
375
369
void V2VCommManager::eventCallback (const String& payload)
376
370
{
377
371
/* Deserialize payload. */
378
- StaticJsonDocument<JSON_DOC_DEFAULT_SIZE> jsonPayload;
379
- DeserializationError error = deserializeJson (jsonPayload, payload.c_str ());
372
+ JsonDocument jsonPayload;
373
+ DeserializationError error = deserializeJson (jsonPayload, payload.c_str ());
380
374
381
375
if (DeserializationError::Ok != error)
382
376
{
383
377
LOG_ERROR (" JSON Deserialization Error %d." , error);
384
378
}
385
379
else
386
380
{
387
- JsonVariant jsonEventVehicleId = jsonPayload[" id" ]; /* Vehicle ID. */
388
- JsonVariant jsonEventType = jsonPayload[" type" ]; /* Event type. */
389
- JsonVariant jsonEventTimestamp = jsonPayload[" timestamp" ]; /* Timestamp [ms]. */
390
- JsonVariant jsonEventData = jsonPayload[" data" ]; /* Event data. */
381
+ JsonVariantConst jsonEventVehicleId = jsonPayload[" id" ]; /* Vehicle ID. */
382
+ JsonVariantConst jsonEventType = jsonPayload[" type" ]; /* Event type. */
383
+ JsonVariantConst jsonEventTimestamp = jsonPayload[" timestamp" ]; /* Timestamp [ms]. */
384
+ JsonVariantConst jsonEventData = jsonPayload[" data" ]; /* Event data. */
391
385
392
386
if ((false == jsonEventVehicleId.isNull ()) && (false == jsonEventType.isNull ()) &&
393
387
(false == jsonEventTimestamp.isNull ()) && (false == jsonEventData.isNull ()))
394
388
{
395
- bool pushEventToQueue = false ;
396
- uint8_t eventVehicleId = jsonEventVehicleId.as <uint8_t >();
397
- V2VEventType eventType = jsonEventType.as <V2VEventType>();
398
- uint32_t eventTimestamp = jsonEventTimestamp.as <uint32_t >();
399
- JsonObject eventDataAsJson = jsonEventData.as <JsonObject >();
400
- void * eventData = nullptr ;
389
+ bool pushEventToQueue = false ;
390
+ uint8_t eventVehicleId = jsonEventVehicleId.as <uint8_t >();
391
+ V2VEventType eventType = jsonEventType.as <V2VEventType>();
392
+ uint32_t eventTimestamp = jsonEventTimestamp.as <uint32_t >();
393
+ JsonObjectConst eventDataAsJson = jsonEventData.as <JsonObjectConst >();
394
+ void * eventData = nullptr ;
401
395
402
396
switch (eventType)
403
397
{
@@ -446,8 +440,8 @@ void V2VCommManager::eventCallback(const String& payload)
446
440
}
447
441
else
448
442
{
449
- JsonVariant jsonEventDataStatus = eventDataAsJson[" status" ]; /* Vehicle status. */
450
- JsonVariant jsonEventDataTimestamp = eventDataAsJson[" timestamp" ]; /* Timestamp [ms]. */
443
+ JsonVariantConst jsonEventDataStatus = eventDataAsJson[" status" ]; /* Vehicle status. */
444
+ JsonVariantConst jsonEventDataTimestamp = eventDataAsJson[" timestamp" ]; /* Timestamp [ms]. */
451
445
452
446
if ((false == jsonEventDataStatus.isNull ()) && (false == jsonEventDataTimestamp.isNull ()))
453
447
{
@@ -466,18 +460,19 @@ void V2VCommManager::eventCallback(const String& payload)
466
460
case V2V_EVENT_PLATOON_HEARTBEAT:
467
461
if (PLATOON_LEADER_ID != m_vehicleId)
468
462
{
469
- JsonVariant jsonEventDataTimestamp = eventDataAsJson[" timestamp" ]; /* Timestamp [ms]. */
463
+ JsonVariantConst jsonEventDataTimestamp = eventDataAsJson[" timestamp" ]; /* Timestamp [ms]. */
470
464
471
465
if (false == jsonEventDataTimestamp.isNull ())
472
466
{
473
467
/* Timestamp is sent back to acknowledge synchronization. */
474
- uint32_t eventDataTimestamp = jsonEventDataTimestamp.as <uint32_t >();
475
- StaticJsonDocument<JSON_HEARTBEAT_MAX_SIZE> heartbeatDoc;
476
- heartbeatDoc[" timestamp" ] = eventDataTimestamp;
477
- heartbeatDoc[" status" ] = m_vehicleStatus;
468
+ uint32_t eventDataTimestamp = jsonEventDataTimestamp.as <uint32_t >();
469
+ JsonDocument jsonHeartbeatDoc;
470
+
471
+ jsonHeartbeatDoc[" timestamp" ] = eventDataTimestamp;
472
+ jsonHeartbeatDoc[" status" ] = m_vehicleStatus;
478
473
479
474
if (false == publishEvent (m_heartbeatResponseTopic, V2V_EVENT_VEHICLE_HEARTBEAT,
480
- heartbeatDoc .as <JsonObject>()))
475
+ jsonHeartbeatDoc .as <JsonObject>()))
481
476
{
482
477
LOG_ERROR (" Failed to publish MQTT message to %s." , m_heartbeatResponseTopic.c_str ());
483
478
}
@@ -500,7 +495,7 @@ void V2VCommManager::eventCallback(const String& payload)
500
495
}
501
496
else
502
497
{
503
- JsonVariant jsonEventDataIVS = eventDataAsJson[" ivs" ]; /* Inter Vehicle Space. */
498
+ JsonVariantConst jsonEventDataIVS = eventDataAsJson[" ivs" ]; /* Inter Vehicle Space. */
504
499
505
500
if (false == jsonEventDataIVS.isNull ())
506
501
{
@@ -729,13 +724,13 @@ bool V2VCommManager::sendPlatoonHeartbeat()
729
724
bool isSuccessful = false ;
730
725
731
726
/* Send platoon heartbeat. */
732
- StaticJsonDocument<JSON_HEARTBEAT_MAX_SIZE> heartbeatDoc ;
733
- String heartbeatPayload;
734
- uint32_t timestamp = millis ();
727
+ JsonDocument jsonHeartbeatDoc ;
728
+ String heartbeatPayload;
729
+ uint32_t timestamp = millis ();
735
730
736
- heartbeatDoc [" timestamp" ] = timestamp;
731
+ jsonHeartbeatDoc [" timestamp" ] = timestamp;
737
732
738
- if (0U == serializeJson (heartbeatDoc , heartbeatPayload))
733
+ if (0U == serializeJson (jsonHeartbeatDoc , heartbeatPayload))
739
734
{
740
735
LOG_ERROR (" Failed to serialize heartbeat." );
741
736
}
@@ -762,8 +757,8 @@ bool V2VCommManager::publishEvent(const String& topic, V2VEventType type, const
762
757
bool isSuccessful = false ;
763
758
764
759
/* Create JSON document. */
765
- StaticJsonDocument<JSON_DOC_DEFAULT_SIZE> jsonPayload;
766
- String payload;
760
+ JsonDocument jsonPayload;
761
+ String payload;
767
762
768
763
jsonPayload[" id" ] = m_vehicleId;
769
764
jsonPayload[" type" ] = type;
@@ -844,8 +839,8 @@ bool V2VCommManager::sendPlatoonLength(const int32_t length) const
844
839
V2VEventType type = V2V_EVENT_IVS;
845
840
846
841
/* Create JSON document. */
847
- StaticJsonDocument<JSON_DOC_DEFAULT_SIZE> jsonPayload;
848
- String payload;
842
+ JsonDocument jsonPayload;
843
+ String payload;
849
844
850
845
jsonPayload[" length" ] = length;
851
846
0 commit comments