1 /*
2 Domoticz Software : http://domoticz.com/
3 File : TeleinfoSerial.cpp
4 Author : Nicolas HILAIRE, Blaise Thauvin
5 Version : 2.3
6 Description : This class decodes the Teleinfo signal from serial/USB devices before processing them
7 
8 History :
9 - 2013-11-01 : Creation
10 - 2014-10-29 : Add 'EJP' contract (Laurent MEY)
11 - 2014-12-13 : Add 'Tempo' contract (Kevin NICOLAS)
12 - 2015-06-10 : Fix bug power divided by 2 (Christophe DELPECH)
13 - 2016-02-05 : Fix bug power display with 'Tempo' contract (Anthony LAGUERRE)
14 - 2016-02-11 : Fix power display when PAPP is missing (Anthony LAGUERRE)
15 - 2016-02-17 : Fix bug power usage (Anthony LAGUERRE). Thanks to Multinet
16 - 2017-01-28 : Add 'Heures Creuses' Switch (A.L)
17 - 2017-03-15 : Renamed from Teleinfo.cpp to TeleinfoSerial.cpp in order to create
18 						   a shared class to process Teleinfo protocol (Blaise Thauvin)
19 - 2017-03-27 : Greatly simplified code
20 - 2017-04-01 : 2.3 Added RateLimit, flag to ignore CRC checks, and new CRC computation algorithm available on newer meters
21 */
22 
23 #pragma once
24 
25 #include "ASyncSerial.h"
26 #include "TeleinfoBase.h"
27 #define TELEINFO_PARITY            boost::asio::serial_port_base::parity::even
28 #define TELEINFO_CARACTER_SIZE      7
29 #define TELEINFO_FLOW_CONTROL      boost::asio::serial_port_base::flow_control::none
30 #define TELEINFO_STOP_BITS         boost::asio::serial_port_base::stop_bits::one
31 
32 class CTeleinfoSerial : public CTeleinfoBase, AsyncSerial
33 {
34 public:
35 	CTeleinfoSerial(const int ID, const std::string& devname, const int datatimeout, unsigned int baud_rate,
36 		const bool disable_crc, const int ratelimit);
37 	~CTeleinfoSerial();
38 	bool WriteToHardware(const char *pdata, const unsigned char length) override;
39 private:
40 	bool StartHardware() override;
41 	bool StopHardware() override;
42 	void Init();
43 	void readCallback(const char *data, size_t len);
44 private:
45 	std::string m_szSerialPort;
46 	boost::asio::serial_port_base::parity m_iOptParity;
47 	boost::asio::serial_port_base::character_size m_iOptCsize;
48 	boost::asio::serial_port_base::flow_control m_iOptFlow;
49 	boost::asio::serial_port_base::stop_bits m_iOptStop;
50 };
51