Fix data format used in OCC communication
Amester and OCC understand only the sequence that is in bytes.
Current OCC pass-through was sending chunk of 4 bytes and that
was breaking the protocol. Since the REST server only handles 4
bytes, OCC pass-through needs to convert array of 4 bytes into
array of 2 bytes prior to sending to OCC driver.
Similarly, pass-through reader now needs to read one byte at a time
than 4 bytes.
Change-Id: Ifc24636f6b1dfb0cc0052362d2982ecfa652fec5
Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
diff --git a/occ_pass_through.cpp b/occ_pass_through.cpp
index 60dbf6c..7027d65 100644
--- a/occ_pass_through.cpp
+++ b/occ_pass_through.cpp
@@ -77,9 +77,17 @@
std::vector<int32_t> response {};
- // Amester packs data in 4 bytes
- ssize_t size = command.size() * sizeof(int32_t);
- auto rc = write((fd)(), command.data(), size);
+ // OCC only understands [bytes] so need array of bytes. Doing this
+ // because rest-server currently treats all int* as 32 bit integer.
+ std::vector<uint8_t> cmdInBytes;
+ cmdInBytes.resize(command.size());
+
+ // Populate uint8_t version of vector.
+ std::transform(command.begin(), command.end(), cmdInBytes.begin(),
+ [](decltype(cmdInBytes)::value_type x){return x;});
+
+ ssize_t size = cmdInBytes.size() * sizeof(decltype(cmdInBytes)::value_type);
+ auto rc = write((fd)(), cmdInBytes.data(), size);
if (rc < 0 || (rc != size))
{
// This would log and terminate since its not handled.
@@ -93,7 +101,7 @@
// Now read the response. This would be the content of occ-sram
while(1)
{
- int32_t data {};
+ uint8_t data {};
auto len = read((fd)(), &data, sizeof(data));
if (len > 0)
{