第 1 阶段:虚拟实训台,项目 2、3 的示例跑通
- 实训台状态由服务器统一保存:滑块和开关设定传感器读数,推给学生程序; 学生程序控制的灯、继电器、LED 屏回写到实训台 - 网页按教材实训台布局图绘制实训台,传感器卡片上直接调节环境 - 新控件:CheckBox、RadioButton(事件顺序与 WinForms 一致),Lamp、Alarm - 设备类库:串口未打开时控制无效,与实物一致 - 修正:列表属性序列化时数字被转成字符串 - 示例:项目 2 任务 2–3、项目 3 任务 1–2;网址参数 ?sample= 打开指定示例 - 测试:实训台单元测试,项目 2、3 的端到端测试 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
98be8331bc
commit
26104ae81e
38 files changed
+2346
-77
No files matched your search
+58
-1
@@ -35,6 +35,53 @@ export interface PropChange {
|
||||
value: unknown
|
||||
}
|
||||
|
||||
/**
|
||||
* 虚拟实训台(按教材实训台布局图)。每个浏览器会话一台,状态由服务器统一保存:
|
||||
* 输入(传感器读数)由网页上的滑块和开关设定,推给学生程序;输出(灯、继电器、LED 屏)由学生程序控制。
|
||||
*/
|
||||
export interface BoardState {
|
||||
/** ADAM-4017 模拟量,按教材整数取值 */
|
||||
analog: {
|
||||
temperature: number // Vin0 温度 ℃
|
||||
humidity: number // Vin1 湿度 %
|
||||
light: number // Vin2 光照 lx
|
||||
airPressure: number // Vin3 气压 kPa
|
||||
airQuality: number // Vin4 空气质量
|
||||
co2: number // Vin5 CO2 ppm
|
||||
wind: number // Vin6 风速 m/s
|
||||
}
|
||||
/** ADAM-4150 数字量输入 */
|
||||
digital: {
|
||||
bodyInfrared: boolean // DI0 人体红外
|
||||
fire: boolean // DI1 火焰
|
||||
smoke: boolean // DI2 烟雾
|
||||
infrared: boolean // DI3 红外对射
|
||||
}
|
||||
/** ADAM-4150 继电器 DO0–DO4:DO0 报警灯、DO1 照明灯、DO2 路灯、DO3 插座 1、DO4 插座 2 */
|
||||
relays: boolean[]
|
||||
/** ZigBee 继电器节点 0、1(教材用节点 1 控制路灯) */
|
||||
zigbee: boolean[]
|
||||
ledText: string
|
||||
}
|
||||
|
||||
export type AnalogKey = keyof BoardState['analog']
|
||||
export type DigitalKey = keyof BoardState['digital']
|
||||
|
||||
/** 4017 通道顺序(Vin0–Vin6)和 4150 输入通道顺序(DI0–DI3),C# 端按通道号读取 */
|
||||
export const ANALOG_CHANNELS: AnalogKey[] = ['temperature', 'humidity', 'light', 'airPressure', 'airQuality', 'co2', 'wind']
|
||||
export const DIGITAL_CHANNELS: DigitalKey[] = ['bodyInfrared', 'fire', 'smoke', 'infrared']
|
||||
|
||||
/** 各模拟量的单位和滑块范围。光照上限取 2000 lx:教材里的阈值都在 200–800 之间 */
|
||||
export const ANALOG_INFO: Record<AnalogKey, { label: string; unit: string; min: number; max: number }> = {
|
||||
temperature: { label: '温度', unit: '℃', min: -20, max: 60 },
|
||||
humidity: { label: '湿度', unit: '%', min: 0, max: 100 },
|
||||
light: { label: '光照', unit: 'lx', min: 0, max: 2000 },
|
||||
airPressure: { label: '气压', unit: 'kPa', min: 80, max: 120 },
|
||||
airQuality: { label: '空气质量', unit: '', min: 0, max: 500 },
|
||||
co2: { label: 'CO₂', unit: 'ppm', min: 300, max: 5000 },
|
||||
wind: { label: '风速', unit: 'm/s', min: 0, max: 30 },
|
||||
}
|
||||
|
||||
/** 运行器发出的消息 */
|
||||
export type RunnerMessage =
|
||||
| { type: 'compiled'; ok: boolean; diagnostics: Diagnostic[]; ms: number }
|
||||
@@ -45,6 +92,7 @@ export type RunnerMessage =
|
||||
| { type: 'controlAdded'; parentId: string; index: number; node: ControlNode }
|
||||
| { type: 'controlRemoved'; id: string }
|
||||
| { type: 'messageBox'; requestId: number; text: string; caption: string; buttons: string; icon: string }
|
||||
/** 学生程序操作了实训台输出:led/text、adam4150/do、zigbee/relay,data 见 DeviceCtrlHelper.cs */
|
||||
| { type: 'device'; device: string; action: string; data: unknown }
|
||||
| { type: 'console'; text: string }
|
||||
| { type: 'exception'; message: string; detail: string }
|
||||
@@ -67,13 +115,22 @@ export type UserAction =
|
||||
export type RunnerInput =
|
||||
| ({ type: 'action'; id: string } & UserAction)
|
||||
| { type: 'reply'; requestId: number; result: unknown }
|
||||
/** 实训台传感器读数,按通道号排列(见 ANALOG_CHANNELS、DIGITAL_CHANNELS) */
|
||||
| { type: 'board'; analog: number[]; digital: boolean[] }
|
||||
| { type: 'stop' }
|
||||
|
||||
/** 浏览器发给服务器的消息 */
|
||||
export type ClientMessage = { type: 'run'; files: SourceFile[] } | RunnerInput
|
||||
export type ClientMessage =
|
||||
| { type: 'run'; files: SourceFile[] }
|
||||
/** 调节实训台环境:拖动滑块、触发传感器 */
|
||||
| { type: 'boardInput'; analog?: Partial<BoardState['analog']>; digital?: Partial<BoardState['digital']> }
|
||||
/** 实训台复位:关掉所有灯和继电器、清空 LED 屏,传感器恢复默认 */
|
||||
| { type: 'boardReset' }
|
||||
| Exclude<RunnerInput, { type: 'board' }>
|
||||
|
||||
/** 服务器发给浏览器的消息 */
|
||||
export type ServerMessage =
|
||||
| RunnerMessage
|
||||
| { type: 'board'; state: BoardState }
|
||||
| { type: 'status'; state: 'compiling' | 'running' | 'stopped' }
|
||||
| { type: 'serverError'; message: string }
|
||||
Reference in new issue
Block a user