Merge branch 'master' of https://github.com/dailab/libsml
Conflicts: sml/src/sml_list.c sml/src/sml_message.c
This commit is contained in:
commit
3c8904acc6
25 changed files with 767 additions and 148 deletions
BIN
CONTRIBUTION.pdf
Normal file
BIN
CONTRIBUTION.pdf
Normal file
Binary file not shown.
|
@ -43,7 +43,8 @@ OBJS = \
|
|||
src/sml_get_proc_parameter_response.o \
|
||||
src/sml_get_profile_pack_request.o \
|
||||
src/sml_get_profile_pack_response.o \
|
||||
src/sml_get_profile_list_request.o
|
||||
src/sml_get_profile_list_request.o \
|
||||
src/sml_get_profile_list_response.o
|
||||
|
||||
ifeq ($(UNAME), Linux)
|
||||
libsml: $(DYN_LIB) $(ST_LIB) $(OBJ_LIB)
|
||||
|
|
|
@ -35,8 +35,6 @@ typedef struct {
|
|||
octet_string *username; // optional
|
||||
octet_string *password; // optional
|
||||
octet_string *list_name; // optional
|
||||
|
||||
|
||||
} sml_get_list_request;
|
||||
|
||||
sml_get_list_request* sml_get_list_request_init();
|
||||
|
|
|
@ -19,6 +19,35 @@
|
|||
#ifndef _SML_GET_PROFILE_LIST_RESPONSE_H
|
||||
#define _SML_GET_PROFILE_LIST_RESPONSE_H
|
||||
|
||||
// TODO
|
||||
#include "sml_shared.h"
|
||||
#include "sml_octet_string.h"
|
||||
#include "sml_time.h"
|
||||
#include "sml_list.h"
|
||||
#include "sml_tree.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
octet_string *server_id;
|
||||
sml_time *act_time;
|
||||
u32 *reg_period;
|
||||
sml_tree_path *parameter_tree_path;
|
||||
sml_time *val_time;
|
||||
u64 *status;
|
||||
sml_sequence *period_list;
|
||||
octet_string *rawdata;
|
||||
sml_signature *period_signature;
|
||||
} sml_get_profile_list_response;
|
||||
|
||||
sml_get_profile_list_response *sml_get_profile_list_response_init();
|
||||
sml_get_profile_list_response *sml_get_profile_list_response_parse(sml_buffer *buf);
|
||||
void sml_get_profile_list_response_write(sml_get_profile_list_response *msg, sml_buffer *buf);
|
||||
void sml_get_profile_list_response_free(sml_get_profile_list_response *msg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -29,14 +29,13 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct {
|
||||
octet_string *server_id;
|
||||
sml_time *act_time; // specified by germans (current time was meant) ;)
|
||||
u32 *reg_period;
|
||||
sml_tree_path *parameter_tree_path;
|
||||
sml_list *list_of_sml_prof_obj_header_entry;
|
||||
sml_list *list_of_sml_prof_obj_period_entry;
|
||||
sml_sequence *header_list; // list of sml_prof_obj_header_entry
|
||||
sml_sequence *period_list; // list of sml_prof_obj_period_entry
|
||||
octet_string *rawdata; // optional
|
||||
sml_signature *profile_signature; // optional
|
||||
|
||||
|
@ -47,6 +46,39 @@ sml_get_profile_pack_response *sml_get_profile_pack_response_parse(sml_buffer *b
|
|||
void sml_get_profile_pack_response_write(sml_get_profile_pack_response *msg, sml_buffer *buf);
|
||||
void sml_get_profile_pack_response_free(sml_get_profile_pack_response *msg);
|
||||
|
||||
typedef struct {
|
||||
octet_string *obj_name;
|
||||
sml_unit *unit;
|
||||
i8 *scaler;
|
||||
} sml_prof_obj_header_entry;
|
||||
|
||||
sml_prof_obj_header_entry *sml_prof_obj_header_entry_init();
|
||||
sml_prof_obj_header_entry *sml_prof_obj_header_entry_parse(sml_buffer *buf);
|
||||
void sml_prof_obj_header_entry_write(sml_prof_obj_header_entry *entry, sml_buffer *buf);
|
||||
void sml_prof_obj_header_entry_free(sml_prof_obj_header_entry *entry);
|
||||
|
||||
typedef struct {
|
||||
sml_time *val_time;
|
||||
u64 *status;
|
||||
sml_sequence *value_list;
|
||||
sml_signature *period_signature;
|
||||
} sml_prof_obj_period_entry;
|
||||
|
||||
sml_prof_obj_period_entry *sml_prof_obj_period_entry_init();
|
||||
sml_prof_obj_period_entry *sml_prof_obj_period_entry_parse(sml_buffer *buf);
|
||||
void sml_prof_obj_period_entry_write(sml_prof_obj_period_entry *entry, sml_buffer *buf);
|
||||
void sml_prof_obj_period_entry_free(sml_prof_obj_period_entry *entry);
|
||||
|
||||
typedef struct {
|
||||
sml_value *value;
|
||||
sml_signature *value_signature;
|
||||
} sml_value_entry;
|
||||
|
||||
sml_value_entry *sml_value_entry_init();
|
||||
sml_value_entry *sml_value_entry_parse(sml_buffer *buf);
|
||||
void sml_value_entry_write(sml_value_entry *entry, sml_buffer *buf);
|
||||
void sml_value_entry_free(sml_value_entry *entry);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -31,6 +31,18 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
void **elems;
|
||||
int elems_len;
|
||||
|
||||
void (*elem_free) (void *elem);
|
||||
} sml_sequence;
|
||||
|
||||
sml_sequence *sml_sequence_init(void (*elem_free) (void *elem));
|
||||
sml_sequence *sml_sequence_parse(sml_buffer *buf, void *(*elem_parse) (sml_buffer *buf), void (*elem_free) (void *elem));
|
||||
void sml_sequence_write(sml_sequence *seq, sml_buffer *buf, void (*elem_write) (void *elem, sml_buffer *buf));
|
||||
void sml_sequence_free(sml_sequence *seq);
|
||||
void sml_sequence_add(sml_sequence *list, void *new_entry);
|
||||
|
||||
typedef struct sml_list_entry {
|
||||
octet_string *obj_name;
|
||||
|
@ -46,12 +58,9 @@ typedef struct sml_list_entry {
|
|||
} sml_list;
|
||||
|
||||
sml_list *sml_list_init();
|
||||
|
||||
sml_list *sml_list_parse(sml_buffer *buf);
|
||||
void sml_list_write(sml_list *list, sml_buffer *buf);
|
||||
void sml_list_add(sml_list *list, sml_list *new_entry);
|
||||
|
||||
sml_list *sml_list_parse(sml_buffer *buf);
|
||||
|
||||
void sml_list_free(sml_list *list);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
#include "sml_get_proc_parameter_request.h"
|
||||
#include "sml_get_proc_parameter_response.h"
|
||||
#include "sml_set_proc_parameter_request.h"
|
||||
#include "sml_set_proc_parameter_response.h"
|
||||
#include "sml_get_list_request.h"
|
||||
#include "sml_get_list_response.h"
|
||||
#include "sml_attention_response.h"
|
||||
|
@ -53,7 +52,7 @@
|
|||
#define SML_MESSAGE_GET_PROC_PARAMETER_REQUEST 0x00000500
|
||||
#define SML_MESSAGE_GET_PROC_PARAMETER_RESPONSE 0x00000501
|
||||
#define SML_MESSAGE_SET_PROC_PARAMETER_REQUEST 0x00000600
|
||||
#define SML_MESSAGE_SET_PROC_PARAMETER_RESPONSE 0x00000601
|
||||
#define SML_MESSAGE_SET_PROC_PARAMETER_RESPONSE 0x00000601 // This doesn't exist in the spec
|
||||
#define SML_MESSAGE_GET_LIST_REQUEST 0x00000700
|
||||
#define SML_MESSAGE_GET_LIST_RESPONSE 0x00000701
|
||||
#define SML_MESSAGE_ATTENTION_RESPONSE 0x0000FF01
|
||||
|
|
|
@ -32,24 +32,21 @@ typedef struct {
|
|||
int len;
|
||||
} octet_string;
|
||||
|
||||
// sml signature
|
||||
typedef octet_string sml_signature;
|
||||
|
||||
octet_string *sml_octet_string_init(unsigned char *str, int length);
|
||||
|
||||
octet_string *sml_octet_string_init_from_hex(char *str);
|
||||
|
||||
void sml_octet_string_free(octet_string *str);
|
||||
|
||||
// Parses a octet string, updates the buffer accordingly, memory must be free'd elsewhere.
|
||||
octet_string *sml_octet_string_parse(sml_buffer *buf);
|
||||
|
||||
octet_string *sml_octet_string_generate_uuid();
|
||||
void sml_octet_string_write(octet_string *str, sml_buffer *buf);
|
||||
|
||||
void sml_octet_string_free(octet_string *str);
|
||||
int sml_octet_string_cmp(octet_string *s1, octet_string *s2);
|
||||
int sml_octet_string_cmp_with_hex(octet_string *str, char *hex);
|
||||
|
||||
octet_string *sml_octet_string_generate_uuid();
|
||||
// sml signature
|
||||
typedef octet_string sml_signature;
|
||||
#define sml_signature_parse(buf) sml_octet_string_parse(buf)
|
||||
#define sml_signature_write(s, buf) sml_octet_string_write(s, buf)
|
||||
#define sml_signature_free(s) sml_octet_string_free(s)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct {
|
||||
octet_string *server_id; // optional
|
||||
octet_string *username; // optional
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
// 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/>.
|
||||
|
||||
#ifndef _SML_SET_PROC_PARAMETER_RESPONSE_H
|
||||
#define _SML_SET_PROC_PARAMETER_RESPONSE_H
|
||||
|
||||
// TODO
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -41,10 +41,13 @@ sml_attention_response *sml_attention_response_parse(sml_buffer *buf){
|
|||
|
||||
msg->server_id = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->attention_number = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->attention_message = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->attention_details = sml_tree_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
|
|
|
@ -55,12 +55,16 @@ sml_get_list_request *sml_get_list_request_parse(sml_buffer *buf) {
|
|||
|
||||
msg->client_id = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->server_id = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->username = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->password = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->list_name = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
|
|
|
@ -41,16 +41,22 @@ sml_get_list_response *sml_get_list_response_parse(sml_buffer *buf) {
|
|||
|
||||
msg->client_id = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->server_id = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->list_name = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->act_sensor_time = sml_time_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->val_list = sml_list_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->list_signature = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->act_gateway_time = sml_time_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
|
|
|
@ -43,12 +43,16 @@ sml_get_proc_parameter_request *sml_get_proc_parameter_request_parse(sml_buffer
|
|||
|
||||
msg->server_id = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->username = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->password = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->parameter_tree_path = sml_tree_path_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->attribute = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
|
|
|
@ -25,10 +25,6 @@ sml_get_proc_parameter_response *sml_get_proc_parameter_response_init() {
|
|||
return msg;
|
||||
}
|
||||
|
||||
octet_string *server_id;
|
||||
sml_tree_path *parameter_tree_path;
|
||||
sml_tree *parameter_tree;
|
||||
|
||||
sml_get_proc_parameter_response *sml_get_proc_parameter_response_parse(sml_buffer *buf) {
|
||||
sml_get_proc_parameter_response *msg = sml_get_proc_parameter_response_init();
|
||||
|
||||
|
@ -44,8 +40,10 @@ sml_get_proc_parameter_response *sml_get_proc_parameter_response_parse(sml_buffe
|
|||
|
||||
msg->server_id = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->parameter_tree_path = sml_tree_path_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->parameter_tree = sml_tree_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
|
|
|
@ -20,3 +20,8 @@
|
|||
|
||||
// this file is just there for symmetry
|
||||
|
||||
|
||||
void sml_get_profile_list_request_noop() {}
|
||||
|
||||
|
||||
|
||||
|
|
106
sml/src/sml_get_profile_list_response.c
Normal file
106
sml/src/sml_get_profile_list_response.c
Normal file
|
@ -0,0 +1,106 @@
|
|||
// 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 <sml/sml_get_profile_list_response.h>
|
||||
|
||||
// sml_get_profile_list_response;
|
||||
|
||||
sml_get_profile_list_response *sml_get_profile_list_response_init() {
|
||||
sml_get_profile_list_response *msg = (sml_get_profile_list_response *) malloc(sizeof(sml_get_profile_list_response));
|
||||
memset(msg, 0, sizeof(sml_get_profile_list_response));
|
||||
return msg;
|
||||
}
|
||||
|
||||
sml_get_profile_list_response *sml_get_profile_list_response_parse(sml_buffer *buf) {
|
||||
sml_get_profile_list_response *msg = sml_get_profile_list_response_init();
|
||||
|
||||
if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) {
|
||||
buf->error = 1;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (sml_buf_get_next_length(buf) != 9) {
|
||||
buf->error = 1;
|
||||
goto error;
|
||||
}
|
||||
|
||||
msg->server_id = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->act_time = sml_time_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->reg_period = sml_u32_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->parameter_tree_path = sml_tree_path_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->val_time = sml_time_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->status = sml_u64_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->period_list = sml_sequence_parse(buf, (void *) &sml_period_entry_parse, (void (*)(void *)) &sml_period_entry_free);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->rawdata = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->period_signature = sml_signature_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
return msg;
|
||||
|
||||
error:
|
||||
buf->error = 1;
|
||||
sml_get_profile_list_response_free(msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sml_get_profile_list_response_write(sml_get_profile_list_response *msg, sml_buffer *buf) {
|
||||
sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 9);
|
||||
|
||||
sml_octet_string_write(msg->server_id, buf);
|
||||
sml_time_write(msg->act_time, buf);
|
||||
sml_u32_write(msg->reg_period, buf);
|
||||
sml_tree_path_write(msg->parameter_tree_path, buf);
|
||||
sml_time_write(msg->val_time, buf);
|
||||
sml_u64_write(msg->status, buf);
|
||||
sml_sequence_write(msg->period_list, buf, (void (*)(void *, sml_buffer *)) &sml_period_entry_write);
|
||||
sml_octet_string_write(msg->rawdata, buf);
|
||||
sml_signature_write(msg->period_signature, buf);
|
||||
}
|
||||
|
||||
void sml_get_profile_list_response_free(sml_get_profile_list_response *msg) {
|
||||
if (msg) {
|
||||
sml_octet_string_free(msg->server_id);
|
||||
sml_time_free(msg->act_time);
|
||||
sml_number_free(msg->reg_period);
|
||||
sml_tree_path_free(msg->parameter_tree_path);
|
||||
sml_time_free(msg->val_time);
|
||||
sml_number_free(msg->status);
|
||||
sml_sequence_free(msg->period_list);
|
||||
sml_octet_string_free(msg->rawdata);
|
||||
sml_signature_free(msg->period_signature);
|
||||
|
||||
free(msg);
|
||||
}
|
||||
}
|
|
@ -75,16 +75,22 @@ sml_get_profile_pack_request *sml_get_profile_pack_request_parse(sml_buffer *buf
|
|||
|
||||
msg->server_id = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->username = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->password = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->with_rawdata = sml_boolean_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->begin_time = sml_time_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->end_time = sml_time_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->parameter_tree_path = sml_tree_path_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
|
|
|
@ -20,20 +20,251 @@
|
|||
#include <sml/sml_get_profile_pack_response.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// sml_get_profile_pack_response
|
||||
|
||||
sml_get_profile_pack_response *sml_get_profile_pack_response_init() {
|
||||
printf("NYI: %s\n", __FUNCTION__);
|
||||
return 0;
|
||||
sml_get_profile_pack_response *msg = (sml_get_profile_pack_response *) malloc(sizeof(sml_get_profile_pack_response));
|
||||
memset(msg, 0, sizeof(sml_get_profile_pack_response));
|
||||
return msg;
|
||||
}
|
||||
|
||||
sml_get_profile_pack_response *sml_get_profile_pack_response_parse(sml_buffer *buf){
|
||||
printf("NYI: %s\n", __FUNCTION__);
|
||||
sml_get_profile_pack_response *msg = sml_get_profile_pack_response_init();
|
||||
|
||||
if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) {
|
||||
buf->error = 1;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (sml_buf_get_next_length(buf) != 8) {
|
||||
buf->error = 1;
|
||||
goto error;
|
||||
}
|
||||
|
||||
msg->server_id = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->act_time = sml_time_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->reg_period = sml_u32_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->parameter_tree_path = sml_tree_path_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->header_list = sml_sequence_parse(buf, (void *) &sml_prof_obj_header_entry_parse, (void (*)(void *)) &sml_prof_obj_header_entry_free);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->period_list = sml_sequence_parse(buf, (void *) &sml_prof_obj_period_entry_parse, (void (*)(void *)) &sml_prof_obj_period_entry_free);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->rawdata = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->profile_signature = sml_signature_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
return msg;
|
||||
|
||||
error:
|
||||
buf->error = 1;
|
||||
sml_get_profile_pack_response_free(msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sml_get_profile_pack_response_write(sml_get_profile_pack_response *msg, sml_buffer *buf) {
|
||||
printf("NYI: %s\n", __FUNCTION__);
|
||||
sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 8);
|
||||
|
||||
sml_octet_string_write(msg->server_id, buf);
|
||||
sml_time_write(msg->act_time, buf);
|
||||
sml_u32_write(msg->reg_period, buf);
|
||||
sml_tree_path_write(msg->parameter_tree_path, buf);
|
||||
sml_sequence_write(msg->header_list, buf, (void (*)(void *, sml_buffer *)) &sml_prof_obj_header_entry_write);
|
||||
sml_sequence_write(msg->period_list, buf, (void (*)(void *, sml_buffer *)) &sml_prof_obj_period_entry_write);
|
||||
sml_octet_string_write(msg->rawdata, buf);
|
||||
sml_signature_write(msg->profile_signature, buf);
|
||||
}
|
||||
|
||||
void sml_get_profile_pack_response_free(sml_get_profile_pack_response *msg){
|
||||
printf("NYI: %s\n", __FUNCTION__);
|
||||
if (msg) {
|
||||
sml_octet_string_free(msg->server_id);
|
||||
sml_time_free(msg->act_time);
|
||||
sml_number_free(msg->reg_period);
|
||||
sml_tree_path_free(msg->parameter_tree_path);
|
||||
sml_sequence_free(msg->header_list);
|
||||
sml_sequence_free(msg->period_list);
|
||||
sml_octet_string_free(msg->rawdata);
|
||||
sml_signature_free(msg->profile_signature);
|
||||
|
||||
free(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// sml_prof_obj_header_entry;
|
||||
|
||||
sml_prof_obj_header_entry *sml_prof_obj_header_entry_init() {
|
||||
sml_prof_obj_header_entry *entry = (sml_prof_obj_header_entry *) malloc(sizeof(sml_prof_obj_header_entry));
|
||||
memset(entry, 0, sizeof(sml_prof_obj_header_entry));
|
||||
return entry;
|
||||
}
|
||||
|
||||
sml_prof_obj_header_entry *sml_prof_obj_header_entry_parse(sml_buffer *buf) {
|
||||
sml_prof_obj_header_entry *entry = sml_prof_obj_header_entry_init();
|
||||
|
||||
if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) {
|
||||
buf->error = 1;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (sml_buf_get_next_length(buf) != 3) {
|
||||
buf->error = 1;
|
||||
goto error;
|
||||
}
|
||||
|
||||
entry->obj_name = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
entry->unit = sml_unit_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
entry->scaler = sml_i8_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
return entry;
|
||||
error:
|
||||
buf->error = 1;
|
||||
sml_prof_obj_header_entry_free(entry);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sml_prof_obj_header_entry_write(sml_prof_obj_header_entry *entry, sml_buffer *buf) {
|
||||
sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 3);
|
||||
|
||||
sml_octet_string_write(entry->obj_name, buf);
|
||||
sml_unit_write(entry->unit, buf);
|
||||
sml_i8_write(entry->scaler, buf);
|
||||
}
|
||||
|
||||
void sml_prof_obj_header_entry_free(sml_prof_obj_header_entry *entry) {
|
||||
if (entry) {
|
||||
sml_octet_string_free(entry->obj_name);
|
||||
sml_unit_free(entry->unit);
|
||||
sml_number_free(entry->scaler);
|
||||
|
||||
free(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// sml_prof_obj_period_entry;
|
||||
|
||||
|
||||
sml_prof_obj_period_entry *sml_prof_obj_period_entry_init() {
|
||||
sml_prof_obj_period_entry *entry = (sml_prof_obj_period_entry *) malloc(sizeof(sml_prof_obj_period_entry));
|
||||
memset(entry, 0, sizeof(sml_prof_obj_period_entry));
|
||||
return entry;
|
||||
}
|
||||
|
||||
sml_prof_obj_period_entry *sml_prof_obj_period_entry_parse(sml_buffer *buf) {
|
||||
sml_prof_obj_period_entry *entry = sml_prof_obj_period_entry_init();
|
||||
|
||||
if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) {
|
||||
buf->error = 1;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (sml_buf_get_next_length(buf) != 4) {
|
||||
buf->error = 1;
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
entry->val_time = sml_time_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
entry->status = sml_u64_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
entry->value_list = sml_sequence_parse(buf, (void *) &sml_value_entry_parse, (void (*)()) &sml_value_entry_free);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
entry->period_signature = sml_signature_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
return entry;
|
||||
|
||||
error:
|
||||
buf->error = 1;
|
||||
sml_prof_obj_period_entry_free(entry);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sml_prof_obj_period_entry_write(sml_prof_obj_period_entry *entry, sml_buffer *buf) {
|
||||
sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 4);
|
||||
sml_time_write(entry->val_time, buf);
|
||||
sml_u64_write(entry->status, buf);
|
||||
sml_sequence_write(entry->value_list, buf, (void (*)(void *, sml_buffer *)) &sml_value_entry_write);
|
||||
sml_signature_write(entry->period_signature, buf);
|
||||
}
|
||||
|
||||
void sml_prof_obj_period_entry_free(sml_prof_obj_period_entry *entry) {
|
||||
if (entry) {
|
||||
sml_time_free(entry->val_time);
|
||||
sml_number_free(entry->status);
|
||||
sml_sequence_free(entry->value_list);
|
||||
sml_signature_free(entry->period_signature);
|
||||
|
||||
free(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// sml_value_entry;
|
||||
|
||||
sml_value_entry *sml_value_entry_init() {
|
||||
sml_value_entry *entry = (sml_value_entry *) malloc(sizeof(sml_value_entry));
|
||||
memset(entry, 0, sizeof(sml_value_entry));
|
||||
return entry;
|
||||
}
|
||||
|
||||
sml_value_entry *sml_value_entry_parse(sml_buffer *buf) {
|
||||
sml_value_entry *entry = sml_value_entry_init();
|
||||
|
||||
if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) {
|
||||
buf->error = 1;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (sml_buf_get_next_length(buf) != 2) {
|
||||
buf->error = 1;
|
||||
goto error;
|
||||
}
|
||||
|
||||
entry->value = sml_value_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
entry->value_signature = sml_signature_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
return entry;
|
||||
error:
|
||||
buf->error = 1;
|
||||
sml_value_entry_free(entry);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sml_value_entry_write(sml_value_entry *entry, sml_buffer *buf) {
|
||||
sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 2);
|
||||
sml_value_write(entry->value, buf);
|
||||
sml_signature_write(entry->value_signature, buf);
|
||||
}
|
||||
|
||||
void sml_value_entry_free(sml_value_entry *entry) {
|
||||
if (entry) {
|
||||
sml_value_free(entry->value);
|
||||
sml_signature_free(entry->value_signature);
|
||||
|
||||
free(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -25,23 +25,82 @@
|
|||
#include <sml/sml_value.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void sml_list_entry_free(sml_list *list) ;
|
||||
sml_list *sml_list_entry_parse(sml_buffer *buf);
|
||||
void sml_list_entry_write(sml_list *list, sml_buffer *buf);
|
||||
sml_sequence *sml_sequence_init(void (*elem_free) (void *elem)) {
|
||||
sml_sequence *seq = (sml_sequence *) malloc(sizeof(sml_sequence));
|
||||
memset(seq, 0, sizeof(sml_sequence));
|
||||
seq->elem_free = elem_free;
|
||||
return seq;
|
||||
}
|
||||
|
||||
sml_sequence *sml_sequence_parse(sml_buffer *buf,
|
||||
void *(*elem_parse) (sml_buffer *buf),
|
||||
void (*elem_free) (void *elem)) {
|
||||
|
||||
if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) {
|
||||
buf->error = 1;
|
||||
goto error;
|
||||
}
|
||||
|
||||
sml_sequence *seq = sml_sequence_init(elem_free);
|
||||
int i, len = sml_buf_get_next_length(buf);
|
||||
void *p;
|
||||
for (i = 0; i < len; i++) {
|
||||
p = elem_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
sml_sequence_add(seq, p);
|
||||
}
|
||||
return seq;
|
||||
|
||||
error:
|
||||
buf->error = 1;
|
||||
sml_sequence_free(seq);
|
||||
return 0;
|
||||
}
|
||||
void sml_sequence_write(sml_sequence *seq, sml_buffer *buf, void (*elem_write) (void *elem, sml_buffer *buf)) {
|
||||
if (seq == 0) {
|
||||
sml_buf_optional_write(buf);
|
||||
return;
|
||||
}
|
||||
|
||||
sml_buf_set_type_and_length(buf, SML_TYPE_LIST, seq->elems_len);
|
||||
|
||||
int i;
|
||||
for (i = 0; i < seq->elems_len; i++) {
|
||||
elem_write((seq->elems)[i], buf);
|
||||
}
|
||||
}
|
||||
|
||||
void sml_sequence_free(sml_sequence *seq) {
|
||||
if (seq) {
|
||||
|
||||
int i;
|
||||
for (i = 0; i < seq->elems_len; i++) {
|
||||
seq->elem_free((seq->elems)[i]);
|
||||
}
|
||||
if (seq->elems != 0) {
|
||||
free(seq->elems);
|
||||
}
|
||||
free(seq);
|
||||
}
|
||||
}
|
||||
|
||||
void sml_sequence_add(sml_sequence *seq, void *new_entry) {
|
||||
seq->elems_len++;
|
||||
seq->elems = (void **) realloc(seq->elems, sizeof(void *) * seq->elems_len);
|
||||
seq->elems[seq->elems_len - 1] = new_entry;
|
||||
}
|
||||
|
||||
|
||||
sml_list *sml_list_init(){
|
||||
sml_list *s = (sml_list *)malloc(sizeof(sml_list));
|
||||
memset(s, 0, sizeof(sml_list));
|
||||
|
||||
return s;
|
||||
return s;
|
||||
}
|
||||
|
||||
void sml_list_add(sml_list *list, sml_list *new_entry) {
|
||||
list->next = new_entry;
|
||||
}
|
||||
|
||||
// This function doesn't free the allocated memory in error cases,
|
||||
// this is done in sml_list_parse.
|
||||
sml_list *sml_list_entry_parse(sml_buffer *buf) {
|
||||
if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) {
|
||||
buf->error = 1;
|
||||
|
@ -56,19 +115,19 @@ sml_list *sml_list_entry_parse(sml_buffer *buf) {
|
|||
|
||||
l->obj_name = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
|
||||
l->status = sml_status_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
|
||||
l->val_time = sml_time_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
l->unit = sml_u8_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
|
||||
l->scaler = sml_i8_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
|
||||
l->value = sml_value_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
|
@ -77,10 +136,11 @@ sml_list *sml_list_entry_parse(sml_buffer *buf) {
|
|||
|
||||
return l;
|
||||
|
||||
error:
|
||||
printf("error\n");
|
||||
buf->error = 1;
|
||||
return 0;
|
||||
error:
|
||||
// This function doesn't free the allocated memory in error cases,
|
||||
// this is done in sml_list_parse.
|
||||
buf->error = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
sml_list *sml_list_parse(sml_buffer *buf) {
|
||||
|
@ -121,6 +181,7 @@ error:
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void sml_list_entry_write(sml_list *list, sml_buffer *buf) {
|
||||
sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 7);
|
||||
sml_octet_string_write(list->obj_name, buf);
|
||||
|
|
|
@ -121,31 +121,52 @@ sml_message_body *sml_message_body_parse(sml_buffer *buf) {
|
|||
|
||||
msg_body->tag = sml_u16_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
|
||||
switch (*(msg_body->tag)) {
|
||||
case SML_MESSAGE_OPEN_REQUEST:
|
||||
msg_body->data = sml_open_request_parse(buf);
|
||||
break;
|
||||
case SML_MESSAGE_OPEN_RESPONSE:
|
||||
case SML_MESSAGE_OPEN_REQUEST:
|
||||
msg_body->data = sml_open_request_parse(buf);
|
||||
break;
|
||||
case SML_MESSAGE_OPEN_RESPONSE:
|
||||
msg_body->data = sml_open_response_parse(buf);
|
||||
break;
|
||||
case SML_MESSAGE_CLOSE_REQUEST:
|
||||
msg_body->data = sml_close_request_parse(buf);
|
||||
break;
|
||||
case SML_MESSAGE_CLOSE_RESPONSE:
|
||||
msg_body->data = sml_close_response_parse(buf);
|
||||
break;
|
||||
case SML_MESSAGE_GET_LIST_RESPONSE:
|
||||
msg_body->data = sml_get_list_response_parse(buf);
|
||||
case SML_MESSAGE_CLOSE_REQUEST:
|
||||
msg_body->data = sml_close_request_parse(buf);
|
||||
break;
|
||||
case SML_MESSAGE_CLOSE_RESPONSE:
|
||||
msg_body->data = sml_close_response_parse(buf);
|
||||
break;
|
||||
case SML_MESSAGE_GET_PROFILE_PACK_REQUEST:
|
||||
msg_body->data = sml_get_profile_pack_request_parse(buf);
|
||||
break;
|
||||
case SML_MESSAGE_GET_PROFILE_PACK_RESPONSE:
|
||||
msg_body->data = sml_get_profile_pack_response_parse(buf);
|
||||
break;
|
||||
case SML_MESSAGE_GET_PROFILE_LIST_REQUEST:
|
||||
msg_body->data = sml_get_profile_list_request_parse(buf);
|
||||
break;
|
||||
case SML_MESSAGE_GET_PROFILE_LIST_RESPONSE:
|
||||
msg_body->data = sml_get_profile_list_response_parse(buf);
|
||||
break;
|
||||
case SML_MESSAGE_GET_PROC_PARAMETER_REQUEST:
|
||||
msg_body->data = sml_get_proc_parameter_request_parse(buf);
|
||||
break;
|
||||
case SML_MESSAGE_GET_PROC_PARAMETER_RESPONSE:
|
||||
msg_body->data = sml_get_proc_parameter_response_parse(buf);
|
||||
break;
|
||||
case SML_MESSAGE_SET_PROC_PARAMETER_REQUEST:
|
||||
msg_body->data = sml_set_proc_parameter_request_parse(buf);
|
||||
break;
|
||||
case SML_MESSAGE_GET_LIST_REQUEST:
|
||||
msg_body->data = sml_get_list_request_parse(buf);
|
||||
break;
|
||||
case SML_MESSAGE_GET_LIST_RESPONSE:
|
||||
msg_body->data = sml_get_list_response_parse(buf);
|
||||
break;
|
||||
case SML_MESSAGE_ATTENTION_RESPONSE:
|
||||
msg_body->data = sml_attention_response_parse(buf);
|
||||
break;
|
||||
default:
|
||||
printf("error: message type %04X not yet implemented\n", *(msg_body->tag));
|
||||
default:
|
||||
printf("error: message type %04X not yet implemented\n", *(msg_body->tag));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -165,66 +186,111 @@ sml_message_body *sml_message_body_init(u16 tag, void *data) {
|
|||
}
|
||||
|
||||
void sml_message_body_write(sml_message_body *message_body, sml_buffer *buf) {
|
||||
sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 2);
|
||||
sml_u16_write(message_body->tag, buf);
|
||||
|
||||
switch (*(message_body->tag)) {
|
||||
case SML_MESSAGE_OPEN_REQUEST:
|
||||
sml_open_request_write((sml_open_request *) message_body->data, buf);
|
||||
sml_buf_set_type_and_length(buf, SML_TYPE_LIST, 2);
|
||||
sml_u16_write(message_body->tag, buf);
|
||||
|
||||
switch (*(message_body->tag)) {
|
||||
case SML_MESSAGE_OPEN_REQUEST:
|
||||
sml_open_request_write((sml_open_request *) message_body->data, buf);
|
||||
break;
|
||||
case SML_MESSAGE_OPEN_RESPONSE:
|
||||
sml_open_response_write((sml_open_response *) message_body->data, buf);
|
||||
break;
|
||||
case SML_MESSAGE_CLOSE_REQUEST:
|
||||
sml_close_request_write((sml_close_request *) message_body->data, buf);
|
||||
break;
|
||||
case SML_MESSAGE_CLOSE_RESPONSE:
|
||||
sml_close_response_write((sml_close_response *) message_body->data, buf);
|
||||
break;
|
||||
case SML_MESSAGE_GET_PROFILE_PACK_REQUEST:
|
||||
sml_get_profile_pack_request_write((sml_get_profile_pack_request *) message_body->data, buf);
|
||||
break;
|
||||
case SML_MESSAGE_GET_PROFILE_PACK_RESPONSE:
|
||||
sml_get_profile_pack_response_write((sml_get_profile_pack_response *) message_body->data, buf);
|
||||
break;
|
||||
case SML_MESSAGE_GET_PROFILE_LIST_REQUEST:
|
||||
sml_get_profile_list_request_write((sml_get_profile_list_request *) message_body->data, buf);
|
||||
break;
|
||||
case SML_MESSAGE_GET_PROFILE_LIST_RESPONSE:
|
||||
sml_get_profile_list_response_write((sml_get_profile_list_response *) message_body->data, buf);
|
||||
break;
|
||||
case SML_MESSAGE_GET_PROC_PARAMETER_REQUEST:
|
||||
sml_get_proc_parameter_request_write((sml_get_proc_parameter_request *) message_body->data, buf);
|
||||
break;
|
||||
case SML_MESSAGE_GET_PROC_PARAMETER_RESPONSE:
|
||||
sml_get_proc_parameter_response_write((sml_get_proc_parameter_response *) message_body->data, buf);
|
||||
break;
|
||||
case SML_MESSAGE_SET_PROC_PARAMETER_REQUEST:
|
||||
sml_set_proc_parameter_request_write((sml_set_proc_parameter_request *) message_body->data, buf);
|
||||
break;
|
||||
case SML_MESSAGE_GET_LIST_REQUEST:
|
||||
sml_get_list_request_write((sml_get_list_request *)message_body->data, buf);
|
||||
break;
|
||||
case SML_MESSAGE_GET_LIST_RESPONSE:
|
||||
sml_get_list_response_write((sml_get_list_response *) message_body->data, buf);
|
||||
break;
|
||||
case SML_MESSAGE_ATTENTION_RESPONSE:
|
||||
sml_attention_response_write((sml_attention_response *) message_body->data, buf);
|
||||
break;
|
||||
case SML_MESSAGE_CLOSE_REQUEST:
|
||||
sml_close_request_write((sml_close_request *) message_body->data, buf);
|
||||
break;
|
||||
case SML_MESSAGE_SET_PROC_PARAMETER_REQUEST:
|
||||
sml_set_proc_parameter_request_write((sml_set_proc_parameter_request *) message_body->data, buf);
|
||||
break;
|
||||
case SML_MESSAGE_GET_PROC_PARAMETER_REQUEST:
|
||||
sml_get_proc_parameter_request_write((sml_get_proc_parameter_request *) message_body->data, buf);
|
||||
break;
|
||||
case SML_MESSAGE_GET_LIST_REQUEST:
|
||||
sml_get_list_request_write((sml_get_list_request *)message_body->data, buf);
|
||||
break;
|
||||
case SML_MESSAGE_GET_PROFILE_PACK_REQUEST:
|
||||
sml_get_profile_pack_request_write((sml_get_profile_pack_request *)message_body->data, buf);
|
||||
break;
|
||||
default:
|
||||
printf("error: message type %04X not yet implemented\n", *(message_body->tag));
|
||||
printf("error: message type %04X not yet implemented\n", *(message_body->tag));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void sml_message_body_free(sml_message_body *message_body) {
|
||||
if (message_body) {
|
||||
switch (*(message_body->tag)) {
|
||||
case SML_MESSAGE_OPEN_REQUEST:
|
||||
sml_open_request_free((sml_open_request *) message_body->data);
|
||||
break;
|
||||
case SML_MESSAGE_OPEN_RESPONSE:
|
||||
sml_open_response_free((sml_open_response *) message_body->data);
|
||||
break;
|
||||
case SML_MESSAGE_CLOSE_REQUEST:
|
||||
sml_close_request_free((sml_close_request *) message_body->data);
|
||||
break;
|
||||
case SML_MESSAGE_CLOSE_RESPONSE:
|
||||
sml_close_response_free((sml_close_response *) message_body->data);
|
||||
break;
|
||||
case SML_MESSAGE_SET_PROC_PARAMETER_REQUEST:
|
||||
sml_set_proc_parameter_request_free((sml_set_proc_parameter_request *) message_body->data);
|
||||
break;
|
||||
case SML_MESSAGE_GET_LIST_REQUEST:
|
||||
sml_get_list_request_free((sml_get_list_request *) message_body->data);
|
||||
break;
|
||||
case SML_MESSAGE_GET_LIST_RESPONSE:
|
||||
sml_get_list_response_free((sml_get_list_response *) message_body->data);
|
||||
break;
|
||||
default:
|
||||
printf("NYI: %s for message type %04X\n", __FUNCTION__, *(message_body->tag));
|
||||
break;
|
||||
}
|
||||
|
||||
sml_number_free(message_body->tag);
|
||||
|
||||
free(message_body);
|
||||
}
|
||||
if (message_body) {
|
||||
sml_number_free(message_body->tag);
|
||||
|
||||
switch (*(message_body->tag)) {
|
||||
case SML_MESSAGE_OPEN_REQUEST:
|
||||
sml_open_request_free((sml_open_request *) message_body->data);
|
||||
break;
|
||||
case SML_MESSAGE_OPEN_RESPONSE:
|
||||
sml_open_response_free((sml_open_response *) message_body->data);
|
||||
break;
|
||||
case SML_MESSAGE_CLOSE_REQUEST:
|
||||
sml_close_request_free((sml_close_request *) message_body->data);
|
||||
break;
|
||||
case SML_MESSAGE_CLOSE_RESPONSE:
|
||||
sml_close_response_free((sml_close_response *) message_body->data);
|
||||
break;
|
||||
case SML_MESSAGE_GET_PROFILE_PACK_REQUEST:
|
||||
sml_get_profile_pack_request_free((sml_get_profile_pack_request *) message_body->data);
|
||||
break;
|
||||
case SML_MESSAGE_GET_PROFILE_PACK_RESPONSE:
|
||||
sml_get_profile_pack_response_free((sml_get_profile_pack_response *) message_body->data);
|
||||
break;
|
||||
case SML_MESSAGE_GET_PROFILE_LIST_REQUEST:
|
||||
sml_get_profile_list_request_free((sml_get_profile_list_request *) message_body->data);
|
||||
break;
|
||||
case SML_MESSAGE_GET_PROFILE_LIST_RESPONSE:
|
||||
sml_get_profile_list_response_free((sml_get_profile_list_response *) message_body->data);
|
||||
break;
|
||||
case SML_MESSAGE_GET_PROC_PARAMETER_REQUEST:
|
||||
sml_get_proc_parameter_request_free((sml_get_proc_parameter_request *) message_body->data);
|
||||
break;
|
||||
case SML_MESSAGE_GET_PROC_PARAMETER_RESPONSE:
|
||||
sml_get_proc_parameter_response_free((sml_get_proc_parameter_response *) message_body->data);
|
||||
break;
|
||||
case SML_MESSAGE_SET_PROC_PARAMETER_REQUEST:
|
||||
sml_set_proc_parameter_request_free((sml_set_proc_parameter_request *) message_body->data);
|
||||
break;
|
||||
case SML_MESSAGE_GET_LIST_REQUEST:
|
||||
sml_get_list_request_free((sml_get_list_request *) message_body->data);
|
||||
break;
|
||||
case SML_MESSAGE_GET_LIST_RESPONSE:
|
||||
sml_get_list_response_free((sml_get_list_response *) message_body->data);
|
||||
break;
|
||||
case SML_MESSAGE_ATTENTION_RESPONSE:
|
||||
sml_attention_response_free((sml_attention_response *) message_body->data);
|
||||
break;
|
||||
default:
|
||||
printf("NYI: %s for message type %04X\n", __FUNCTION__, *(message_body->tag));
|
||||
break;
|
||||
}
|
||||
|
||||
free(message_body);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,12 +40,16 @@ sml_set_proc_parameter_request *sml_set_proc_parameter_request_parse(sml_buffer
|
|||
|
||||
msg->server_id = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->username = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->password = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->parameter_tree_path = sml_tree_path_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
msg->parameter_tree = sml_tree_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
|
|
|
@ -123,7 +123,10 @@ sml_tree *sml_tree_parse(sml_buffer *buf){
|
|||
}
|
||||
|
||||
tree->parameter_name = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
tree->parameter_value = sml_proc_par_value_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
if (!sml_buf_optional_is_skipped(buf)) {
|
||||
if (sml_buf_get_next_type(buf) != SML_TYPE_LIST) {
|
||||
|
@ -334,37 +337,58 @@ sml_tupel_entry *sml_tupel_entry_parse(sml_buffer *buf) {
|
|||
}
|
||||
|
||||
tupel->server_id = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
tupel->sec_index = sml_time_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
tupel->status = sml_u64_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
tupel->unit_pA = sml_unit_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
tupel->scaler_pA = sml_i8_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
tupel->value_pA = sml_i64_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
tupel->unit_R1 = sml_unit_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
tupel->scaler_R1 = sml_i8_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
tupel->value_R1 = sml_i64_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
tupel->unit_R4 = sml_unit_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
tupel->scaler_R4 = sml_i8_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
tupel->value_R4 = sml_i64_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
tupel->signature_pA_R1_R4 = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
tupel->unit_mA = sml_unit_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
tupel->scaler_mA = sml_i8_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
tupel->value_mA = sml_i64_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
tupel->unit_R2 = sml_unit_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
tupel->scaler_R2 = sml_i8_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
tupel->value_R2 = sml_i64_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
tupel->unit_R3 = sml_unit_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
tupel->scaler_R3 = sml_i8_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
tupel->value_R3 = sml_i64_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
tupel->signature_mA_R2_R3 = sml_octet_string_parse(buf);
|
||||
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
return tupel;
|
||||
|
@ -455,6 +479,7 @@ void sml_tupel_entry_free(sml_tupel_entry *tupel) {
|
|||
}
|
||||
|
||||
|
||||
|
||||
// SML_PERIOD_ENTRY
|
||||
|
||||
sml_period_entry *sml_period_entry_init() {
|
||||
|
@ -481,11 +506,18 @@ sml_period_entry *sml_period_entry_parse(sml_buffer *buf) {
|
|||
}
|
||||
|
||||
period->obj_name = sml_octet_string_parse(buf);
|
||||
period->unit = sml_unit_parse(buf);
|
||||
period->scaler = sml_i8_parse(buf);
|
||||
period->value = sml_value_parse(buf);
|
||||
period->value_signature = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
period->unit = sml_unit_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
period->scaler = sml_i8_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
period->value = sml_value_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
period->value_signature = sml_octet_string_parse(buf);
|
||||
if (sml_buf_has_errors(buf)) goto error;
|
||||
|
||||
return period;
|
||||
|
|
|
@ -88,3 +88,57 @@ TEST_GROUP_RUNNER(sml_list) {
|
|||
RUN_TEST_CASE(sml_list, write_one_entry);
|
||||
RUN_TEST_CASE(sml_list, write_optional);
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST_GROUP(sml_sequence);
|
||||
|
||||
sml_buffer *buf;
|
||||
|
||||
TEST_SETUP(sml_sequence) {
|
||||
buf = sml_buffer_init(512);
|
||||
}
|
||||
|
||||
TEST_TEAR_DOWN(sml_sequence) {
|
||||
sml_buffer_free(buf);
|
||||
}
|
||||
|
||||
TEST(sml_sequence, init) {
|
||||
sml_sequence *seq = sml_sequence_init(&free);
|
||||
TEST_ASSERT_NOT_NULL(seq);
|
||||
}
|
||||
|
||||
TEST(sml_sequence, parse_octet_string) {
|
||||
hex2binary("720648616C6C6F0648616C6C6F", sml_buf_get_current_buf(buf));
|
||||
|
||||
sml_sequence *seq = sml_sequence_parse(buf, (void *) &sml_octet_string_parse, (void (*)(void *))&sml_octet_string_free);
|
||||
TEST_ASSERT_NOT_NULL(seq);
|
||||
TEST_ASSERT_EQUAL(2, seq->elems_len);
|
||||
}
|
||||
|
||||
TEST(sml_sequence, write_octet_string) {
|
||||
sml_sequence *seq = sml_sequence_init((void (*)(void *))&sml_octet_string_free);
|
||||
sml_sequence_add(seq, sml_octet_string_init((unsigned char *)"Hallo", 5));
|
||||
sml_sequence_add(seq, sml_octet_string_init((unsigned char *)"Hallo", 5));
|
||||
|
||||
sml_sequence_write(seq, buf, (void (*)(void *, sml_buffer *))&sml_octet_string_write);
|
||||
expected_buf(buf, "720648616C6C6F0648616C6C6F", 13);
|
||||
}
|
||||
|
||||
TEST(sml_sequence, free_octet_string) {
|
||||
sml_sequence *seq = sml_sequence_init((void (*)(void *))&sml_octet_string_free);
|
||||
sml_sequence_add(seq, sml_octet_string_init((unsigned char *)"Hallo", 5));
|
||||
sml_sequence_free(seq);
|
||||
}
|
||||
|
||||
TEST_GROUP_RUNNER(sml_sequence) {
|
||||
RUN_TEST_CASE(sml_sequence, init);
|
||||
RUN_TEST_CASE(sml_sequence, parse_octet_string);
|
||||
RUN_TEST_CASE(sml_sequence, write_octet_string);
|
||||
RUN_TEST_CASE(sml_sequence, free_octet_string);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ static void runAllTests() {
|
|||
RUN_TEST_GROUP(sml_value);
|
||||
RUN_TEST_GROUP(sml_status);
|
||||
RUN_TEST_GROUP(sml_list);
|
||||
RUN_TEST_GROUP(sml_sequence);
|
||||
RUN_TEST_GROUP(sml_time);
|
||||
RUN_TEST_GROUP(sml_tree);
|
||||
RUN_TEST_GROUP(sml_tree_path);
|
||||
|
|
Loading…
Add table
Reference in a new issue