diff options
author | Dante Russo <drusso@codeaurora.org> | 2013-06-05 09:11:09 -0700 |
---|---|---|
committer | Dante Russo <drusso@codeaurora.org> | 2013-06-11 14:58:24 -0700 |
commit | 85f672fa7130c68030239940fcfb9308c4f49f33 (patch) | |
tree | f27d85c1f69e1e6654cf5b7a761f8ad7f359b2cf /utils | |
parent | 838f00b1ef086231e9ef49744eaf7006619b27aa (diff) | |
download | gps-85f672fa7130c68030239940fcfb9308c4f49f33.tar.gz |
Merge branch jb_mr1 into jb_2.6
Merged from from label
AU_LINUX_ANDROID_JB_MR1.04.02.02.049.306
Change-Id: Ie2f7fd3d25f8f28f5d1b6e733974bb5f75999ee8
Diffstat (limited to 'utils')
-rw-r--r--[-rwxr-xr-x] | utils/Android.mk | 8 | ||||
-rw-r--r-- | utils/linked_list.c | 4 | ||||
-rw-r--r-- | utils/linked_list.h | 4 | ||||
-rw-r--r-- | utils/loc_cfg.cpp | 260 | ||||
-rw-r--r-- | utils/loc_cfg.h | 49 | ||||
-rw-r--r-- | utils/loc_log.cpp | 35 | ||||
-rw-r--r-- | utils/loc_log.h | 6 | ||||
-rw-r--r-- | utils/loc_target.cpp | 118 | ||||
-rw-r--r-- | utils/loc_target.h | 52 | ||||
-rw-r--r-- | utils/log_util.h | 17 | ||||
-rw-r--r-- | utils/msg_q.c | 6 | ||||
-rw-r--r-- | utils/msg_q.h | 4 |
12 files changed, 378 insertions, 185 deletions
diff --git a/utils/Android.mk b/utils/Android.mk index ff2810b..912dcae 100755..100644 --- a/utils/Android.mk +++ b/utils/Android.mk @@ -16,12 +16,15 @@ LOCAL_SRC_FILES += \ loc_log.cpp \ loc_cfg.cpp \ msg_q.c \ - linked_list.c + linked_list.c \ + loc_target.cpp LOCAL_CFLAGS += \ -fno-short-enums \ -D_ANDROID_ +LOCAL_LDFLAGS += -Wl,--export-dynamic + ## Includes LOCAL_C_INCLUDES:= @@ -31,7 +34,8 @@ LOCAL_COPY_HEADERS:= \ loc_cfg.h \ log_util.h \ linked_list.h \ - msg_q.h + msg_q.h \ + loc_target.h LOCAL_MODULE := libgps.utils diff --git a/utils/linked_list.c b/utils/linked_list.c index 16f2aa2..31ec52d 100644 --- a/utils/linked_list.c +++ b/utils/linked_list.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2011, Code Aurora Forum. All rights reserved. +/* Copyright (c) 2011, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -9,7 +9,7 @@ * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. - * * Neither the name of Code Aurora Forum, Inc. nor the names of its + * * Neither the name of The Linux Foundation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * diff --git a/utils/linked_list.h b/utils/linked_list.h index cfc945a..a85f09a 100644 --- a/utils/linked_list.h +++ b/utils/linked_list.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2011, Code Aurora Forum. All rights reserved. +/* Copyright (c) 2011, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -9,7 +9,7 @@ * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. - * * Neither the name of Code Aurora Forum, Inc. nor the names of its + * * Neither the name of The Linux Foundation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * diff --git a/utils/loc_cfg.cpp b/utils/loc_cfg.cpp index de96078..e4a4772 100644 --- a/utils/loc_cfg.cpp +++ b/utils/loc_cfg.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2011 Code Aurora Forum. All rights reserved. +/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -9,7 +9,7 @@ * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. - * * Neither the name of Code Aurora Forum, Inc. nor the names of its + * * Neither the name of The Linux Foundation, nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * @@ -47,77 +47,18 @@ *============================================================================*/ /* Parameter data */ -loc_gps_cfg_s_type gps_conf; +static uint8_t DEBUG_LEVEL = 3; +static uint8_t TIMESTAMP = 0; /* Parameter spec table */ - -loc_param_s_type loc_parameter_table[] = +static loc_param_s_type loc_parameter_table[] = { - {"INTERMEDIATE_POS", &gps_conf.INTERMEDIATE_POS, 'n'}, - {"ACCURACY_THRES", &gps_conf.ACCURACY_THRES, 'n'}, - {"ENABLE_WIPER", &gps_conf.ENABLE_WIPER, 'n'}, - /* DEBUG LEVELS: 0 - none, 1 - Error, 2 - Warning, 3 - Info - 4 - Debug, 5 - Verbose */ - {"DEBUG_LEVEL", &gps_conf.DEBUG_LEVEL, 'n'}, - {"SUPL_VER", &gps_conf.SUPL_VER, 'n'}, - {"CAPABILITIES", &gps_conf.CAPABILITIES, 'n'}, - {"TIMESTAMP", &gps_conf.TIMESTAMP, 'n'}, - {"GYRO_BIAS_RANDOM_WALK", &gps_conf.GYRO_BIAS_RANDOM_WALK, 'f'}, - {"SENSOR_ACCEL_BATCHES_PER_SEC", &gps_conf.SENSOR_ACCEL_BATCHES_PER_SEC, 'n'}, - {"SENSOR_ACCEL_SAMPLES_PER_BATCH", &gps_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH, 'n'}, - {"SENSOR_GYRO_BATCHES_PER_SEC", &gps_conf.SENSOR_GYRO_BATCHES_PER_SEC, 'n'}, - {"SENSOR_GYRO_SAMPLES_PER_BATCH", &gps_conf.SENSOR_GYRO_SAMPLES_PER_BATCH, 'n'}, - {"SENSOR_CONTROL_MODE", &gps_conf.SENSOR_CONTROL_MODE, 'n'}, - {"SENSOR_USAGE", &gps_conf.SENSOR_USAGE, 'n'}, + {"DEBUG_LEVEL", &DEBUG_LEVEL, NULL, 'n'}, + {"TIMESTAMP", &TIMESTAMP, NULL, 'n'}, }; - int loc_param_num = sizeof(loc_parameter_table) / sizeof(loc_param_s_type); /*=========================================================================== -FUNCTION loc_default_parameters - -DESCRIPTION - Resets the parameters to default - -DEPENDENCIES - N/A - -RETURN VALUE - None - -SIDE EFFECTS - N/A -===========================================================================*/ - -static void loc_default_parameters() -{ - /* defaults */ - gps_conf.INTERMEDIATE_POS = 0; - gps_conf.ACCURACY_THRES = 0; - gps_conf.ENABLE_WIPER = 0; - gps_conf.DEBUG_LEVEL = 3; /* debug level */ - gps_conf.SUPL_VER = 0x10000; - gps_conf.CAPABILITIES = 0x7; - gps_conf.TIMESTAMP = 0; - - gps_conf.GYRO_BIAS_RANDOM_WALK = 0; - - gps_conf.SENSOR_ACCEL_BATCHES_PER_SEC = 2; - gps_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH = 5; - gps_conf.SENSOR_GYRO_BATCHES_PER_SEC = 2; - gps_conf.SENSOR_GYRO_SAMPLES_PER_BATCH = 5; - gps_conf.SENSOR_CONTROL_MODE = 0; /* AUTO */ - gps_conf.SENSOR_USAGE = 0; /* Enabled */ - - /* Value MUST be set by OEMs in configuration for sensor-assisted - navigation to work. There is NO default value */ - gps_conf.GYRO_BIAS_RANDOM_WALK_VALID = 0; - - /* reset logging mechanism */ - loc_logger_init(gps_conf.DEBUG_LEVEL, 0); -} - -/*=========================================================================== FUNCTION trim_space DESCRIPTION @@ -161,11 +102,26 @@ void trim_space(char *org_string) if (last_nonspace) { *last_nonspace = '\0'; } } +typedef struct loc_param_v_type +{ + char* param_name; + + char* param_str_value; + int param_int_value; + double param_double_value; +}loc_param_v_type; + /*=========================================================================== -FUNCTION loc_read_gps_conf +FUNCTION loc_set_config_entry DESCRIPTION - Reads the gps.conf file and sets global parameter data + Potentially sets a given configuration table entry based on the passed in + configuration value. This is done by using a string comparison of the + parameter names and those found in the configuration file. + +PARAMETERS: + config_entry: configuration entry in the table to possibly set + config_value: value to store in the entry if the parameter names match DEPENDENCIES N/A @@ -176,97 +132,151 @@ RETURN VALUE SIDE EFFECTS N/A ===========================================================================*/ -void loc_read_gps_conf(void) +void loc_set_config_entry(loc_param_s_type* config_entry, loc_param_v_type* config_value) +{ + if(NULL == config_entry || NULL == config_value) + { + LOC_LOGE("%s: INVALID config entry or parameter", __FUNCTION__); + return; + } + + if (strcmp(config_entry->param_name, config_value->param_name) == 0 && + config_entry->param_ptr) + { + switch (config_entry->param_type) + { + case 's': + if (strcmp(config_value->param_str_value, "NULL") == 0) + { + *((char*)config_entry->param_ptr) = '\0'; + } + else { + strlcpy((char*) config_entry->param_ptr, + config_value->param_str_value, + LOC_MAX_PARAM_STRING + 1); + } + /* Log INI values */ + LOC_LOGD("%s: PARAM %s = %s", __FUNCTION__, config_entry->param_name, (char*)config_entry->param_ptr); + + if(NULL != config_entry->param_set) + { + *(config_entry->param_set) = 1; + } + break; + 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); + + if(NULL != config_entry->param_set) + { + *(config_entry->param_set) = 1; + } + break; + 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); + + if(NULL != config_entry->param_set) + { + *(config_entry->param_set) = 1; + } + break; + default: + LOC_LOGE("%s: PARAM %s parameter type must be n, f, or s", __FUNCTION__, config_entry->param_name); + } + } +} + +/*=========================================================================== +FUNCTION loc_read_conf + +DESCRIPTION + 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_file_name: configuration file to read + config_table: table definition of strings to places to store information + table_length: length of the configuration table + +DEPENDENCIES + N/A + +RETURN VALUE + None + +SIDE EFFECTS + N/A +===========================================================================*/ +void loc_read_conf(const char* conf_file_name, loc_param_s_type* config_table, uint32_t table_length) { FILE *gps_conf_fp = NULL; char input_buf[LOC_MAX_PARAM_LINE]; /* declare a char array */ char *lasts; - char *param_name, *param_str_value; - int param_int_value = 0; - double param_double_value = 0; - int i; + loc_param_v_type config_value; + uint32_t i; - loc_default_parameters(); - - if((gps_conf_fp = fopen(GPS_CONF_FILE, "r")) != NULL) + if((gps_conf_fp = fopen(conf_file_name, "r")) != NULL) { - LOC_LOGD("%s: using %s", __FUNCTION__, GPS_CONF_FILE); + LOC_LOGD("%s: using %s", __FUNCTION__, conf_file_name); } else { - LOC_LOGW("%s: no %s file, using defaults", __FUNCTION__, GPS_CONF_FILE); + LOC_LOGW("%s: no %s file found", __FUNCTION__, conf_file_name); + loc_logger_init(DEBUG_LEVEL, TIMESTAMP); return; /* no parameter file */ } + /* Clear all validity bits */ + for(i = 0; NULL != config_table && i < table_length; i++) + { + if(NULL != config_table[i].param_set) + { + *(config_table[i].param_set) = 0; + } + } + while(fgets(input_buf, LOC_MAX_PARAM_LINE, gps_conf_fp) != NULL) { + memset(&config_value, 0, sizeof(config_value)); + /* Separate variable and value */ - param_name = strtok_r(input_buf, "=", &lasts); - if (param_name == NULL) continue; /* skip lines that do not contain "=" */ - param_str_value = strtok_r(NULL, "=", &lasts); - if (param_str_value == NULL) continue; /* skip lines that do not contain two operands */ + config_value.param_name = strtok_r(input_buf, "=", &lasts); + if (config_value.param_name == NULL) continue; /* skip lines that do not contain "=" */ + config_value.param_str_value = strtok_r(NULL, "=", &lasts); + if (config_value.param_str_value == NULL) continue; /* skip lines that do not contain two operands */ /* Trim leading and trailing spaces */ - trim_space(param_name); - trim_space(param_str_value); - - // printf("*(%s) = (%s)\n", param_name, param_str_value); + trim_space(config_value.param_name); + trim_space(config_value.param_str_value); /* Parse numerical value */ - if (param_str_value[0] == '0' && tolower(param_str_value[1]) == 'x') + if (config_value.param_str_value[0] == '0' && tolower(config_value.param_str_value[1]) == 'x') { /* hex */ - param_int_value = (int) strtol(¶m_str_value[2], (char**) NULL, 16); + config_value.param_int_value = (int) strtol(&config_value.param_str_value[2], (char**) NULL, 16); } else { - param_double_value = (double) atof(param_str_value); /* float */ - param_int_value = atoi(param_str_value); /* dec */ + 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 */ } - if (strcmp("GYRO_BIAS_RANDOM_WALK", param_name) == 0) + for(i = 0; NULL != config_table && i < table_length; i++) { - gps_conf.GYRO_BIAS_RANDOM_WALK_VALID = 1; + loc_set_config_entry(&config_table[i], &config_value); } for(i = 0; i < loc_param_num; i++) { - if (strcmp(loc_parameter_table[i].param_name, param_name) == 0 && - loc_parameter_table[i].param_ptr) - { - switch (loc_parameter_table[i].param_type) - { - case 's': - if (strcmp(param_str_value, "NULL") == 0) - { - *((char*)loc_parameter_table[i].param_ptr) = '\0'; - } - else { - strlcpy((char*) loc_parameter_table[i].param_ptr, - param_str_value, - LOC_MAX_PARAM_STRING + 1); - } - /* Log INI values */ - LOC_LOGD("%s: PARAM %s = %s", __FUNCTION__, param_name, (char*)loc_parameter_table[i].param_ptr); - break; - case 'n': - *((int *)loc_parameter_table[i].param_ptr) = param_int_value; - /* Log INI values */ - LOC_LOGD("%s: PARAM %s = %d", __FUNCTION__, param_name, param_int_value); - break; - case 'f': - *((double *)loc_parameter_table[i].param_ptr) = param_double_value; - /* Log INI values */ - LOC_LOGD("%s: PARAM %s = %f", __FUNCTION__, param_name, param_double_value); - break; - default: - LOC_LOGE("%s: PARAM %s parameter type must be n or n", __FUNCTION__, param_name); - } - } + loc_set_config_entry(&loc_parameter_table[i], &config_value); } } fclose(gps_conf_fp); /* Initialize logging mechanism with parsed data */ - loc_logger_init(gps_conf.DEBUG_LEVEL, gps_conf.TIMESTAMP); + loc_logger_init(DEBUG_LEVEL, TIMESTAMP); } diff --git a/utils/loc_cfg.h b/utils/loc_cfg.h index ffeb83c..df83338 100644 --- a/utils/loc_cfg.h +++ b/utils/loc_cfg.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2011 Code Aurora Forum. All rights reserved. +/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -9,7 +9,7 @@ * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. - * * Neither the name of Code Aurora Forum, Inc. nor the names of its + * * Neither the name of The Linux Foundation, nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * @@ -30,14 +30,17 @@ #ifndef LOC_CFG_H #define LOC_CFG_H -#define LOC_MAX_PARAM_NAME 36 +#include <stdint.h> + +#define LOC_MAX_PARAM_NAME 48 #define LOC_MAX_PARAM_STRING 80 #define LOC_MAX_PARAM_LINE 80 -// Don't want to overwrite the pre-def'ed value -#ifndef GPS_CONF_FILE -#define GPS_CONF_FILE "/etc/gps.conf" //??? platform independent -#endif +#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])) /*============================================================================= * @@ -48,30 +51,12 @@ typedef struct { char param_name[LOC_MAX_PARAM_NAME]; void *param_ptr; - char param_type; /* 'n' for number; 's' for string */ + uint8_t *param_set; /* was this value set by config file? */ + char param_type; /* 'n' for number, + 's' for string, + 'f' for float */ } loc_param_s_type; -/* GPS.conf support */ -typedef struct loc_gps_cfg_s -{ - unsigned long INTERMEDIATE_POS; - unsigned long ACCURACY_THRES; - unsigned long ENABLE_WIPER; - unsigned long DEBUG_LEVEL; - unsigned long SUPL_VER; - unsigned long CAPABILITIES; - unsigned long TIMESTAMP; - unsigned long 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_CONTROL_MODE; - unsigned long SENSOR_USAGE; - // char string_val[LOC_MAX_PARAM_STRING + 1]; /* An example string value */ -} loc_gps_cfg_s_type; - /*============================================================================= * * MODULE EXTERNAL DATA @@ -82,14 +67,14 @@ typedef struct loc_gps_cfg_s extern "C" { #endif -extern loc_gps_cfg_s_type gps_conf; - /*============================================================================= * * MODULE EXPORTED FUNCTIONS * *============================================================================*/ -extern void loc_read_gps_conf(void); +extern void loc_read_conf(const char* conf_file_name, + loc_param_s_type* config_table, + uint32_t table_length); #ifdef __cplusplus } diff --git a/utils/loc_log.cpp b/utils/loc_log.cpp index e4fb76c..ecdfc8f 100644 --- a/utils/loc_log.cpp +++ b/utils/loc_log.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2011 Code Aurora Forum. All rights reserved. +/* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -9,7 +9,7 @@ * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. - * * Neither the name of Code Aurora Forum, Inc. nor the names of its + * * Neither the name of The Linux Foundation, nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * @@ -34,7 +34,6 @@ #include <sys/time.h> #include "loc_log.h" #include "msg_q.h" - #include "log_util.h" // Logging Improvements @@ -100,6 +99,36 @@ const char* log_succ_fail_string(int is_succ) return is_succ? "successful" : "failed"; } +//Target names +loc_name_val_s_type target_name[] = +{ + NAME_VAL(TARGET_OTHER), + NAME_VAL(TARGET_APQ8064_STANDALONE), + NAME_VAL(TARGET_APQ8064_FUSION3), + NAME_VAL(TARGET_MPQ8064), + NAME_VAL(TARGET_MSM8930), + NAME_VAL(TARGET_APQ8030_STANDALONE) +}; + +static int target_name_num = sizeof(target_name)/sizeof(loc_name_val_s_type); + +/*=========================================================================== + +FUNCTION loc_get_target_name + +DESCRIPTION + Returns pointer to a string that contains name of the target + + XX:XX:XX.000\0 + +RETURN VALUE + The target name string + +===========================================================================*/ +const char *loc_get_target_name(targetEnumType target) +{ + return loc_get_name_from_val(target_name, target_name_num, (long)target); +} /*=========================================================================== diff --git a/utils/loc_log.h b/utils/loc_log.h index 8b071a4..abe29b7 100644 --- a/utils/loc_log.h +++ b/utils/loc_log.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2011 Code Aurora Forum. All rights reserved. +/* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -9,7 +9,7 @@ * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. - * * Neither the name of Code Aurora Forum, Inc. nor the names of its + * * Neither the name of The Linux Foundation, nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * @@ -36,6 +36,7 @@ extern "C" #endif #include <ctype.h> +#include "loc_target.h" typedef struct { @@ -54,6 +55,7 @@ typedef struct const char* loc_get_name_from_mask(loc_name_val_s_type table[], int table_size, long mask); const char* loc_get_name_from_val(loc_name_val_s_type table[], int table_size, long value); const char* loc_get_msg_q_status(int status); +const char* loc_get_target_name(targetEnumType target); extern const char* log_succ_fail_string(int is_succ); diff --git a/utils/loc_target.cpp b/utils/loc_target.cpp new file mode 100644 index 0000000..92eaa45 --- /dev/null +++ b/utils/loc_target.cpp @@ -0,0 +1,118 @@ +/* Copyright (c) 2012, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <errno.h> +#include <hardware/gps.h> +#include <cutils/properties.h> +#include "loc_target.h" +#include "loc_log.h" +#include "log_util.h" + +#define APQ8064_ID_1 "109" +#define APQ8064_ID_2 "153" +#define MPQ8064_ID_1 "130" +#define MSM8930_ID_1 "142" +#define MSM8930_ID_2 "116" +#define APQ8030_ID_1 "157" +#define APQ8074_ID_1 "184" + +#define LINE_LEN 100 +#define STR_LIQUID "Liquid" +#define STR_SURF "Surf" +#define STR_MTP "MTP" +#define STR_APQ "apq" +#define IS_STR_END(c) ((c) == '\0' || (c) == '\n' || (c) == '\r') +#define LENGTH(s) (sizeof(s) - 1) +#define GPS_CHECK_NO_ERROR 0 +#define GPS_CHECK_NO_GPS_HW 1 + +static int gss_fd = 0; + +static int read_a_line(const char * file_path, char * line, int line_size) +{ + FILE *fp; + int result = 0; + + * line = '\0'; + fp = fopen(file_path, "r" ); + if( fp == NULL ) { + LOC_LOGE("open failed: %s: %s\n", file_path, strerror(errno)); + result = -1; + } else { + int len; + fgets(line, line_size, fp); + len = strlen(line); + len = len < line_size - 1? len : line_size - 1; + line[len] = '\0'; + LOC_LOGD("cat %s: %s", file_path, line); + fclose(fp); + } + return result; +} + +targetEnumType get_target(void) +{ + targetEnumType target = TARGET_OTHER; + + char hw_platform[] = "/sys/devices/system/soc/soc0/hw_platform"; + char id[] = "/sys/devices/system/soc/soc0/id"; + char mdm[] = "/dev/mdm"; // No such file or directory + + char rd_hw_platform[LINE_LEN]; + char rd_id[LINE_LEN]; + char rd_mdm[LINE_LEN]; + + read_a_line(hw_platform, rd_hw_platform, LINE_LEN); + read_a_line( id, rd_id, LINE_LEN); + + if( (!memcmp(rd_hw_platform, STR_LIQUID, LENGTH(STR_LIQUID)) && IS_STR_END(rd_hw_platform[LENGTH(STR_LIQUID)])) || + (!memcmp(rd_hw_platform, STR_SURF, LENGTH(STR_SURF)) && IS_STR_END(rd_hw_platform[LENGTH(STR_SURF)])) || + (!memcmp(rd_hw_platform, STR_MTP, LENGTH(STR_MTP)) && IS_STR_END(rd_hw_platform[LENGTH(STR_MTP)]))) { + if (!read_a_line( mdm, rd_mdm, LINE_LEN)) + target = TARGET_APQ8064_FUSION3; + else if( (!memcmp(rd_id, APQ8064_ID_1, LENGTH(APQ8064_ID_1)) && IS_STR_END(rd_id[LENGTH(APQ8064_ID_1)])) || + (!memcmp(rd_id, APQ8064_ID_2, LENGTH(APQ8064_ID_2)) && IS_STR_END(rd_id[LENGTH(APQ8064_ID_2)])) ) + target = TARGET_APQ8064_STANDALONE; + else if((!memcmp(rd_id, APQ8030_ID_1, LENGTH(APQ8030_ID_1)) && IS_STR_END(rd_id[LENGTH(APQ8030_ID_1)]))) + target = TARGET_APQ8030_STANDALONE; + } + else if (!memcmp(rd_id, APQ8074_ID_1, LENGTH(APQ8074_ID_1)) && IS_STR_END(rd_id[LENGTH(APQ8074_ID_1)])) + target = TARGET_APQ8064_STANDALONE; + else if( !memcmp(rd_id, MPQ8064_ID_1, LENGTH(MPQ8064_ID_1)) && IS_STR_END(rd_id[LENGTH(MPQ8064_ID_1)]) ) + target = TARGET_MPQ8064; + else if( (!memcmp(rd_id, MSM8930_ID_1, LENGTH(MSM8930_ID_1)) && IS_STR_END(rd_id[LENGTH(MSM8930_ID_1)])) || + (!memcmp(rd_id, MSM8930_ID_2, LENGTH(MSM8930_ID_2)) && IS_STR_END(rd_id[LENGTH(MSM8930_ID_2)])) ) + target = TARGET_MSM8930; + return target; +} diff --git a/utils/loc_target.h b/utils/loc_target.h new file mode 100644 index 0000000..32c64b5 --- /dev/null +++ b/utils/loc_target.h @@ -0,0 +1,52 @@ +/* Copyright (c) 2012, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef LOC_TARGET_H +#define LOC_TARGET_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef enum { + TARGET_OTHER = 0, + TARGET_APQ8064_STANDALONE, + TARGET_APQ8064_FUSION3, + TARGET_MPQ8064, + TARGET_MSM8930, + TARGET_APQ8030_STANDALONE +}targetEnumType; + +targetEnumType get_target(void); + +#ifdef __cplusplus +} +#endif + +#endif /*LOC_TARGET_H*/ diff --git a/utils/log_util.h b/utils/log_util.h index b3dae3c..56dca62 100644 --- a/utils/log_util.h +++ b/utils/log_util.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2011 Code Aurora Forum. All rights reserved. +/* Copyright (c) 2011 The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -9,7 +9,7 @@ * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. - * * Neither the name of Code Aurora Forum, Inc. nor the names of its + * * Neither the name of The Linux Foundation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * @@ -86,15 +86,15 @@ else if (loc_logger.DEBUG_LEVEL <= 0) { ALOGW("W/"__VA_ARGS__); } #define LOC_LOGI(...) \ if (loc_logger.DEBUG_LEVEL >= 3) { ALOGE("I/"__VA_ARGS__); } \ -else if (loc_logger.DEBUG_LEVEL <= 0) { ALOGI("W/"__VA_ARGS__); } +else if (loc_logger.DEBUG_LEVEL <= 0) { ALOGI("I/"__VA_ARGS__); } #define LOC_LOGD(...) \ if (loc_logger.DEBUG_LEVEL >= 4) { ALOGE("D/"__VA_ARGS__); } \ -else if (loc_logger.DEBUG_LEVEL <= 0) { ALOGD("W/"__VA_ARGS__); } +else if (loc_logger.DEBUG_LEVEL <= 0) { ALOGD("D/"__VA_ARGS__); } #define LOC_LOGV(...) \ if (loc_logger.DEBUG_LEVEL >= 5) { ALOGE("V/"__VA_ARGS__); } \ -else if (loc_logger.DEBUG_LEVEL <= 0) { ALOGV("W/"__VA_ARGS__); } +else if (loc_logger.DEBUG_LEVEL <= 0) { ALOGV("V/"__VA_ARGS__); } #else /* DEBUG_DMN_LOC_API */ @@ -135,7 +135,6 @@ else if (loc_logger.DEBUG_LEVEL <= 0) { ALOGV("W/"__VA_ARGS__); } #define EXIT_LOG(SPEC, VAL) LOG_V(EXIT_TAG, __func__, SPEC, VAL) -#ifdef DEBUG_TRACE_CALLFLOW // Used for logging callflow from Android Framework #define ENTRY_LOG_CALLFLOW() LOG_I(FROM_AFW, __func__, %s, "") // Used for logging callflow to Modem @@ -144,12 +143,6 @@ else if (loc_logger.DEBUG_LEVEL <= 0) { ALOGV("W/"__VA_ARGS__); } #define MODEM_LOG_CALLFLOW(SPEC, VAL) LOG_I(FROM_MODEM, __func__, SPEC, VAL) // Used for logging callflow to Android Framework #define CALLBACK_LOG_CALLFLOW(CB, SPEC, VAL) LOG_I(TO_AFW, CB, SPEC, VAL) -#else -#define ENTRY_LOG_CALLFLOW() -#define EXIT_LOG_CALLFLOW(SPEC, VAL) -#define MODEM_LOG_CALLFLOW(SPEC, VAL) -#define CALLBACK_LOG_CALLFLOW(CB, SPEC, VAL) -#endif #ifdef __cplusplus } diff --git a/utils/msg_q.c b/utils/msg_q.c index 252921e..2c26417 100644 --- a/utils/msg_q.c +++ b/utils/msg_q.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2011, Code Aurora Forum. All rights reserved. +/* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -9,7 +9,7 @@ * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. - * * Neither the name of Code Aurora Forum, Inc. nor the names of its + * * Neither the name of The Linux Foundation, nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * @@ -249,7 +249,7 @@ msq_q_err_type msg_q_rcv(void* msg_q_data, void** msg_obj) pthread_mutex_unlock(&p_msg_q->list_mutex); - LOC_LOGD("%s: Received message %p rv = %d\n", __FUNCTION__, *msg_obj, rv); + LOC_LOGD("%s: Received message 0x%08X rv = %d\n", __FUNCTION__, *msg_obj, rv); return rv; } diff --git a/utils/msg_q.h b/utils/msg_q.h index 4171540..d3d5cc5 100644 --- a/utils/msg_q.h +++ b/utils/msg_q.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2011, Code Aurora Forum. All rights reserved. +/* Copyright (c) 2011, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -9,7 +9,7 @@ * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. - * * Neither the name of Code Aurora Forum, Inc. nor the names of its + * * Neither the name of The Linux Foundation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * |