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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
/**
* Wrapper around libsml
*
* @package vzlogger
* @copyright Copyright (c) 2011 - 2023, The volkszaehler.org project
* @copyright Copyright (c) 2011, DAI-Labor, TU-Berlin
* @license http://www.gnu.org/licenses/gpl.txt GNU Public License
* @author Steffen Vogel <info@steffenvogel.de>
* @author Juri Glass
* @author Mathias Runge
* @author Nadim El Sayed
*/
/*
* This file is part of volkzaehler.org
*
* volkzaehler.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _SML_H_
#define _SML_H_
#include <sml/sml_file.h>
#include <sml/sml_value.h>
#include <termios.h>
#include "Obis.hpp"
#include <protocols/Protocol.hpp>
class MeterSML : public vz::protocol::Protocol {
public:
MeterSML(std::list<Option> options);
MeterSML(const MeterSML &mtr);
virtual ~MeterSML();
// MeterSML& operator=(const MeterSML&proto) { std::cout<<"====>MeterSML - equal!" <<
// std::endl; return (*this); }
int open();
int close();
ssize_t read(std::vector<Reading> &rds, size_t n);
virtual bool allowInterval() const {
return false;
} // don't allow conf setting interval with sml
const char *host() const { return _host.c_str(); }
const char *device() const { return _device.c_str(); }
protected:
std::string _host;
std::string _device;
speed_t _baudrate;
parity_type_t _parity;
std::string _pull;
bool _use_local_time;
int _fd; /* file descriptor of port */
struct termios _old_tio; /* required to reset port */
const int BUFFER_LEN;
/**
* @brief reopen the underlying device. We do this to workaround issue #362
* @return true if reopen was successful. False otherwise.
* */
bool reopen();
/**
* Parses SML list entry and stores it in reading pointed by rd
*
* @param list the list entry
* @param rd the reading to store to
* @return true if it is a valid entry
*/
bool _parse(sml_list *list, Reading *rd);
/**
* Open serial port by device
*
* @param device the device path, usually /dev/ttyS*
* @param old_config pointer to termios structure, will be filled with old port configuration
* @param baudrate the baudrate
* @return file descriptor, <0 on error
*/
int _openDevice(struct termios *old_config, speed_t baudrate);
/**
* 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);
};
#endif /* _SML_H_ */
|