Exemple #1
0
int
getprop_main(const struct cmd_getprop_info* info)
{
    const char* format = info->getprop.format;
    const char* format_not_found = info->getprop.format_not_found;
    bool null = info->getprop.null;
    if (null && format == NULL && format_not_found == NULL)
        usage_error("must supply --format or "
                    "--format-not-found or both if using -0");

    find_symbol_in_libc("__system_property_foreach",
                        &property_foreach);
    if (property_foreach == NULL)
        property_foreach = compat_property_foreach;

    dbg("using %s for property enumeration",
        property_foreach == compat_property_foreach
        ? "compat_property_foreach"
        : "__system_property_foreach");

    int exit_status = 0;

    struct json_writer* writer = NULL;
    if (format == NULL && format_not_found == NULL) {
        writer = json_writer_create(xstdout);
        json_begin_object(writer);
    }

    const char** properties = ARGV_CONCAT(info->properties);
    bool first = true;
    char sep = null ? '\0' : '\n';
    if (*properties == NULL) {
        struct property_vector* pv = find_all_properties();
        char prev_name[PROP_NAME_MAX];
        for (size_t i = 0; i < pv->size; ++i) {
            char name[PROP_NAME_MAX];
            char value[PROP_VALUE_MAX];
            (void) __system_property_read(pv->props[i], name, value);
            if (i > 0 && strcmp(name, prev_name) == 0)
                continue;
            if (writer != NULL) {
                json_begin_field(writer, name);
                json_emit_string(writer, value);
            } else {
                output_property(&first, sep, format, name, value);
            }
            strcpy(prev_name, name);
        }
    } else {
        size_t nproperties = argv_count(properties);
        qsort(properties,
              nproperties,
              sizeof (properties[0]),
              property_argv_compare);
        const char* property;
        const char* prev_property = NULL;
        while ((property = *properties++)) {
            if (prev_property != NULL && !strcmp(prev_property, property))
                continue;
            if (writer != NULL)
                json_begin_field(writer, property);
            const prop_info* pi = __system_property_find(property);
            if (pi) {
                char value[PROP_VALUE_MAX];
                __system_property_read(pi, NULL, value);
                if (writer != NULL)
                    json_emit_string(writer, value);
                else if (format != NULL)
                    output_property(&first, sep, format, property, value);
            } else {
                if (writer != NULL)
                    json_emit_null(writer);
                else if (format_not_found != NULL)
                    output_property(&first, sep,
                                    format_not_found,
                                    property, NULL);
                exit_status = 4;
            }
            prev_property = property;
        }
    }

    if (writer == NULL && !first && !null)
        xputc(sep, xstdout);

    if (writer != NULL)
        json_end_object(writer);

    xflush(xstdout);
    return exit_status;
}
void gprs_send_data_log() {
	
	if(gprs_log_buf.head != gprs_log_buf.temp_tail) {
		gps_logging_enabled = 0;	//Disable gps request commands, enabled again in post request callback.
		gprs_log_buf.ready = 0;
	
		char send_string[HTTP_PACKAGE_STRING_LENGTH];
		uint16_t pos = 0;
		log_entry entry;
		char tempVar[15];
		uint8_t i = 0;
		
		//Only for debug:
		if(gprs_log_buf.head > 200) {
			volatile uint8_t testVar = 1;
		}

		memset(send_string, '\0', HTTP_PACKAGE_STRING_LENGTH);	//Clear buffer
	
		json_begin_object(send_string, &pos, !i);
	
		sprintf(tempVar, "%d", gprs_log_buf.data.device);
		json_add_variable(send_string, &pos, "Device", tempVar, 1);
	
		json_add_variable(send_string, &pos, "Entries", '\0', 0);
	
		json_begin_array(send_string, &pos, 1);
	
		while(i < HTTP_PACKAGE_MAX_LOG_ENTRIES && gprs_log_buf.head != gprs_log_buf.temp_tail) {
		
			entry = gprs_buf_temp_pull(&gprs_log_buf);
		
			json_begin_object(send_string, &pos, !i);
		
			sprintf(tempVar, "%d", entry.time);
			json_add_variable(send_string, &pos, "t", tempVar, 1);
		
			sprintf(tempVar, "%.5f", entry.lat);
			json_add_variable(send_string, &pos, "la", tempVar, 0);
		
			sprintf(tempVar, "%.5f", entry.lng);
			json_add_variable(send_string, &pos, "ln", tempVar, 0);
		
			sprintf(tempVar, "%.1f", entry.speed);
			json_add_variable(send_string, &pos, "s", tempVar, 0);
		
			sprintf(tempVar, "%d", entry.cadence);
			json_add_variable(send_string, &pos, "c", tempVar, 0);
		
			sprintf(tempVar, "%d", entry.inclination);
			json_add_variable(send_string, &pos, "i", tempVar, 0);
		
			sprintf(tempVar, "%.1f", entry.g_force);
			json_add_variable(send_string, &pos, "g", tempVar, 0);
		
			sprintf(tempVar, "%d", entry.upload_interval);
			json_add_variable(send_string, &pos, "f", tempVar, 0);
		
			json_close_object(send_string, &pos);
		
			i++;
		}
	
		json_close_array(send_string, &pos);
		json_close_object(send_string, &pos);
	
		i = 0;
	
		// ONLY FOR DEBUG USE:
		char *completeString;
		volatile uint16_t len;
		completeString = &send_string;
		len = strlen(completeString);
	
		// TODO: Send post request to server:
		command cmd;
		char cmd_name[25];
	
		sprintf(cmd_name, "AT+HTTPDATA=%d,30000", strlen(send_string));
		cmd.cmd = cmd_name;
		cmd.expected_response = "DOWNLOAD";
		cmd.callback_enabled = 0;
	
		sim808_send_command(cmd);
		delay_ms(200);
		//if(sim808_parse_response_wait(SIM808_RECEIVE_DELAY_NORMAL)) {
			printf(send_string);
			last_command.expected_response = "OK";
			last_command.callback_enabled = 1;
			last_command.response_cb = SIM808_response_gprs_send_post_request;
			//sim808_parse_response_wait(SIM808_RECEIVE_DELAY_NORMAL);
		//}		
	}
}