diff --git a/src/v2i-hub/TelematicBridgePlugin/src/TelematicUnit.cpp b/src/v2i-hub/TelematicBridgePlugin/src/TelematicUnit.cpp index e9ed23a33..355fe8fe3 100644 --- a/src/v2i-hub/TelematicBridgePlugin/src/TelematicUnit.cpp +++ b/src/v2i-hub/TelematicBridgePlugin/src/TelematicUnit.cpp @@ -29,18 +29,9 @@ namespace TelematicBridge auto s = natsConnection_RequestString(&reply, _conn, REGISTER_UNIT_TOPIC, payload.c_str(), TIME_OUT); if (s == NATS_OK) { - auto responseStr = natsMsg_GetData(reply); - PLOG(logINFO) << "Received registered reply: " << responseStr; - auto root = parseJson(responseStr); - if (root.isMember(LOCATION) && root.isMember(TESTING_TYPE) && root.isMember(EVENT_NAME)) - { - _eventLocation = root[LOCATION].asString(); - _testingType = root[TESTING_TYPE].asString(); - _eventName = root[EVENT_NAME].asString(); - - // Unit is registered when server responds with event information (location, testing_type, event_name) - _isRegistered = true; - } + auto replyStr = natsMsg_GetData(reply); + PLOG(logINFO) << "Received registered reply: " << replyStr; + updateRegisterStatus(replyStr); natsMsg_Destroy(reply); } else @@ -59,6 +50,20 @@ namespace TelematicBridge } } + void TelematicUnit::updateRegisterStatus(const string ®isterReply) + { + auto root = parseJson(registerReply); + if (root.isMember(LOCATION) && root.isMember(TESTING_TYPE) && root.isMember(EVENT_NAME)) + { + _eventLocation = root[LOCATION].asString(); + _testingType = root[TESTING_TYPE].asString(); + _eventName = root[EVENT_NAME].asString(); + + // Unit is registered when server responds with event information (location, testing_type, event_name) + _isRegistered = true; + } + } + void TelematicUnit::availableTopicsReplier() { if (!_subAvailableTopic) diff --git a/src/v2i-hub/TelematicBridgePlugin/src/TelematicUnit.h b/src/v2i-hub/TelematicBridgePlugin/src/TelematicUnit.h index da1e8e455..031439f44 100644 --- a/src/v2i-hub/TelematicBridgePlugin/src/TelematicUnit.h +++ b/src/v2i-hub/TelematicBridgePlugin/src/TelematicUnit.h @@ -120,6 +120,12 @@ namespace TelematicBridge */ void updateAvailableTopics(const string &newTopic); + /** + * @brief Update telematic unit registration status with the registration reply from NATS server + * @param string Register reply in Json format + */ + void updateRegisterStatus(const string& registerReply); + /** * @brief construct Json data string that will be streamed into the cloud by a publisher * @param unit_st struct that contains unit related information diff --git a/src/v2i-hub/TelematicBridgePlugin/test/test_TelematicUnit.cpp b/src/v2i-hub/TelematicBridgePlugin/test/test_TelematicUnit.cpp index d93cf96f8..58bc92c2f 100644 --- a/src/v2i-hub/TelematicBridgePlugin/test/test_TelematicUnit.cpp +++ b/src/v2i-hub/TelematicBridgePlugin/test/test_TelematicUnit.cpp @@ -133,4 +133,13 @@ namespace TelematicBridge _telematicUnitPtr->clearSelectedTopics(); ASSERT_FALSE(_telematicUnitPtr->inSelectedTopics(selectedTopic)); } + TEST_F(test_TelematicUnit, updateRegisterStatus) + { + string replyStr = "{\"event_name\":\"Test\",\"location\":\"Local\",\"testing_type\":\"Integration\"}"; + _telematicUnitPtr->updateRegisterStatus(replyStr); + ASSERT_EQ("Local", _telematicUnitPtr->getEventLocation()); + ASSERT_EQ("Test", _telematicUnitPtr->getEventName()); + ASSERT_EQ("Integration", _telematicUnitPtr->getTestingType()); + } + } \ No newline at end of file