コード例 #1
0
ファイル: sml_transport.c プロジェクト: DerArtem/libsml
void sml_transport_listen(int fd, void (*sml_transport_receiver)(unsigned char *buffer, size_t buffer_len)) {
	unsigned char buffer[MC_SML_BUFFER_LEN];
	size_t bytes;

	while (1) {
		bytes = sml_transport_read(fd, buffer, MC_SML_BUFFER_LEN);

		if (bytes > 0) {
			sml_transport_receiver(buffer, bytes);
		}
	}
}
コード例 #2
0
ファイル: sml.c プロジェクト: meisel2000/vzlogger
size_t meter_read_sml(meter_t *meter, reading_t rds[], size_t n) {
	meter_handle_sml_t *handle = &meter->handle.sml;

 	unsigned char buffer[SML_BUFFER_LEN];
	size_t bytes, m = 0;

	sml_file *file;
	sml_get_list_response *body;
	sml_list *entry;

	/* blocking read from fd */
	bytes = sml_transport_read(handle->fd, buffer, SML_BUFFER_LEN);

	/* parse SML file & stripping escape sequences */
	file = sml_file_parse(buffer + 8, bytes - 16);

	/* obtain SML messagebody of type getResponseList */
	for (short i = 0; i < file->messages_len; i++) {
		sml_message *message = file->messages[i];

		if (*message->message_body->tag == SML_MESSAGE_GET_LIST_RESPONSE) {
			body = (sml_get_list_response *) message->message_body->data;
			entry = body->val_list;

			/* iterating through linked list */
			for (m = 0; m < n && entry != NULL; m++) {
				meter_sml_parse(entry, &rds[m]);
				entry = entry->next;
			}
		}
	}

	/* free the malloc'd memory */
	sml_file_free(file);

	return m+1;
}
コード例 #3
0
ファイル: MeterSML.cpp プロジェクト: mysmartgrid/vzlogger
ssize_t MeterSML::read(std::vector<Reading> &rds, size_t n) {

	unsigned char buffer[SML_BUFFER_LEN];
	size_t bytes, m = 0;

	sml_file *file;
	sml_get_list_response *body;
	sml_list *entry;

	/* wait until a we receive a new datagram from the meter (blocking read) */
	bytes = sml_transport_read(_fd, buffer, SML_BUFFER_LEN);

	/* parse SML file & stripping escape sequences */
	file = sml_file_parse(buffer + 8, bytes - 16);

	/* obtain SML messagebody of type getResponseList */
	for (short i = 0; i < file->messages_len; i++) {
		sml_message *message = file->messages[i];

		if (*message->message_body->tag == SML_MESSAGE_GET_LIST_RESPONSE) {
			body = (sml_get_list_response *) message->message_body->data;
			entry = body->val_list;

			/* iterating through linked list */
			for (m = 0; m < n && entry != NULL; m++) {
				_parse(entry, &rds[m]);
				entry = entry->next;
			}
		}
	}

	/* free the malloc'd memory */
	sml_file_free(file);

	return m+1;
}