From 2b386b09782ecc66ed67bd9633c08df09c0c199d Mon Sep 17 00:00:00 2001 From: Douglas Hall Date: Mon, 23 May 2016 22:59:19 -0600 Subject: [PATCH] Add R900 BCD Protocol (#58) * Implement R900 BCD parser. * Register r900bcd protocol in main program. * Add r900bcd to msgtype flag description and readme. * Correct samplefile default value in documentation. --- README.md | 3 +-- flags.go | 2 +- main.go | 1 + r900bcd/r900bcd.go | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 r900bcd/r900bcd.go diff --git a/README.md b/README.md index 68d460f55..363ec69de 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Usage of rtlamr: -format=plain: format to write log messages in: plain, csv, json, xml or gob -gobunsafe=false: allow gob output to stdout -logfile=/dev/stdout: log statement dump file - -msgtype=scm: message type to receive: scm, idm, r900 or scm+ + -msgtype=scm: message type to receive: scm, scm+, idm, r900 and r900bcd -quiet=false: suppress printing state information at startup -samplefile=/dev/null: raw signal dump file -single=false: one shot execution, if used with -filterid, will wait for exactly one packet from each meter id @@ -53,7 +53,6 @@ rtltcp specific: -tunergain=0: set tuner gain in dB -tunergainmode=false: enable/disable tuner gain -tunerxtalfreq=0: set tuner xtal frequency - ``` Running the receiver is as simple as starting an `rtl_tcp` instance and then starting the receiver: diff --git a/flags.go b/flags.go index 856b8abc4..df5dcfe32 100644 --- a/flags.go +++ b/flags.go @@ -38,7 +38,7 @@ var logFile *os.File var sampleFilename = flag.String("samplefile", os.DevNull, "raw signal dump file") var sampleFile *os.File -var msgType = flag.String("msgtype", "scm", "message type to receive: scm, idm, r900 or scm+") +var msgType = flag.String("msgtype", "scm", "message type to receive: scm, scm+, idm, r900 and r900bcd") var symbolLength = flag.Int("symbollength", 72, "symbol length in samples") diff --git a/main.go b/main.go index 9be40f847..f46c7992b 100644 --- a/main.go +++ b/main.go @@ -34,6 +34,7 @@ import ( _ "github.com/bemasher/rtlamr/idm" _ "github.com/bemasher/rtlamr/r900" + _ "github.com/bemasher/rtlamr/r900bcd" _ "github.com/bemasher/rtlamr/scm" _ "github.com/bemasher/rtlamr/scmplus" ) diff --git a/r900bcd/r900bcd.go b/r900bcd/r900bcd.go new file mode 100644 index 000000000..174f73c2e --- /dev/null +++ b/r900bcd/r900bcd.go @@ -0,0 +1,49 @@ +// RTLAMR - An rtl-sdr receiver for smart meters operating in the 900MHz ISM band. +// Copyright (C) 2014 Douglas Hall +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package r900bcd + +import ( + "strconv" + + "github.com/bemasher/rtlamr/parse" + "github.com/bemasher/rtlamr/r900" +) + +func init() { + parse.Register("r900bcd", NewParser) +} + +type Parser struct { + parse.Parser +} + +func NewParser(symbolLength, decimation int) parse.Parser { + return Parser{r900.NewParser(symbolLength, decimation)} +} + +// Parse messages using r900 parser and convert consumption from BCD to int. +func (p Parser) Parse(indices []int) (msgs []parse.Message) { + msgs = p.Parser.Parse(indices) + for idx, msg := range msgs { + r900msg := msg.(r900.R900) + hex := strconv.FormatUint(uint64(r900msg.Consumption), 16) + consumption, _ := strconv.ParseUint(hex, 10, 32) + r900msg.Consumption = uint32(consumption) + msgs[idx] = r900msg + } + return +}