Skip to content

Commit ef322d9

Browse files
rerickson1nashif
authored andcommitted
drivers: modem: hl7800 Add Site Survey
Add API to determine nearby cell towers and their signal strength. Signed-off-by: Ryan Erickson <[email protected]>
1 parent 13ba7c7 commit ef322d9

File tree

2 files changed

+105
-1
lines changed

2 files changed

+105
-1
lines changed

drivers/modem/hl7800.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,22 @@ int32_t mdm_hl7800_polte_locate(void)
12201220

12211221
#endif /* CONFIG_MODEM_HL7800_POLTE */
12221222

1223+
/**
1224+
* @brief Perform a site survey.
1225+
*
1226+
*/
1227+
int32_t mdm_hl7800_perform_site_survey(void)
1228+
{
1229+
int ret;
1230+
1231+
hl7800_lock();
1232+
wakeup_hl7800();
1233+
ret = send_at_cmd(NULL, "at%meas=\"97\"", MDM_CMD_SEND_TIMEOUT, 0, false);
1234+
allow_sleep(true);
1235+
hl7800_unlock();
1236+
return ret;
1237+
}
1238+
12231239
void mdm_hl7800_generate_status_events(void)
12241240
{
12251241
hl7800_lock();
@@ -3045,6 +3061,74 @@ static bool on_cmd_modem_functionality(struct net_buf **buf, uint16_t len)
30453061
return true;
30463062
}
30473063

3064+
/* There can be multiple responses from a single command.
3065+
* %MEAS: EARFCN=5826, CellID=420, RSRP=-99, RSRQ=-15
3066+
* %MEAS: EARFCN=6400, CellID=201, RSRP=-93, RSRQ=-21
3067+
*/
3068+
static bool on_cmd_survey_status(struct net_buf **buf, uint16_t len)
3069+
{
3070+
struct net_buf *frag = NULL;
3071+
char response[sizeof("EARFCN=XXXXXXXXXXX, CellID=XXXXXXXXXXX, RSRP=-XXX, RSRQ=-XXX")];
3072+
char *key;
3073+
size_t out_len;
3074+
char *value;
3075+
struct mdm_hl7800_site_survey site_survey;
3076+
3077+
wait_for_modem_data_and_newline(buf, net_buf_frags_len(*buf),
3078+
sizeof(response));
3079+
3080+
frag = NULL;
3081+
len = net_buf_findcrlf(*buf, &frag);
3082+
if (!frag) {
3083+
LOG_ERR("Unable to find end");
3084+
goto done;
3085+
}
3086+
3087+
out_len = net_buf_linearize(response, sizeof(response), *buf, 0, len);
3088+
LOG_HEXDUMP_DBG(response, out_len, "Site Survey");
3089+
3090+
key = "EARFCN=";
3091+
value = strstr(response, key);
3092+
if (value == NULL) {
3093+
goto done;
3094+
} else {
3095+
value += strlen(key);
3096+
site_survey.earfcn = strtoul(value, NULL, 10);
3097+
}
3098+
3099+
key = "CellID=";
3100+
value = strstr(response, key);
3101+
if (value == NULL) {
3102+
goto done;
3103+
} else {
3104+
value += strlen(key);
3105+
site_survey.cell_id = strtoul(value, NULL, 10);
3106+
}
3107+
3108+
key = "RSRP=";
3109+
value = strstr(response, key);
3110+
if (value == NULL) {
3111+
goto done;
3112+
} else {
3113+
value += strlen(key);
3114+
site_survey.rsrp = strtol(value, NULL, 10);
3115+
}
3116+
3117+
key = "RSRQ=";
3118+
value = strstr(response, key);
3119+
if (value == NULL) {
3120+
goto done;
3121+
} else {
3122+
value += strlen(key);
3123+
site_survey.rsrq = strtol(value, NULL, 10);
3124+
}
3125+
3126+
event_handler(HL7800_EVENT_SITE_SURVEY, &site_survey);
3127+
3128+
done:
3129+
return true;
3130+
}
3131+
30483132
#ifdef CONFIG_NEWLIB_LIBC
30493133
/* Handler: +CCLK: "yy/MM/dd,hh:mm:ss±zz" */
30503134
static bool on_cmd_rtc_query(struct net_buf **buf, uint16_t len)
@@ -4012,6 +4096,7 @@ static void hl7800_rx(void)
40124096
CMD_HANDLER("+KCARRIERCFG: ", operator_index_query),
40134097
CMD_HANDLER("AT+CIMI", atcmdinfo_imsi),
40144098
CMD_HANDLER("+CFUN: ", modem_functionality),
4099+
CMD_HANDLER("%MEAS: ", survey_status),
40154100
#ifdef CONFIG_NEWLIB_LIBC
40164101
CMD_HANDLER("+CCLK: ", rtc_query),
40174102
#endif

include/drivers/modem/hl7800.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ struct mdm_hl7800_apn {
8484

8585
#define MDM_HL7800_SET_POLTE_USER_AND_PASSWORD_FMT_STR "AT%%POLTECMD=\"SERVERAUTH\",\"%s\",\"%s\""
8686

87+
struct mdm_hl7800_site_survey {
88+
uint32_t earfcn; /* EUTRA Absolute Radio Frequency Channel Number */
89+
uint32_t cell_id;
90+
int rsrp;
91+
int rsrq;
92+
};
93+
8794
enum mdm_hl7800_radio_mode { MDM_RAT_CAT_M1 = 0, MDM_RAT_CAT_NB1 };
8895

8996
enum mdm_hl7800_event {
@@ -104,7 +111,8 @@ enum mdm_hl7800_event {
104111
HL7800_EVENT_GPS_POSITION_STATUS,
105112
HL7800_EVENT_POLTE_REGISTRATION,
106113
HL7800_EVENT_POLTE_LOCATE_STATUS,
107-
HL7800_EVENT_POLTE
114+
HL7800_EVENT_POLTE,
115+
HL7800_EVENT_SITE_SURVEY,
108116
};
109117

110118
enum mdm_hl7800_startup_state {
@@ -237,6 +245,7 @@ struct mdm_hl7800_polte_location_data {
237245
* HL7800_EVENT_POLTE_REGISTRATION mdm_hl7800_polte_registration_event_data
238246
* HL7800_EVENT_POLTE mdm_hl7800_polte_location_data
239247
* HL7800_EVENT_POLTE_LOCATE_STATUS int
248+
* HL7800_EVENT_SITE_SURVEY mdm_hl7800_site_survey
240249
*/
241250
typedef void (*mdm_hl7800_event_callback_t)(enum mdm_hl7800_event event,
242251
void *event_data);
@@ -441,6 +450,16 @@ int32_t mdm_hl7800_polte_enable(char *user, char *password);
441450
*/
442451
int32_t mdm_hl7800_polte_locate(void);
443452

453+
/**
454+
* @brief Perform a site survey. This command may return different values
455+
* each time it is run (depending on what is in range).
456+
*
457+
* HL7800_EVENT_SITE_SURVEY is generated for each response received from modem.
458+
*
459+
* @retval negative error code, 0 on success
460+
*/
461+
int32_t mdm_hl7800_perform_site_survey(void);
462+
444463
#ifdef __cplusplus
445464
}
446465
#endif

0 commit comments

Comments
 (0)