feat(device): TX/RX 日志附加完整 JSON 字符串
This commit is contained in:
@@ -2,6 +2,7 @@ import 'dart:async';
|
||||
|
||||
import '../../programs/models/program.dart';
|
||||
import '../../programs/models/step.dart';
|
||||
import 'device_log.dart';
|
||||
import 'device_message.dart';
|
||||
import 'device_message_service.dart';
|
||||
import 'runner_interface.dart';
|
||||
@@ -65,6 +66,8 @@ class JsonSerialRunner implements Runner {
|
||||
final messageId = _msg.nextId();
|
||||
_pendingCreateTaskId = messageId;
|
||||
final msg = payload.toMessage(messageId, needAck: true);
|
||||
DeviceLog.info('Runner.start: program="${program.name}" steps=${steps.length} '
|
||||
'temperature=${program.temperature} airflow=${program.airflowTime}');
|
||||
_msg.send(msg).then((ok) {
|
||||
if (!ok) {
|
||||
_pendingCreateTaskId = null;
|
||||
@@ -77,6 +80,7 @@ class JsonSerialRunner implements Runner {
|
||||
@override
|
||||
void pause() {
|
||||
if (status != RunnerStatus.running) return;
|
||||
DeviceLog.info('Runner.pause');
|
||||
_sendControl('pause');
|
||||
_stopLocalTicker();
|
||||
status = RunnerStatus.paused;
|
||||
@@ -85,6 +89,7 @@ class JsonSerialRunner implements Runner {
|
||||
@override
|
||||
void resume() {
|
||||
if (status != RunnerStatus.paused) return;
|
||||
DeviceLog.info('Runner.resume');
|
||||
_sendControl('continue');
|
||||
status = RunnerStatus.running;
|
||||
_startLocalTicker();
|
||||
@@ -93,6 +98,7 @@ class JsonSerialRunner implements Runner {
|
||||
@override
|
||||
void stop() {
|
||||
if (status == RunnerStatus.idle) return;
|
||||
DeviceLog.info('Runner.stop');
|
||||
_sendControl('stop');
|
||||
_teardown();
|
||||
status = RunnerStatus.idle;
|
||||
@@ -125,6 +131,7 @@ class JsonSerialRunner implements Runner {
|
||||
void _onCreateTaskAck(DeviceMessage ack) {
|
||||
if (ack.ack != _pendingCreateTaskId) return;
|
||||
_pendingCreateTaskId = null;
|
||||
DeviceLog.info('Runner received create_task ack: id=${ack.messageId}');
|
||||
// ack 即视为下位机已接受任务,进入 running 状态
|
||||
if (status == RunnerStatus.idle || status == RunnerStatus.error) {
|
||||
status = RunnerStatus.running;
|
||||
@@ -135,6 +142,7 @@ class JsonSerialRunner implements Runner {
|
||||
void _onControlAck(DeviceMessage ack) {
|
||||
if (ack.ack != _pendingControlId) return;
|
||||
_pendingControlId = null;
|
||||
DeviceLog.info('Runner received control ack: id=${ack.messageId}');
|
||||
// control ack 不修改状态,状态机在调用 pause/resume/stop 时已切过
|
||||
}
|
||||
|
||||
@@ -149,6 +157,7 @@ class JsonSerialRunner implements Runner {
|
||||
if (_remainingSeconds <= 0) {
|
||||
_currentStepIndex++;
|
||||
if (_currentStepIndex >= _steps.length) {
|
||||
DeviceLog.info('Runner 本地倒计时完成 (timeout fallback)');
|
||||
_stopLocalTicker();
|
||||
status = RunnerStatus.completed;
|
||||
_callbacks?.onComplete?.call();
|
||||
|
||||
Reference in New Issue
Block a user