Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00060 #ifndef __MBUS_PROTOCOL_AUX_H__
00061 #define __MBUS_PROTOCOL_AUX_H__
00062
00063 #include <mbus/mbus.h>
00064 #include <mbus/mbus-protocol.h>
00065 #include <mbus/mbus-serial.h>
00066 #include <mbus/mbus-tcp.h>
00067
00068 #define MBUS_PROBE_NOTHING 0
00069 #define MBUS_PROBE_SINGLE 1
00070 #define MBUS_PROBE_COLLISION 2
00071 #define MBUS_PROBE_ERROR -1
00072
00073
00077 typedef struct _mbus_handle {
00078 char is_serial;
00079 union {
00080 mbus_tcp_handle * m_tcp_handle;
00081 mbus_serial_handle * m_serial_handle;
00082 };
00083 } mbus_handle;
00084
00085
00089 typedef struct _mbus_address {
00090 char is_primary;
00091 union {
00092 int primary;
00093 char * secondary;
00094 };
00095 } mbus_address;
00096
00097
00104 typedef struct _mbus_string {
00105 char * value;
00106 int size;
00107 } mbus_string;
00108
00109
00113 typedef union _mbus_value {
00114 double real_val;
00115 mbus_string str_val;
00116 } mbus_value;
00117
00118
00122 typedef struct _mbus_record {
00123 mbus_value value;
00124 char is_numeric;
00125 char *unit;
00126 char *function_medium;
00127 char *quantity;
00128 } mbus_record;
00129
00130
00138 mbus_handle * mbus_connect_serial(const char * device);
00139
00148 mbus_handle * mbus_connect_tcp(const char *host, int port);
00149
00157 int mbus_disconnect(mbus_handle * handle);
00158
00167 int mbus_recv_frame(mbus_handle * handle, mbus_frame *frame);
00168
00177 int mbus_send_frame(mbus_handle * handle, mbus_frame *frame);
00178
00187 int mbus_send_select_frame(mbus_handle * handle, const char *secondary_addr_str);
00188
00197 int mbus_send_data_request_frame(mbus_handle * handle, int address);
00198
00208 int mbus_probe_secondary_address(mbus_handle * handle, const char *mask, char *matching_addr);
00209
00219 int mbus_read_slave(mbus_handle *handle, mbus_address *address, mbus_frame *reply);
00220
00221
00227 mbus_record * mbus_record_new();
00228
00234 void mbus_record_free(mbus_record *rec);
00235
00236
00246 mbus_record *mbus_parse_fixed_record(char statusByte, char medium_unit_byte, u_char *data);
00247
00248
00256 mbus_record * mbus_parse_variable_record(mbus_data_record *record);
00257
00258
00259
00273 int mbus_data_fixed_normalize(int medium_unit_byte, long medium_value, char **unit_out, double *value_out, char **quantity_out);
00274
00275
00276
00287 int mbus_data_variable_value_decode(mbus_record *record, double *value_out_real, char **value_out_str, int *value_out_str_size);
00288
00300 int mbus_vif_unit_normalize(int vif, double value, char **unit_out, double *value_out, char **quantity_out);
00301
00313 int mbus_vib_unit_normalize(mbus_value_information_block *vib, double value, char **unit_out, double *value_out, char ** quantity_out);
00314
00324 int mbus_scan_2nd_address_range(mbus_handle * handle, int pos, char *addr_mask);
00325
00326 #endif // __MBUS_PROTOCOL_AUX_H__