Merge "allow reconfiguration update happen before HAL init"

This commit is contained in:
Linux Build Service Account 2014-10-21 18:29:18 -07:00 committed by Gerrit - the friendly Code Review server
commit d2dab2d154
5 changed files with 233 additions and 81 deletions

View file

@ -127,7 +127,7 @@ static const GpsXtraInterface sLocEngXTRAInterface =
static void loc_ni_init(GpsNiCallbacks *callbacks);
static void loc_ni_respond(int notif_id, GpsUserResponseType user_response);
const GpsNiInterface sLocEngNiInterface =
static const GpsNiInterface sLocEngNiInterface =
{
sizeof(GpsNiInterface),
loc_ni_init,
@ -181,6 +181,14 @@ static const SuplCertificateInterface sLocEngAGpsCertInterface =
loc_agps_revoke_certificates
};
static void loc_configuration_update(const char* config_data, int32_t length);
static const GnssConfigurationInterface sLocEngConfigInterface =
{
sizeof(GnssConfigurationInterface),
loc_configuration_update
};
static loc_eng_data_s_type loc_afw_data;
static int gss_fd = -1;
@ -761,6 +769,10 @@ const void* loc_get_extension(const char* name)
{
ret_val = &sLocEngAGpsCertInterface;
}
else if (strcmp(name, GNSS_CONFIGURATION_INTERFACE) == 0)
{
ret_val = &sLocEngConfigInterface;
}
else
{
LOC_LOGE ("get_extension: Invalid interface passed in\n");
@ -1059,6 +1071,13 @@ static int loc_agps_revoke_certificates(const Sha1CertificateFingerprint* finger
return ret_val;
}
static void loc_configuration_update(const char* config_data, int32_t length)
{
ENTRY_LOG();
loc_eng_configuration_update(loc_afw_data, config_data, length);
EXIT_LOG(%s, VOID_RET);
}
static void local_loc_cb(UlpLocation* location, void* locExt)
{
ENTRY_LOG();

View file

@ -2589,6 +2589,33 @@ int loc_eng_agps_install_certificates(loc_eng_data_s_type &loc_eng_data,
return ret_val;
}
void loc_eng_configuration_update (loc_eng_data_s_type &loc_eng_data,
const char* config_data, int32_t length)
{
ENTRY_LOG_CALLFLOW();
if (config_data && length > 0) {
loc_gps_cfg_s_type gps_conf_old = gps_conf;
UTIL_UPDATE_CONF(config_data, length, loc_parameter_table);
LocEngAdapter* adapter = loc_eng_data.adapter;
// it is possible that HAL is not init'ed at this time
if (adapter) {
if (gps_conf_old.SUPL_VER != gps_conf.SUPL_VER) {
adapter->sendMsg(new LocEngSuplVer(adapter, gps_conf.SUPL_VER));
}
if (gps_conf_old.LPP_PROFILE != gps_conf.LPP_PROFILE) {
adapter->sendMsg(new LocEngLppConfig(adapter, gps_conf.LPP_PROFILE));
}
if (gps_conf_old.A_GLONASS_POS_PROTOCOL_SELECT != gps_conf.A_GLONASS_POS_PROTOCOL_SELECT) {
adapter->sendMsg(new LocEngAGlonassProtocol(adapter,
gps_conf.A_GLONASS_POS_PROTOCOL_SELECT));
}
}
}
EXIT_LOG(%s, VOID_RET);
}
/*===========================================================================
FUNCTION loc_eng_report_status

View file

@ -141,36 +141,36 @@ typedef struct loc_eng_data_s
/* GPS.conf support */
typedef struct loc_gps_cfg_s
{
unsigned long INTERMEDIATE_POS;
unsigned long ACCURACY_THRES;
unsigned long SUPL_VER;
unsigned long CAPABILITIES;
unsigned long LPP_PROFILE;
uint32_t INTERMEDIATE_POS;
uint32_t ACCURACY_THRES;
uint32_t SUPL_VER;
uint32_t CAPABILITIES;
uint32_t LPP_PROFILE;
uint8_t NMEA_PROVIDER;
unsigned long A_GLONASS_POS_PROTOCOL_SELECT;
unsigned long XTRA_VERSION_CHECK;
char XTRA_SERVER_1[MAX_XTRA_SERVER_URL_LENGTH];
char XTRA_SERVER_2[MAX_XTRA_SERVER_URL_LENGTH];
char XTRA_SERVER_3[MAX_XTRA_SERVER_URL_LENGTH];
unsigned long AGPS_CERT_WRITABLE_MASK;
unsigned long USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL;
uint32_t XTRA_VERSION_CHECK;
char XTRA_SERVER_1[MAX_XTRA_SERVER_URL_LENGTH];
char XTRA_SERVER_2[MAX_XTRA_SERVER_URL_LENGTH];
char XTRA_SERVER_3[MAX_XTRA_SERVER_URL_LENGTH];
uint32_t USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL;
uint32_t A_GLONASS_POS_PROTOCOL_SELECT;
uint32_t AGPS_CERT_WRITABLE_MASK;
} loc_gps_cfg_s_type;
typedef struct
{
uint8_t GYRO_BIAS_RANDOM_WALK_VALID;
double GYRO_BIAS_RANDOM_WALK;
unsigned long SENSOR_ACCEL_BATCHES_PER_SEC;
unsigned long SENSOR_ACCEL_SAMPLES_PER_BATCH;
unsigned long SENSOR_GYRO_BATCHES_PER_SEC;
unsigned long SENSOR_GYRO_SAMPLES_PER_BATCH;
unsigned long SENSOR_ACCEL_BATCHES_PER_SEC_HIGH;
unsigned long SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH;
unsigned long SENSOR_GYRO_BATCHES_PER_SEC_HIGH;
unsigned long SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH;
unsigned long SENSOR_CONTROL_MODE;
unsigned long SENSOR_USAGE;
unsigned long SENSOR_ALGORITHM_CONFIG_MASK;
uint32_t SENSOR_ACCEL_BATCHES_PER_SEC;
uint32_t SENSOR_ACCEL_SAMPLES_PER_BATCH;
uint32_t SENSOR_GYRO_BATCHES_PER_SEC;
uint32_t SENSOR_GYRO_SAMPLES_PER_BATCH;
uint32_t SENSOR_ACCEL_BATCHES_PER_SEC_HIGH;
uint32_t SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH;
uint32_t SENSOR_GYRO_BATCHES_PER_SEC_HIGH;
uint32_t SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH;
uint32_t SENSOR_CONTROL_MODE;
uint32_t SENSOR_USAGE;
uint32_t SENSOR_ALGORITHM_CONFIG_MASK;
uint8_t ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID;
double ACCEL_RANDOM_WALK_SPECTRAL_DENSITY;
uint8_t ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID;
@ -179,7 +179,7 @@ typedef struct
double RATE_RANDOM_WALK_SPECTRAL_DENSITY;
uint8_t VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID;
double VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY;
unsigned long SENSOR_PROVIDER;
uint32_t SENSOR_PROVIDER;
} loc_sap_cfg_s_type;
extern loc_gps_cfg_s_type gps_conf;
@ -241,6 +241,9 @@ extern void loc_eng_ni_request_handler(loc_eng_data_s_type &loc_eng_data,
const void* passThrough);
extern void loc_eng_ni_reset_on_engine_restart(loc_eng_data_s_type &loc_eng_data);
void loc_eng_configuration_update (loc_eng_data_s_type &loc_eng_data,
const char* config_data, int32_t length);
#ifdef __cplusplus
}
#endif /* __cplusplus */

View file

@ -56,12 +56,12 @@ static uint8_t DEBUG_LEVEL = 0xff;
static uint8_t TIMESTAMP = 0;
/* Parameter spec table */
static loc_param_s_type loc_parameter_table[] =
static loc_param_s_type loc_param_table[] =
{
{"DEBUG_LEVEL", &DEBUG_LEVEL, NULL, 'n'},
{"TIMESTAMP", &TIMESTAMP, NULL, 'n'},
};
int loc_param_num = sizeof(loc_parameter_table) / sizeof(loc_param_s_type);
int loc_param_num = sizeof(loc_param_table) / sizeof(loc_param_s_type);
typedef struct loc_param_v_type
{
@ -117,7 +117,8 @@ int loc_set_config_entry(loc_param_s_type* config_entry, loc_param_v_type* confi
LOC_MAX_PARAM_STRING + 1);
}
/* Log INI values */
LOC_LOGD("%s: PARAM %s = %s", __FUNCTION__, config_entry->param_name, (char*)config_entry->param_ptr);
LOC_LOGD("%s: PARAM %s = %s", __FUNCTION__,
config_entry->param_name, (char*)config_entry->param_ptr);
if(NULL != config_entry->param_set)
{
@ -128,7 +129,8 @@ int loc_set_config_entry(loc_param_s_type* config_entry, loc_param_v_type* confi
case 'n':
*((int *)config_entry->param_ptr) = config_value->param_int_value;
/* Log INI values */
LOC_LOGD("%s: PARAM %s = %d", __FUNCTION__, config_entry->param_name, config_value->param_int_value);
LOC_LOGD("%s: PARAM %s = %d", __FUNCTION__,
config_entry->param_name, config_value->param_int_value);
if(NULL != config_entry->param_set)
{
@ -139,7 +141,8 @@ int loc_set_config_entry(loc_param_s_type* config_entry, loc_param_v_type* confi
case 'f':
*((double *)config_entry->param_ptr) = config_value->param_double_value;
/* Log INI values */
LOC_LOGD("%s: PARAM %s = %f", __FUNCTION__, config_entry->param_name, config_value->param_double_value);
LOC_LOGD("%s: PARAM %s = %f", __FUNCTION__,
config_entry->param_name, config_value->param_double_value);
if(NULL != config_entry->param_set)
{
@ -148,12 +151,85 @@ int loc_set_config_entry(loc_param_s_type* config_entry, loc_param_v_type* confi
ret = 0;
break;
default:
LOC_LOGE("%s: PARAM %s parameter type must be n, f, or s", __FUNCTION__, config_entry->param_name);
LOC_LOGE("%s: PARAM %s parameter type must be n, f, or s",
__FUNCTION__, config_entry->param_name);
}
}
return ret;
}
/*===========================================================================
FUNCTION loc_fill_conf_item
DESCRIPTION
Takes a line of configuration item and sets defined values based on
the passed in configuration table. This table maps strings to values to
set along with the type of each of these values.
PARAMETERS:
input_buf : buffer contanis config item
config_table: table definition of strings to places to store information
table_length: length of the configuration table
DEPENDENCIES
N/A
RETURN VALUE
0: No config or incomplete config or invalid parameter
1: Filled a record
SIDE EFFECTS
N/A
===========================================================================*/
int loc_fill_conf_item(char* input_buf,
loc_param_s_type* config_table, uint32_t table_length)
{
int ret = 0;
if (input_buf && config_table) {
char *lasts;
loc_param_v_type config_value;
memset(&config_value, 0, sizeof(config_value));
/* Separate variable and value */
config_value.param_name = strtok_r(input_buf, "=", &lasts);
/* skip lines that do not contain "=" */
if (config_value.param_name) {
config_value.param_str_value = strtok_r(NULL, "=", &lasts);
/* skip lines that do not contain two operands */
if (config_value.param_str_value) {
/* Trim leading and trailing spaces */
loc_util_trim_space(config_value.param_name);
loc_util_trim_space(config_value.param_str_value);
/* Parse numerical value */
if ((strlen(config_value.param_str_value) >=3) &&
(config_value.param_str_value[0] == '0') &&
(tolower(config_value.param_str_value[1]) == 'x'))
{
/* hex */
config_value.param_int_value = (int) strtol(&config_value.param_str_value[2],
(char**) NULL, 16);
}
else {
config_value.param_double_value = (double) atof(config_value.param_str_value); /* float */
config_value.param_int_value = atoi(config_value.param_str_value); /* dec */
}
for(uint32_t i = 0; NULL != config_table && i < table_length; i++)
{
if(!loc_set_config_entry(&config_table[i], &config_value)) {
ret = 1;
}
}
}
}
}
return ret;
}
/*===========================================================================
FUNCTION loc_read_conf_r (repetitive)
@ -185,10 +261,6 @@ SIDE EFFECTS
===========================================================================*/
int loc_read_conf_r(FILE *conf_fp, loc_param_s_type* config_table, uint32_t table_length)
{
char input_buf[LOC_MAX_PARAM_LINE]; /* declare a char array */
char *lasts;
loc_param_v_type config_value;
uint32_t i;
int ret=0;
unsigned int num_params=table_length;
@ -199,13 +271,16 @@ int loc_read_conf_r(FILE *conf_fp, loc_param_s_type* config_table, uint32_t tabl
}
/* Clear all validity bits */
for(i = 0; NULL != config_table && i < table_length; i++)
for(uint32_t i = 0; NULL != config_table && i < table_length; i++)
{
if(NULL != config_table[i].param_set)
{
*(config_table[i].param_set) = 0;
}
}
char input_buf[LOC_MAX_PARAM_LINE]; /* declare a char array */
LOC_LOGD("%s:%d]: num_params: %d\n", __func__, __LINE__, num_params);
while(num_params)
{
@ -214,46 +289,67 @@ int loc_read_conf_r(FILE *conf_fp, loc_param_s_type* config_table, uint32_t tabl
break;
}
memset(&config_value, 0, sizeof(config_value));
/* Separate variable and value */
config_value.param_name = strtok_r(input_buf, "=", &lasts);
/* skip lines that do not contain "=" */
if (config_value.param_name == NULL) continue;
config_value.param_str_value = strtok_r(NULL, "=", &lasts);
/* skip lines that do not contain two operands */
if (config_value.param_str_value == NULL) continue;
/* Trim leading and trailing spaces */
loc_util_trim_space(config_value.param_name);
loc_util_trim_space(config_value.param_str_value);
/* Parse numerical value */
if ((strlen(config_value.param_str_value) >=3) &&
(config_value.param_str_value[0] == '0') &&
(tolower(config_value.param_str_value[1]) == 'x'))
{
/* hex */
config_value.param_int_value = (int) strtol(&config_value.param_str_value[2],
(char**) NULL, 16);
}
else {
config_value.param_double_value = (double) atof(config_value.param_str_value); /* float */
config_value.param_int_value = atoi(config_value.param_str_value); /* dec */
}
for(i = 0; NULL != config_table && i < table_length; i++)
{
if(!loc_set_config_entry(&config_table[i], &config_value)) {
num_params--;
}
}
num_params -= loc_fill_conf_item(input_buf, config_table, table_length);
}
err:
return ret;
}
/*===========================================================================
FUNCTION loc_udpate_conf
DESCRIPTION
Parses the passed in buffer for configuration items, and update the table
that is also passed in.
Reads the specified configuration file and sets defined values based on
the passed in configuration table. This table maps strings to values to
set along with the type of each of these values.
PARAMETERS:
conf_data: configuration items in bufferas a string
length: strlen(conf_data)
config_table: table definition of strings to places to store information
table_length: length of the configuration table
DEPENDENCIES
N/A
RETURN VALUE
number of the records in the table that is updated at time of return.
SIDE EFFECTS
N/A
===========================================================================*/
int loc_update_conf(const char* conf_data, int32_t length,
loc_param_s_type* config_table, uint32_t table_length)
{
int ret = -1;
if (conf_data && length && config_table && table_length) {
// make a copy, so we do not tokenize the original data
char* conf_copy = (char*)malloc(length+1);
memcpy(conf_copy, conf_data, length);
// we hard NULL the end of string to be safe
conf_copy[length] = 0;
// start with one record off
uint32_t num_params = table_length - 1;
char* saveptr = NULL;
char* input_buf = strtok_r(conf_copy, "\n", &saveptr);
ret = 0;
LOC_LOGD("%s:%d]: num_params: %d\n", __func__, __LINE__, num_params);
while(num_params && input_buf) {
ret++;
num_params -= loc_fill_conf_item(input_buf, config_table, table_length);
input_buf = strtok_r(NULL, "\n", &saveptr);
}
}
return ret;
}
/*===========================================================================
FUNCTION loc_read_conf
@ -279,20 +375,20 @@ SIDE EFFECTS
void loc_read_conf(const char* conf_file_name, loc_param_s_type* config_table,
uint32_t table_length)
{
FILE *gps_conf_fp = NULL;
FILE *conf_fp = NULL;
char *lasts;
loc_param_v_type config_value;
uint32_t i;
if((gps_conf_fp = fopen(conf_file_name, "r")) != NULL)
if((conf_fp = fopen(conf_file_name, "r")) != NULL)
{
LOC_LOGD("%s: using %s", __FUNCTION__, conf_file_name);
if(table_length && config_table) {
loc_read_conf_r(gps_conf_fp, config_table, table_length);
rewind(gps_conf_fp);
loc_read_conf_r(conf_fp, config_table, table_length);
rewind(conf_fp);
}
loc_read_conf_r(gps_conf_fp, loc_parameter_table, loc_param_num);
fclose(gps_conf_fp);
loc_read_conf_r(conf_fp, loc_param_table, loc_param_num);
fclose(conf_fp);
}
/* Initialize logging mechanism with parsed data */
loc_logger_init(DEBUG_LEVEL, TIMESTAMP);

View file

@ -37,11 +37,15 @@
#define LOC_MAX_PARAM_STRING 80
#define LOC_MAX_PARAM_LINE (LOC_MAX_PARAM_NAME + LOC_MAX_PARAM_STRING)
#define UTIL_UPDATE_CONF(conf_data, len, config_table) \
loc_update_conf((conf_data), (len), (config_table), \
sizeof(config_table) / sizeof(config_table[0]))
#define UTIL_READ_CONF_DEFAULT(filename) \
loc_read_conf((filename), NULL, 0);
#define UTIL_READ_CONF(filename, config_table) \
loc_read_conf((filename), (config_table), sizeof(config_table) / sizeof(config_table[0]))
loc_read_conf((filename), (config_table), sizeof(config_table) / sizeof(config_table[0]))
/*=============================================================================
*
@ -73,10 +77,13 @@ extern "C" {
* MODULE EXPORTED FUNCTIONS
*
*============================================================================*/
extern void loc_read_conf(const char* conf_file_name,
loc_param_s_type* config_table,
uint32_t table_length);
extern int loc_read_conf_r(FILE *conf_fp, loc_param_s_type* config_table, uint32_t table_length);
void loc_read_conf(const char* conf_file_name,
loc_param_s_type* config_table,
uint32_t table_length);
int loc_read_conf_r(FILE *conf_fp, loc_param_s_type* config_table,
uint32_t table_length);
int loc_update_conf(const char* conf_data, int32_t length,
loc_param_s_type* config_table, uint32_t table_length);
#ifdef __cplusplus
}
#endif