ade7878

package module
v0.0.0-...-82828e4 Latest Latest
Warning

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

Go to latest
Published: May 30, 2020 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ADE7878_ADDR int = 0x38
	SAMPLES      int = 100
)
View Source
const (
	PhaseA
	PhaseB
	PhaseC
	PhaseN
)

Variables

View Source
var ADE7878REG = map[string][]byte{}/* 136 elements not displayed */
View Source
var (
	CTTypes = map[string]CTFactors{
		"YHDC_SCT013": CTFactors{
			CurrentResistor:       7.07107,
			CurrentClampFactor:    0.05,
			OffsetCurrent:         1.049084906,
			OffsetVoltage:         1.0,
			PowerCorrectionFactor: 0.019413,
		},
		"X/1A": CTFactors{
			CurrentResistor:       0.33,
			CurrentClampFactor:    1.0,
			OffsetCurrent:         1.010725941,
			OffsetVoltage:         1.0,
			PowerCorrectionFactor: 0.043861,
		},
	}
)
View Source
var MainPhases = []Phase{PhaseA, PhaseB, PhaseC}

Functions

func CalculatePowerFactor

func CalculatePowerFactor(c *Config, phase Phase, watts float64, voltAmps float64, voltAmpsReactive float64) float64

func DeviceFetchInt

func DeviceFetchInt(d *i2c.Device, l int, cmd []byte) int64

Fetch a number of bytes from the device and convert it to an int.

func InitADE7878

func InitADE7878(c *Config) (*i2c.Device, error)

func ReadActiveEnergy

func ReadActiveEnergy(d *i2c.Device, c *Config, phase Phase) (energy float64)

func ReadActiveWatts

func ReadActiveWatts(d *i2c.Device, c *Config, phase Phase) (watts float64)

func ReadAngle

func ReadAngle(d *i2c.Device, c *Config, phase Phase) (angle float64)

func ReadApparentPower

func ReadApparentPower(d *i2c.Device, c *Config, phase Phase) float64

func ReadCurrent

func ReadCurrent(d *i2c.Device, c *Config, phase Phase) (current float64)

func ReadFrequency

func ReadFrequency(d *i2c.Device, c *Config, phase Phase) (frequency float64)

func ReadPhase

func ReadPhase(d *i2c.Device, c *Config, p Phase, v *ADE7878Readout)

func ReadReactivePower

func ReadReactivePower(d *i2c.Device, c *Config, phase Phase) (rewatts float64)

func ReadVoltage

func ReadVoltage(d *i2c.Device, c *Config, phase Phase) (voltage float64, measureVoltage bool)

func WriteRegister

func WriteRegister(d *i2c.Device, register string, data ...byte) (err error)

Types

type ADE7878Readout

type ADE7878Readout struct {
	Current       Readings
	Voltage       Readings
	ActiveWatts   Readings
	CosPhi        Readings
	Frequency     Readings
	ApparentPower Readings
	ReactivePower Readings
	PowerFactor   Readings
	ActiveEnergy  Readings
}

type CTFactors

type CTFactors struct {
	CurrentResistor, CurrentClampFactor, OffsetCurrent, OffsetVoltage, PowerCorrectionFactor float64
}

type Config

type Config struct {
	// [base]
	Serial               string
	Name                 string
	LogLevel             log.Level
	MetricsListenAddress string

	// [location]
	Lat float64
	Lng float64

	// [device]
	I2CDevice            string
	PowerFrequency       float64
	Samplerate           int
	Integrator           bool
	CTType               map[Phase]string
	CTTypePrimaryCurrent map[Phase]int
	CurrentDirection     map[Phase]bool
	MeasureCurrent       map[Phase]bool
	MeasureVoltage       map[Phase]bool
	Voltage              map[Phase]float64

	// [calibration]
	CalibrationfactorI map[Phase]float64
	CalibrationfactorU map[Phase]float64
}

func NewConfig

func NewConfig() *Config

func (*Config) ReadParameterFromFile

func (p *Config) ReadParameterFromFile()

type Phase

type Phase uint

func (Phase) PhaseNumber

func (p Phase) PhaseNumber() string

func (Phase) String

func (p Phase) String() string

type Readings

type Readings map[Phase]float64

Jump to

Keyboard shortcuts

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