Modify comment type & mcp2515 log

This commit is contained in:
miketsai 2026-07-16 15:59:31 +08:00
parent 384990fb8d
commit 4d37fb5075
3 changed files with 17 additions and 93 deletions

View File

@ -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);
}
/* ── 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};
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_TREE] * 100.0f);
/* ── 2. Grass / motion state ── */
/*2. Grass / motion state*/
if (ana->on_grass)
printf("[STDC] ON GRASS: %.1fs%s\n",
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;
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.
* 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_bottom = (draw_h * 95u) / 100u;
stdc_add_trapezoid_outline(di, &cnt,
x_tl, x_tr, x_bl, x_br,
y_top, y_bottom);
stdc_add_trapezoid_outline(di, &cnt,x_tl, x_tr, x_bl, x_br,y_top, y_bottom);
/* 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) {
stdc_add_trapezoid_outline(di, &cnt,
x_tl + 4u, x_tr - 4u, x_bl + 8u, x_br - 8u,
y_top + 4u, y_bottom - 4u);
stdc_add_trapezoid_outline(di, &cnt,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.

View File

@ -1194,9 +1194,7 @@ static void save_jpeg(const char *path, const uint8_t *buf, int size)
fflush(stdout);
}
/* ═══════════════════════════════════════════════════════════════════════════
* State machine helpers
* */
/* * State machine helpers*/
static void request_snap(const char *filename, const char *work_dir,
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 */
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);
fire_json_async(g_grass.event_id, "lane", level);
char filename[32];
snprintf(filename, sizeof(filename), "level%d.jpg", level);
request_snap(filename, g_grass.work_dir,
g_grass.event_id, "grass", level, 0 /* not immediate */);
request_snap(filename, g_grass.work_dir,g_grass.event_id, "grass", level, 0 );/* not immediate */
}
/* * Public API**/
@ -1273,7 +1268,6 @@ void event_recorder_init(const char *upload_url,
/* Recv callback: drives state machine */
void event_recorder_update(const stdc_analysis_t *ana)
{
#if 1
if (!s_enabled) return;
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.max_level = 1;
g_grass.upload_busy = 0;
snprintf(g_grass.event_id, sizeof(g_grass.event_id),
"%ld", g_grass.t_l1.tv_sec);
snprintf(g_grass.event_id, sizeof(g_grass.event_id),"%ld", g_grass.t_l1.tv_sec);
make_work_dir(g_grass.event_id, g_grass.work_dir, sizeof(g_grass.work_dir));
g_grass.state = GRASS_L1;
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_any_col_last = col_now;
#endif
#if 0
/* ── [TEST] violation2.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) {
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] alert2.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 ─────────────────────── */
/*Send callback: take VMF_SNAP if one is pending*/
void event_recorder_provide_frame(void)
{
if (!s_enabled) return;
@ -1548,7 +1477,6 @@ void event_recorder_provide_frame(void)
if (req.immediate_upload) {
const char imgs[4][64] = { "snapshot.jpg", "", "", "" };
int image_count = snap_ok ? 1 : 0;
launch_upload(req.work_dir, req.event_id, req.event_type,
req.max_level, 0.0f, imgs, image_count, 0);
launch_upload(req.work_dir, req.event_id, req.event_type,req.max_level, 0.0f, imgs, image_count, 0);
}
}

View File

@ -484,19 +484,19 @@ uint8_t mcp2515_setMode(mcp2515_dev *mcp2515_device,const CANCTRL_REQOP_MODE mod
uint8_t newmode = canstat_full & CANSTAT_OPMOD;
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) {
/* 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;
}
usleep(1000); /* 1 ms retry delay */
time_count++;
}
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;