diff --git a/.gitignore b/.gitignore index 473b0b8..bdb7fda 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ data *.exe scm/Makefile release.7z -*.diff \ No newline at end of file +*.diff +desktop.ini +*~ diff --git a/flags.go b/flags.go index 7259a3a..4f18ce8 100644 --- a/flags.go +++ b/flags.go @@ -46,6 +46,7 @@ var decimation = flag.Int("decimation", 1, "integer decimation factor, keep ever var timeLimit = flag.Duration("duration", 0, "time to run for, 0 for infinite, ex. 1h5m10s") var meterID UintMap var meterType UintMap +var unique = flag.Bool("unique", false, "do not print duplicate values from each meter") var encoder Encoder var format = flag.String("format", "plain", "format to write log messages in: plain, csv, json, xml or gob") @@ -73,6 +74,7 @@ func RegisterFlags() { "format": true, "gobunsafe": true, "quiet": true, + "unique": true, "single": true, "cpuprofile": true, "fastmag": true, diff --git a/idm/idm.go b/idm/idm.go index 124e447..67b052b 100644 --- a/idm/idm.go +++ b/idm/idm.go @@ -163,6 +163,11 @@ func (idm IDM) MeterType() uint8 { return idm.ERTType } +func (idm IDM) MeterValue() uint32 { + // don't know yet + return 0 +} + func (idm IDM) String() string { var fields []string diff --git a/parse/parse.go b/parse/parse.go index 4e4a2ce..b0b50a8 100644 --- a/parse/parse.go +++ b/parse/parse.go @@ -50,6 +50,7 @@ type Message interface { MsgType() string MeterID() uint32 MeterType() uint8 + MeterValue() uint32 } type LogMessage struct { diff --git a/r900/r900.go b/r900/r900.go index a34762e..d5348ec 100644 --- a/r900/r900.go +++ b/r900/r900.go @@ -253,6 +253,10 @@ func (r900 R900) MeterType() uint8 { return r900.Unkn1 } +func (r900 R900) MeterValue() uint32 { + return r900.Consumption +} + func (r900 R900) String() string { return fmt.Sprintf("{ID:%10d Unkn1:0x%02X NoUse:%2d BackFlow:%1d Consumption:%8d Unkn3:0x%02X Leak:%2d LeakNow:%1d}", r900.ID, diff --git a/recv.go b/recv.go index 1aac532..23b8723 100644 --- a/recv.go +++ b/recv.go @@ -36,6 +36,7 @@ import ( ) var rcvr Receiver +var lastValue map[uint]uint32 type Receiver struct { rtltcp.SDR @@ -126,6 +127,7 @@ func (rcvr *Receiver) Run() { }() block := make([]byte, rcvr.p.Cfg().BlockSize2) + lastValue = make(map[uint]uint32) start := time.Now() for { @@ -154,6 +156,12 @@ func (rcvr *Receiver) Run() { if len(meterType) > 0 && !meterType[uint(pkt.MeterType())] { continue } + if *unique { + if lastValue[uint(pkt.MeterID())] == pkt.MeterValue() { + continue + } + lastValue[uint(pkt.MeterID())] = pkt.MeterValue() + } var msg parse.LogMessage msg.Time = time.Now() diff --git a/scm/scm.go b/scm/scm.go index 7e4785e..609cf37 100644 --- a/scm/scm.go +++ b/scm/scm.go @@ -130,6 +130,10 @@ func (scm SCM) MeterType() uint8 { return scm.Type } +func (scm SCM) MeterValue() uint32 { + return scm.Consumption +} + func (scm SCM) String() string { return fmt.Sprintf("{ID:%8d Type:%2d Tamper:{Phy:%02X Enc:%02X} Consumption:%8d CRC:0x%04X}", scm.ID, scm.Type, scm.TamperPhy, scm.TamperEnc, scm.Consumption, scm.Checksum,