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