gombus

package module
v0.0.0-...-416db9f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2024 License: Apache-2.0 Imports: 12 Imported by: 3

README

gombus Build Status codecov Go Report Card

Work in progress implementing mbus protocol in pure go.

Tested and fully working with the following devices:

  • Itron M-Bus Cyble v2.0
  • Garo GNM3D-MBUS / Carlo Gavazzi EM340-M1

Documentation

Index

Constants

View Source
const (
	DATA_RECORD_DIF_MASK_INST        = 0x00
	DATA_RECORD_DIF_MASK_MIN         = 0x10
	DATA_RECORD_DIF_MASK_TYPE_INT32  = 0x04
	DATA_RECORD_DIF_MASK_DATA        = 0x0F
	DATA_RECORD_DIF_MASK_FUNCTION    = 0x30
	DATA_RECORD_DIF_MASK_STORAGE_NO  = 0x40
	DATA_RECORD_DIF_MASK_EXTENSION   = 0x80
	DATA_RECORD_DIF_MASK_NON_DATA    = 0xF0
	DATA_RECORD_DIFE_MASK_STORAGE_NO = 0x0F
	DATA_RECORD_DIFE_MASK_TARIFF     = 0x30
	DATA_RECORD_DIFE_MASK_DEVICE     = 0x40
	DATA_RECORD_DIFE_MASK_EXTENSION  = 0x80

	DIB_DIF_WITHOUT_EXTENSION     = 0x7F
	DIB_DIF_EXTENSION_BIT         = 0x80
	DIB_VIF_WITHOUT_EXTENSION     = 0x7F
	DIB_VIF_EXTENSION_BIT         = 0x80
	DIB_DIF_MANUFACTURER_SPECIFIC = 0x0F
	DIB_DIF_MORE_RECORDS_FOLLOW   = 0x1F
	DIB_DIF_IDLE_FILLER           = 0x2F

	VARIABLE_DATA_MEDIUM_OTHER         = 0x00
	VARIABLE_DATA_MEDIUM_OIL           = 0x01
	VARIABLE_DATA_MEDIUM_ELECTRICITY   = 0x02
	VARIABLE_DATA_MEDIUM_GAS           = 0x03
	VARIABLE_DATA_MEDIUM_HEAT_OUT      = 0x04
	VARIABLE_DATA_MEDIUM_STEAM         = 0x05
	VARIABLE_DATA_MEDIUM_HOT_WATER     = 0x06
	VARIABLE_DATA_MEDIUM_WATER         = 0x07
	VARIABLE_DATA_MEDIUM_HEAT_COST     = 0x08
	VARIABLE_DATA_MEDIUM_COMPR_AIR     = 0x09
	VARIABLE_DATA_MEDIUM_COOL_OUT      = 0x0A
	VARIABLE_DATA_MEDIUM_COOL_IN       = 0x0B
	VARIABLE_DATA_MEDIUM_HEAT_IN       = 0x0C
	VARIABLE_DATA_MEDIUM_HEAT_COOL     = 0x0D
	VARIABLE_DATA_MEDIUM_BUS           = 0x0E
	VARIABLE_DATA_MEDIUM_UNKNOWN       = 0x0F
	VARIABLE_DATA_MEDIUM_IRRIGATION    = 0x10
	VARIABLE_DATA_MEDIUM_WATER_LOGGER  = 0x11
	VARIABLE_DATA_MEDIUM_GAS_LOGGER    = 0x12
	VARIABLE_DATA_MEDIUM_GAS_CONV      = 0x13
	VARIABLE_DATA_MEDIUM_COLORIFIC     = 0x14
	VARIABLE_DATA_MEDIUM_BOIL_WATER    = 0x15
	VARIABLE_DATA_MEDIUM_COLD_WATER    = 0x16
	VARIABLE_DATA_MEDIUM_DUAL_WATER    = 0x17
	VARIABLE_DATA_MEDIUM_PRESSURE      = 0x18
	VARIABLE_DATA_MEDIUM_ADC           = 0x19
	VARIABLE_DATA_MEDIUM_SMOKE         = 0x1A
	VARIABLE_DATA_MEDIUM_ROOM_SENSOR   = 0x1B
	VARIABLE_DATA_MEDIUM_GAS_DETECTOR  = 0x1C
	VARIABLE_DATA_MEDIUM_BREAKER_E     = 0x20
	VARIABLE_DATA_MEDIUM_VALVE         = 0x21
	VARIABLE_DATA_MEDIUM_CUSTOMER_UNIT = 0x25
	VARIABLE_DATA_MEDIUM_WASTE_WATER   = 0x28
	VARIABLE_DATA_MEDIUM_GARBAGE       = 0x29
	VARIABLE_DATA_MEDIUM_VOC           = 0x2B
	VARIABLE_DATA_MEDIUM_SERVICE_UNIT  = 0x30
	VARIABLE_DATA_MEDIUM_RC_SYSTEM     = 0x36
	VARIABLE_DATA_MEDIUM_RC_METER      = 0x37

	CONTROL_MASK_FCB = 0x20
	CONTROL_MASK_FCV = 0x10
)
View Source
const SingleCharacterFrame = 0xe5

Variables

View Source
var ErrNoLongFrameFound = fmt.Errorf("no long frame found")

// Does not handle timeout! the new one in tcp.go does // perhaps use io.ReadCloser and close after timeout?

func ReadLongFrame(r io.Reader) (LongFrame, error) {
	buf := bufio.NewReader(r)
	// TODO if this should be used again must implement whole frame detection from conn.ReadLongFrame
	msg, err := buf.ReadBytes(0x16)
	if err != nil {
		return nil, err
	}
	return LongFrame(msg), nil
}
View Source
var VIFUnit = map[string]int{
	"ENERGY_WH":              0x07,
	"ENERGY_J":               0x0F,
	"VOLUME":                 0x17,
	"MASS":                   0x1F,
	"ON_TIME":                0x23,
	"OPERATING_TIME":         0x27,
	"POWER_W":                0x2F,
	"POWER_J_H":              0x37,
	"VOLUME_FLOW":            0x3F,
	"VOLUME_FLOW_EXT":        0x47,
	"VOLUME_FLOW_EXT_S":      0x4F,
	"MASS_FLOW":              0x57,
	"FLOW_TEMPERATURE":       0x5B,
	"RETURN_TEMPERATURE":     0x5F,
	"TEMPERATURE_DIFFERENCE": 0x63,
	"EXTERNAL_TEMPERATURE":   0x67,
	"PRESSURE":               0x6B,
	"DATE":                   0x6C,
	"DATE_TIME_GENERAL":      0x6D,
	"DATE_TIME":              0x6D,
	"EXTENTED_TIME":          0x6D,
	"EXTENTED_DATE_TIME":     0x6D,
	"UNITS_FOR_HCA":          0x6E,
	"RES_THIRD_VIFE_TABLE":   0x6F,
	"AVG_DURATION":           0x73,
	"ACTUALITY_DURATION":     0x77,
	"FABRICATION_NO":         0x78,
	"IDENTIFICATION":         0x79,
	"ADDRESS":                0x7A,

	"FIRST_EXT_VIF_CODES":     0xFB,
	"VARIABLE_VIF":            0xFC,
	"VIF_FOLLOWING":           0x7C,
	"SECOND_EXT_VIF_CODES":    0xFD,
	"THIRD_EXT_VIF_CODES_RES": 0xEF,
	"ANY_VIF":                 0x7E,
	"MANUFACTURER_SPEC":       0x7F,
}
View Source
var VIFUnitExt = map[string]int{

	"CURRENCY_CREDIT": 0x03,
	"CURRENCY_DEBIT":  0x07,

	"ACCESS_NUMBER":    0x08,
	"MEDIUM":           0x09,
	"MANUFACTURER":     0x0A,
	"PARAMETER_SET_ID": 0x0B,
	"MODEL_VERSION":    0x0C,
	"HARDWARE_VERSION": 0x0D,
	"FIRMWARE_VERSION": 0x0E,
	"SOFTWARE_VERSION": 0x0F,

	"CUSTOMER_LOCATION":           0x10,
	"CUSTOMER":                    0x11,
	"ACCESS_CODE_USER":            0x12,
	"ACCESS_CODE_OPERATOR":        0x13,
	"ACCESS_CODE_SYSTEM_OPERATOR": 0x14,
	"ACCESS_CODE_DEVELOPER":       0x15,
	"PASSWORD":                    0x16,
	"ERROR_FLAGS":                 0x17,
	"ERROR_MASKS":                 0x18,
	"RESERVED":                    0x19,
	"DIGITAL_OUTPUT":              0x1A,
	"DIGITAL_INPUT":               0x1B,
	"BAUDRATE":                    0x1C,
	"RESPONSE_DELAY":              0x1D,
	"RETRY":                       0x1E,
	"RESERVED_2":                  0x1F,

	"FIRST_STORAGE_NR":       0x20,
	"LAST_STORAGE_NR":        0x21,
	"SIZE_OF_STORAGE_BLOCK":  0x22,
	"RESERVED_3":             0x23,
	"STORAGE_INTERVAL":       0x27,
	"STORAGE_INTERVAL_MONTH": 0x28,
	"STORAGE_INTERVAL_YEARS": 0x29,

	"DURATION_SINCE_LAST_READOUT": 0x2F,

	"START_OF_TARIFF":        0x30,
	"DURATION_OF_TARIFF":     0x3,
	"PERIOD_OF_TARIFF":       0x37,
	"PERIOD_OF_TARIFF_MONTH": 0x38,
	"PERIOD_OF_TARIFF_YEARS": 0x39,
	"DIMENSIONLESS":          0x3A,

	"VOLTS":                          0x4F,
	"AMPERE":                         0x5F,
	"RESET_COUNTER":                  0x60,
	"CUMULATION_COUNTER":             0x61,
	"CONTROL_SIGNAL":                 0x62,
	"DAY_OF_WEEK":                    0x63,
	"WEEK_NUMBER":                    0x64,
	"TIME_POINT_OF_DAY_CHANGE":       0x65,
	"STATE_OF_PARAMETER_ACTIVATION":  0x66,
	"SPECIAL_SUPPLIER_INFORMATION":   0x67,
	"DURATION_SINCE_LAST_CUMULATION": 0x6B,
	"OPERATING_TIME_BATTERY":         0x6F,
	"DATEAND_TIME_OF_BATTERY_CHANGE": 0x70,

	"RSSI": 0x71,
}
View Source
var VIFUnitSecExt = map[string]int{
	"RELATIVE_HUMIDITY": 0x1A,
}

Functions

func ReadAnyAndPrint

func ReadAnyAndPrint(r io.Reader) error

ReadAnyAndPrint is used for debugging.

Types

type C

type C byte

func (C) FCB

func (c C) FCB() bool

FCB Frame Count-Bit.

func (C) FCV

func (c C) FCV() bool

FCV Frame Count Valid indicates we want to use frame counting in the following request/responses.

type Conn

type Conn interface {
	Read(b []byte) (n int, err error)
	Write(b []byte) (n int, err error)
	SetReadDeadline(t time.Time) error
	Close() error
}

func DialSerial

func DialSerial(device string) (Conn, error)

func DialTCP

func DialTCP(addr string) (Conn, error)

type DateCalculator

type DateCalculator struct{}

func (*DateCalculator) GetDate

func (dc *DateCalculator) GetDate(day int, month int) string

func (*DateCalculator) GetDay

func (dc *DateCalculator) GetDay(day int) int

func (*DateCalculator) GetHour

func (dc *DateCalculator) GetHour(hour int) int

func (*DateCalculator) GetMinutes

func (dc *DateCalculator) GetMinutes(minute int) int

func (*DateCalculator) GetMonth

func (dc *DateCalculator) GetMonth(month int) int

func (*DateCalculator) GetSeconds

func (dc *DateCalculator) GetSeconds(second int) int

func (*DateCalculator) GetTime

func (dc *DateCalculator) GetTime(minute int, hour int) string

func (*DateCalculator) GetTimeWithSeconds

func (dc *DateCalculator) GetTimeWithSeconds(second int, minute int, hour int) string

func (*DateCalculator) GetYear

func (dc *DateCalculator) GetYear(v1 int, v2 int, hundredYearValue int, calcHundredYear bool) int

type DecodedDataRecord

type DecodedDataRecord struct {
	Function      string
	StorageNumber int

	Tariff int
	Device int

	Unit     Unit
	Exponent float64
	Type     string
	Quantity string

	Value       float64
	ValueString string
	RawValue    float64

	HasMoreRecords bool
}

type DecodedFrame

type DecodedFrame struct {
	SerialNumber int
	Manufacturer string
	ProductName  string
	Version      int
	DeviceType   string
	AccessNumber int16

	Signature int16

	Status int

	DataRecords []DecodedDataRecord
	// contains filtered or unexported fields
}

func ReadAllFrames

func ReadAllFrames(conn Conn, primaryID int) ([]*DecodedFrame, error)

ReadAllFrames supports FCB and reads out all frames from the device using primaryID.

func ReadSingleFrame

func ReadSingleFrame(conn Conn, primaryID int) (*DecodedFrame, error)

ReadSingleFrame reads one frame from the device. Does not reset device before asking.

func (DecodedFrame) HasMoreRecords

func (df DecodedFrame) HasMoreRecords() bool

func (DecodedFrame) SecondaryAddressString

func (df DecodedFrame) SecondaryAddressString() string

type Frame

type Frame []byte

type LongFrame

type LongFrame Frame

func ApplicationReset

func ApplicationReset(primaryID uint8) LongFrame

func ReadLongFrame

func ReadLongFrame(conn Conn) (LongFrame, error)

func ReadSingleCharFrame

func ReadSingleCharFrame(r io.Reader) (LongFrame, error)

func SendUD2

func SendUD2() LongFrame

water meter has 19004636 7704 14 07.

func SetPrimaryUsingPrimary

func SetPrimaryUsingPrimary(oldPrimary uint8, newPrimary uint8) LongFrame

func SetPrimaryUsingSecondary

func SetPrimaryUsingSecondary(secondary uint64, primary uint8) LongFrame

func (LongFrame) A

func (lf LongFrame) A() byte

func (LongFrame) C

func (lf LongFrame) C() C

func (LongFrame) CI

func (lf LongFrame) CI() byte

func (LongFrame) ClearFCB

func (lf LongFrame) ClearFCB()

func (LongFrame) ClearFCV

func (lf LongFrame) ClearFCV()

func (LongFrame) Decode

func (lf LongFrame) Decode() (*DecodedFrame, error)

func (LongFrame) DecodeManufacturer

func (lf LongFrame) DecodeManufacturer() (string, error)

func (LongFrame) L

func (lf LongFrame) L() int

func (LongFrame) SetChecksum

func (lf LongFrame) SetChecksum()

func (LongFrame) SetFCB

func (lf LongFrame) SetFCB()

func (LongFrame) SetFCV

func (lf LongFrame) SetFCV()

func (LongFrame) SetLength

func (lf LongFrame) SetLength()

type ShortFrame

type ShortFrame Frame

func NewShortFrame

func NewShortFrame() ShortFrame

func RequestUD2

func RequestUD2(primaryID uint8) ShortFrame

func SndNKE

func SndNKE(primaryID uint8) ShortFrame

SndNKE slave will ack with SingleCharacterFrame (e5).

func (ShortFrame) A

func (sf ShortFrame) A() byte

func (ShortFrame) C

func (sf ShortFrame) C() C

func (ShortFrame) ClearFCB

func (sf ShortFrame) ClearFCB()

func (ShortFrame) ClearFCV

func (sf ShortFrame) ClearFCV()

func (ShortFrame) SetAddress

func (sf ShortFrame) SetAddress(primary uint8)

func (ShortFrame) SetC

func (sf ShortFrame) SetC(c uint8)

func (ShortFrame) SetChecksum

func (sf ShortFrame) SetChecksum()

func (ShortFrame) SetFCB

func (sf ShortFrame) SetFCB()

func (ShortFrame) SetFCV

func (sf ShortFrame) SetFCV()

type Unit

type Unit struct {
	Exp         float64
	Unit        string
	Type        int
	VIFUnitDesc string
}

func (Unit) Value

func (vif Unit) Value(v float64) float64

Directories

Path Synopsis
cmd
mbusctl command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL