/** * @file di/drv/hl854x.h * @defgroup hl854x HL854x 3G Modem * Driver for Sierra Wireless HL854x modem using AT-Command interface * @{ */ #ifndef DI_DRV_HL854X_H_ #define DI_DRV_HL854X_H_ #include #include #include #include #ifdef __cplusplus extern "C" { #endif struct di_drv_hl854x_ctx; #include #include #include #include #include /** * AT-Command reply response */ enum di_drv_hl854x_reply { HL854X_REPLY_TIMEOUT = -1, HL854X_REPLY_UNKNOWN = 0, HL854X_REPLY_NONBLOCK, HL854X_REPLY_ABORTED, HL854X_REPLY_CONNECT, HL854X_REPLY_OK, HL854X_REPLY_ERROR, HL854X_REPLY_SUCCESS, HL854X_REPLY_NO_CARRIER, HL854X_REPLY_EOF }; /** Carrier registration status */ enum di_drv_hl854x_carrier_status { HL854X_CARRIER_STATUS_NOT_REG = 0, /**< Not registered, ME is not currently * searching a new operator to register to */ HL854X_CARRIER_STATUS_REG_HOME = 1, /**< Registered, home network */ HL854X_CARRIER_STATUS_NOT_REG_SEARCH = 2, /**< Not registered, but ME is currently * searching a new operator to register to */ HL854X_CARRIER_STATUS_REG_DENIED = 3, /**< Registration denied */ HL854X_CARRIER_STATUS_UNKNOWN = 4, /**< Unknown */ HL854X_CARRIER_STATUS_REG_ROAMING = 5, /**< Registered, roaming */ HL854X_CARRIER_STATUS_REQUESTED = 6 /**< Requested carrier status */ }; /** Carrier access technology */ enum di_drv_hl854x_carrier_act { HL854X_CARRIER_ACT_GSM = 0, /** GSM */ HL854X_CARRIER_ACT_UMTS = 2, /** UMTS */ }; /** Sim status */ enum di_drv_hl854x_sim_status { HL854X_SIM_STATUS_UNKNOWN = 0, /**< SIM status unknown */ HL854X_SIM_STATUS_READY = 1, /**< SIM ready */ HL854X_SIM_STATUS_SIM_PIN = 2, /**< SIM pin pending */ HL854X_SIM_STATUS_SIM_PUK = 3, /**< SIM puk pending */ HL854X_SIM_STATUS_SELECTED = 127, /**< SIM selected */ HL854X_SIM_STATUS_ERROR = 128 /**< SIM error */ }; /** Sleep modes */ enum di_drv_hl854x_sleep_mode { HL854X_SLEEP_MODE_0 = 0, /**< The module doesn’t go in sleep mode as long as DTR is active (low level) */ HL854X_SLEEP_MODE_1 = 1, /**< The module decides by itself (internal timing) */ HL854X_SLEEP_MODE_2 = 2 /**< Never go to sleep (default) */ }; /** Connection state */ enum di_drv_hl854x_con_state { HL854X_CON_STATE_UNKNOWN = 0, HL854X_CON_STATE_WRITTEN = 1, HL854X_CON_STATE_DEFINED = 2, HL854X_CON_STATE_CLOSED = 3, HL854X_CON_STATE_CONNECTED = 4, HL854X_CON_STATE_CONNECTING = 5 }; enum di_drv_hl854x_gps_state { HL854X_GPS_STATE_UNINIT = 0, HL854X_GPS_STATE_INITIALIZED = 1, HL854X_GPS_STATE_START = 3, HL854X_GPS_STATE_SLEEP = 4, HL854X_GPS_STATE_STOP = 5 }; enum di_drv_hl854x_baudrate { HL854X_BAUDRATE_115K2 = 115200, HL854X_BAUDRATE_500K0 = 500000, HL854X_BAUDRATE_921K6 = 921600 }; #define HL854X_BAUDRATE_FACTORY HL854X_BAUDRATE_115K2 /**< Factory default baudrate */ struct di_drv_hl854x_gps { uint8_t state; /**< State of GPS chipset @see di_drv_hl854x_gps_state */ bool time_shot_enabled; /**< Enables time sync shot on next PVT time frame */ struct { uint8_t tm_sec; /**< Seconds after the minute, range 0-59 */ uint8_t tm_min; /**< Minutes after the hour, range 0-59 */ uint8_t tm_hour; /**< Hours since midnight, range 0-23 */ uint8_t tm_mday; /**< Day of the month, range 1-31 */ uint8_t tm_mon; /**< Months since January, range 0-11 */ uint16_t tm_year; /**< Current year, e.g 2015 */ uint32_t unix; /**< UNIX time since epoch, in second granularity */ } time; struct di_rpc_sensor_data_gps data; }; struct di_drv_hl854x_ctx_tcp { int8_t state; /**< State @see di_drv_hl854x_tcp_state */ uint64_t tx_bytes; /**< Amount of bytes send with di_drv_hl854x_tcp_send */ uint64_t rx_bytes; /**< Amount of bytes send with di_drv_hl854x_tcp_recv */ char remote_addr[32]; /**< Remote address. E.g "beta.dualinventive.com" */ char remote_port[6]; /**< Remote port. E.g "3003" */ size_t recv_size; /**< Amount of bytes in receive buffer */ size_t cc_size; void *cc_data; }; /** * HL854X driver */ struct di_drv_hl854x_ctx { uint8_t linebuffer[256]; /**< Linebuffer for matching engine */ uint8_t readbuffer[256]; /**< Reader for serial driver */ enum di_drv_hl854x_reply reply; /**< Last reply status @see di_drv_hl854x_reply */ enum di_drv_hl854x_error error; /**< Last error report @see di_drv_hl854x_error */ enum di_drv_hl854x_cme_error cme_error; /**< CME Error code @see di_drv_hl854x_cme_error_codes */ enum di_drv_hl854x_ktcp_notif ktcp_notif; /**< KTCP_NOTIF */ struct modem { char revision[128]; /**< Identification Information */ char imei[16]; /**< 15 digits IMEI (8 digits for TAC + 6 digits for SNR + 1 check digit) */ } modem; struct sim { uint8_t status; /**< Status of SIM @see di_drv_hl854x_sim_status */ char ccid[23]; /**< Integrated Circuit Card ID of the SIM card */ char imsi[20]; /**< IMSI of the SIM card */ } sim; struct carrier { uint8_t status; /**< GPRS carrier status, see @see di_drv_hl854x_carrier_status */ char operator_name[17]; /**< Operator name string */ uint8_t act; /**< Access technology @see di_drv_hl854x_carrier_act */ int8_t rssi; /**< RSSI quality */ int8_t ber; /**< Bit error rate */ } carrier; struct di_drv_hl854x_gps gps; struct con { int8_t state; /**< State @see di_drv_hl854x_con_state */ } con; struct di_drv_hl854x_ctx_tcp tcp; /* Private */ struct di_me_ctx me; /**< HL854x driver matching engine context */ enum di_me_item_states me_items_state[DI_DRV_HL854X_ME_ITEMS_SIZE]; struct lock { di_bsem_t ctx; di_bsem_t reader; } lock; /* Timeouts */ struct timeout { uint32_t read; uint32_t cmd; } timeout; /* Callbacks */ size_t (*read)(void *buf, size_t n); size_t (*write)(const void *buf, size_t n); struct cb { di_drv_hl854x_error_cb_t error; di_drv_hl854x_cme_error_cb_t cme_error; } cb; }; /** * HL854x initialize context * - Resets ALL fields in ctx */ void di_drv_hl854x_init(struct di_drv_hl854x_ctx *ctx); static inline void di_drv_hl854x_set_read(struct di_drv_hl854x_ctx *ctx, size_t (*read)(void *buf, size_t n)) { ctx->read = read; } void di_drv_hl854x_set_read_timeout_ms(struct di_drv_hl854x_ctx *ctx, uint32_t timeout); static inline void di_drv_hl854x_set_write(struct di_drv_hl854x_ctx *ctx, size_t (*write)(const void *buf, size_t n)) { ctx->write = write; } void di_drv_hl854x_set_cmd_timeout_ms(struct di_drv_hl854x_ctx *ctx, uint32_t timeout); /** * HL854x feed data */ size_t di_drv_hl854x_read(struct di_drv_hl854x_ctx *ctx); /** * Send command to hl854x */ void di_drv_hl854x_cmd(struct di_drv_hl854x_ctx *ctx, const char *s, uint8_t reply); void di_drv_hl854x_cmd_nolock(struct di_drv_hl854x_ctx *ctx, const char *s, uint8_t reply); void di_drv_hl854x_write_wait(struct di_drv_hl854x_ctx *ctx, const char *s, uint8_t reply, bool newline); void di_drv_hl854x_write_wait_nolock(struct di_drv_hl854x_ctx *ctx, const char *s, uint8_t reply, bool newline); void di_drv_hl854x_req_modem_revision(struct di_drv_hl854x_ctx *ctx); void di_drv_hl854x_req_sim_imsi(struct di_drv_hl854x_ctx *ctx); void di_drv_hl854x_net_req_rssi(struct di_drv_hl854x_ctx *ctx); /* Wrapped commands */ void di_drv_hl854x_disable_echo(struct di_drv_hl854x_ctx *ctx); void di_drv_hl854x_set_baudrate(struct di_drv_hl854x_ctx *ctx, enum di_drv_hl854x_baudrate baudrate); void di_drv_hl854x_req_imeisv(struct di_drv_hl854x_ctx *ctx); void di_drv_hl854x_set_sleep_mode(struct di_drv_hl854x_ctx *ctx, enum di_drv_hl854x_sleep_mode s); /** */ void di_drv_hl854x_gps_start(struct di_drv_hl854x_ctx *ctx); void di_drv_hl854x_gps_sleep(struct di_drv_hl854x_ctx *ctx); void di_drv_hl854x_gps_stop(struct di_drv_hl854x_ctx *ctx); void di_drv_hl854x_con_cfg(struct di_drv_hl854x_ctx *ctx); #ifdef __cplusplus } #endif /** @} */ #endif /* DI_DRV_HL854X_H__ */