Skip to content

Commit 2b386b0

Browse files
committed
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.
1 parent 17b0016 commit 2b386b0

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Usage of rtlamr:
3131
-format=plain: format to write log messages in: plain, csv, json, xml or gob
3232
-gobunsafe=false: allow gob output to stdout
3333
-logfile=/dev/stdout: log statement dump file
34-
-msgtype=scm: message type to receive: scm, idm, r900 or scm+
34+
-msgtype=scm: message type to receive: scm, scm+, idm, r900 and r900bcd
3535
-quiet=false: suppress printing state information at startup
3636
-samplefile=/dev/null: raw signal dump file
3737
-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:
5353
-tunergain=0: set tuner gain in dB
5454
-tunergainmode=false: enable/disable tuner gain
5555
-tunerxtalfreq=0: set tuner xtal frequency
56-
5756
```
5857

5958
Running the receiver is as simple as starting an `rtl_tcp` instance and then starting the receiver:

flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var logFile *os.File
3838
var sampleFilename = flag.String("samplefile", os.DevNull, "raw signal dump file")
3939
var sampleFile *os.File
4040

41-
var msgType = flag.String("msgtype", "scm", "message type to receive: scm, idm, r900 or scm+")
41+
var msgType = flag.String("msgtype", "scm", "message type to receive: scm, scm+, idm, r900 and r900bcd")
4242

4343
var symbolLength = flag.Int("symbollength", 72, "symbol length in samples")
4444

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434

3535
_ "github.com/bemasher/rtlamr/idm"
3636
_ "github.com/bemasher/rtlamr/r900"
37+
_ "github.com/bemasher/rtlamr/r900bcd"
3738
_ "github.com/bemasher/rtlamr/scm"
3839
_ "github.com/bemasher/rtlamr/scmplus"
3940
)

r900bcd/r900bcd.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// RTLAMR - An rtl-sdr receiver for smart meters operating in the 900MHz ISM band.
2+
// Copyright (C) 2014 Douglas Hall
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as published
6+
// by the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
package r900bcd
18+
19+
import (
20+
"strconv"
21+
22+
"github.com/bemasher/rtlamr/parse"
23+
"github.com/bemasher/rtlamr/r900"
24+
)
25+
26+
func init() {
27+
parse.Register("r900bcd", NewParser)
28+
}
29+
30+
type Parser struct {
31+
parse.Parser
32+
}
33+
34+
func NewParser(symbolLength, decimation int) parse.Parser {
35+
return Parser{r900.NewParser(symbolLength, decimation)}
36+
}
37+
38+
// Parse messages using r900 parser and convert consumption from BCD to int.
39+
func (p Parser) Parse(indices []int) (msgs []parse.Message) {
40+
msgs = p.Parser.Parse(indices)
41+
for idx, msg := range msgs {
42+
r900msg := msg.(r900.R900)
43+
hex := strconv.FormatUint(uint64(r900msg.Consumption), 16)
44+
consumption, _ := strconv.ParseUint(hex, 10, 32)
45+
r900msg.Consumption = uint32(consumption)
46+
msgs[idx] = r900msg
47+
}
48+
return
49+
}

0 commit comments

Comments
 (0)