Sebastián Pastor / EtheriosCloudConnector
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers connector_def.h Source File

connector_def.h

00001 /*
00002  * Copyright (c) 2013 Digi International Inc.,
00003  * All rights not expressly granted are reserved.
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
00007  * You can obtain one at http://mozilla.org/MPL/2.0/.
00008  *
00009  * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
00010  * =======================================================================
00011  */
00012 
00013 #ifndef CONNECTOR_DEF_H_
00014 #define CONNECTOR_DEF_H_
00015 
00016 #ifndef CONNECTOR_MAX_VENDOR_ID_NUMBER
00017 #define CONNECTOR_MAX_VENDOR_ID_NUMBER 0xFE000000
00018 #endif
00019 
00020 #define UNUSED_VARIABLE(x)      ((void) (x))
00021 #define UNUSED_PARAMETER(x)     UNUSED_VARIABLE(x)
00022 
00023 #define ON_FALSE_DO_(cond, code)        do { if (!(cond)) {code;} } while (0)
00024 
00025 #if (defined CONNECTOR_DEBUG)
00026 #define ON_ASSERT_DO_(cond, code, output)   ON_FALSE_DO_((cond), {ASSERT(cond); code;})
00027 #else
00028 #define ON_ASSERT_DO_(cond, code, output)   ON_FALSE_DO_((cond), {code})
00029 #endif
00030 
00031 #define ASSERT_GOTO(cond, label)    ON_ASSERT_DO_((cond), {goto label;}, {})
00032 #define CONFIRM(cond)               do { switch(0) {case 0: case (cond):;} } while (0)
00033 
00034 #define COND_ELSE_GOTO(cond, label)    ON_FALSE_DO_((cond), {goto label;})
00035 
00036 
00037 #define DEVICE_ID_LENGTH    16
00038 #define CLOUD_URL_LENGTH   64
00039 
00040 #define CONNECTOR_GSM_IMEI_LENGTH   8
00041 #define CONNECTOR_ESN_HEX_LENGTH    4
00042 #define CONNECTOR_MEID_HEX_LENGTH   7
00043 
00044 #define MAC_ADDR_LENGTH     6
00045 
00046 #define MIN_VALUE(x,y)        (((x) < (y))? (x): (y))
00047 #define MAX_VALUE(x,y)        (((x) > (y))? (x): (y))
00048 
00049 #define MAX_RECEIVE_TIMEOUT_IN_SECONDS  1
00050 #define MIN_RECEIVE_TIMEOUT_IN_SECONDS  0
00051 
00052 #if !(defined CONNECTOR_TRANSPORT_RECONNECT_AFTER)
00053 #define CONNECTOR_TRANSPORT_RECONNECT_AFTER     30
00054 #endif
00055 
00056 typedef enum {
00057 #if (defined CONNECTOR_TRANSPORT_TCP)
00058     connector_network_tcp,
00059 #endif
00060 #if (defined CONNECTOR_TRANSPORT_UDP)
00061     connector_network_udp,
00062 #endif
00063 #if (defined CONNECTOR_TRANSPORT_SMS)
00064     connector_network_sms,
00065 #endif
00066     connector_network_count
00067 } connector_network_type_t;
00068 
00069 typedef enum {
00070     connector_transport_idle,
00071     connector_transport_open,
00072     connector_transport_send,
00073     connector_transport_receive,
00074     connector_transport_close,
00075     connector_transport_terminate,
00076     connector_transport_redirect,
00077     connector_transport_wait_for_reconnect
00078 } connector_transport_state_t;
00079 
00080 #define connector_bool(cond)    ((cond) ? connector_true : connector_false)
00081 
00082 #define add_list_node(head, tail, node) \
00083     do { \
00084         ASSERT(node != NULL); \
00085         if (*head != NULL) \
00086         {\
00087             *head->prev = node;\
00088         }\
00089         node->next = *head;\
00090         node->prev = NULL;\
00091         *head = node;\
00092         if ((tail != NULL) && (*tail == NULL)) \
00093         { \
00094             *tail = node; \
00095         } \
00096    } while (0)
00097 
00098 #define remove_list_node(head, tail, node) \
00099     do { \
00100         ASSERT(node != NULL); \
00101         if (node->next != NULL) \
00102         {\
00103             node->next->prev = node->prev;\
00104         }\
00105         if (node->prev != NULL) \
00106         {\
00107             node->prev->next = node->next;\
00108         }\
00109         if (node == *head)\
00110         {\
00111             *head = node->next;\
00112         }\
00113         if ((tail != NULL) && (node == *tail))\
00114         {\
00115             *tail = node->prev;\
00116         }\
00117     } while (0)
00118 
00119 #define add_node(head, node) \
00120     do { \
00121         ASSERT(node != NULL); \
00122         if (*head != NULL) \
00123         {\
00124             *head->prev = node;\
00125         }\
00126         node->next = *head;\
00127         node->prev = NULL;\
00128         *head = node;\
00129     } while (0)
00130 
00131 #define remove_node(head, node) \
00132     do { \
00133         ASSERT(node != NULL); \
00134         if (node->next != NULL) \
00135         {\
00136             node->next->prev = node->prev;\
00137         }\
00138         if (node->prev != NULL) \
00139         {\
00140             node->prev->next = node->next;\
00141         }\
00142         if (node == *head)\
00143         {\
00144             *head = node->next;\
00145         }\
00146     } while (0)
00147 
00148 struct connector_data;
00149 
00150 #if (defined CONNECTOR_TRANSPORT_TCP)
00151 #include "connector_edp_def.h"
00152 #endif
00153 
00154 #if defined(CONNECTOR_SHORT_MESSAGE)
00155 #include "connector_sm_def.h"
00156 #endif
00157 
00158 typedef struct connector_data {
00159 
00160     char const * signature;
00161 
00162     uint8_t device_id[DEVICE_ID_LENGTH];
00163     uint8_t * mac_addr;
00164     uint8_t * wan_id;
00165     size_t wan_id_length;
00166 
00167     char * device_cloud_url;
00168     size_t device_cloud_url_length;
00169 
00170     char * device_cloud_phone;
00171     size_t device_cloud_phone_length;
00172 
00173     char * device_cloud_service_id;
00174     size_t device_cloud_service_id_length;
00175 
00176     connector_connection_type_t connection_type;
00177 
00178     connector_wan_type_t wan_type;
00179 
00180 #if !(defined CONNECTOR_WAN_LINK_SPEED_IN_BITS_PER_SECOND)
00181     uint32_t link_speed;
00182 #endif
00183 
00184 #if !(defined CONNECTOR_WAN_PHONE_NUMBER_DIALED)
00185     char * phone_dialed;
00186     size_t phone_dialed_length;
00187 #endif
00188 
00189     connector_device_id_method_t device_id_method;
00190     connector_bool_t connector_got_device_id;
00191 #if (CONNECTOR_TRANSPORT_COUNT > 1)
00192     connector_network_type_t first_running_network;
00193 #endif
00194 
00195     connector_callback_t  callback;
00196     connector_status_t error_code;
00197 
00198 #if (defined CONNECTOR_TRANSPORT_UDP || defined CONNECTOR_TRANSPORT_SMS)
00199     uint32_t last_request_id;
00200 #endif
00201 
00202 #if (defined CONNECTOR_TRANSPORT_UDP)
00203     connector_sm_data_t sm_udp;
00204 #endif
00205 
00206 #if (defined CONNECTOR_TRANSPORT_SMS)
00207     connector_sm_data_t sm_sms;
00208 #endif
00209 
00210 #if (defined CONNECTOR_TRANSPORT_TCP)
00211     connector_edp_data_t edp_data;
00212 #endif
00213 
00214     struct {
00215         enum {
00216             connector_state_running,
00217             connector_state_stop_by_initiate_action,
00218             connector_state_terminate_by_initiate_action,
00219             connector_state_abort_by_callback
00220         } state;
00221         connector_stop_condition_t condition;
00222         void * user_context;
00223     } stop;
00224 
00225 } connector_data_t;
00226 
00227 #endif
00228