refactor: lowercase channel name suffixes and rename PS to PF
- change all ChannelSuffix values from uppercase to lowercase
- rename ChannelSuffixPS ("PS") to ChannelSuffixPF ("pf")
- align channel suffix naming with downstream measurement keys
This commit is contained in:
parent
82622d0d85
commit
c82ad773a3
|
|
@ -19,15 +19,15 @@ const (
|
|||
|
||||
// channel name suffix
|
||||
const (
|
||||
ChannelSuffixP = "P"
|
||||
ChannelSuffixQ = "Q"
|
||||
ChannelSuffixS = "S"
|
||||
ChannelSuffixPS = "PS"
|
||||
ChannelSuffixF = "F"
|
||||
ChannelSuffixDeltaF = "deltaF"
|
||||
ChannelSuffixUAB = "UAB"
|
||||
ChannelSuffixUBC = "UBC"
|
||||
ChannelSuffixUCA = "UCA"
|
||||
ChannelSuffixP = "p"
|
||||
ChannelSuffixQ = "q"
|
||||
ChannelSuffixS = "s"
|
||||
ChannelSuffixPF = "pf"
|
||||
ChannelSuffixF = "f"
|
||||
ChannelSuffixDeltaF = "df"
|
||||
ChannelSuffixUAB = "uab"
|
||||
ChannelSuffixUBC = "ubc"
|
||||
ChannelSuffixUCA = "uca"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
|||
|
|
@ -2,24 +2,20 @@
|
|||
package diagram
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"modelRT/util"
|
||||
)
|
||||
|
||||
// anchorValueOverview define struct of storage all anchor value
|
||||
var anchorValueOverview sync.Map
|
||||
// anchorValueOverview define struct of storage all anchor value keyed by component uuid
|
||||
var anchorValueOverview util.TypedMap[string, string]
|
||||
|
||||
// GetAnchorValue define func of get circuit diagram data by componentID
|
||||
func GetAnchorValue(componentUUID string) (string, error) {
|
||||
value, ok := diagramsOverview.Load(componentUUID)
|
||||
anchorValue, ok := anchorValueOverview.Load(componentUUID)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("can not find anchor value by componentUUID:%s", componentUUID)
|
||||
}
|
||||
anchorValue, ok := value.(string)
|
||||
if !ok {
|
||||
return "", errors.New("convert to string failed")
|
||||
}
|
||||
return anchorValue, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,32 +2,27 @@
|
|||
package diagram
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"modelRT/orm"
|
||||
"modelRT/util"
|
||||
)
|
||||
|
||||
// diagramsOverview define struct of storage all circuit diagram data
|
||||
var diagramsOverview sync.Map
|
||||
// diagramsOverview define struct of storage all circuit diagram data keyed by component uuid
|
||||
var diagramsOverview util.TypedMap[string, *orm.Component]
|
||||
|
||||
// GetComponentMap define func of get circuit diagram data by component uuid
|
||||
func GetComponentMap(componentUUID string) (*orm.Component, error) {
|
||||
value, ok := diagramsOverview.Load(componentUUID)
|
||||
componentInfo, ok := diagramsOverview.Load(componentUUID)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("can not find graph by global uuid:%s", componentUUID)
|
||||
}
|
||||
componentInfo, ok := value.(*orm.Component)
|
||||
if !ok {
|
||||
return nil, errors.New("convert to component map struct failed")
|
||||
}
|
||||
return componentInfo, nil
|
||||
}
|
||||
|
||||
// UpdateComponentMap define func of update circuit diagram data by component uuid and component info
|
||||
func UpdateComponentMap(componentID int64, componentInfo *orm.Component) bool {
|
||||
_, result := diagramsOverview.Swap(componentID, componentInfo)
|
||||
func UpdateComponentMap(componentUUID string, componentInfo *orm.Component) bool {
|
||||
_, result := diagramsOverview.Swap(componentUUID, componentInfo)
|
||||
return result
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ func CircuitDiagramUpdateHandler(c *gin.Context) {
|
|||
c.JSON(http.StatusOK, resp)
|
||||
return
|
||||
}
|
||||
diagram.UpdateComponentMap(info.ID, component)
|
||||
diagram.UpdateComponentMap(info.UUID, component)
|
||||
}
|
||||
|
||||
if len(request.FreeVertexs) > 0 {
|
||||
|
|
|
|||
|
|
@ -59,36 +59,36 @@ func NewPower104DataSource(station string, packet, offset int) (*MeasurementData
|
|||
}
|
||||
|
||||
func generateChannelName(prefix string, number int, suffix string) (string, error) {
|
||||
// shortPrefix is the literal prefix written into the channel name (tm/ts/tc),
|
||||
// maxNumber is the inclusive upper bound, padWidth is the zero-padded digit width.
|
||||
var shortPrefix string
|
||||
var maxNumber, padWidth int
|
||||
switch prefix {
|
||||
case constants.ChannelPrefixTelemetry:
|
||||
if number > 10 {
|
||||
return "", common.ErrExceedsLimitType
|
||||
}
|
||||
var builder strings.Builder
|
||||
numberStr := strconv.Itoa(number)
|
||||
builder.Grow(len(prefix) + len(numberStr) + len(suffix))
|
||||
builder.WriteString(prefix)
|
||||
builder.WriteString(numberStr)
|
||||
builder.WriteString(suffix)
|
||||
channelName := builder.String()
|
||||
return channelName, nil
|
||||
shortPrefix, maxNumber, padWidth = "tm", 8, 1
|
||||
case constants.ChannelPrefixTelesignal:
|
||||
var numberStr string
|
||||
if number < 10 {
|
||||
numberStr = "0" + strconv.Itoa(number)
|
||||
}
|
||||
numberStr = strconv.Itoa(number)
|
||||
|
||||
var builder strings.Builder
|
||||
builder.Grow(len(prefix) + len(numberStr) + len(suffix))
|
||||
builder.WriteString(prefix)
|
||||
builder.WriteString(numberStr)
|
||||
builder.WriteString(suffix)
|
||||
channelName := builder.String()
|
||||
return channelName, nil
|
||||
shortPrefix, maxNumber, padWidth = "ts", 16, 2
|
||||
case constants.ChannelPrefixTelecommand:
|
||||
shortPrefix, maxNumber, padWidth = "tc", 9, 1
|
||||
default:
|
||||
return "", common.ErrUnsupportedChannelPrefixType
|
||||
}
|
||||
|
||||
if number < 1 || number > maxNumber {
|
||||
return "", common.ErrExceedsLimitType
|
||||
}
|
||||
|
||||
numberStr := strconv.Itoa(number)
|
||||
if len(numberStr) < padWidth {
|
||||
numberStr = strings.Repeat("0", padWidth-len(numberStr)) + numberStr
|
||||
}
|
||||
|
||||
var builder strings.Builder
|
||||
builder.Grow(len(shortPrefix) + len(numberStr) + len(suffix))
|
||||
builder.WriteString(shortPrefix)
|
||||
builder.WriteString(numberStr)
|
||||
builder.WriteString(suffix)
|
||||
return builder.String(), nil
|
||||
}
|
||||
|
||||
// NewTelemetryChannel define func of generate telemetry channel CL3611 data source
|
||||
|
|
@ -109,6 +109,15 @@ func NewTelesignalChannel(station, device, channelNameSuffix string, channelNumb
|
|||
return NewCL3611DataSource(station, device, channelName)
|
||||
}
|
||||
|
||||
// NewTelecommandChannel define func of generate telecommand channel CL3611 data source
|
||||
func NewTelecommandChannel(station, device, channelNameSuffix string, channelNumber int) (*MeasurementDataSource, error) {
|
||||
channelName, err := generateChannelName(constants.ChannelPrefixTelecommand, channelNumber, channelNameSuffix)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to generate channel name: %w", err)
|
||||
}
|
||||
return NewCL3611DataSource(station, device, channelName)
|
||||
}
|
||||
|
||||
// NewStandardChannel define func of generate standard channel CL3611 data source
|
||||
func NewStandardChannel(station, device, channelType string) (*MeasurementDataSource, error) {
|
||||
return NewCL3611DataSource(station, device, channelType)
|
||||
|
|
@ -264,9 +273,9 @@ func GenerateMeasureIdentifier(source map[string]any) (string, error) {
|
|||
func concatP104WithPlus(station string, packet int, offset int) string {
|
||||
packetStr := strconv.Itoa(packet)
|
||||
offsetStr := strconv.Itoa(offset)
|
||||
return station + ":" + packetStr + ":" + offsetStr
|
||||
return strings.ToLower(station + ":104:" + packetStr + ":" + offsetStr)
|
||||
}
|
||||
|
||||
func concatCL361WithPlus(station, device, channel string) string {
|
||||
return station + ":" + device + ":" + "phasor" + ":" + channel
|
||||
return strings.ToLower(station + ":" + device + ":" + "phasor" + ":" + channel)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue