added simple sml_server example, updated README
This commit is contained in:
parent
25b1c76e62
commit
32e0767e1e
6 changed files with 85 additions and 14 deletions
|
@ -1,5 +0,0 @@
|
|||
libSML
|
||||
======
|
||||
|
||||
Implementation in C of the Smart Messaging Language (SML) protocol
|
||||
|
11
README.md
Normal file
11
README.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
libSML is a library which implements the Smart Messaging Language (SML) protocol specified by VDE's Forum Netztechnik/Netzbetrieb (FNN).
|
||||
It can be utilized to communicate to FNN specified Smart Meters (EDL/MUC).
|
||||
|
||||
# Version
|
||||
This is an alpha version, meaning the basics are implemented but there is still some work to do.
|
||||
|
||||
# Usage
|
||||
Examples how to use libSML are in the examples directory.
|
||||
|
||||
# License
|
||||
libSML is licensed with the GPL, other licenses are available.
|
11
examples/Makefile
Normal file
11
examples/Makefile
Normal file
|
@ -0,0 +1,11 @@
|
|||
CFLAGS += -I../sml/include/ -g -Wall
|
||||
OBJS = sml_server.o
|
||||
LIBS = -L../sml/lib/ ../sml/lib/libsml.o
|
||||
|
||||
sml_server : $(OBJS)
|
||||
$(CC) $(CFLAGS) $(LIBS) -o sml_server $(OBJS)
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
@rm -f *.o
|
||||
@rm -f sml_server
|
53
examples/sml_server.c
Normal file
53
examples/sml_server.c
Normal file
|
@ -0,0 +1,53 @@
|
|||
// Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed
|
||||
// DAI-Labor, TU-Berlin
|
||||
//
|
||||
// This file is part of libSML.
|
||||
//
|
||||
// libSML 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
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// libSML 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 libSML. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sml/sml.h>
|
||||
#include <sml/sml_transport.h>
|
||||
|
||||
void 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
|
||||
sml_file_print(file);
|
||||
|
||||
// all elements returned by parsing functions must be free'd
|
||||
sml_file_free(file);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
char *device = "your device here";
|
||||
|
||||
// this depends on your device (serial port, ip)
|
||||
int fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
|
||||
if (fd < 0) {
|
||||
printf("error: %s - %s\n", device, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
// this is a blocking call
|
||||
sml_transport_listen(fd, &transport_receiver);
|
||||
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
|
@ -21,25 +21,28 @@
|
|||
|
||||
#include "sml_message.h"
|
||||
#include "sml_shared.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// a SML file consist of multiple SML messages
|
||||
typedef struct {
|
||||
sml_message **messages;
|
||||
short messages_len;
|
||||
sml_buffer *buf;
|
||||
} sml_file;
|
||||
|
||||
// Parses a SML file.
|
||||
// parses a SML file.
|
||||
sml_file *sml_file_parse(unsigned char *buffer, size_t buffer_len);
|
||||
|
||||
sml_file *sml_file_init();
|
||||
void sml_file_add_message(sml_file *file, sml_message *message);
|
||||
void sml_file_write(sml_file *file);
|
||||
|
||||
void sml_file_free(sml_file *file);
|
||||
|
||||
void sml_file_print(sml_file *file);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -31,8 +31,6 @@
|
|||
|
||||
sml_file *sml_file_parse(unsigned char *buffer, size_t buffer_len) {
|
||||
|
||||
//buffer += 8;
|
||||
//buffer_len -= 16;
|
||||
sml_file *file = (sml_file*) malloc(sizeof(sml_file));
|
||||
memset(file, 0, sizeof(sml_file));
|
||||
|
||||
|
@ -51,16 +49,16 @@ sml_file *sml_file_parse(unsigned char *buffer, size_t buffer_len) {
|
|||
continue;
|
||||
}
|
||||
|
||||
msg = sml_message_parse(buf);
|
||||
|
||||
msg = sml_message_parse(buf);
|
||||
|
||||
if (sml_buf_has_errors(buf)) {
|
||||
printf("warning: could not read the whole file\n");
|
||||
break;
|
||||
printf("warning: could not read the whole file\n");
|
||||
break;
|
||||
}
|
||||
|
||||
sml_file_add_message(file, msg);
|
||||
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue