Esempio n. 1
0
void PrefsDb::synchronizeCustomerCareInfo() {
	
	char* jsonStr = Utils::readFile(s_custCareNumberFile);
	if (!jsonStr) {
		g_warning("PrefsDb::synchronizeCustomerCareInfo(): Failed to load customer care file: %s", s_custCareNumberFile);
		return;
	}

	json_object* root = 0;
	std::string ccnumber;
	int ret;
	gchar* queryStr;

	root = json_tokener_parse(jsonStr);
	if (!root || is_error(root)) {
		g_warning("PrefsDb::synchronizeCustomerCareInfo(): Failed to parse file contents into json");
		return;
	}
	
	json_object_object_foreach(root, key, val) {

		if (val == NULL)
			continue;		//TODO: really should delete this key if it is in the database
		char * p_cDbv = json_object_to_json_string(val);
		if (p_cDbv == NULL)
			continue;
		
		//check the key to see if it exists in the db already
		std::string cv = getPref(key);
		std::string dbv(p_cDbv);
		
		if (cv.length() == 0) {
			queryStr = g_strdup_printf("INSERT INTO Preferences "
					"VALUES ('%s', '%s')",
					key, json_object_to_json_string(val));
			if (!queryStr) {
				g_warning("PrefsDb::synchronizeCustomerCareInfo(): Failed to allocate query string for key %s",key);
				continue;
			}

			ret = sqlite3_exec(m_prefsDb, queryStr, NULL, NULL, NULL);
			g_free(queryStr);

			if (ret) {
				g_warning("PrefsDb::synchronizeCustomerCareInfo(): Failed to execute query for key %s", key);
				continue;
			}
		}
		else if (cv != dbv) {
			//update
			setPref(key,dbv);
		}
	}
	
	json_object_put(root);
		
}
Esempio n. 2
0
void PrefsDb::synchronizePlatformDefaults() {
	
	char* jsonStr = Utils::readFile(s_defaultPlatformPrefsFile);
	if (!jsonStr) {
		g_warning("PrefsDb::synchronizePlatformDefaults(): Failed to load default platform prefs file: %s", s_defaultPlatformPrefsFile);
		return;
	}

	json_object* root = 0;
	json_object* label = 0;
	std::string ccnumber;
	int ret;
	gchar* queryStr;

	root = json_tokener_parse(jsonStr);
	if (!root || is_error(root)) {
		g_warning("PrefsDb::synchronizePlatformDefaults(): Failed to parse file contents into json");
		return;
	}

	label = json_object_object_get(root, "preferences");
	if (!label || is_error(label)) {
		g_warning("PrefsDb::synchronizePlatformDefaults(): Failed to get preferences entry from file");
		json_object_put(root);
		return;
	}

	json_object_object_foreach(label, key, val) {

		if (val == NULL)
			continue;		//TODO: really should delete this key if it is in the database
		char * p_cDbv = json_object_to_json_string(val);
		if (p_cDbv == NULL)
			continue;
		//check the key to see if it exists in the db already
		
		std::string cv = getPref(key);
		std::string dbv(p_cDbv);
		
		if (cv.length() == 0) {
			queryStr = g_strdup_printf("INSERT INTO Preferences "
					"VALUES ('%s', '%s')",
					key, json_object_to_json_string(val));
			if (!queryStr) {
				g_warning("PrefsDb::synchronizePlatformDefaults(): Failed to allocate query string for key %s",key);
				continue;
			}

			ret = sqlite3_exec(m_prefsDb, queryStr, NULL, NULL, NULL);
			g_free(queryStr);

			if (ret) {
				g_warning("PrefsDb::synchronizePlatformDefaults(): Failed to execute query for key %s", key);
				continue;
			}
		}
		
	}
	
	json_object_put(root);
		
}
Esempio n. 3
0
/*PARSE RADAR DATA - traverse the two data array's and
 * use the start_array to determine
 * the start of a pulse.  Keep track of the pulse,
 * and log the pulse data based on the
 * pulse count into a 2 dimensional array, response_parsed.
 * NOTE: intensity_time must be of size NUM_TRIGGERS*SAMPLES_PER_PULSE*/
void process_radar_data(char* intensity_time,
                      rdata_t* trigger, rdata_t* response, int buf_size){

   int count = 0;
   int i, j;
   rdata_t average, max;

   assert(intensity_time != NULL);
   assert(trigger != NULL);
   assert(response != NULL);

   /*for size of radar data to be correct, init_processing must be
    *called before this function                                */
   rdata_t response_parsed[NUM_TRIGGERS][size_of_sendarray];

   /*create a simplied edge trigger based off the transmit signal*/
   memset(start, 0, buf_size);
   find_trigger_start(trigger, start, buf_size);

#ifdef PRINT_TRIGGERING
   for (i = 0; i < buf_size; i++) {
     printf("%d: %d %f %f\n", i, start[i], trigger[i], response[i]);
   }
#endif

   for(i = 13; i < buf_size-SAMPLES_PER_PULSE; i++){

     /*find the trigger and if found, load data into the 2-d array,
       while keeping track of the time of the pulse*/
     if (start[i] == 1 && none(start,i-11,i-1) == 0){
       rdata_t_cpy(response_parsed[count], &response[i], SAMPLES_PER_PULSE);
       count = count + 1;
     }

     /*only record for a preset amount of triggers*/
     if (count == NUM_TRIGGERS)
       break;

   }

#ifdef PRINT_PARSED

   for (i = 0; i < NUM_TRIGGERS; i++){
     for (j = 0; j < SAMPLES_PER_PULSE/10; j++) {
       printf("%d ", (int)floorf(response_parsed[i][j]));
     }
     printf("\n");
   }
#endif

   /*subtract the avarage value of each sub array!*/
   for(i = 0; i < NUM_TRIGGERS; i++){
       average = mean(response_parsed[i], 0, SAMPLES_PER_PULSE-1);
       rdata_t_addi(response_parsed[i], -1.0*average, SAMPLES_PER_PULSE);
   }


#ifdef PRINT_AVERAGED

   for (i = 0; i < NUM_TRIGGERS; i++){
     for (j = 0; j < SAMPLES_PER_PULSE/10; j++) {
       printf("%d ", (int)floorf(response_parsed[i][j]));
     }
     printf("\n");
   }
#endif



   /*create 2-pulse cancelor*/
   for (i = 1; i < NUM_TRIGGERS; i++)
       sub_array(response_parsed[i], response_parsed[i-1], SAMPLES_PER_PULSE);


#ifdef PRINT_CANCELOR

   for (i = 0; i < NUM_TRIGGERS; i++){
     for (j = 0; j < SAMPLES_PER_PULSE/10; j++) {
       printf("%d ", (int)floorf(response_parsed[i][j]));
     }
     printf("\n");
   }
#endif


   /*ifft and convert to intensity values*/
   for(i = 0; i < NUM_TRIGGERS; i++){
       ifft(ifft_array,response_parsed[i]);
       rdata_t_cpy(response_parsed[i], ifft_array, size_of_sendarray);
       dbv(response_parsed[i], size_of_sendarray);
   }

#ifdef PRINT_IFFT
   for (i = 0; i < NUM_TRIGGERS; i++){
     for (j = 0; j < SAMPLES_PER_PULSE/10; j++) {
       printf("%d ", (int)floor(response_parsed[i][j]));
     }
     printf("\n");
   }
#endif


   max = find_max(&response_parsed[0][0], NUM_TRIGGERS*size_of_sendarray);

   rdata_t_addi(&response_parsed[0][0], -1.0*max, NUM_TRIGGERS*size_of_sendarray);

   intensify(intensity_time, &(response_parsed[0][0]), size_of_sendarray*NUM_TRIGGERS);


#ifdef PRINT_FINAL
   for (i = 0; i < NUM_TRIGGERS; i++){
     for (j = 0; j < SAMPLES_PER_PULSE/10; j++) {
         printf("%d ", (unsigned int)(unsigned char)floor(intensity_time[NUM_TRIGGERS*i+j]));
     }
     printf("\n");
   }
#endif



}