iot接口适配

This commit is contained in:
walker 2023-12-18 16:26:17 +08:00
parent e1498dc348
commit d527e528fd

View File

@ -3,12 +3,12 @@ package cidcmodbus
import (
"context"
"fmt"
"log/slog"
"time"
"joylink.club/bj-rtsts-server/config"
"joylink.club/bj-rtsts-server/ts/simulation/wayside/memory"
"joylink.club/iot/service"
"joylink.club/iot/service/model"
"joylink.club/iot/service/proto"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/entity"
@ -53,8 +53,7 @@ type cidcModbusService struct {
vs *memory.VerifySimulation // 仿真对象
modbusConfig *config.CidcModbusConfig // modbus驱采配置
ecsUid string // 联锁集中站uid
dcData model.QC // 驱采数据
mdms service.IotService // modbus驱采映射服务
qcms service.IotQcMappingService // modbus驱采映射服务
cancel context.CancelFunc
}
@ -80,15 +79,18 @@ func (s *cidcModbusService) update() {
if qcs == nil {
panic(fmt.Sprintf("联锁驱采Modbus服务查询状态失败,集中站联锁驱采状态不存在: %s", s.ecsUid))
}
s.dcData.UpdateCollectByBytes(0, qcs.Cbs)
qs := s.dcData.GetDrive()
err := s.qcms.WriteCjBytes(qcs.Cbs)
if err != nil {
slog.Error("联锁驱采Modbus服务写采集数据失败", err)
}
qs := s.qcms.GetQdBytes()
qcs.Qbs = qs
}
// Stop implements CidcModbusService.
func (s *cidcModbusService) Stop() {
s.cancel()
s.mdms.Stop()
s.qcms.Stop()
}
func newCidcModbusService(vs *memory.VerifySimulation, modbusConfig *config.CidcModbusConfig) (*cidcModbusService, error) {
@ -108,8 +110,7 @@ func newCidcModbusService(vs *memory.VerifySimulation, modbusConfig *config.Cidc
if err != nil {
return nil, fmt.Errorf("联锁驱采Modbus服务创建失败,Modbus地址映射配置错误: %s", err)
}
dc := model.NewDC(make([]byte, len(qcs.Qbs)), make([]byte, len(qcs.Cbs)))
mdms, err := service.NewModbusQcService(converToModbusDcConfig(modbusConfig), dc)
qcms, err := service.NewModbusQcService(converToModbusDcConfig(modbusConfig), make([]byte, len(qcs.Qbs)), make([]byte, len(qcs.Cbs)))
if err != nil {
return nil, fmt.Errorf("联锁驱采Modbus服务创建失败: %s", err)
}
@ -117,8 +118,7 @@ func newCidcModbusService(vs *memory.VerifySimulation, modbusConfig *config.Cidc
vs: vs,
modbusConfig: modbusConfig,
ecsUid: ecsId,
dcData: dc,
mdms: mdms,
qcms: qcms,
}
ctx, cancel := context.WithCancel(context.Background())
go cms.run(ctx)