Skip to content

Commit

Permalink
add -unique
Browse files Browse the repository at this point in the history
Add option to suppress duplicate meter readings
  • Loading branch information
loverso authored and bemasher committed Jul 9, 2015
1 parent ae0364d commit b9240f9
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ data
*.exe
scm/Makefile
release.7z
*.diff
*.diff
desktop.ini
*~
2 changes: 2 additions & 0 deletions flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -73,6 +74,7 @@ func RegisterFlags() {
"format": true,
"gobunsafe": true,
"quiet": true,
"unique": true,
"single": true,
"cpuprofile": true,
"fastmag": true,
Expand Down
5 changes: 5 additions & 0 deletions idm/idm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type Message interface {
MsgType() string
MeterID() uint32
MeterType() uint8
MeterValue() uint32
}

type LogMessage struct {
Expand Down
4 changes: 4 additions & 0 deletions r900/r900.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions recv.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
)

var rcvr Receiver
var lastValue map[uint]uint32

type Receiver struct {
rtltcp.SDR
Expand Down Expand Up @@ -126,6 +127,7 @@ func (rcvr *Receiver) Run() {
}()

block := make([]byte, rcvr.p.Cfg().BlockSize2)
lastValue = make(map[uint]uint32)

start := time.Now()
for {
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions scm/scm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b9240f9

Please sign in to comment.