diff --git a/README.markdown b/README.markdown
deleted file mode 100644
index 2e2393a..0000000
--- a/README.markdown
+++ /dev/null
@@ -1,5 +0,0 @@
-libSML
-======
-
-Implementation in C of the Smart Messaging Language (SML) protocol
-
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..db61804
--- /dev/null
+++ b/README.md
@@ -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.
diff --git a/examples/Makefile b/examples/Makefile
new file mode 100644
index 0000000..42cc4df
--- /dev/null
+++ b/examples/Makefile
@@ -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
diff --git a/examples/sml_server.c b/examples/sml_server.c
new file mode 100644
index 0000000..68919d7
--- /dev/null
+++ b/examples/sml_server.c
@@ -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 .
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+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;
+}
diff --git a/sml/include/sml/sml.h b/sml/include/sml/sml.h
index 0b2477e..b7b4375 100644
--- a/sml/include/sml/sml.h
+++ b/sml/include/sml/sml.h
@@ -21,25 +21,28 @@
#include "sml_message.h"
#include "sml_shared.h"
-
#include
#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
diff --git a/sml/src/sml.c b/sml/src/sml.c
index 4961965..7221b15 100644
--- a/sml/src/sml.c
+++ b/sml/src/sml.c
@@ -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;
}