适配IOT模块调整
This commit is contained in:
parent
42a5523e4a
commit
fef6fe46a4
|
@ -12,7 +12,7 @@ import (
|
|||
"joylink.club/bj-rtsts-server/middleware"
|
||||
"joylink.club/bj-rtsts-server/service"
|
||||
"joylink.club/bj-rtsts-server/sys_error"
|
||||
"joylink.club/iot/service/proto"
|
||||
iotdto "joylink.club/iot/dto"
|
||||
)
|
||||
|
||||
func InitProjectRunConfigRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||
|
@ -225,8 +225,8 @@ func parseRunCofigStruct(m interface{}) []*dto.RunConfigDescription {
|
|||
c.SelectOptions = modbus_EndiannessSelectOptions
|
||||
case "proto.Modbus_Function":
|
||||
c.SelectOptions = modbus_FunctionSelectOptions
|
||||
case "proto.Modbus_WriteStrategy":
|
||||
c.SelectOptions = modbus_WriteStrategySelectOptions
|
||||
// case "proto.Modbus_WriteStrategy":
|
||||
// c.SelectOptions = modbus_WriteStrategySelectOptions
|
||||
case "proto.DataType":
|
||||
c.SelectOptions = dataTypeSelectOptions
|
||||
default:
|
||||
|
@ -240,8 +240,8 @@ var modbus_EndiannessSelectOptions = buildModbus_EndiannessSelectOptions()
|
|||
|
||||
func buildModbus_EndiannessSelectOptions() []*dto.RunConfigSelectOption {
|
||||
return []*dto.RunConfigSelectOption{
|
||||
{Label: "大端", Value: int32(proto.Modbus_BigEndian)},
|
||||
{Label: "小端", Value: int32(proto.Modbus_LittleEndian)},
|
||||
{Label: "大端", Value: int32(iotdto.Modbus_BigEndian)},
|
||||
{Label: "小端", Value: int32(iotdto.Modbus_LittleEndian)},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -249,33 +249,33 @@ var modbus_FunctionSelectOptions = buildModbus_FunctionSelectOptions()
|
|||
|
||||
func buildModbus_FunctionSelectOptions() []*dto.RunConfigSelectOption {
|
||||
return []*dto.RunConfigSelectOption{
|
||||
{Label: "读线圈", Value: int32(proto.Modbus_ReadCoil)},
|
||||
{Label: "读离散输入", Value: int32(proto.Modbus_ReadDiscreteInput)},
|
||||
{Label: "读保持寄存器", Value: int32(proto.Modbus_ReadHoldingRegister)},
|
||||
{Label: "读输入寄存器", Value: int32(proto.Modbus_ReadInputRegister)},
|
||||
{Label: "写单个线圈", Value: int32(proto.Modbus_WriteCoil)},
|
||||
{Label: "写多个线圈", Value: int32(proto.Modbus_WriteCoils)},
|
||||
{Label: "写单个寄存器", Value: int32(proto.Modbus_WriteRegister)},
|
||||
{Label: "写多个寄存器", Value: int32(proto.Modbus_WriteRegisters)},
|
||||
{Label: "读写多个线圈", Value: int32(proto.Modbus_RWCoils)},
|
||||
{Label: "读写多个寄存器", Value: int32(proto.Modbus_RWRegisters)},
|
||||
{Label: "读线圈", Value: int32(iotdto.Modbus_ReadCoil)},
|
||||
{Label: "读离散输入", Value: int32(iotdto.Modbus_ReadDiscreteInput)},
|
||||
{Label: "读保持寄存器", Value: int32(iotdto.Modbus_ReadHoldingRegister)},
|
||||
{Label: "读输入寄存器", Value: int32(iotdto.Modbus_ReadInputRegister)},
|
||||
{Label: "写单个线圈", Value: int32(iotdto.Modbus_WriteCoil)},
|
||||
{Label: "写多个线圈", Value: int32(iotdto.Modbus_WriteCoils)},
|
||||
{Label: "写单个寄存器", Value: int32(iotdto.Modbus_WriteRegister)},
|
||||
{Label: "写多个寄存器", Value: int32(iotdto.Modbus_WriteRegisters)},
|
||||
{Label: "读写多个线圈", Value: int32(iotdto.Modbus_RWCoils)},
|
||||
{Label: "读写多个寄存器", Value: int32(iotdto.Modbus_RWRegisters)},
|
||||
}
|
||||
}
|
||||
|
||||
var modbus_WriteStrategySelectOptions = buildModbus_WriteStrategySelectOptions()
|
||||
// var modbus_WriteStrategySelectOptions = buildModbus_WriteStrategySelectOptions()
|
||||
|
||||
func buildModbus_WriteStrategySelectOptions() []*dto.RunConfigSelectOption {
|
||||
return []*dto.RunConfigSelectOption{
|
||||
{Label: "数据更新时写", Value: int32(proto.Modbus_OnUpdate)},
|
||||
{Label: "定时写", Value: int32(proto.Modbus_OnScheduled)},
|
||||
}
|
||||
}
|
||||
// func buildModbus_WriteStrategySelectOptions() []*dto.RunConfigSelectOption {
|
||||
// return []*dto.RunConfigSelectOption{
|
||||
// {Label: "数据更新时写", Value: int32(iotdto.Modbus_OnUpdate)},
|
||||
// {Label: "定时写", Value: int32(iotdto.Modbus_OnScheduled)},
|
||||
// }
|
||||
// }
|
||||
|
||||
var dataTypeSelectOptions = buildDataTypeSelectOptions()
|
||||
|
||||
func buildDataTypeSelectOptions() []*dto.RunConfigSelectOption {
|
||||
return []*dto.RunConfigSelectOption{
|
||||
{Label: "采集数据", Value: int32(proto.DataType_CollectTable)},
|
||||
{Label: "驱动数据", Value: int32(proto.DataType_DriveTable)},
|
||||
{Label: "采集数据", Value: int32(iotdto.DataType_CJ)},
|
||||
{Label: "驱动数据", Value: int32(iotdto.DataType_QD)},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"log/slog"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"joylink.club/iot/service/proto"
|
||||
"joylink.club/iot/dto"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -72,22 +72,22 @@ type ThridPartyConfig struct {
|
|||
}
|
||||
|
||||
type CidcModbusConfig struct {
|
||||
Open bool `json:"open" description:"是否开启"`
|
||||
Url string `json:"url" description:"接口URL(格式tcp://{ip}:{port})" default:"tcp://127.0.0.1:502"` // 连接地址
|
||||
UnitId uint32 `json:"unitId" description:"从机unitId"` // 从机unitId
|
||||
Endianness proto.Modbus_Endianness `json:"endianness" description:"字节序(大端/小端)"` // 16位寄存器字节序
|
||||
Interval uint32 `json:"interval" description:"定时请求间隔" default:"1000"` // 循环请求间隔(毫秒),0表示不主动请求,只当有变化时请求
|
||||
Timeout uint32 `json:"timeout" description:"请求超时时间" default:"1000"` // 超时时间(毫秒)
|
||||
Ecs string `json:"ecs" description:"联锁集中站"` // 所属集中站
|
||||
Mapping []ModbusDcMapping `json:"mapping" description:"modbus数据与驱动/采集码表映射配置"`
|
||||
Open bool `json:"open" description:"是否开启"`
|
||||
Url string `json:"url" description:"接口URL(格式tcp://{ip}:{port})" default:"tcp://127.0.0.1:502"` // 连接地址
|
||||
UnitId uint32 `json:"unitId" description:"从机unitId"` // 从机unitId
|
||||
Endianness dto.Modbus_Endianness `json:"endianness" description:"字节序(大端/小端)"` // 16位寄存器字节序
|
||||
Interval uint32 `json:"interval" description:"定时请求间隔" default:"1000"` // 循环请求间隔(毫秒),0表示不主动请求,只当有变化时请求
|
||||
Timeout uint32 `json:"timeout" description:"请求超时时间" default:"1000"` // 超时时间(毫秒)
|
||||
Ecs string `json:"ecs" description:"联锁集中站"` // 所属集中站
|
||||
Mapping []ModbusDcMapping `json:"mapping" description:"modbus数据与驱动/采集码表映射配置"`
|
||||
}
|
||||
type ModbusDcMapping struct {
|
||||
Function proto.Modbus_Function `json:"function" description:"Modbus功能"` // 功能
|
||||
Addr uint32 `json:"addr" description:"Modbus功能起始地址,位类型的功能为起始位地址,寄存器类型的功能为起始字(2个字节)地址"` // 起始地址,当功能为位功能时,表示起始位地址,当功能为寄存器功能时,表示起始字(2个字节)地址
|
||||
Quantity uint32 `json:"quantity" description:"Modbus读取数量,位类型的为位数,寄存器类型的为字(2个字节)数"` // 数量,当功能为位功能时,表示位数,当功能为寄存器功能时,表示字(2个字节)数
|
||||
WriteStrategy proto.Modbus_WriteStrategy `json:"writeStrategy" description:"写入策略"` // 当功能为写入类功能时(不包含读写类功能),写策略
|
||||
Type proto.DataType `json:"type" description:"映射的数据类型"` // 对应数据类型
|
||||
Start uint32 `json:"start" description:"映射数据的起始地址,位类型的为起始位地址,寄存器类型的为起始字节地址"` // 映射起始地址
|
||||
Function dto.Modbus_Function `json:"function" description:"Modbus功能"` // 功能
|
||||
Addr uint32 `json:"addr" description:"Modbus功能起始地址,位类型的功能为起始位地址,寄存器类型的功能为起始字(2个字节)地址"` // 起始地址,当功能为位功能时,表示起始位地址,当功能为寄存器功能时,表示起始字(2个字节)地址
|
||||
Quantity uint32 `json:"quantity" description:"Modbus读取数量,位类型的为位数,寄存器类型的为字(2个字节)数"` // 数量,当功能为位功能时,表示位数,当功能为寄存器功能时,表示字(2个字节)数
|
||||
// WriteStrategy proto.Modbus_WriteStrategy `json:"writeStrategy" description:"写入策略"` // 当功能为写入类功能时(不包含读写类功能),写策略
|
||||
Type dto.DataType `json:"type" description:"映射的数据类型"` // 对应数据类型
|
||||
Start uint32 `json:"start" description:"映射数据的起始地址,位类型的为起始位地址,寄存器类型的为起始字节地址"` // 映射起始地址
|
||||
}
|
||||
type DynamicsConfig struct {
|
||||
Ip string `json:"ip" description:"IP配置"`
|
||||
|
|
|
@ -7,8 +7,8 @@ import (
|
|||
|
||||
"joylink.club/bj-rtsts-server/config"
|
||||
"joylink.club/bj-rtsts-server/ts/simulation/wayside/memory"
|
||||
"joylink.club/iot/dto"
|
||||
"joylink.club/iot/service"
|
||||
"joylink.club/iot/service/proto"
|
||||
"joylink.club/rtsssimulation/component"
|
||||
"joylink.club/rtsssimulation/entity"
|
||||
)
|
||||
|
@ -93,7 +93,7 @@ func newCidcModbusService(vs *memory.VerifySimulation, modbusConfig *config.Cidc
|
|||
return nil, fmt.Errorf("联锁驱采Modbus服务创建失败,仿真不存在集中站联锁: %s", ecsId)
|
||||
}
|
||||
qcs := component.CiQcStateType.Get(qce)
|
||||
qcms, err := service.NewModbusQcService(converToModbusDcConfig(modbusConfig), make([]byte, len(qcs.Qbs)), make([]byte, len(qcs.Cbs)))
|
||||
qcms, err := service.NewModbusQcService(converToModbusDcConfig(modbusConfig, len(qcs.Qbs), len(qcs.Cbs)))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("联锁驱采Modbus服务创建失败: %s", err)
|
||||
}
|
||||
|
@ -108,27 +108,28 @@ func newCidcModbusService(vs *memory.VerifySimulation, modbusConfig *config.Cidc
|
|||
return cms, nil
|
||||
}
|
||||
|
||||
func converToModbusDcConfig(config *config.CidcModbusConfig) *proto.ModbusConfig {
|
||||
return &proto.ModbusConfig{
|
||||
func converToModbusDcConfig(config *config.CidcModbusConfig, qdl, cjl int) *dto.ModbusConfig {
|
||||
return &dto.ModbusConfig{
|
||||
Url: config.Url,
|
||||
UnitId: config.UnitId,
|
||||
Endianness: config.Endianness,
|
||||
Interval: config.Interval,
|
||||
Timeout: config.Timeout,
|
||||
Qdl: uint32(qdl),
|
||||
Cjl: uint32(cjl),
|
||||
Mapping: convertToModbusDcMapping(config.Mapping),
|
||||
}
|
||||
}
|
||||
|
||||
func convertToModbusDcMapping(modbusDcMapping []config.ModbusDcMapping) []*proto.ModbusDcMapping {
|
||||
res := make([]*proto.ModbusDcMapping, 0)
|
||||
func convertToModbusDcMapping(modbusDcMapping []config.ModbusDcMapping) []*dto.ModbusDcMapping {
|
||||
res := make([]*dto.ModbusDcMapping, 0)
|
||||
for _, mdm := range modbusDcMapping {
|
||||
res = append(res, &proto.ModbusDcMapping{
|
||||
Function: mdm.Function,
|
||||
Addr: mdm.Addr,
|
||||
Quantity: mdm.Quantity,
|
||||
WriteStrategy: mdm.WriteStrategy,
|
||||
Type: mdm.Type,
|
||||
Start: mdm.Start,
|
||||
res = append(res, &dto.ModbusDcMapping{
|
||||
Function: mdm.Function,
|
||||
Addr: mdm.Addr,
|
||||
Quantity: mdm.Quantity,
|
||||
Type: mdm.Type,
|
||||
Start: mdm.Start,
|
||||
})
|
||||
}
|
||||
return res
|
||||
|
|
Loading…
Reference in New Issue