[ncp] adding SpinelEncoder class and updating NCP implementation (#2221)

This commit adds a new class `SpinelEncoder` which provides a set of
methods/APIs to help in encoding/writing content using Spinel formating
(it is practically a C++ wrapper over Spinel C APIs). A unit test
`test_spinel_encoder` is also added in this commit.

This commit also updates the `NcpBase` implementation to adopt the new
`SpinelEncoder` class mainly in implementation of get, insert, and
remove  handlers for different Spinel properties. The new class
provides the following advantages: (a) it simplifies the
implementation of handers, particularly get-handlers for properties
with a single type output; (b) it adds type-checking and type-safety
when frames are being created, e.g., if the Spinel format expects a
`SPINEL_DATATYPE_UINT8` but a `uint16_t` value is provided, the new
model will cause a compile-time error (few instances in code where the
types did not match are fixed in this commit).
This commit is contained in:
Abtin Keshavarzian
2017-09-27 23:04:53 -07:00
committed by Jonathan Hui
parent 7dbc20d2dd
commit 192df6cf00
16 changed files with 2576 additions and 2604 deletions
@@ -66,6 +66,7 @@
<ClCompile Include="..\..\src\ncp\ncp_buffer.cpp" />
<ClCompile Include="..\..\src\ncp\ncp_spi.cpp" />
<ClCompile Include="..\..\src\ncp\spinel.c" />
<ClCompile Include="..\..\src\ncp\spinel_encoder.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\ncp\changed_props_set.hpp" />
@@ -73,6 +74,7 @@
<ClInclude Include="..\..\src\ncp\ncp_buffer.hpp" />
<ClInclude Include="..\..\src\ncp\ncp_spi.hpp" />
<ClInclude Include="..\..\src\ncp\spinel.h" />
<ClInclude Include="..\..\src\ncp\spinel_encoder.hpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
@@ -36,6 +36,9 @@
<ClCompile Include="..\..\src\ncp\spinel.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ncp\spinel_encoder.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ncp\ncp_spi.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@@ -56,5 +59,8 @@
<ClInclude Include="..\..\src\ncp\spinel.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ncp\spinel_encoder.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
@@ -67,6 +67,7 @@
<ClCompile Include="..\..\src\ncp\ncp_buffer.cpp" />
<ClCompile Include="..\..\src\ncp\ncp_uart.cpp" />
<ClCompile Include="..\..\src\ncp\spinel.c" />
<ClCompile Include="..\..\src\ncp\spinel_encoder.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\ncp\changed_props_set.hpp" />
@@ -75,6 +76,7 @@
<ClInclude Include="..\..\src\ncp\ncp_buffer.hpp" />
<ClInclude Include="..\..\src\ncp\ncp_uart.hpp" />
<ClInclude Include="..\..\src\ncp\spinel.h" />
<ClInclude Include="..\..\src\ncp\spinel_encoder.hpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
@@ -42,6 +42,9 @@
<ClCompile Include="..\..\src\ncp\spinel.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ncp\spinel_encoder.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\ncp\changed_props_set.hpp">
@@ -62,5 +65,8 @@
<ClInclude Include="..\..\src\ncp\spinel.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ncp\spinel_encoder.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>