Skip to content

Commit

Permalink
Merge pull request #116 from andig/mpm3pm
Browse files Browse the repository at this point in the history
Refactor connection setup
  • Loading branch information
andig authored Apr 27, 2020
2 parents 8528afb + 8a831fa commit e83718d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 16 deletions.
15 changes: 4 additions & 11 deletions cmd/confighandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (conf *DeviceConfigHandler) createDeviceForManager(
}

sort.SearchStrings(sunspecTypes, meterType)
if _, ok := manager.Conn.(*meters.TCP); ok || isSunspec {
if isSunspec {
meter = sunspec.NewDevice(meterType)
} else {
var err error
Expand All @@ -171,12 +171,6 @@ func (conf *DeviceConfigHandler) createDeviceForManager(
return meter
}

// isRTUDevice checks if type is a known RTU device type
func (conf *DeviceConfigHandler) isRTUDevice(meterType string) bool {
_, ok := rs485.Producers[strings.ToUpper(meterType)]
return ok
}

// CreateDevice creates new device and adds it to the connection manager
func (conf *DeviceConfigHandler) CreateDevice(devConf DeviceConfig) {
if devConf.Adapter == "" {
Expand Down Expand Up @@ -235,10 +229,9 @@ func (conf *DeviceConfigHandler) CreateDeviceFromSpec(deviceDef string) {
log.Fatalf("Error parsing device id %s: %v. See -h for help.", devID, err)
}

// RTU flag is inferred if the device is of RTU type.
// It is used to implicitly create an RTUOverTCP instead of a TCP connection
rtu := conf.isRTUDevice(meterType)
manager := conf.ConnectionManager(connSpec, rtu, 0, "")
// If this is an RTU over TCP device, a default RTU over TCP should already
// have been created of the --rtu flag was specified. We'll not re-check this here.
manager := conf.ConnectionManager(connSpec, false, 0, "")

meter := conf.createDeviceForManager(manager, meterType)
if err := manager.Add(uint8(id), meter); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion docs/mbmd_inspect.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ mbmd inspect [flags]
Valid types are:
RTU
ABB ABB A/B-Series meters
BE Bernecker Engineering MPM3PM meters
DZG DZG Metering GmbH DVH4013 meters
INEPRO Inepro Metering Pro 380
JANITZA Janitza B-Series meters
MPM Bernecker Engineering MPM3PM meters
SBC Saia Burgess Controls ALE3 meters
SDM Eastron SDM630
SDM220 Eastron SDM220
Expand Down
2 changes: 1 addition & 1 deletion docs/mbmd_run.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ mbmd run [flags]
Valid types are:
RTU
ABB ABB A/B-Series meters
BE Bernecker Engineering MPM3PM meters
DZG DZG Metering GmbH DVH4013 meters
INEPRO Inepro Metering Pro 380
JANITZA Janitza B-Series meters
MPM Bernecker Engineering MPM3PM meters
SBC Saia Burgess Controls ALE3 meters
SDM Eastron SDM630
SDM220 Eastron SDM220
Expand Down
6 changes: 3 additions & 3 deletions meters/rs485/mpm3pm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ func init() {
}

const (
METERTYPE_BE = "BE"
METERTYPE_MPM = "MPM"
)

type MPM3MPProducer struct {
Expand Down Expand Up @@ -50,7 +50,7 @@ func NewMPM3MPProducer() Producer {

// Type implements Producer interface
func (p *MPM3MPProducer) Type() string {
return METERTYPE_BE
return METERTYPE_MPM
}

// Description implements Producer interface
Expand All @@ -60,7 +60,7 @@ func (p *MPM3MPProducer) Description() string {

func (p *MPM3MPProducer) snip(iec Measurement, readlen uint16, transform RTUTransform, scaler ...float64) Operation {
snip := Operation{
FuncCode: ReadInputReg,
FuncCode: ReadHoldingReg,
OpCode: p.Opcodes[iec],
ReadLen: readlen,
Transform: transform,
Expand Down

0 comments on commit e83718d

Please sign in to comment.