Modify comment type & mcp2515 log
This commit is contained in:
parent
384990fb8d
commit
4d37fb5075
@ -520,7 +520,7 @@ int app_header_recv_inference(uint32_t buf_addr, bool *bl_run_next_inference)
|
|||||||
pthread_mutex_unlock(&g_stdc_seg_mutex);
|
pthread_mutex_unlock(&g_stdc_seg_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ── 1. Console log — class ratios + status (at most once per second) ── */
|
/* 1. Console log class ratios + status (at most once per second) */
|
||||||
{
|
{
|
||||||
static struct timeval s_last_log = {0, 0};
|
static struct timeval s_last_log = {0, 0};
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
@ -544,7 +544,7 @@ int app_header_recv_inference(uint32_t buf_addr, bool *bl_run_next_inference)
|
|||||||
ana->class_ratio[STDC_CLASS_ROAD] * 100.0f,
|
ana->class_ratio[STDC_CLASS_ROAD] * 100.0f,
|
||||||
ana->class_ratio[STDC_CLASS_TREE] * 100.0f);
|
ana->class_ratio[STDC_CLASS_TREE] * 100.0f);
|
||||||
|
|
||||||
/* ── 2. Grass / motion state ── */
|
/*2. Grass / motion state*/
|
||||||
if (ana->on_grass)
|
if (ana->on_grass)
|
||||||
printf("[STDC] ON GRASS: %.1fs%s\n",
|
printf("[STDC] ON GRASS: %.1fs%s\n",
|
||||||
ana->grass_duration_sec,
|
ana->grass_duration_sec,
|
||||||
@ -555,7 +555,7 @@ int app_header_recv_inference(uint32_t buf_addr, bool *bl_run_next_inference)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ── 3. Warning log (on state change — matches Python sections H/I/J) ── */
|
/* 3. Warning log (on state change — matches Python sections H/I/J) */
|
||||||
{
|
{
|
||||||
static int s_last_warn = -1;
|
static int s_last_warn = -1;
|
||||||
int warn_mask = (ana->collision_risk ? 0x001 : 0)
|
int warn_mask = (ana->collision_risk ? 0x001 : 0)
|
||||||
@ -599,7 +599,7 @@ int app_header_recv_inference(uint32_t buf_addr, bool *bl_run_next_inference)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ── 4. Visual overlay via g_atDrawInfo (rendered by draw_box DMA thread) ──
|
/* 4. Visual overlay via g_atDrawInfo (rendered by draw_box DMA thread)
|
||||||
*
|
*
|
||||||
* Requires DrawBoxEnable=1 in host_stream.ini / demo_rtsp.sh.
|
* Requires DrawBoxEnable=1 in host_stream.ini / demo_rtsp.sh.
|
||||||
* The draw_box thread calls draw_rect() for each entry 0..g_dwResultCounts-1.
|
* The draw_box thread calls draw_rect() for each entry 0..g_dwResultCounts-1.
|
||||||
@ -636,15 +636,11 @@ int app_header_recv_inference(uint32_t buf_addr, bool *bl_run_next_inference)
|
|||||||
unsigned int y_top = (draw_h * 55u) / 100u;
|
unsigned int y_top = (draw_h * 55u) / 100u;
|
||||||
unsigned int y_bottom = (draw_h * 95u) / 100u;
|
unsigned int y_bottom = (draw_h * 95u) / 100u;
|
||||||
|
|
||||||
stdc_add_trapezoid_outline(di, &cnt,
|
stdc_add_trapezoid_outline(di, &cnt,x_tl, x_tr, x_bl, x_br,y_top, y_bottom);
|
||||||
x_tl, x_tr, x_bl, x_br,
|
|
||||||
y_top, y_bottom);
|
|
||||||
|
|
||||||
/* Collision emphasis: draw a second inner trapezoid when active. */
|
/* Collision emphasis: draw a second inner trapezoid when active. */
|
||||||
if (ana->collision_risk && x_tr > x_tl + 8u && x_br > x_bl + 16u && y_bottom > y_top + 8u) {
|
if (ana->collision_risk && x_tr > x_tl + 8u && x_br > x_bl + 16u && y_bottom > y_top + 8u) {
|
||||||
stdc_add_trapezoid_outline(di, &cnt,
|
stdc_add_trapezoid_outline(di, &cnt,x_tl + 4u, x_tr - 4u,
x_bl + 8u, x_br - 8u,y_top + 4u, y_bottom - 4u);
|
||||||
x_tl + 4u, x_tr - 4u,
x_bl + 8u, x_br - 8u,
|
|
||||||
y_top + 4u, y_bottom - 4u);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Side warning/class panels are intentionally disabled.
|
/* Side warning/class panels are intentionally disabled.
|
||||||
|
|||||||
@ -1194,9 +1194,7 @@ static void save_jpeg(const char *path, const uint8_t *buf, int size)
|
|||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ═══════════════════════════════════════════════════════════════════════════
|
/* * State machine helpers*/
|
||||||
* State machine helpers
|
|
||||||
* ═══════════════════════════════════════════════════════════════════════════ */
|
|
||||||
|
|
||||||
static void request_snap(const char *filename, const char *work_dir,
|
static void request_snap(const char *filename, const char *work_dir,
|
||||||
const char *event_id, const char *event_type,
|
const char *event_id, const char *event_type,
|
||||||
@ -1221,16 +1219,13 @@ static void request_snap(const char *filename, const char *work_dir,
|
|||||||
/* Enter a grass level: fire JSON + request snap */
|
/* Enter a grass level: fire JSON + request snap */
|
||||||
static void grass_enter_level(int level)
|
static void grass_enter_level(int level)
|
||||||
{
|
{
|
||||||
char ts[32];
|
|
||||||
now_iso(ts, sizeof(ts));
|
|
||||||
printf("[EVT] grass Level %d id=%s\n", level, g_grass.event_id);
|
printf("[EVT] grass Level %d id=%s\n", level, g_grass.event_id);
|
||||||
|
|
||||||
fire_json_async(g_grass.event_id, "lane", level);
|
fire_json_async(g_grass.event_id, "lane", level);
|
||||||
|
|
||||||
char filename[32];
|
char filename[32];
|
||||||
snprintf(filename, sizeof(filename), "level%d.jpg", level);
|
snprintf(filename, sizeof(filename), "level%d.jpg", level);
|
||||||
request_snap(filename, g_grass.work_dir,
|
request_snap(filename, g_grass.work_dir,g_grass.event_id, "grass", level, 0 );/* not immediate */
|
||||||
g_grass.event_id, "grass", level, 0 /* not immediate */);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* * Public API**/
|
/* * Public API**/
|
||||||
@ -1273,7 +1268,6 @@ void event_recorder_init(const char *upload_url,
|
|||||||
/* Recv callback: drives state machine */
|
/* Recv callback: drives state machine */
|
||||||
void event_recorder_update(const stdc_analysis_t *ana)
|
void event_recorder_update(const stdc_analysis_t *ana)
|
||||||
{
|
{
|
||||||
#if 1
|
|
||||||
if (!s_enabled) return;
|
if (!s_enabled) return;
|
||||||
|
|
||||||
if (g_test_mode) {
|
if (g_test_mode) {
|
||||||
@ -1299,8 +1293,7 @@ void event_recorder_update(const stdc_analysis_t *ana)
|
|||||||
g_grass.t_last_active = g_grass.t_l1;
|
g_grass.t_last_active = g_grass.t_l1;
|
||||||
g_grass.max_level = 1;
|
g_grass.max_level = 1;
|
||||||
g_grass.upload_busy = 0;
|
g_grass.upload_busy = 0;
|
||||||
snprintf(g_grass.event_id, sizeof(g_grass.event_id),
|
snprintf(g_grass.event_id, sizeof(g_grass.event_id),"%ld", g_grass.t_l1.tv_sec);
|
||||||
"%ld", g_grass.t_l1.tv_sec);
|
|
||||||
make_work_dir(g_grass.event_id, g_grass.work_dir, sizeof(g_grass.work_dir));
|
make_work_dir(g_grass.event_id, g_grass.work_dir, sizeof(g_grass.work_dir));
|
||||||
g_grass.state = GRASS_L1;
|
g_grass.state = GRASS_L1;
|
||||||
pthread_mutex_unlock(&g_grass_mtx);
|
pthread_mutex_unlock(&g_grass_mtx);
|
||||||
@ -1436,73 +1429,9 @@ void event_recorder_update(const stdc_analysis_t *ana)
|
|||||||
g_last_right_alert = right_now;
|
g_last_right_alert = right_now;
|
||||||
}
|
}
|
||||||
g_any_col_last = col_now;
|
g_any_col_last = col_now;
|
||||||
#endif
|
|
||||||
#if 0
|
|
||||||
/* ── [TEST] violation(2.2.2)靜態測試向量 ──────────────────────────
|
|
||||||
* 每隔 3 秒依序送出 level 1 → 2 → 3 → 0,模擬一次完整違規事件週期:
|
|
||||||
* level 1:違規發生
|
|
||||||
* level 2:違規持續 6 秒
|
|
||||||
* level 3:違規持續 10 秒
|
|
||||||
* level 0:違規解除
|
|
||||||
* 啟用:把 #if 0 改成 #if 1
|
|
||||||
* ------------------------------------------------------------------ */
|
|
||||||
{
|
|
||||||
static int s_viol_tick = 0;
|
|
||||||
static int s_viol_phase = 0;
|
|
||||||
static int s_viol_last = -1;
|
|
||||||
static char s_viol_id[24] = "";
|
|
||||||
|
|
||||||
s_viol_tick++;
|
|
||||||
if (s_viol_tick >= 75) { /* 約 3 秒(25 fps × 3)*/
|
|
||||||
s_viol_tick = 0;
|
|
||||||
s_viol_phase = (s_viol_phase + 1) % 4;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s_viol_phase != s_viol_last) {
|
/*Send callback: take VMF_SNAP if one is pending*/
|
||||||
s_viol_last = s_viol_phase;
|
|
||||||
if (s_viol_phase == 0)
|
|
||||||
snprintf(s_viol_id, sizeof(s_viol_id), "%ld", (long)time(NULL));
|
|
||||||
static const int levels[] = {1, 2, 3, 0};
|
|
||||||
int lvl = levels[s_viol_phase];
|
|
||||||
fire_json_async(s_viol_id, "lane", lvl);
|
|
||||||
printf("[TEST] violation id=%s level=%d\n", s_viol_id, lvl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#if 0
|
|
||||||
/* ── [TEST] alert(2.2.4)靜態測試向量 ──────────────────────────────
|
|
||||||
* 每隔 5 秒輪流送出四種組合,驗證 iPad 端能正確顯示:
|
|
||||||
* 0: 左右都無危險
|
|
||||||
* 1: 左側 tree,右側無危險
|
|
||||||
* 2: 左側無危險,右側 person
|
|
||||||
* 3: 左右都有危險(tree / vehicle)
|
|
||||||
* 啟用:把 #if 0 改成 #if 1
|
|
||||||
* ------------------------------------------------------------------ */
|
|
||||||
{
|
|
||||||
static int s_test_tick = 0;
|
|
||||||
static int s_test_phase = 0;
|
|
||||||
static int s_last_phase = -1;
|
|
||||||
|
|
||||||
s_test_tick++;
|
|
||||||
if (s_test_tick >= 125) { /* 約 5 秒(25 fps × 5)*/
|
|
||||||
s_test_tick = 0;
|
|
||||||
s_test_phase = (s_test_phase + 1) % 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s_test_phase != s_last_phase) {
|
|
||||||
s_last_phase = s_test_phase;
|
|
||||||
switch (s_test_phase) {
|
|
||||||
case 0: fire_alert(0, NULL, 0, NULL); printf("[TEST] alert: left=0 right=0\n"); break;
|
|
||||||
case 1: fire_alert(1, "tree", 0, NULL); printf("[TEST] alert: left=tree right=0\n"); break;
|
|
||||||
case 2: fire_alert(0, NULL, 1, "person"); printf("[TEST] alert: left=0 right=person\n"); break;
|
|
||||||
case 3: fire_alert(1, "tree", 1, "vehicle");printf("[TEST] alert: left=tree right=vehicle\n"); break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ── Send callback: take VMF_SNAP if one is pending ─────────────────────── */
|
|
||||||
void event_recorder_provide_frame(void)
|
void event_recorder_provide_frame(void)
|
||||||
{
|
{
|
||||||
if (!s_enabled) return;
|
if (!s_enabled) return;
|
||||||
@ -1548,7 +1477,6 @@ void event_recorder_provide_frame(void)
|
|||||||
if (req.immediate_upload) {
|
if (req.immediate_upload) {
|
||||||
const char imgs[4][64] = { "snapshot.jpg", "", "", "" };
|
const char imgs[4][64] = { "snapshot.jpg", "", "", "" };
|
||||||
int image_count = snap_ok ? 1 : 0;
|
int image_count = snap_ok ? 1 : 0;
|
||||||
launch_upload(req.work_dir, req.event_id, req.event_type,
|
launch_upload(req.work_dir, req.event_id, req.event_type,req.max_level, 0.0f, imgs, image_count, 0);
|
||||||
req.max_level, 0.0f, imgs, image_count, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -484,19 +484,19 @@ uint8_t mcp2515_setMode(mcp2515_dev *mcp2515_device,const CANCTRL_REQOP_MODE mod
|
|||||||
uint8_t newmode = canstat_full & CANSTAT_OPMOD;
|
uint8_t newmode = canstat_full & CANSTAT_OPMOD;
|
||||||
|
|
||||||
modeMatch = newmode == mode;
|
modeMatch = newmode == mode;
|
||||||
if (time_count == 0 || time_count == 9 || modeMatch) {
|
|
||||||
printf("[MCP] setMode(%s/0x%02X): attempt %d, CANSTAT=0x%02X (mode bits=0x%02X), expect=0x%02X %s\n",
|
|
||||||
mode_str, mode, time_count, canstat_full, newmode, mode, modeMatch ? "✓" : "");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (modeMatch) {
|
if (modeMatch) {
|
||||||
|
/* Only log on success if it took more than one attempt (retry needed) */
|
||||||
|
if (time_count > 0)
|
||||||
|
printf("[MCP] setMode(%s): OK after %d retries (CANSTAT=0x%02X)\n",
|
||||||
|
mode_str, time_count, canstat_full);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
usleep(1000); /* 1 ms retry delay */
|
usleep(1000); /* 1 ms retry delay */
|
||||||
time_count++;
|
time_count++;
|
||||||
}
|
}
|
||||||
if (!modeMatch) {
|
if (!modeMatch) {
|
||||||
printf("[MCP] ERROR: setMode(%s) failed after %d attempts\n", mode_str, time_count);
|
printf("[MCP] ERROR: setMode(%s/0x%02X) failed after %d attempts, CANSTAT=0x%02X\n",
|
||||||
|
mode_str, mode, time_count, mcp2515_read_register_once(mcp2515_device, MCP_CANSTAT));
|
||||||
}
|
}
|
||||||
return modeMatch ? ERROR_OK : ERROR_FAIL;
|
return modeMatch ? ERROR_OK : ERROR_FAIL;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user