Skip to content

Commit

Permalink
Add R900 BCD Protocol (#58)
Browse files Browse the repository at this point in the history
* Implement R900 BCD parser.
* Register r900bcd protocol in main program.
* Add r900bcd to msgtype flag description and readme.
* Correct samplefile default value in documentation.
  • Loading branch information
bemasher committed May 24, 2016
1 parent 17b0016 commit 2b386b0
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
49 changes: 49 additions & 0 deletions r900bcd/r900bcd.go
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

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
}

0 comments on commit 2b386b0

Please sign in to comment.