src.dualinventive.com/jjacobs/dinetrpcll-sniffer/libdi/include/di/drv/hl854x.h

228 lines
7.1 KiB
C

/**
* @file di/drv/hl854x.h
* @defgroup hl854x HL854x 3G Modem
* Driver for Sierra Wireless HL854x modem using AT-Command interface
* @{
*/
#ifndef LIBDI_INCLUDE_DI_DRV_HL854X_H_
#define LIBDI_INCLUDE_DI_DRV_HL854X_H_
#include <stdint.h>
#include <stdbool.h>
#include <di/semaphore.h>
#include <di/encoding/me.h>
#include <di/rpc/structures.h>
#define HL854X_TIMEOUT_INFINITE DI_BSEM_TIMEOUT_INFINITE
#ifdef __cplusplus
extern "C" {
#endif
struct di_drv_hl854x_ctx;
#include <di/drv/hl854x/me.h>
#include <di/drv/hl854x/str.h>
#include <di/drv/hl854x/tcp.h>
#include <di/drv/hl854x/udp.h>
#include <di/drv/hl854x/error.h>
#include <di/drv/hl854x/cme_error.h>
#include <di/drv/hl854x/definitions.h>
#include <di/drv/hl854x/structures.h>
/**
* HL854x initialize context
* - Resets ALL fields in ctx
*/
void di_drv_hl854x_init(struct di_drv_hl854x_ctx *ctx);
/**
* Lock context for atomic operation
* @param ctx Modem context
*/
void di_drv_hl854x_lock(struct di_drv_hl854x_ctx *ctx);
/**
* Unlock context for atomic operation
* @param ctx Modem context
*/
void di_drv_hl854x_unlock(struct di_drv_hl854x_ctx *ctx);
/**
* Set the lowlevel driver read callback (e.g UART read wrapper)
* @param ctx Modem context
* @param read Read callback
*/
void di_drv_hl854x_set_read(struct di_drv_hl854x_ctx *ctx, size_t (*read)(void *buf, size_t n));
/**
* Set the lowlevel driver write callback (e.g UART write wrapper)
* @param ctx Modem context
* @param write Write callback
*/
void di_drv_hl854x_set_write(struct di_drv_hl854x_ctx *ctx, size_t (*write)(const void *buf, size_t n));
/**
* Set lowlevel driver read timeout
* @param ctx Modem context
* @param timeout Timeout in milliseconds
*/
void di_drv_hl854x_set_read_timeout_ms(struct di_drv_hl854x_ctx *ctx, uint32_t timeout);
/**
* Set driver AT command reply timeout
* @param ctx Modem context
* @param timeout Timeout in milliseconds
*/
void di_drv_hl854x_set_cmd_timeout_ms(struct di_drv_hl854x_ctx *ctx, uint32_t timeout);
/**
* HL854x feed data from the lowlevel driver read callback into the driver
* @param ctx Modem context
* @retval Size of bytes read into the driver, when zero no bytes are read
*/
size_t di_drv_hl854x_read(struct di_drv_hl854x_ctx *ctx);
/**
* Send AT command to HL854x
* @param ctx Modem context
* @param cmd Null terminated AT command string
* @param reply Expected AT reply on command
* @note Locks the driver context
* @retval Returns the received modem reply (should be equal to expected reply parameter)
*/
enum di_drv_hl854x_reply di_drv_hl854x_cmd(struct di_drv_hl854x_ctx *ctx,
const char *cmd, enum di_drv_hl854x_reply reply);
/**
* Send command to HL854x without locking the driver
* @param ctx Modem context
* @param cmd Null terminated AT command string
* @param reply Expected reply on command
* @note The caller is responsible for the driver context lock control with di_drv_hl854x_lock|unlock
* @retval Returns the received modem reply (should be equal to expected reply parameter)
*/
enum di_drv_hl854x_reply di_drv_hl854x_cmd_nolock(struct di_drv_hl854x_ctx *ctx, const char *cmd,
enum di_drv_hl854x_reply reply);
/**
* Send command to HL854x with and wait for the given reply until timeout
* @param ctx Modem context
* @param cmd Null terminated AT command string
* @param reply Expected reply on command
* @param timeout_ms Timeout in milliseconds to wait for given reply parameter from modem
* @retval Returns the received modem reply (should be equal to expected reply parameter)
*/
enum di_drv_hl854x_reply di_drv_hl854x_cmd_with_timeout(struct di_drv_hl854x_ctx *ctx,
const char *cmd,
const enum di_drv_hl854x_reply reply,
const uint32_t timeout_ms);
/**
* Write data and wait for reply
* @param ctx Modem context
* @param cmd Null terminated AT command string
* @param reply Expected reply on command
* @param newline Write a newline
* @retval Returns the received modem reply (should be equal to expected reply parameter)
*/
enum di_drv_hl854x_reply di_drv_hl854x_write_wait(struct di_drv_hl854x_ctx *ctx,
const char *cmd,
const enum di_drv_hl854x_reply reply,
const bool newline);
/**
* Write data and wait for reply without locking the driver
* @param ctx Modem context
* @param cmd Null terminated AT command string
* @param reply Expected reply on command
* @param newline Write a newline
* @note The caller must make sure the driver context is locked with di_drv_hl854x_lock
* @retval Returns the received modem reply (should be equal to expected reply parameter)
*/
enum di_drv_hl854x_reply di_drv_hl854x_write_wait_nolock(struct di_drv_hl854x_ctx *ctx,
const char *cmd,
const enum di_drv_hl854x_reply reply,
const bool newline);
/**
* Request modem revision. Stores the revision to ctx->revision
*/
void di_drv_hl854x_req_modem_revision(struct di_drv_hl854x_ctx *ctx);
/**
* Request currently active SIM IMSI. Stores the IMSI to ctx->sim.imsi
*/
void di_drv_hl854x_req_sim_imsi(struct di_drv_hl854x_ctx *ctx);
/**
* Request current RSSI and BER (using CSQ AT command). Stores the values to ctx->carrier.rssi and .ber
*/
void di_drv_hl854x_net_req_rssi(struct di_drv_hl854x_ctx *ctx);
/**
* Disable AT command echoing
*/
void di_drv_hl854x_disable_echo(struct di_drv_hl854x_ctx *ctx);
/**
* Set baudrate (using AT command)
* @param ctx Modem context
* @param baudrate Preffered baudrate
*/
void di_drv_hl854x_set_baudrate(struct di_drv_hl854x_ctx *ctx, enum di_drv_hl854x_baudrate baudrate);
/**
* Request Modem IMEISV number. Stores the value in ctx->modem.imei
*/
void di_drv_hl854x_req_imeisv(struct di_drv_hl854x_ctx *ctx);
/**
* Set the modem sleep mode
* @param ctx Modem context
* @param s Sleep mode
*/
void di_drv_hl854x_set_sleep_mode(struct di_drv_hl854x_ctx *ctx, enum di_drv_hl854x_sleep_mode s);
/**
* Configure data connection APN, login and password
* @param ctx Modem context
* @param apn Bearer APN name
* @param login Bearer APN login
* @param password Bearer APN password
*/
void di_drv_hl854x_con_cfg(struct di_drv_hl854x_ctx *ctx, const char *apn, const char *login, const char *password);
/**
* Check if modem has a carrier (registered to the network from +CREG)
* * Carrier state must be HL854X_CARRIER_STATUS_REG_HOME
* * Or carrier state must be HL854X_CARRIER_STATUS_REG_ROAMING
* @param[in] ctx Modem context
* @return true when the modem has a carrier, false otherwise
*/
bool di_drv_hl854x_has_carrier(struct di_drv_hl854x_ctx *ctx);
/**
* Check if the modem has a carrier and if the PDP context is connected
* @param[in] ctx Modem context
* @return true when the modem has a carrier and the PDP context is connected
*/
bool di_drv_hl854x_is_connected(struct di_drv_hl854x_ctx *ctx);
/**
* Manual set the operator selection based on MCC/MNC (which can be the prefix of the simcard)
* @param[in] ctx Modem context
* @param mcc_mnc The MCC/MNC number
*/
di_errno_t di_drv_hl854x_net_set_manual_cops_mcc_mnc(struct di_drv_hl854x_ctx *ctx, const uint32_t mcc_mnc);
#include <di/drv/hl854x/gps.h>
#ifdef __cplusplus
}
#endif
/** @} */
#endif /* LIBDI_INCLUDE_DI_DRV_HL854X_H_ */