00001
00002
00003
00009
00010
00011
00012
00013 #ifndef OWWL_H
00014 #define OWWL_H 1
00015
00016 #include <time.h>
00017
00018 #ifndef SOCKET
00019 #define SOCKET int
00020 #endif
00021
00022
00025 #define OWW_PROTO_VERSION 101L
00039 enum owwl_unit_class_enum {
00040 owwl_unit_class_unknown = -1,
00041 owwl_unit_class_dimensionless = 0,
00042 owwl_unit_class_time,
00043 owwl_unit_class_count,
00044 owwl_unit_class_count_rate,
00045 owwl_unit_class_length,
00046 owwl_unit_class_length_rate,
00047 owwl_unit_class_speed,
00048 owwl_unit_class_temperature,
00049 owwl_unit_class_pressure,
00050 owwl_unit_class_direction,
00051 owwl_unit_class_humidity,
00052 owwl_unit_class_voltage,
00053 owwl_unit_class_muvoltage,
00054 owwl_unit_class_nanocurrent,
00055 owwl_unit_class_cryo,
00056 owwl_unit_class_resistance,
00057 OWWL_UNIT_CLASS_LIMIT
00058 } ;
00064
00065
00078 #define OwwlUnit_Metric 0
00079 #define OwwlUnit_Imperial 1
00081 #define OwwlUnit_Alt1 2
00082 #define OwwlUnit_Alt2 3
00091 #define OwwlUnit_Celcius OwwlUnit_Metric
00092 #define OwwlUnit_Fahrenheit OwwlUnit_Imperial
00093 #define OwwlUnit_Kelvin OwwlUnit_Alt1
00094 #define OwwlUnit_Rankine OwwlUnit_Alt2
00095
00103 #define OwwlUnit_CryoKelvin OwwlUnit_Metric
00104 #define OwwlUnit_CryoRankine OwwlUnit_Imperial
00105 #define OwwlUnit_CryoCelcius OwwlUnit_Alt1
00106 #define OwwlUnit_CryoFahrenheit OwwlUnit_Alt2
00107
00115 #define OwwlUnit_Mm OwwlUnit_Metric
00116 #define OwwlUnit_Inch OwwlUnit_Imperial
00125 #define OwwlUnit_Kph OwwlUnit_Metric
00126 #define OwwlUnit_Mph OwwlUnit_Imperial
00127 #define OwwlUnit_Mps OwwlUnit_Alt1
00128 #define OwwlUnit_Knot OwwlUnit_Alt2
00137 #define OwwlUnit_Mbar OwwlUnit_Metric
00138 #define OwwlUnit_InchHg OwwlUnit_Imperial
00139 #define OwwlUnit_Kpa OwwlUnit_Alt1
00140 #define OwwlUnit_Atm OwwlUnit_Alt2
00149 #define OwwlUnit_Bearing OwwlUnit_Metric
00150 #define OwwlUnit_Point16 OwwlUnit_Imperial
00151 #define OwwlUnit_Name OwwlUnit_Alt1
00152 #define OwwlUnit_Radians OwwlUnit_Alt2
00182 enum owwl_device_type_enum {
00183 OwwlDev_Any = -1,
00184 OwwlDev_Temperature = 0,
00185 OwwlDev_Barometer,
00186 OwwlDev_Humidity,
00187 OwwlDev_Wind,
00188 OwwlDev_Rain,
00189 OwwlDev_Gpc,
00190 OwwlDev_Solar,
00191 OwwlDev_Psb = 64,
00192 OwwlDev_Diode,
00193 OwwlDev_Grt,
00194 OwwlDev_Cryo,
00195 OwwlDev_Heater,
00196 OwwlDev_Resistance,
00197 OwwlDev_Invalid
00198 } ;
00199
00204 #define OwwlSubtype_Any -1
00205 #define OwwlSubtype_Default 0
00213 enum owwl_temperature_subtype_enum {
00214 OwwlTemp_Any = OwwlSubtype_Any,
00215 OwwlTemp_Thermometer = OwwlSubtype_Default,
00216 OwwlTemp_Humidity,
00217 OwwlTemp_Barometer
00218 } ;
00225 typedef struct {
00226 float T ;
00227 float padding[9] ;
00228 } owwl_data_temperature ;
00229
00234 typedef struct {
00235 float bp ;
00236 float padding[9] ;
00237 } owwl_data_barometer ;
00238
00243 typedef struct {
00244 float RH ;
00245 float padding[9];
00246 } owwl_data_humidity ;
00247
00252 typedef struct {
00253 float solar ;
00254 float padding[9];
00255 } owwl_data_solar ;
00256
00261 typedef struct {
00262 float speed ;
00263 float gust ;
00264 float bearing ;
00265 float padding[7] ;
00266 } owwl_data_wind ;
00267
00272 typedef struct {
00273 unsigned int rain_count ;
00274 time_t rain_reset_time ;
00275 float rain_since_reset ;
00276 float rain_rate ;
00277 float padding[6] ;
00278 } owwl_data_rain ;
00279
00284 typedef struct {
00285 unsigned int gpc_count ;
00286 time_t gpc_reset_time ;
00287 float gpc_calibrated ;
00288 float gpc_rate ;
00289 float gpc_delta ;
00290 float padding[5] ;
00291 } owwl_data_gpc ;
00292
00297 typedef struct {
00298 int psb_a ;
00299 int psb_b ;
00300 float padding[8] ;
00301 } owwl_data_psb ;
00302
00307 typedef struct {
00308 float V ;
00309 float padding[9] ;
00310 } owwl_data_diode ;
00311
00316 typedef struct {
00317 float V ;
00318 float Vq ;
00319 float I ;
00320 float padding[7] ;
00321 } owwl_data_grt ;
00322
00327 typedef struct {
00328 float T ;
00329 float padding[9] ;
00330 } owwl_data_cryo ;
00331
00336 typedef struct {
00337 float V ;
00338 float padding[9] ;
00339 } owwl_data_heater ;
00340
00345 typedef struct {
00346 float R ;
00347 float padding[9] ;
00348 } owwl_data_resistance ;
00349
00356 enum owwl_cryo_subtype_enum {
00357 OwwlCryo_Any = OwwlSubtype_Any,
00358 OwwlCryo_Thermometer = OwwlSubtype_Default,
00359 OwwlCryo_Diode,
00360 OwwlCryo_Grt
00361 } ;
00368 typedef struct {
00369 float floats[10] ;
00370 } owwl_data_floats ;
00377 typedef union {
00378 owwl_data_temperature temperature ;
00379 owwl_data_humidity humidity ;
00380 owwl_data_wind wind ;
00381 owwl_data_rain rain ;
00382 owwl_data_gpc gpc ;
00383 owwl_data_barometer barom ;
00384 owwl_data_solar solar ;
00385 owwl_data_psb psb ;
00386 owwl_data_diode diode ;
00387 owwl_data_grt grt ;
00388 owwl_data_cryo cryo ;
00389 owwl_data_heater heater ;
00390 owwl_data_resistance resistance ;
00391 owwl_data_floats floats ;
00392 } device_data_union ;
00393
00402 typedef struct owwl_data_ {
00403 int device_type ;
00404 device_data_union device_data ;
00405 int device_subtype ;
00407 int index ;
00408 int in_use ;
00409 void *user_data ;
00411 char * (*str)(struct owwl_data_ *self, char *buffer, int bufflen, int unit_type, int precision, int arg) ;
00413 double (*val)(struct owwl_data_ *self, int unit_type, int arg) ;
00414
00415
00416 } owwl_data ;
00435 typedef struct owwl_client_ {
00436 struct owwl_client_ *prev ;
00437 struct owwl_client_ *next ;
00438 SOCKET socket ;
00439 } owwl_client ;
00440
00449 typedef struct owwl_server_ {
00450 SOCKET socket_listen ;
00451 owwl_client *first_client ;
00452 } owwl_server ;
00455 struct readstr {
00456 int data_size ;
00457 int data_to_get ;
00458 unsigned long data_word_n[16] ;
00459 int state ;
00460 } ;
00461
00467 typedef struct {
00468 SOCKET socket ;
00469 int read_result ;
00470 time_t data_time ;
00471 long data_time_usec;
00472 int interval ;
00473 float longitude ;
00474 float latitude ;
00475 owwl_data *data ;
00476 int data_count ;
00477 void *user_data ;
00478 owwl_server *server ;
00479 int nserver ;
00480 struct readstr rd ;
00481 } owwl_conn ;
00482
00486 typedef struct {
00487 unsigned long *buffer ;
00488 int next ;
00489 int size ;
00490 } owwl_buffer ;
00491
00492 #define OwwlBuffInc 16
00493 #define Owwl_Buffer_Init {(unsigned long *) NULL, 0, 0}
00494
00497 typedef int (*owwl_func) (owwl_conn *conn, owwl_data *data, void *user_data) ;
00498
00503 enum owwl_read_result {
00504 Owwl_Read_Disconnect = -2,
00505 Owwl_Read_Error = -1,
00506 Owwl_Read_Read_And_Decoded = 0,
00507 Owwl_Read_Again
00508 } ;
00511
00518 #define OWW_TRX_END 0L
00519 #define OWW_TRX_TIME 0x1000000L
00520 #define OWW_TRX_WIND 0x2000000L
00521 #define OWW_TRX_RAIN 0x3000000L
00522 #define OWW_TRX_T 0x4000000L
00523 #define OWW_TRX_RH 0x6000000L
00524 #define OWW_TRX_BP 0x7000000L
00525 #define OWW_TRX_SOLAR 0xb000000L
00526 #define OWW_TRX_PSB 0x10000000L
00527 #define OWW_TRX_DIODE 0x11000000L
00528 #define OWW_TRX_GRT 0x12000000L
00529 #define OWW_TRX_CRYO 0x13000000L
00530 #define OWW_TRX_HEATER 0x14000000L
00531 #define OWW_TRX_RESISTANCE 0x15000000L
00532 #define OWW_TRX_UPDT 0x80000000L
00533 #define OWW_TRX_GPC 0x90000000L
00534 #define OWW_TRX_LOC 0xa0000000L
00535 #define OWW_TRX_HEAD 0xff000000L
00537 #define OWW_TRX_SUB_TRH 0x10000L
00538 #define OWW_TRX_SUB_TB 0x20000L
00540 #define OWW_TRX_SUB_TCD 0x10000L
00541 #define OWW_TRX_SUB_TCG 0x20000L
00543 #define OWW_TRX_SERIAL 0x100L
00545 #define OWW_TRX_SIZE 1L
00552 #define OWW_TRX_MSG_WSDATA 1
00553 #define OWW_TRX_MSG_UPDT 2
00554 #define OWW_TRX_MSG_MORT 3
00555 #define OWW_TRX_MSG_ANNOUN 4
00559
00560
00561
00562 enum owwl_device_types {
00563 dummy = 0
00564 } ;
00565
00566
00567
00568
00569
00576 owwl_conn *
00577 owwl_new_conn(int socket, void *user_data) ;
00578
00588 int
00589 owwl_read(owwl_conn *conn) ;
00590
00592 int
00593 owwl_free(owwl_conn *conn) ;
00594
00601 unsigned int
00602 owwl_data_arg_to_id(owwl_data *data, int arg) ;
00603
00611 void
00612 owwl_id_to_data_arg(owwl_conn *conn, unsigned int id, owwl_data **data, int *arg) ;
00613
00614
00627 int
00628 owwl_foreach(owwl_conn *conn, owwl_func func, void *user_data) ;
00629
00642 int
00643 owwl_foreach_ordered(owwl_conn *conn, owwl_func func, void *user_data) ;
00644
00657 char *
00658 owwl_name(owwl_data *data, char *buffer, int bufflen, int *length, int long_not_short) ;
00659
00668 char *
00669 owwl_arg_stem(enum owwl_device_type_enum device_type, int device_subtype, int arg) ;
00670
00682 char *
00683 owwl_arg_name(owwl_data *data, char *buffer, int bufflen, int *length, int long_not_short, int arg) ;
00684
00691 enum owwl_unit_class_enum owwl_unit_class(owwl_data *data, int arg) ;
00692
00704 char *owwl_unit_name(owwl_data *data, int unit_type, int arg) ;
00705
00717 char *owwl_unit_desc(owwl_data *data, int unit_type, int arg) ;
00718
00726 int owwl_next_arg(owwl_data *data, int arg) ;
00727
00737 owwl_data *
00738 owwl_find(owwl_conn *conn,
00739 enum owwl_device_type_enum device_type,
00740 int device_subtype,
00741 int index) ;
00742
00751 owwl_data *
00752 owwl_find_first(owwl_conn *conn,
00753 enum owwl_device_type_enum device_type,
00754 int device_subtype) ;
00755
00763 int
00764 owwl_tx_build(owwl_conn *conn, int msg_type, owwl_buffer *buff) ;
00765
00817 int
00818 owwl_data_in(
00819 owwl_conn *conn,
00820 enum owwl_device_type_enum device_type,
00821 int device_subtype,
00822 int index,
00823 ...) ;
00824
00825
00832 int
00833 owwl_tx_new_server(owwl_conn *conn, SOCKET socket) ;
00834
00841 int
00842 owwl_tx(owwl_conn *conn, owwl_buffer *buff) ;
00843
00849 void
00850 owwl_tx_add_timestamp(owwl_conn *conn) ;
00851
00857 int
00858 owwl_tx_poll_servers(owwl_conn *conn) ;
00859
00860 #endif