added first draft od SML support
This commit is contained in:
parent
3490213877
commit
1e09bd52f4
3 changed files with 163 additions and 1 deletions
|
@ -49,9 +49,10 @@
|
|||
*/
|
||||
static protocol_t protocols[] = {
|
||||
{"1wire", "Dallas 1-Wire sensors (via OWFS)", onewire_get, onewire_init, onewire_close, MODE_SENSOR},
|
||||
{"obis", "Plaintext OBIS", obis_get, obis_init, obis_close, MODE_SENSOR},
|
||||
// {"obis", "Plaintext OBIS", obis_get, obis_init, obis_close, MODE_SENSOR},
|
||||
{"random", "Random walk", random_get, random_init, random_close, MODE_SENSOR},
|
||||
{"rawS0", "S0 on RS232", rawS0_get, rawS0_init, rawS0_close, MODE_METER},
|
||||
// {"sml", "Smart Meter Language", sml_get, sml_init, sml_close, MODE_SENSOR},
|
||||
// {"fluksousb", "FluksoUSB board", flukso_get, flukso_init, flukso_close, MODE_SENSOR},
|
||||
{NULL} /* stop condition for iterator */
|
||||
};
|
||||
|
|
115
misc/controller/vzlogger/src/protocols/sml.c
Normal file
115
misc/controller/vzlogger/src/protocols/sml.c
Normal file
|
@ -0,0 +1,115 @@
|
|||
/**
|
||||
* Wrapper around libsml
|
||||
*
|
||||
* @package vzlogger
|
||||
* @copyright Copyright (c) 2011, 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/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <termios.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <sml/sml_file.h>
|
||||
#include <sml/sml_transport.h>
|
||||
|
||||
int sml_init(char *device) {
|
||||
sml_state_t *state;
|
||||
|
||||
/* initialize handle */
|
||||
state = malloc(sizeof(sml_state_t));
|
||||
|
||||
/* this example assumes that a EDL21 meter sending SML messages via a
|
||||
* serial device. Adjust as needed. */
|
||||
int fd = serial_port_open(device);
|
||||
|
||||
if (fd > 0) {
|
||||
// start thread
|
||||
|
||||
/* listen on the serial device, this call is blocking */
|
||||
sml_transport_listen(fd, &transport_receiver);
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
void sml_close(void *handle) {
|
||||
|
||||
}
|
||||
|
||||
reading_t sml_get(void *handle) {
|
||||
|
||||
}
|
||||
|
||||
void sml_transport_receiver(unsigned char *buffer, size_t buffer_len) {
|
||||
// the buffer contains the whole message, with transport escape sequences.
|
||||
// these escape sequences are stripped here.
|
||||
sml_file *file = sml_file_parse(buffer + 8, buffer_len - 16);
|
||||
// the sml file is parsed now
|
||||
|
||||
// read here some values ..
|
||||
|
||||
// this prints some information about the file
|
||||
sml_file_print(file);
|
||||
|
||||
// free the malloc'd memory
|
||||
sml_file_free(file);
|
||||
}
|
||||
|
||||
int sml_open_port(char *device) {
|
||||
int bits;
|
||||
struct termios config;
|
||||
memset(&config, 0, sizeof(config));
|
||||
|
||||
int fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
|
||||
if (fd < 0) {
|
||||
printf("error: open(%s): %s\n", device, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
// set RTS
|
||||
ioctl(fd, TIOCMGET, &bits);
|
||||
bits |= TIOCM_RTS;
|
||||
ioctl(fd, TIOCMSET, &bits);
|
||||
|
||||
tcgetattr( fd, &config ) ;
|
||||
|
||||
// set 8-N-1
|
||||
config.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
|
||||
config.c_oflag &= ~OPOST;
|
||||
config.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
|
||||
config.c_cflag &= ~(CSIZE | PARENB | PARODD | CSTOPB);
|
||||
config.c_cflag |= CS8;
|
||||
|
||||
// set speed to 9600 baud
|
||||
cfsetispeed( &config, B9600);
|
||||
cfsetospeed( &config, B9600);
|
||||
|
||||
tcsetattr(fd, TCSANOW, &config);
|
||||
return fd;
|
||||
}
|
46
misc/controller/vzlogger/src/protocols/sml.h
Normal file
46
misc/controller/vzlogger/src/protocols/sml.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* Wrapper around libsml
|
||||
*
|
||||
* @package vzlogger
|
||||
* @copyright Copyright (c) 2011, 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 "../protocol.h"
|
||||
|
||||
typedef struct {
|
||||
int fd;
|
||||
// termios etc..
|
||||
} sml_state_t;
|
||||
|
||||
void * sml_init(char *port);
|
||||
void sml_close(void *handle);
|
||||
reading_t sml_get(void *handle);
|
||||
int sml_open_port(char *device);
|
||||
void sml_transport_receiver(unsigned char *buffer, size_t buffer_len);
|
||||
|
||||
#endif /* _SML_H_ */
|
Loading…
Add table
Reference in a new issue