Files
sunnypilot/selfdrive/modeld/dmonitoringmodeld.cc
Willem Melching 7f0b3180a4 Use C++ version of SubMaster and PubMaster (#1548)
* add PubMaster & SubMaster

remove 'delete msg'

remove headers

* use constructor to initial all submster

* modify drain sockets

* fix typo in ssconscript.remove lines

no checkValid in loggerd

last modify

handle_message:event->&event

fix type

remove heads

event to auto

* new interface

* api changed

* Revert "use constructor to initial all submster"

This reverts commit 73be7ea46250a325ce41d3a0445e34395a2ae692.

* change to new api

* revert loggerd

* dd

* use new PubSub api

* update to new interface

don't modify loggerd

reset panda

reset opendbc

remove empty lines

* switch to new pubMaster

* update to the new inteface

change

remove error code

. to ->

merge paramsd.cc

update panda

fix typo

simplify

fix typo

* Fix build

* always conflate

Co-authored-by: deanlee <deanlee3@gmail.com>
old-commit-hash: ab5af232b2
2020-05-21 16:04:33 -07:00

93 lines
2.2 KiB
C++

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <cassert>
#include "common/visionbuf.h"
#include "common/visionipc.h"
#include "common/swaglog.h"
#include "models/dmonitoring.h"
#ifndef PATH_MAX
#include <linux/limits.h>
#endif
volatile sig_atomic_t do_exit = 0;
static void set_do_exit(int sig) {
do_exit = 1;
}
int main(int argc, char **argv) {
int err;
set_realtime_priority(1);
// messaging
SubMaster sm({"dMonitoringState"});
PubMaster pm({"driverState"});
// init the models
DMonitoringModelState dmonitoringmodel;
dmonitoring_init(&dmonitoringmodel);
// loop
VisionStream stream;
while (!do_exit) {
VisionStreamBufs buf_info;
err = visionstream_init(&stream, VISION_STREAM_YUV_FRONT, true, &buf_info);
if (err) {
printf("visionstream connect fail\n");
usleep(100000);
continue;
}
LOGW("connected with buffer size: %d", buf_info.buf_len);
double last = 0;
int chk_counter = 0;
while (!do_exit) {
VIPCBuf *buf;
VIPCBufExtra extra;
buf = visionstream_get(&stream, &extra);
if (buf == NULL) {
printf("visionstream get failed\n");
visionstream_destroy(&stream);
break;
}
//printf("frame_id: %d %dx%d\n", extra.frame_id, buf_info.width, buf_info.height);
if (!dmonitoringmodel.is_rhd_checked) {
if (chk_counter >= RHD_CHECK_INTERVAL) {
if (sm.update(0) > 0) {
auto state = sm["dMonitoringState"].getDMonitoringState();
dmonitoringmodel.is_rhd = state.getIsRHD();
dmonitoringmodel.is_rhd_checked = state.getRhdChecked();
}
chk_counter = 0;
}
chk_counter += 1;
}
double t1 = millis_since_boot();
DMonitoringResult res = dmonitoring_eval_frame(&dmonitoringmodel, buf->addr, buf_info.width, buf_info.height);
double t2 = millis_since_boot();
// send dm packet
dmonitoring_publish(pm, extra.frame_id, res);
LOGD("dmonitoring process: %.2fms, from last %.2fms", t2-t1, t1-last);
last = t1;
}
}
visionstream_destroy(&stream);
dmonitoring_free(&dmonitoringmodel);
return 0;
}