File: MeterOMS.hpp

package info (click to toggle)
vzlogger 0.8.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,140 kB
  • sloc: cpp: 12,020; sh: 331; ansic: 157; makefile: 25
file content (71 lines) | stat: -rw-r--r-- 1,970 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
 * OMS (M-Bus) based meter/device support
 * for spec see e.g. http://oms-group.org/fileadmin/pdf/OMS-Spec_Vol2_Primary_v301.pdf
 *
 * @copyright Copyright (c) 2015 - 2023, the volkszaehler.org project
 * @license http://www.gnu.org/licenses/gpl2.txt GNU Public License v2
 * @author Matthias Behr <mbehr (a) mcbehr.de>
 * */

#ifndef _meteroms_hpp_
#define _meteroms_hpp_

#include <mbus/mbus.h>
#include <protocols/Protocol.hpp>

class MeterOMS : public vz::protocol::Protocol {
  public:
	// abstract hw interface access for testability:
	class OMSHWif {
	  public:
		OMSHWif(){};
		virtual ~OMSHWif(){};

		virtual ssize_t read(void *buf, size_t count) = 0;        // similar to ::read
		virtual ssize_t write(const void *buf, size_t count) = 0; // similar to ::write

		virtual bool open() { return true; }
		virtual bool close() { return true; }

		virtual int send_frame(mbus_frame *frame);
		virtual int receive_frame(mbus_frame *frame);
	};

	class OMSSerialHWif : public OMSHWif {
	  public:
		OMSSerialHWif(const std::string &dev, int baudrate);
		virtual ~OMSSerialHWif();
		virtual ssize_t read(void *buf, size_t count) { return -1; };        // similar to ::read
		virtual ssize_t write(const void *buf, size_t count) { return -1; }; // similar to ::write

		virtual bool open();
		virtual bool close();

		virtual int send_frame(mbus_frame *frame);
		virtual int receive_frame(mbus_frame *frame);

	  protected:
		mbus_handle *_handle;
		int _baudrate;
	};

	MeterOMS(const std::list<Option> &options, OMSHWif *hwif = 0);
	virtual ~MeterOMS();

	virtual int open();
	virtual int close();
	virtual ssize_t read(std::vector<Reading> &rds, size_t n);
	bool aes_decrypt(unsigned char *data, int data_len, unsigned char *key, unsigned char *iv);

  protected:
	double get_record_value(mbus_data_record *) const;

	OMSHWif *_hwif;
	unsigned char *_aes_key;
	std::string _device;
	bool _mbus_debug;
	bool _use_local_time;
	double _last_timestamp;
};

#endif