|
| 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