IPC Dashboard

Lab 4: Hardware IPC Dashboard

Part 4 - IPC & Event Bus (Hardware Labs)


1. โครงสร้างภาพรวม (Overview)

Why? - ทำไมต้องเรียนรู้เรื่องนี้

ในระบบ Industrial จริง Dashboard ต้องแสดงข้อมูลหลายอย่างพร้อมกัน และ ควบคุมอุปกรณ์หลายตัวผ่าน Multi-Core IPC:

  • SCADA System: หน้าจอ HMI แสดง sensor data, alarm status, control panels ทั้งหมดในหน้าเดียว

  • Factory Floor Dashboard: แสดง production line status, machine health, operator controls

  • Smart Building BMS: HVAC sensor data + lighting control + access events ใน TabView

  • IoT Gateway: Sensor fusion จากหลาย source แสดงรวมพร้อม control interface

Lab นี้รวมทุกอย่างจาก Lab 5 (LED) + Lab 6 (Button) เข้ากับ Sensor data (IMU, ADC) ที่ส่งจาก CM33-NS ผ่าน IPC --> แสดงใน TabView Dashboard บน CM55

What? - จะได้เรียนรู้อะไร

  1. Multi-Channel IPC: จัดการ IPC หลาย command type พร้อมกัน (LED + Button + IMU + ADC)

  2. TabView Dashboard: แยก UI เป็น 3 Tabs: Controls | Sensors | Status

  3. Real-Time Charts: แสดง IMU data แบบ real-time chart ผ่าน IPC

  4. Bidirectional IPC: CM55 ส่งคำสั่ง + CM33 ส่ง data/events กลับพร้อมกัน

  5. System Health: Monitor IPC latency, error count, uptime

  6. Concurrent Flag Management: จัดการ flags หลายตัวสำหรับ IPC commands ต่าง ๆ

How? - ทำอย่างไร

สร้าง TabView Dashboard บน CM55 ที่แบ่งเป็น 3 tabs:

  • Controls: LED switches + brightness slider + button status

  • Sensors: IMU 3-axis chart + ADC gauge (data จาก CM33 ผ่าน IPC)

  • Status: IPC statistics + event log + system health

CM33-NS ทำหน้าที่: อ่าน sensor data ส่งมาทุก 100ms + รับคำสั่ง LED + ส่ง button events


2. หลักการทำงาน (Technical Principles)

2.1 Full IPC Dashboard Architecture

2.2 IPC Command Map (All Channels)

2.3 Multi-Flag Management Pattern

2.4 Program Flowchart


3. ฟังก์ชันสำคัญ (API Reference)

3.1 CM55 IPC Functions

Function
Description
Return

cm55_ipc_set_led(id, state)

ส่ง LED ON/OFF

cy_en_ipc_pipe_status_t

cm55_ipc_set_led_brightness(id, bright)

ส่ง LED brightness

cy_en_ipc_pipe_status_t

cm55_ipc_request_sensor(type)

ขอ sensor data จาก CM33

cy_en_ipc_pipe_status_t

cm55_ipc_request_button(id)

ขอ button state

cy_en_ipc_pipe_status_t

cm55_ipc_send_cmd(IPC_CMD_PING, tick)

ส่ง PING + timestamp

cy_en_ipc_pipe_status_t

cm55_ipc_get_stats(tx, rx, err)

ดึง IPC statistics

void

3.2 LVGL TabView Functions

Function
Description
Return

lv_tabview_create(parent)

สร้าง TabView container

lv_obj_t *

lv_tabview_add_tab(tv, title)

เพิ่ม tab ใหม่

lv_obj_t *

lv_tabview_set_active(tv, idx, anim)

เลือก tab ที่ active

void

lv_tabview_get_tab_bar(tv)

ดึง tab bar สำหรับ styling

lv_obj_t *

3.3 LVGL Chart Functions

Function
Description
Return

lv_chart_create(parent)

สร้าง chart widget

lv_obj_t *

lv_chart_add_series(chart, color, axis)

เพิ่ม data series

lv_chart_series_t *

lv_chart_set_next_value(chart, ser, val)

เพิ่มค่าถัดไป

void

lv_chart_set_range(chart, axis, min, max)

ตั้งช่วงค่า

void

lv_chart_set_point_count(chart, count)

จำนวน data points

void

3.4 CM33-NS Sensor Functions

Function
Description
Return

aic_sensors_init()

Initialize sensor subsystem

void

imu_shared_read_accel(&ax, &ay, &az)

อ่าน accelerometer

void

aic_adc_read(channel)

อ่าน ADC channel

uint16_t

cm33_ipc_send_imu(data)

ส่ง IMU data ไป CM55

cy_en_ipc_pipe_status_t

cm33_ipc_send_adc(data)

ส่ง ADC data ไป CM55

cy_en_ipc_pipe_status_t


4. โค้ดตัวอย่าง (Code Examples)

4.1 CM55 Code - Full IPC Dashboard

4.2 CM33-NS Code - Multi-Channel Handler


5. องค์ความรู้และเทคนิค (Patterns & Tips)

5.1 Multi-Flag IPC Handler Pattern

5.2 TabView Best Practices

5.3 IPC RTT Measurement

5.4 Sensor Request Rate Control


6. แบบฝึกหัด (Exercises)

Exercise 1: System Health Monitor (Intermediate)

เพิ่ม System Health Monitor ใน Status tab:

Requirements:

  • IPC Latency Graph: chart แสดง RTT 20 ค่าล่าสุด

  • Error Rate: % ของ messages ที่ error (error/total * 100)

  • Connection Status LED: เขียว (RTT < 50ms), เหลือง (50-200ms), แดง (>200ms หรือ no pong)

  • Message Rate: แสดง TX/s และ RX/s (คำนวณจาก delta per second)

  • Health Score: 0-100 คำนวณจาก RTT + error rate + uptime

  • Auto-alert: ถ้า health score < 50 ให้ LED widget แดงกะพริบ

Expected Output:

Hints:

  • Health Score = 100 - (RTT > 100 ? 30 : RTT * 0.3) - (error_pct * 2)

  • Rate calculation: count_now - count_1s_ago

  • ใช้ lv_chart_create() สำหรับ RTT graph

  • PING ทุก 2s แทน 5s สำหรับ responsive health monitoring


Exercise 2: Alarm Conditions (Advanced)

เพิ่มระบบ alarm ที่ sensor threshold trigger action:

Requirements:

  • Alarm rules (configurable):

    • IMU |accel| > 1500: "VIBRATION ALERT" --> flash Red LED

    • ADC > 80%: "HIGH VOLTAGE" --> turn on Green LED as warning

    • ADC < 10%: "LOW SIGNAL" --> blink Blue LED

  • Alarm panel แสดง active alarms (max 5) พร้อม timestamp

  • Alarm history (last 10 alarms)

  • Alarm acknowledge button: กด ACK เพื่อ silence alarm

  • Sound indicator: LED widget กะพริบเมื่อมี unacknowledged alarm

  • Auto-clear: alarm หายเมื่อ condition กลับปกติ

Expected Output:

Hints:

  • Alarm state: INACTIVE -> ACTIVE -> ACKNOWLEDGED -> CLEARED

  • Check thresholds ใน LVGL timer หลัง update sensor data

  • LED control ผ่าน IPC ด้วย 20ms delay

  • ใช้ lv_obj_set_style_bg_opa(panel, LV_OPA_100, 0) + animation สำหรับ flash

  • Timestamp: ใช้ xTaskGetTickCount() / 1000 เป็น seconds since boot


7. สรุปและขั้นตอนถัดไป (Summary & Next Steps)

สิ่งที่เรียนรู้ใน Lab นี้

  1. Multi-Channel IPC: จัดการ 10+ IPC command types ในระบบเดียว

  2. TabView Dashboard: แยก UI complex ออกเป็น logical tabs

  3. Bidirectional Communication: CM55 ส่งคำสั่ง + รับ data จาก CM33 พร้อมกัน

  4. Real-Time Sensor Display: Chart + Gauge update จาก IPC data stream

  5. System Health Monitoring: RTT, error rate, connection status

Architecture Lessons

ขั้นตอนถัดไป

  • Mini Project Part 4: Multi-Core Sensor Fusion System

    • รวมทุกอย่าง + Event Bus + Advanced Logging

    • ระบบ production-grade ที่ถูก grade

Application ในงานจริง

ด้าน
ตัวอย่าง

SCADA/HMI

Factory floor monitoring + control dashboard

Building Management

HVAC + lighting + security ใน TabView

Medical Devices

Patient monitoring + pump control + alarm

Automotive

Instrument cluster + vehicle diagnostics

Last updated

Was this helpful?