Skip to content

Commit

Permalink
[MeterChinaDC] crappy chinese hall-effect DC meter with serial output
Browse files Browse the repository at this point in the history
  • Loading branch information
r00t- committed Apr 3, 2021
1 parent 9e37fd6 commit af9025b
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 952 deletions.
1 change: 1 addition & 0 deletions include/meter_protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ typedef enum meter_procotol {
meter_protocol_ocr,
meter_protocol_w1therm,
meter_protocol_oms,
meter_protocol_chinadc,
} meter_protocol_t;
#endif /* _meter_protocol_hpp_ */
60 changes: 13 additions & 47 deletions include/protocols/MeterChinaDC.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* Plaintext protocol according to DIN EN 62056-21
* crappy chinese hall-effect DC meter with serial output
*
* This protocol uses OBIS to identify the readout data
* And is also sometimes called "D0"
* (code based on MeterD0)
*
* @package vzlogger
* @copyright Copyright (c) 2011, The volkszaehler.org project
* @copyright Copyright (c) 2021, The volkszaehler.org project
* @license http://www.gnu.org/licenses/gpl.txt GNU Public License
* @author Steffen Vogel <info@steffenvogel.de>
* @author Thorben T. <r00t@constancy.org>
*/
/*
* This file is part of volkzaehler.org
Expand All @@ -25,67 +25,33 @@
* You should have received a copy of the GNU General Public License
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
// RW: added ack
#ifndef _D0_H_
#define _D0_H_

#define D0_BUFFER_LENGTH 1024
#ifndef _CHINADC_H_
#define _CHINADC_H_

#include <termios.h>

#include <protocols/Protocol.hpp>

class MeterD0 : public vz::protocol::Protocol {
class MeterChinaDC : public vz::protocol::Protocol {
public:
MeterD0(std::list<Option> &options);
virtual ~MeterD0();
MeterChinaDC(std::list<Option> &options);
virtual ~MeterChinaDC();

int open();
int close();
ssize_t read(std::vector<Reading> &rds, size_t n);
virtual bool allowInterval() const {
return _pull.size() ? true : false;
} // only allow conf setting interval if pull is set (otherwise meter sends autom.)

const char *host() const { return _host.c_str(); }
virtual bool allowInterval() const { return false; }
const char *device() const { return _device.c_str(); }

private:
std::string _host;
std::string _device;
std::string _dump_file;
int _baudrate;
int _baudrate_read;

parity_type_t _parity;
std::string _pull;
std::string _ack;
bool _auto_ack;
bool _wait_sync_end;
int _read_timeout_s;
int _baudrate_change_delay_ms;
int _reaction_time_ms; // reaction time t_r according to 62056-21

int _fd; /* file descriptor of port */
FILE *_dump_fd;
int _fd; /* file descriptor of port */
struct termios _oldtio; /* required to reset port */

/**
* Open socket
*
* @param node the hostname or ASCII encoded IP address
* @param the ASCII encoded portnum or service as in /etc/services
* @return file descriptor, <0 on error
*/
int _openSocket(const char *node, const char *service);
int _openDevice(struct termios *old_tio, speed_t baudrate);

enum DUMP_MODE { NONE, CTRL, DUMP_IN, DUMP_OUT };
DUMP_MODE _old_mode;
int _dump_pos;
void dump_file(DUMP_MODE mode, const char *str);
void dump_file(DUMP_MODE mode, const char *buf, size_t len);
void dump_file(const char &c) { dump_file(DUMP_IN, &c, 1); };
int _openDevice(struct termios *old_tio);
};

#endif /* _D0_H_ */
#endif /* _CHINADC_H_ */
6 changes: 6 additions & 0 deletions src/Meter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#ifdef OMS_SUPPORT
#include "protocols/MeterOMS.hpp"
#endif
#include "protocols/MeterChinaDC.hpp"
//#include <protocols/.h>

#define METER_DETAIL(NAME, CLASSNAME, DESC, MAX_RDS) \
Expand All @@ -71,6 +72,7 @@ static const meter_details_t protocols[] = {
#ifdef OMS_SUPPORT
METER_DETAIL(oms, OMS, "OMS (M-BUS) protocol based devices", 100),
#endif
METER_DETAIL(chinadc, ChinaDC, "crappy chinese DC meter with serial output", 1),
//{} /* stop condition for iterator */
METER_DETAIL(none, NULL, NULL, 0),
};
Expand Down Expand Up @@ -187,6 +189,10 @@ Meter::Meter(std::list<Option> pOptions) : _name("meter") {
_identifier = ReadingIdentifier::Ptr(new ObisIdentifier());
break;
#endif
case meter_protocol_chinadc:
_protocol = vz::protocol::Protocol::Ptr(new MeterChinaDC(pOptions));
_identifier = ReadingIdentifier::Ptr(new StringIdentifier());
break;
default:
break;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Reading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ ReadingIdentifier::Ptr reading_id_parse(meter_protocol_t protocol, const char *s
ReadingIdentifier::Ptr rid;

switch (protocol) {
case meter_protocol_chinadc:
rid = ReadingIdentifier::Ptr(new StringIdentifier(string));
break;
case meter_protocol_d0:
case meter_protocol_sml:
case meter_protocol_oms:
Expand Down
1 change: 1 addition & 0 deletions src/protocols/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ set(proto_srcs
MeterRandom.cpp
MeterW1therm.cpp ../../include/protocols/MeterW1therm.hpp
${oms_srcs}
MeterChinaDC.cpp ../../include/protocols/MeterChinaDC.hpp
)

add_library(proto ${proto_srcs})
Expand Down
Loading

0 comments on commit af9025b

Please sign in to comment.