/* * bg96.h * * Created on: Jan 11, 2023 * Author: Sword */ #ifndef MAIN_MODEM_H_ #define MAIN_MODEM_H_ #include #include #include "sdkconfig.h" #define MODEM_STATUS_OK 0 #define MODEM_STATUS_ERROR -1 #define MODEM_STATUS_TIMEOUT -2 #define MODEM_STATUS_MQTT_PUB_OVERFLOW -10 #define MODEM_STATUS_HTTP_POST_WAITRES -11 #define MCU_OTA_FILE_LOCAL "OTA.bin" typedef struct { /* Fields read from AT+QCSQ command */ int16_t rssi; int16_t rsrp; int16_t sinr; int16_t rsrq; } modem_signal_strength_t; /* Modem's unique identifier IMEI string, null terminated. * Maximum size of buffer returned via modem_get_imei(). */ #define MODEM_IMEI_LEN 16 /* Modem's firmware version string, null terminated. * This can include format where modem+application versions are reported. * Maximum size of buffer returned via modem_get_fw_ver(). */ #define MODEM_FWVER_LEN 32 /////////////////////////////////////////////////////////////// // BG96 module process interface typedef void (*modem_start_cb_t)(int status); /* Operation complete indication callback */ typedef void (*modem_op_cb_t)(int status); /* Connect to network service provider * once the modem is ready. * * Non-blocking. * * Returns OK if command sequence started. * Callback is invoked when completed. */ int modem_network_connect(modem_op_cb_t cb); /*==== HTTP API ==== */ /* Setup the HTTP context */ int modem_http_setup(modem_op_cb_t cb); /* Make an HTTP GET request and frame result in internal buffer */ int modem_http_get_to_buf(modem_op_cb_t cb, const char* url); /* Call to get access to framed buffer. */ int modem_http_get_buf(char** bufptr, int* len); /* Make an HTTP GET request and store result to file on modem file system. * Use modem_read_from_file to get contents. */ int modem_http_post_message(modem_op_cb_t cb, const char *url, const char *message); int modem_http_get_to_file(modem_op_cb_t cb, const char* url, const char* file); /* Read data from a file on the modem file system. * Calls user callback Open if the file is found and successfully opened. * Calls user callback Data to transfer data in chunks. * * The file is streamed in chunks via the user Data callback, in the context of * the bg96 process. It will request from the modem a chunk of data, yield, when * response is received it invokes Data immediately. When user is finished with the data * the bg96 process repeats the command/response cycle with the modem. Other processes will * get to run at least once in between the command/response. */ typedef int(*modem_read_from_file_open)(uint32_t fileSize); typedef int(*modem_read_from_file_data)(const char* buf, int buf_len); /* Return OK if operation started, ERROR otherwise. */ int modem_read_from_file( modem_op_cb_t cb, /* callback on overall API success of failure */ const char* file, /* file name string */ modem_read_from_file_open cbOpen, /* callback when file is opened successfully on modem */ modem_read_from_file_data cbData); /* callback for each chunk of streamed data of 1024 bytes or less. */ /*==== MQTT API ==== */ /* Connect to an MQTT server at given port. * server may be IP address or domain. * Client ID for MQTT CONNECT */ int modem_mqtt_connect(modem_op_cb_t cb, const char* host, int port, const char* clientID);//, const char* jwt); /* Publish data to the specific topic */ int modem_mqtt_publish(modem_op_cb_t cb, const char* topic, const char* data, int len); /* Close MQTT session */ int modem_mqtt_close(modem_op_cb_t cb); /*==== Update API ==== */ /* Update the modem from BGXX firmware image available * at specified URL. * Must be connected to a network. */ int modem_update_modem(modem_op_cb_t cb, const char* url); /*====================*/ /* Initialize process. */ int modem_init(void); /* Start process. */ int modem_start(modem_start_cb_t cb); /* Stop process. */ int modem_stop(void); /* Poll process. */ int modem_poll(void); /*declaration signal strength function*/ int modem_Rssi(void); /* Check if the process needs to be polled. */ bool modem_needs_poll(void); /* Check if the process is started */ bool modem_is_started(void); /* Check if the process is ready */ bool modem_is_ready(void); /**/ char* modem_get_rxbuf(void); /* Get modem IMEI. * String is valid only after modem has been started and is ready. */ const char* modem_get_imei(void); /* Get modem ICCID. * String is valid only after modem has been started and is ready. */ const char* modem_get_iccid(void); /* Get modem version. * String is valid only after modem has been started and is ready. */ const char* modem_get_fw_ver(void); /* Get the signal strength data - only valid if connected */ const modem_signal_strength_t* modem_get_signal_strength(void); /* Get Serving cell data*/ const char* modem_get_serving_cell(void); /* Get neighbour cell list*/ const char* modem_get_neighbour_cell(void); #endif /* MAIN_MODEM_H_ */