ncsi: encapsulate NC-SI commands with NCSICommand / NCSIResponse structs
... and rename Interface::sendOemCommand to Interface::sendCommand.
This provides a more clear facility to pass command and response objects
around, for future command and transport implementations.
Change-Id: I46e594ab6467ed87cfc27189c3ec4bd321726ee5
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
diff --git a/src/ncsi_util.hpp b/src/ncsi_util.hpp
index 048bb71..0ca0df1 100644
--- a/src/ncsi_util.hpp
+++ b/src/ncsi_util.hpp
@@ -16,6 +16,7 @@
constexpr auto DEFAULT_VALUE = -1;
constexpr auto NONE = 0;
+constexpr uint8_t CHANNEL_ID_NONE = 0x1f;
struct ChannelInfo
{
@@ -40,10 +41,37 @@
std::vector<PackageInfo> packages;
};
+struct NCSICommand
+{
+ /* constructs a message; the payload span is copied into the internal
+ * command vector */
+ NCSICommand(uint8_t opcode, uint8_t package, std::optional<uint8_t> channel,
+ std::span<unsigned char> payload);
+
+ uint8_t getChannel();
+
+ uint8_t opcode;
+ uint8_t package;
+ std::optional<uint8_t> channel;
+ std::vector<unsigned char> payload;
+};
+
+struct NCSIResponse
+{
+ uint8_t opcode;
+ uint8_t response, reason;
+ std::span<unsigned char> payload;
+ std::vector<unsigned char> full_payload;
+
+ /* Given an incoming response with full_payload set, check that we have
+ * enough data for a correct response, and populate the rest of the struct
+ * to suit
+ */
+ int parseFullPayload();
+};
+
struct Interface
{
- using ncsiMessage = std::span<const unsigned char>;
-
/* @brief This function will ask underlying NCSI driver
* to send an OEM command (command type 0x50) with
* the specified payload as the OEM data.
@@ -55,8 +83,7 @@
* @param[in] payload - OEM data to send.
* @returns the NCSI response message to this command, or no value on error.
*/
- std::optional<std::vector<unsigned char>> sendOemCommand(
- int package, int channel, int opcode, ncsiMessage payload);
+ std::optional<NCSIResponse> sendCommand(NCSICommand& cmd);
/* @brief This function will ask underlying NCSI driver
* to set a specific package or package/channel