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 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); }
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; }
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; }