create library for using locationd in python using ffi (#20711)

* create library for using locationd in python using ffi

* lib is not required in release

* cleanup

* dont build liblocationd on release

* add check on buffer size
pull/20733/head
Joost Wooning 2021-04-20 17:50:40 +02:00 committed by GitHub
parent ed8acfa284
commit e08a570a13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 3 deletions

View File

@ -10,9 +10,13 @@ if GetOption('kaitai'):
env.Program("ubloxd", ["ubloxd.cc", "ublox_msg.cc", "generated/ubx.cpp", "generated/gps.cpp"], LIBS=loc_libs)
ekf_sym_cc = env.Object("#rednose/helpers/ekf_sym.cc")
ekf_sym_cc = env.SharedObject("#rednose/helpers/ekf_sym.cc")
locationd_sources = ["locationd.cc", "models/live_kf.cc", ekf_sym_cc]
lenv = env.Clone()
lenv["_LIBFLAGS"] += f' {libkf[0].get_labspath()}'
locationd = lenv.Program("locationd", ["locationd.cc", "models/live_kf.cc", ekf_sym_cc],
LIBS=loc_libs + transformations)
locationd = lenv.Program("locationd", locationd_sources, LIBS=loc_libs + transformations)
lenv.Depends(locationd, libkf)
if File("liblocationd.cc").exists():
liblocationd = lenv.SharedLibrary("liblocationd", ["liblocationd.cc"] + locationd_sources, LIBS=loc_libs + transformations)
lenv.Depends(liblocationd, libkf)

View File

@ -0,0 +1,22 @@
#include "locationd.h"
extern "C" {
typedef Localizer* Localizer_t;
Localizer *localizer_init() {
return new Localizer();
}
void localizer_get_message_bytes(Localizer *localizer, uint64_t logMonoTime,
bool inputsOK, bool sensorsOK, bool gpsOK, char *buff, size_t buff_size)
{
MessageBuilder msg_builder;
kj::ArrayPtr<char> arr = localizer->get_message_bytes(msg_builder, logMonoTime, inputsOK, sensorsOK, gpsOK).asChars();
assert(buff_size >= arr.size());
memcpy(buff, arr.begin(), arr.size());
}
void localizer_handle_msg_bytes(Localizer *localizer, const char *data, size_t size) {
localizer->handle_msg_bytes(data, size);
}
}