Skip to content

Commit

Permalink
Merge pull request #8 from Auterion/updates
Browse files Browse the repository at this point in the history
Update libmav to latest, more bindings
  • Loading branch information
ThomasDebrunner authored Apr 2, 2024
2 parents a91fef9 + 73b43f4 commit 72aa809
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/bind_Message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ void bind_Message(py::module m) {
py::arg("field_key"), py::arg("value"), py::arg("array_index") = 0)
.def("__setitem__", &Message::set<const std::string&>,
py::arg("field_key"), py::arg("value"), py::arg("array_index") = 0)
.def("set_as_float_pack", &Message::setAsFloatPack<int32_t>,
py::arg("field_key"), py::arg("value"), py::arg("array_index") = 0)
.def("set_as_float_pack", &Message::setAsFloatPack<uint32_t>,
py::arg("field_key"), py::arg("value"), py::arg("array_index") = 0)
.def("get_as_float_unpack", &Message::getAsFloatUnpack<int32_t>,
py::arg("field_key"), py::arg("array_index") = 0)
.def("get_as_float_unpack_unsigned", &Message::getAsFloatUnpack<uint32_t>,
py::arg("field_key"), py::arg("array_index") = 0)
.def("set_from_dict", [](Message &m, const py::dict &d) {
setFromDict(m, d);
return m;
Expand Down
1 change: 1 addition & 0 deletions src/bind_PhysicalNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void bind_PhysicalNetwork(py::module m) {

py::class_<UDPServer, NetworkInterface>(m, "UDPServer")
.def(py::init<int>(), py::arg("local_port"))
.def("join_multicast_group", &UDPServer::joinMulticastGroup)
.def("close", &UDPServer::close);

py::class_<TCPServer, NetworkInterface>(m, "TCPServer")
Expand Down
4 changes: 4 additions & 0 deletions src/bind_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ void bind_utils(py::module m) {
.def("crc16", &CRC::crc16)
.def("crc8", &CRC::crc8);

m.def("float_pack", &floatPack<int32_t>);
m.def("float_pack", &floatPack<uint32_t>);
m.def("float_unpack", &floatUnpack<int32_t>);
m.def("float_unpack_unsigned", &floatUnpack<uint32_t>);
}
5 changes: 5 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ def testMessageSetGet(self):
self.assertEqual(message['float_arr_field'], [1.0, 2.0, 3.0])
self.assertEqual(message['int32_arr_field'], [4, 5, 6])

def testMessageFloatPackUnpack(self):
message = self.message_set.create('BIG_MESSAGE')
message.set_as_float_pack('float_field', 12)
self.assertEqual(message.get_as_float_unpack('float_field'), 12)

def testSetFromDict(self):
message = self.message_set.create('BIG_MESSAGE')

Expand Down

0 comments on commit 72aa809

Please sign in to comment.