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:
douxu 2026-06-17 10:47:35 +08:00
parent 82622d0d85
commit c82ad773a3
5 changed files with 56 additions and 56 deletions

View File

@ -19,15 +19,15 @@ const (
// channel name suffix // channel name suffix
const ( const (
ChannelSuffixP = "P" ChannelSuffixP = "p"
ChannelSuffixQ = "Q" ChannelSuffixQ = "q"
ChannelSuffixS = "S" ChannelSuffixS = "s"
ChannelSuffixPS = "PS" ChannelSuffixPF = "pf"
ChannelSuffixF = "F" ChannelSuffixF = "f"
ChannelSuffixDeltaF = "deltaF" ChannelSuffixDeltaF = "df"
ChannelSuffixUAB = "UAB" ChannelSuffixUAB = "uab"
ChannelSuffixUBC = "UBC" ChannelSuffixUBC = "ubc"
ChannelSuffixUCA = "UCA" ChannelSuffixUCA = "uca"
) )
const ( const (

View File

@ -2,24 +2,20 @@
package diagram package diagram
import ( import (
"errors"
"fmt" "fmt"
"sync"
"modelRT/util"
) )
// anchorValueOverview define struct of storage all anchor value // anchorValueOverview define struct of storage all anchor value keyed by component uuid
var anchorValueOverview sync.Map var anchorValueOverview util.TypedMap[string, string]
// GetAnchorValue define func of get circuit diagram data by componentID // GetAnchorValue define func of get circuit diagram data by componentID
func GetAnchorValue(componentUUID string) (string, error) { func GetAnchorValue(componentUUID string) (string, error) {
value, ok := diagramsOverview.Load(componentUUID) anchorValue, ok := anchorValueOverview.Load(componentUUID)
if !ok { if !ok {
return "", fmt.Errorf("can not find anchor value by componentUUID:%s", componentUUID) 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 return anchorValue, nil
} }

View File

@ -2,32 +2,27 @@
package diagram package diagram
import ( import (
"errors"
"fmt" "fmt"
"sync"
"modelRT/orm" "modelRT/orm"
"modelRT/util"
) )
// diagramsOverview define struct of storage all circuit diagram data // diagramsOverview define struct of storage all circuit diagram data keyed by component uuid
var diagramsOverview sync.Map var diagramsOverview util.TypedMap[string, *orm.Component]
// GetComponentMap define func of get circuit diagram data by component uuid // GetComponentMap define func of get circuit diagram data by component uuid
func GetComponentMap(componentUUID string) (*orm.Component, error) { func GetComponentMap(componentUUID string) (*orm.Component, error) {
value, ok := diagramsOverview.Load(componentUUID) componentInfo, ok := diagramsOverview.Load(componentUUID)
if !ok { if !ok {
return nil, fmt.Errorf("can not find graph by global uuid:%s", componentUUID) 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 return componentInfo, nil
} }
// UpdateComponentMap define func of update circuit diagram data by component uuid and component info // UpdateComponentMap define func of update circuit diagram data by component uuid and component info
func UpdateComponentMap(componentID int64, componentInfo *orm.Component) bool { func UpdateComponentMap(componentUUID string, componentInfo *orm.Component) bool {
_, result := diagramsOverview.Swap(componentID, componentInfo) _, result := diagramsOverview.Swap(componentUUID, componentInfo)
return result return result
} }

View File

@ -137,7 +137,7 @@ func CircuitDiagramUpdateHandler(c *gin.Context) {
c.JSON(http.StatusOK, resp) c.JSON(http.StatusOK, resp)
return return
} }
diagram.UpdateComponentMap(info.ID, component) diagram.UpdateComponentMap(info.UUID, component)
} }
if len(request.FreeVertexs) > 0 { if len(request.FreeVertexs) > 0 {

View File

@ -59,36 +59,36 @@ func NewPower104DataSource(station string, packet, offset int) (*MeasurementData
} }
func generateChannelName(prefix string, number int, suffix string) (string, error) { 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 { switch prefix {
case constants.ChannelPrefixTelemetry: case constants.ChannelPrefixTelemetry:
if number > 10 { shortPrefix, maxNumber, padWidth = "tm", 8, 1
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
case constants.ChannelPrefixTelesignal: case constants.ChannelPrefixTelesignal:
var numberStr string shortPrefix, maxNumber, padWidth = "ts", 16, 2
if number < 10 { case constants.ChannelPrefixTelecommand:
numberStr = "0" + strconv.Itoa(number) shortPrefix, maxNumber, padWidth = "tc", 9, 1
}
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
default: default:
return "", common.ErrUnsupportedChannelPrefixType 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 // 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) 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 // NewStandardChannel define func of generate standard channel CL3611 data source
func NewStandardChannel(station, device, channelType string) (*MeasurementDataSource, error) { func NewStandardChannel(station, device, channelType string) (*MeasurementDataSource, error) {
return NewCL3611DataSource(station, device, channelType) 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 { func concatP104WithPlus(station string, packet int, offset int) string {
packetStr := strconv.Itoa(packet) packetStr := strconv.Itoa(packet)
offsetStr := strconv.Itoa(offset) offsetStr := strconv.Itoa(offset)
return station + ":" + packetStr + ":" + offsetStr return strings.ToLower(station + ":104:" + packetStr + ":" + offsetStr)
} }
func concatCL361WithPlus(station, device, channel string) string { func concatCL361WithPlus(station, device, channel string) string {
return station + ":" + device + ":" + "phasor" + ":" + channel return strings.ToLower(station + ":" + device + ":" + "phasor" + ":" + channel)
} }