1 /* 2 * Copyright (C) 2021 metraTec GmbH 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_INCLUDE_DRIVERS_MODEM_SIMCOM_SIM7080_H 8 #define ZEPHYR_INCLUDE_DRIVERS_MODEM_SIMCOM_SIM7080_H 9 10 #include <zephyr/types.h> 11 12 #include <stdint.h> 13 14 #ifdef __cplusplus 15 extern "C" { 16 #endif 17 18 #define SIM7080_GNSS_DATA_UTC_LEN 20 19 #define SIM7080_SMS_MAX_LEN 160 20 21 struct sim7080_gnss_data { 22 /** 23 * Whether gnss is powered or not. 24 */ 25 bool run_status; 26 /** 27 * Whether fix is acquired or not. 28 */ 29 bool fix_status; 30 /** 31 * UTC in format yyyyMMddhhmmss.sss 32 */ 33 char utc[SIM7080_GNSS_DATA_UTC_LEN]; 34 /** 35 * Latitude in 10^-7 degree. 36 */ 37 int32_t lat; 38 /** 39 * Longitude in 10^-7 degree. 40 */ 41 int32_t lon; 42 /** 43 * Altitude in mm. 44 */ 45 int32_t alt; 46 /** 47 * Horizontal dilution of precision in 10^-2. 48 */ 49 uint16_t hdop; 50 /** 51 * Course over ground un 10^-2 degree. 52 */ 53 uint16_t cog; 54 /** 55 * Speed in 10^-1 km/h. 56 */ 57 uint16_t kmh; 58 }; 59 60 /** 61 * Possible sms states in memory. 62 */ 63 enum sim7080_sms_stat { 64 SIM7080_SMS_STAT_REC_UNREAD = 0, 65 SIM7080_SMS_STAT_REC_READ, 66 SIM7080_SMS_STAT_STO_UNSENT, 67 SIM7080_SMS_STAT_STO_SENT, 68 SIM7080_SMS_STAT_ALL, 69 }; 70 71 /** 72 * Possible ftp return codes. 73 */ 74 enum sim7080_ftp_rc { 75 /* Operation finished correctly. */ 76 SIM7080_FTP_RC_OK = 0, 77 /* Session finished. */ 78 SIM7080_FTP_RC_FINISHED, 79 /* An error occurred. */ 80 SIM7080_FTP_RC_ERROR, 81 }; 82 83 /** 84 * Buffer structure for sms. 85 */ 86 struct sim7080_sms { 87 /* First octet of the sms. */ 88 uint8_t first_octet; 89 /* Message protocol identifier. */ 90 uint8_t tp_pid; 91 /* Status of the sms in memory. */ 92 enum sim7080_sms_stat stat; 93 /* Index of the sms in memory. */ 94 uint16_t index; 95 /* Time the sms was received. */ 96 struct { 97 uint8_t year; 98 uint8_t month; 99 uint8_t day; 100 uint8_t hour; 101 uint8_t minute; 102 uint8_t second; 103 uint8_t timezone; 104 } time; 105 /* Buffered sms. */ 106 char data[SIM7080_SMS_MAX_LEN + 1]; 107 /* Length of the sms in buffer. */ 108 uint8_t data_len; 109 }; 110 111 /** 112 * Buffer structure for sms reads. 113 */ 114 struct sim7080_sms_buffer { 115 /* sms structures to read to. */ 116 struct sim7080_sms *sms; 117 /* Number of sms structures. */ 118 uint8_t nsms; 119 }; 120 121 /** 122 * @brief Power on the Sim7080. 123 * 124 * @return 0 on success. Otherwise -1 is returned. 125 */ 126 int mdm_sim7080_power_on(void); 127 128 /** 129 * @brief Power off the Sim7080. 130 * 131 * @return 0 on success. Otherwise -1 is returned. 132 */ 133 int mdm_sim7080_power_off(void); 134 135 /** 136 * @brief Starts the modem in network operation mode. 137 * 138 * @return 0 on success. Otherwise <0 is returned. 139 */ 140 int mdm_sim7080_start_network(void); 141 142 /** 143 * @brief Starts the modem in gnss operation mode. 144 * 145 * @return 0 on success. Otherwise <0 is returned. 146 */ 147 int mdm_sim7080_start_gnss(void); 148 149 /** 150 * @brief Query gnss position form the modem. 151 * 152 * @return 0 on success. If no fix is acquired yet -EAGAIN is returned. 153 * Otherwise <0 is returned. 154 */ 155 int mdm_sim7080_query_gnss(struct sim7080_gnss_data *data); 156 157 /** 158 * Get the sim7080 manufacturer. 159 */ 160 const char *mdm_sim7080_get_manufacturer(void); 161 162 /** 163 * Get the sim7080 model information. 164 */ 165 const char *mdm_sim7080_get_model(void); 166 167 /** 168 * Get the sim7080 revision. 169 */ 170 const char *mdm_sim7080_get_revision(void); 171 172 /** 173 * Get the sim7080 imei number. 174 */ 175 const char *mdm_sim7080_get_imei(void); 176 177 /** 178 * Read sms from sim module. 179 * 180 * @param buffer Buffer structure for sms. 181 * @return Number of sms read on success. Otherwise -1 is returned. 182 * 183 * @note The buffer structure needs to be initialized to 184 * the size of the sms buffer. When this function finishes 185 * successful, nsms will be set to the number of sms read. 186 * If the whole structure is filled a subsequent read may 187 * be needed. 188 */ 189 int mdm_sim7080_read_sms(struct sim7080_sms_buffer *buffer); 190 191 /** 192 * Delete a sms at a given index. 193 * 194 * @param index The index of the sms in memory. 195 * @return 0 on success. Otherwise -1 is returned. 196 */ 197 int mdm_sim7080_delete_sms(uint16_t index); 198 199 /** 200 * Start a ftp get session. 201 * 202 * @param server The ftp servers address. 203 * @param user User name for the ftp server. 204 * @param passwd Password for the ftp user. 205 * @param file File to be downloaded. 206 * @param path Path to the file on the server. 207 * @return 0 if the session was started. Otherwise -1 is returned. 208 */ 209 int mdm_sim7080_ftp_get_start(const char *server, const char *user, const char *passwd, 210 const char *file, const char *path); 211 212 /** 213 * Read data from a ftp get session. 214 * 215 * @param dst The destination buffer. 216 * @param size Initialize to the size of dst. Gets set to the number 217 * of bytes actually read. 218 * @return According sim7080_ftp_rc. 219 */ 220 int mdm_sim7080_ftp_get_read(char *dst, size_t *size); 221 222 #ifdef __cplusplus 223 } 224 #endif 225 226 #endif /* ZEPHYR_INCLUDE_DRIVERS_MODEM_SIMCOM_SIM7080_H */ 227