diff options
Diffstat (limited to 'occ_pass_through.cpp')
-rw-r--r-- | occ_pass_through.cpp | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/occ_pass_through.cpp b/occ_pass_through.cpp index 88a0d29..1b3bffa 100644 --- a/occ_pass_through.cpp +++ b/occ_pass_through.cpp @@ -1,6 +1,7 @@ #include <memory> #include <algorithm> #include <fcntl.h> +#include <errno.h> #include <phosphor-logging/log.hpp> #include "occ_pass_through.hpp" #include "occ_finder.hpp" @@ -62,9 +63,53 @@ int PassThrough::openDevice() std::vector<int32_t> PassThrough::send(std::vector<int32_t> command) { - return {}; + using namespace phosphor::logging; + + 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); + if (rc < 0 || (rc != size)) + { + log<level::ERR>("Error writing to OCC"); + + // In the next commit, it will have exceptions. + return response; + } + + // Now read the response. This would be the content of occ-sram + while(1) + { + errno = 0; + int32_t data {}; + auto len = read((fd)(), &data, sizeof(data)); + if (len > 0) + { + response.emplace_back(data); + } + else if (len < 0 && errno == EAGAIN) + { + // We may have data coming still + continue; + } + else if (len == 0) + { + // We have read all that we can. + break; + } + else + { + // Will have exception in the next commit. + log<level::ERR>("Error reading from OCC"); + break; + } + } + + return response; } + } // namespace pass_through } // namespace occ } // namespace open_power |