VMS Utils: Fixed createDataMessage method.
Before, it used to process only the payload but now it also
takes in VMS layer info and publisher ID.
Bug: 135051289
Fixes: 135051289
Test: Updated unit tests in VmsUtilsTest. Ran the tests on Hawk.
Change-Id: I6c11f95a815af5d7b9fc9288692285766d2ca98f
diff --git a/automotive/vehicle/2.0/default/common/include/vhal_v2_0/VmsUtils.h b/automotive/vehicle/2.0/default/common/include/vhal_v2_0/VmsUtils.h
index 7082566..87010ce 100644
--- a/automotive/vehicle/2.0/default/common/include/vhal_v2_0/VmsUtils.h
+++ b/automotive/vehicle/2.0/default/common/include/vhal_v2_0/VmsUtils.h
@@ -60,6 +60,8 @@
};
struct VmsLayerAndPublisher {
+ VmsLayerAndPublisher(VmsLayer layer, int publisher_id)
+ : layer(layer), publisher_id(publisher_id) {}
VmsLayer layer;
int publisher_id;
};
@@ -162,12 +164,16 @@
std::unique_ptr<VehiclePropValue> createSubscriptionsRequest();
// Creates a VehiclePropValue containing a message of type VmsMessageType.DATA.
-// Returns a nullptr if the byte string in bytes is empty.
+// Returns a nullptr if the vms_packet string in bytes is empty or if the layer_publisher
+// information in VmsLayerAndPublisher format is missing the later or publisher
+// information.
//
// For example, to build a VehiclePropValue message containing a proto, the caller
-// should convert the proto to a byte string using the SerializeToString proto
-// API, then use this inteface to build the VehicleProperty.
-std::unique_ptr<VehiclePropValue> createDataMessage(const std::string& bytes);
+// should first convert the proto to a byte string (vms_packet) using the
+// SerializeToString proto API. Then, it use this interface to build the VehicleProperty
+// by passing publisher and layer information (layer_publisher) and the vms_packet.
+std::unique_ptr<VehiclePropValue> CreateDataMessageWithLayerPublisherInfo(
+ const VmsLayerAndPublisher& layer_publisher, const std::string& vms_packet);
// Creates a VehiclePropValue containing a message of type
// VmsMessageType.PUBLISHER_ID_REQUEST with the given publisher information.
diff --git a/automotive/vehicle/2.0/default/common/src/VmsUtils.cpp b/automotive/vehicle/2.0/default/common/src/VmsUtils.cpp
index 111f6ea..f16489c 100644
--- a/automotive/vehicle/2.0/default/common/src/VmsUtils.cpp
+++ b/automotive/vehicle/2.0/default/common/src/VmsUtils.cpp
@@ -126,10 +126,13 @@
return result;
}
-std::unique_ptr<VehiclePropValue> createDataMessage(const std::string& bytes) {
- auto result = createBaseVmsMessage(kMessageTypeSize);
- result->value.int32Values = hidl_vec<int32_t>{toInt(VmsMessageType::DATA)};
- result->value.bytes = std::vector<uint8_t>(bytes.begin(), bytes.end());
+std::unique_ptr<VehiclePropValue> CreateDataMessageWithLayerPublisherInfo(
+ const VmsLayerAndPublisher& layer_publisher, const std::string& vms_packet) {
+ auto result = createBaseVmsMessage(kMessageTypeSize + kLayerAndPublisherSize);
+ result->value.int32Values = hidl_vec<int32_t>{
+ toInt(VmsMessageType::DATA), layer_publisher.layer.type, layer_publisher.layer.subtype,
+ layer_publisher.layer.version, layer_publisher.publisher_id};
+ result->value.bytes = std::vector<uint8_t>(vms_packet.begin(), vms_packet.end());
return result;
}
diff --git a/automotive/vehicle/2.0/default/tests/VmsUtils_test.cpp b/automotive/vehicle/2.0/default/tests/VmsUtils_test.cpp
index 2b3efc7..8a434c8 100644
--- a/automotive/vehicle/2.0/default/tests/VmsUtils_test.cpp
+++ b/automotive/vehicle/2.0/default/tests/VmsUtils_test.cpp
@@ -139,12 +139,23 @@
}
TEST(VmsUtilsTest, dataMessage) {
- std::string bytes = "aaa";
- auto message = createDataMessage(bytes);
+ const std::string bytes = "aaa";
+ const VmsLayerAndPublisher layer_and_publisher(VmsLayer(2, 0, 1), 123);
+ auto message = CreateDataMessageWithLayerPublisherInfo(layer_and_publisher, bytes);
ASSERT_NE(message, nullptr);
EXPECT_TRUE(isValidVmsMessage(*message));
EXPECT_EQ(message->prop, toInt(VehicleProperty::VEHICLE_MAP_SERVICE));
- EXPECT_EQ(message->value.int32Values.size(), 0x1ul);
+ EXPECT_EQ(message->value.int32Values.size(), 0x5ul);
+ EXPECT_EQ(message->value.int32Values[0], toInt(VmsMessageType::DATA));
+
+ // Layer
+ EXPECT_EQ(message->value.int32Values[1], 2);
+ EXPECT_EQ(message->value.int32Values[2], 0);
+ EXPECT_EQ(message->value.int32Values[3], 1);
+
+ // Publisher ID
+ EXPECT_EQ(message->value.int32Values[4], 123);
+
EXPECT_EQ(parseMessageType(*message), VmsMessageType::DATA);
EXPECT_EQ(message->value.bytes.size(), bytes.size());
EXPECT_EQ(memcmp(message->value.bytes.data(), bytes.data(), bytes.size()), 0);
@@ -164,8 +175,9 @@
}
TEST(VmsUtilsTest, parseDataMessage) {
- std::string bytes = "aaa";
- auto message = createDataMessage(bytes);
+ const std::string bytes = "aaa";
+ const VmsLayerAndPublisher layer_and_publisher(VmsLayer(1, 0, 1), 123);
+ auto message = CreateDataMessageWithLayerPublisherInfo(layer_and_publisher, bytes);
auto data_str = parseData(*message);
ASSERT_FALSE(data_str.empty());
EXPECT_EQ(data_str, bytes);