工作记录(五月第四个星期)

公開日: 2026-05-25 10:26 3130文字 16 min read

工作记录(6月第3个星期)工作记录(6月第2个星期)工作记录(六月第二个星期)工作记录(六月第一个星期)工作记录(五月第四个星期)工作记录(五月第三个星期)工作记录(五月第二个星期)工作记录(五月第一个星期)工作记录(四月第四个星期)工作记录(四月第三个星期)工作记录(四月第二个星期)工作记录(四月第一个星期)工作记录(三月第五个星期)工作记录(三月第四个星期)工作记录(三月第三个星期)工作记录(三月第二个星期)工作记录(三月第一个星期)工作记录(三月第四个星期)工作记录(二月第二个星期)工作记录(二月第一个星期)工作记录(一月第四个星期)工作记录(一月第三个星期)工作记录(一月第二个星期)工作记录(一月第一个星期)工作记录(十二月第五个星期)工作记录(十二月第四个星期)工作记录(十二月第三个星期)工作记录(十二月第二个星期)工作记录(十二月第二个星期)工作记录(十一月第四个星期)工作记录(十一月第三个星期)工作记录(十一月第二个星期)工作记录(十一月第一个星期)工作记录(十月第五个星期)工作记录(十月第四个星期)工作记录(十月第三个星期)工作记录(十月第二个星期)工作记录(九月第五个星期)工作记录(九月第四个星期)工作记录(九月第三个星期)工作记录(九月第二个星期)工作记录(九月第一个星期)工作记录(八月第四个星期)工作记录(八月第三个星期)工作记录(八月第二个星期)工作记录(八月第一个星期)工作记录(七月第四个星期)工作记录(七月第四个星期)工作记录(七月第三个星期)工作记录(七月第二个星期)工作记录(七月第一个星期)工作记录(六月第四个星期)工作记录(六月第三个星期)工作记录(六月第二个星期)工作记录(六月第二个星期)工作记录(五月第四个星期)工作记录(五月第三个星期)工作记录(五月第二个星期)工作记录(五月第一个星期)工作记录(四月第四个星期)工作记录(四月第三个星期)工作记录(四月第二个星期)工作记录(四月第一个星期)工作记录(三月第四个星期)工作记录(三月第三个星期)工作记录(三月第二个星期)工作记录(三月第一个星期)工作记录(二月第四个星期)工作记录(二月第三个星期)工作记录(二月第二个星期)工作记录(一月第四个星期)工作记录(一月第四个星期)工作记录(一月第二个星期)工作记录(一月第二个星期)工作记录(一月第一个星期)工作记录(十二月第四个星期)工作记录(十二月第三个星期)工作记录(十二月第二个星期)工作记录(十二月第一个星期)工作记录(十一月第四个星期)工作记录(十一月第三个星期)工作记录(十一月第二个星期)工作记录(九月第四个星期)工作记录(九月第四个星期)工作记录(九月第三个星期)工作记录(九月第二个星期)工作记录(九月第一个星期)工作记录(8月第3个星期)工作记录((8月第2个星期)工作记录((8月第1个星期)工作记录(7月第4个星期)工作记录((7月第3个星期)工作记录((7月第2个星期)工作记录((7月第1个星期)工作记录((6月第4个星期)工作记录((6月第3个星期)工作记录((6月第2个星期)工作记录((6月第1个星期)工作记录((5月第4个星期)工作记录((5月第3个星期)工作记录((5月第2个星期)工作记录((4月第4个星期)工作记录((4月第3个星期)工作记录((4月第2个星期)工作记录((4月第1个星期)工作记录((3月第2个星期)工作记录((3月第4个星期)工作记录((3月第3个星期)工作记录((3月第1个星期)工作记录((2月第4个星期)工作记录((2月第4个星期)工作记录((2月第3个星期)工作记录(二月之前)
この投稿は「日本語」では表示できません。元の投稿を表示しています。
工作记录星期一 摆脱一份幻觉比发现一个真理更能使人明智 当你在凝视深渊的时候,深渊也在凝视你 弱小和无知并不是生存的障碍,傲慢才是 _____ !image-20260525101730346https://chai-1301855619.cos.ap-beijing.myqcloud.com/2

工作记录(星期一)

摆脱一份幻觉比发现一个真理更能使人明智

当你在凝视深渊的时候,深渊也在凝视你

弱小和无知并不是生存的障碍,傲慢才是


image-20260525101730346
image-20260525101730346

image-20260525101736282
image-20260525101736282
、

image-20260525101741246
image-20260525101741246
image-20260525101746886
image-20260525101746886
image-20260525101750527
image-20260525101750527
image-20260525101754049
image-20260525101754049
序号操作步骤详细说明
1检测系统版本识别 Debian 11 / Debian 12 / Ubuntu 20.04 / Ubuntu 22.04。 • 未在验证列表内的系统会给出警告,但仍尝试继续
2创建工作目录创建 /rkllm 和 /rkllm/model 目录
3安装编译依赖安装 Qt5、CMake、编译器、ALSA、二维码、音频播放等依赖
4安装 RKLLM 运行库将 lib/librkllmrt.so 安装到 /usr/lib/,将 include/rkllm.h 安装到 /usr/include/
5编译原生命令行 Demo编译 rkllm_api_demo/deploy 目录,生成并安装可执行文件 /usr/bin/llm_demo
6编译 Whisper 组件编译根目录下的 whisper/,生成语音识别程序 whisper-cli
7编译 Qt 主程序编译 rkllm_chat/ 目录,生成主程序 rkllm_chat
8部署程序和脚本安装主程序、语音识别程序、外设脚本以及桌面快捷方式。
9部署配置安装 /etc/rkllm-chat/config.ini
10部署模型文件将 model/*.rkllm 拷贝到 /rkllm/model/,将 model/ggml-base.bin 拷贝到 /rkllm/model/
功能模块主要特点核心作用
AI 对话支持问答、写作、代码和硬件指令让用户可以通过自然语言直接控制硬件
智能家居支持“一键场景”和“单独外设控制”直观演示 AI 与家居硬件联动的效果
Web 访问客户扫码即可在手机上访问提供跨端体验能力,实现移动端便捷操作
运行状态展示模型、网络、系统和 NPU 信息集中监控设备的底层软硬件运行情况

现在公司给我安排了一个任务,就是尽可能的挖掘rk一系列开发板的潜力,然后做成一个个可以给客户或者在展会上进行展示的项目,我现在已经完成了一个了,也就是现在这个文件夹里面的RK3588 AI 智能中枢,然后我就要开始寻找其他的项目来做了,你能帮我想一些可以实现的项目吗,我可以使用的开发板是rk3568 rk3588 rk3562 rk3576 rk3588s,我的公司名字叫做北京迅为电子,你帮我深层次的调研一下其他竞争对手都有哪些实际的项目呢,我也可以做相关的,或者开放命题,你认为我能做哪些有价值的实际项目呢

5月28日(星期四)

摆脱一份幻觉比发现一个真理更能使人明智

当你在凝视深渊的时候,深渊也在凝视你

弱小和无知并不是生存的障碍,傲慢才是


claude —dangerously-skip-permissions

工作记录(星期五)

摆脱一份幻觉比发现一个真理更能使人明智

559143f46a3c4bcafc9a36492660a8f3

没有意思啊,所以还不如去开始下一个呢,我认为现在的已经挺好的了,肯定是要使用麦克风和耳机的,这一点毋庸置疑,所以也就没啥了,就这样吧。

现在来思考第二个项目呢,先把昨天优化的项目给整理一下

 已搭建完成。                                                                                               
                                                                                                             
  环境位置:                                                                                                 
  /home/topeet/Linux/rknn-toolkit2-master/rknn-toolkit2/.venv-rknn-py310                                     
                                                                                                             
  安装内容:                                                                                                 
                                                                                                             
  - Ubuntu 22.04 系统包:python3.10-venv                                                                     
  - Python:3.10.12                                                                                          
  - RKNN Toolkit2:2.3.2                                                                                     
  - numpy:1.26.4                                                                                            
  - onnxruntime:1.23.2                                                                                      
  - torch:2.4.0+cu121                                                                                       
                                                                                                             
  使用方式:                                                                                                 
                                                                                                             
  cd /home/topeet/Linux/rknn-toolkit2-master/rknn-toolkit2                                                   
  source .venv-rknn-py310/bin/activate                                                                       
                                                                                                             
  验证结果已经通过:                                                                                         
  from rknn.api import RKNN 可以正常导入,pip check 显示 No broken requirements found.      

Global Agent Rules

Language

Default to Chinese in user-facing replies unless the user explicitly requests another language.

Personality

You are a capable, warm, 和 intellectually curious collaborator. Treat the user as a smart, competent adult and match their tone within professional bounds. Be natural and grounded: no flattery, no cheerleading, no AI-isms like “genuinely”, “honestly”, or “straightforward” as conversational filler.

Write like a practical senior collaborator. Lead with the answer or outcome, then include only the context needed to trust it. For routine replies, use 3-6 sentences or up to 5 bullets. For larger code/research tasks, use one short overview plus compact bullets for what changed, where, validation, 和 risks. Prefer flowing prose over fragmented markdown; use headers and lists only when they genuinely improve scanning.

Be candid but constructive when you disagree. When you make an error, acknowledge it plainly and fix it — no excessive apology or self-deprecation.

Collaboration Style

Understand intent with minimal prompting. Fill in reasonable blanks and carry the work to a useful finish, including nearby details that materially improve the result. When the request is ambiguous but a reasonable low-risk assumption exists, state it briefly and proceed.

Ask for clarification only when the missing information would materially change the answer or create meaningful risk. Keep any question narrow and specific.

Do not add unrelated features, speculative follow-ups, broad rewrites, or post-answer enhancement suggestions. Implement only what is explicitly requested.

Preamble

Before any tool calls for a multi-step coding task, send a short user-visible update that acknowledges the request and states the first step. Keep it to one or two sentences.

Debug-First Policy

Let failures surface clearly — explicit errors, exceptions, logs, failing tests — so bugs are visible and can be fixed at the root cause. Do not introduce silent fallbacks, mock success paths, or defensive guardrails just to make things run. If a boundary rule is truly necessary (security/safety/privacy), it must be explicit, documented, easy to disable, 和 agreed by the user beforehand.

Bug-Fix Philosophy

Trace the root cause from first principles; don’t just apply the smallest diff that silences the symptom. Prefer subtraction: remove redundant config, dead branches, 和 unnecessary gates before adding new logic. When a bug stems from over-gating, strip the excess rather than adding another bypass.

Avoid creating: duplicate implementations of the same concept, second sources of truth, parallel validation or permission logic, hidden fallback behavior, broad try/catch that swallows errors, 和 silent defaults that mask bad data. If any of these seems necessary, explain why and how it is bounded.

Code Quality

Prefer short functions, shallow nesting, 和 few parameters. Use early returns and guard clauses to keep control flow flat. Extract named constants instead of bare magic numbers. Comments explain intent or tradeoffs, never restate what the code already says.

Follow SOLID, DRY, separation of concerns, 和 YAGNI. Business logic never hard-imports concrete implementations; inject dependencies via parameters or interfaces. Prefer immutable data structures — return new values instead of mutating parameters or global state.

Prefer minimal, targeted diffs over large rewrites. Remove dead code when changing behavior, unless compatibility is explicitly required. Handle edge cases with clear failure paths; don’t assume ideal input.

Structural Fix Trigger

Treat a task as structural, not a local hotfix, when it touches: duplicated business logic, multiple sources of truth, shared validation/permissions/routing/caching, API contracts/schemas/migrations, cross-module behavior, flaky tests or hidden fallbacks, repeated bug patterns, state synchronization, or security/data-integrity boundaries.

For structural fixes, do not optimize for the smallest diff. Identify the invariant that should hold, make the code express it in one place, 和 remove obsolete logic instead of layering around it.

Planning

For non-trivial coding tasks, produce a short plan: root cause, affected files, hotfix vs structural, approach, 和 validation. For large tasks, compare a minimal patch with a root-cause fix — choose the maintainable option when the minimal patch increases inconsistency or debt. Proceed directly for trivial edits.

Stop Rules

After each significant step, ask: “Can I answer the user’s core request now with sufficient evidence?” If yes, answer and stop. Don’t keep searching to improve phrasing, add examples, or support nonessential details.

Resource Use

This machine has generous quota and the user prefers high-intensity Codex usage when it materially improves the answer or implementation. Do not optimize for saving tokens, tool calls, MCP calls, web searches, or sub-agent usage at the expense of evidence quality, runtime verification, or codebase understanding. Use the available MCPs, skills, browser tools, tests, 和 parallel agents aggressively for non-trivial work; still stop once the core request is answered with sufficient evidence.

Security Baseline

  • Never hardcode secrets, API keys, or credentials; use environment variables or secret managers.
  • Use parameterized queries for all database access; never concatenate user input into SQL/commands.
  • Validate and sanitize all external input at system boundaries.

Testing and Validation

  • Keep code testable; verify with automated checks whenever feasible.
  • Backend unit tests: enforce a hard timeout of 60 秒之前.
  • Prefer static checks and reproducible verification over ad-hoc manual confidence.
  • For Chrome MCP smoke tests: starting the server is not evidence — make a real MCP tool call (e.g. new_page) and keep the window open if the user needs to see it.

After making code changes, run validation in this order when applicable:

  1. Targeted unit tests for changed behavior.
  2. Type checks or lint checks.
  3. Build checks for affected packages.
  4. A minimal smoke test.

If validation cannot be run, explain why and state the next best check.

Diff Review

Before finalizing, scan the diff for: symptom patching, duplicated logic, hidden fallbacks, broad error swallowing, second sources of truth, dead code, unmentioned behavior changes, weak tests, 和 security regressions. Fix any clear issues before responding.

Agent Execution

Prefer parallel agents when sub-tasks are independent; go serial only when there’s a real dependency. For parallel code editing, plan first, then spawn isolated workers.

Codebase reading roles:

  • Broad ingest, locating, evidence pack → read-only exploration agent.
  • Large-context synthesis, invariants, risk extraction → read-only analysis agent.
  • Final decisions and code changes stay with the main agent or a dedicated reviewer.

Skills

Skills live in ~/.codex/skills/ (personal) and .codex/skills/ (project-shared). Before starting a task, scan available skills. If one matches, read its SKILL.md and follow it. Announce which skill you’re using.

 /multichannel_ai_nvr/build/stage2_single_yolo --video data/videos/person-bicycle-car-detection.mp4 --display  
 
 

项目通读总结

架构:典型的生产者-消费者多线程管线(全在 nvr_core.cpp)

N个 stream_worker 线程 1个 共享 InferenceQueue M个 npu_worker 线程(默认3,绑核0/1/2)
(每路1个,解码+抽帧+丢旧帧) → (push_latest,满了丢队首) → (RKNN推理→回写StreamState)
↓
主循环每50ms: 拼宫格Mat → JPEG写盘(mosaic.jpg) + status.json
↓
Qt console(同进程,500ms 读盘JPEG) + 内置HTTP(web前端 1s 拉JPEG/status, 2s 拉system)

代码质量整体不错:原子停止、异常传播、letterbox 数学、int8 反量化都写得规范。下面按影响力分层列出可优化点,都标了 文件

。


第一梯队:性能瓶颈(嵌入式上收益最大)

  1. 「宫格→JPEG→写盘→各端读盘」是最大的架构浪费 nvr_core.cpp
  • 每 50ms(~20fps)把整张宫格(9路=1920×1080)做 JPEG 编码 + 临时文件 + rename 写盘;
  • Qt 又每 500ms 从盘 QPixmap(mosaicPath()) 读回解码(nvr_qt_console.cpp
    );
  • HTTP 每次请求再读盘一次(embedded_web_server.cpp
    )。
  • 关键点:Qt 和 NVR core 是同一个进程(NvrWorker 是 QThread 调 nvr::run),却绕了一圈磁盘。20fps 持续写 eMMC/SD 还伤闪存寿命。
  • 方向:给 RunControl 加一个 std::function on_mosaic 回调,core 直接把宫格 Mat 交给 Qt 内存预览;HTTP 端改成按需懒编码 JPEG(缓存上一帧,限频≤5/s),编码次数与客户端数解耦,磁盘 I/O 归零。
  1. 视频解码走 CPU 软解 nvr_core.cpp
    open_capture 用默认 cv::VideoCapture(FFmpeg 软解)
  • 9 路 1080p H.264 软解会吃满 CPU,这是你冲「9 路稳定」的头号天花板。
  • 方向:RK3588 有 MPP 硬解(可几十路 1080p)。用带 GStreamer 的 OpenCV + rtspsrc ! rkmppdec 管线,或直接调 MPP SDK。(板端验证)
  1. 预处理全 CPU rknn_yolo_detector.cpp
    + yolo_postprocess.cpp
    letterbox
  • 每次推理都 CPU 做 resize + BGR2RGB + padding。多路叠加很重。
  • 方向:用 RGA(2D 硬件加速器)一次完成 缩放+色彩转换+letterbox 填充。这是多路场景单项最大的 CPU 收益。(板端验证)
  1. RKNN 走 inputs_set/outputs_get 拷贝式 I/O rknn_yolo_detector.cpp
    ,241
  • 每次推理拷入 1.2MB 输入、拷出输出。
  • 方向:零拷贝 API(rknn_create_mem + rknn_set_io_mem),配合 RGA 输出直接喂 NPU。(板端验证)
  1. int8 解码热循环里 std::pow(x, 2.0f) yolo_postprocess.cpp
    ,297
  • 三重循环里每个候选 cell 调 std::pow 算平方,无 -ffast-math 时不会自动优化成 x*x。
  • 方向:改 x*x。纯软件、可在 WSL 验证的零风险小优化。

第二梯队:正确性 / 健壮性

  1. 预览帧率被锁死成「推理帧率」而非「解码帧率」 nvr_core.cpp
  • update_stream_frame 只在 infer_frame_index==0(首次推理前)更新 state.frame;之后画面只随推理完成才前进。所以 NPU 一忙,预览就卡顿,哪怕解码很流畅。
  • 方向:分离「最新解码帧(用于显示)」和「最新检测框(可滞后几帧叠加)」,画面跟解码走、框跟推理走。
  1. std::localtime 非线程安全 embedded_web_server.cpp
  • 多个 detached 客户端线程并发 → 静态 tm 数据竞争。改 localtime_r。
  1. 每次请求重新编译 std::regex embedded_web_server.cpp
    、nvr_qt_console.cpp
  • NPU load 解析正则每 1-2s 重建一次。改 static const std::regex。
  1. read_cpu_percent 在 HTTP 线程里 sleep(50ms) embedded_web_server.cpp
  • 每个 /api/system 请求阻塞 50ms;且与 Qt 的 CPU 算法重复且不一致。
  • 方向:后台采样缓存,请求直接读缓存值。
  1. HTTP 一次性 recv(4096) + 每连接 detached 线程无上限 embedded_web_server.cpp
    ,249
  • 大请求头/分段到达会解析失败;连接洪泛可耗尽线程。demo 风险低,但前端每秒新建 TCP(Connection: close)也有连接抖动。
  • 方向:循环读到 \r\n\r\n;考虑 MJPEG 流或线程池/keep-alive。

第三梯队:架构 / 路线图缺口

  1. 「事件」是前端假造的 web/app.js

    :靠检测数变大来 unshift 事件,刷新即丢、计数涨≠新目标。阶段五/九要的是真事件 + SQLite 持久化。

  2. 全是 CLI flag,无配置文件:阶段五要的「每路检测区域 YAML」无处落脚。建议引入 JSON/YAML 配置(源、阈值、区域、每路开关)。

  3. Web 是轮询不是 WebSocket(阶段四任务 7 明确要 WebSocket 推送)。

  4. 所有通道共用一个模型/阈值,无法做阶段六/七的「按通道开关烟火/车牌」。


第四梯队:代码质量

  1. 系统指标读取代码重复:CPU/内存/NPU/温度在 embedded_web_server.cpp 和 nvr_qt_console.cpp 各写一遍 → 抽成 nvr_core 里的共享模块。
  2. json_escape 重复且不一致:nvr_core 版转义控制字符,web 版不转义 → 合并。
  3. 零测试:后处理(letterbox/NMS/decode)是纯函数、极易测,建议加 CTest。
  4. 3 个 RKNN context 各自 rknn_init nvr_core.cpp
    → 模型权重占 3 份内存,可用 rknn_dup_context 共享。

关于「更深层次的优化」

image-20260601101212265
image-20260601101212265

​

© 2023 - 2026 chai @chai0705
Powered by theme astro-koharu · Inspired by Shoka