Exemplo n.º 1
0
void read_matrixes(int* sizes, int** matx1, int** matx2,int fd){
	read_int_from_file(&sizes[0],fd);
	read_int_from_file(&sizes[1],fd);
	read_int_from_file(&sizes[2],fd);	
	if((*matx1 = (int*)malloc(sizes[0]*sizes[1]*sizeof(int)))==(int*)NULL) print_err("allocate memory for the first matrix");
	if((*matx2 = (int*)malloc(sizes[2]*sizes[1]*sizeof(int)))==(int*)NULL) print_err("allocate memory for the second matrix");	
	int i,j;
	for(i=0;i<sizes[0];i++) for(j=0;j<sizes[1];j++) read_int_from_file(*matx1 + i*sizes[1] + j,fd);
//second matrix is transposed
	for(j=0;j<sizes[1];j++) for(i=0;i<sizes[2];i++) read_int_from_file(*matx2 + i*sizes[1] + j,fd);
}
Exemplo n.º 2
0
bool is_battery_charging(void)
{
    if (is_nx1()) {
        return read_int_from_file(
                "/sys/devices/platform/micom-ctrl/bat_charging") == 1;
    } else if (is_nx500()) {
        return read_int_from_file("/sys/devices/platform/d5-adc-battery"
                                  "/power_supply/battery/charge_now") == 1;
    } else if (is_old_nx_model()) {
        return read_int_from_file(
                "/sys/devices/platform/jack/charger1_online") == 1;
    }

    return false;
}
Exemplo n.º 3
0
DialMode get_dial_mode(void)
{
    if (s_mode == MODE_UNKNOWN) {
        if (is_nx1()) {
            s_mode = read_int_from_file(
                        "/sys/devices/platform/d5keys-polled/dial_mode");

        } else if (is_nx500()) {
            s_mode = read_int_from_file(
                        "/sys/devices/platform/d5-keys/dial_mode");
        } else if (is_old_nx_model()) {
            int mode = read_int_from_file(
                        "/sys/devices/platform/d4keys-polled/mode");
            switch (mode) {
                case 0:
                    s_mode = MODE_NX300_LENS_PRIORITY;
                    break;
                case 3:
                    s_mode = MODE_SCENE;
                    break;
                case 2:
                    s_mode = MODE_NX300_WIFI;
                    break;
                case 5:
                    s_mode = MODE_SMART;
                    break;
                case 6:
                    s_mode = MODE_P;
                    break;
                case 7:
                    s_mode = MODE_A;
                    break;
                case 8:
                    s_mode = MODE_S;
                    break;
                case 9:
                    s_mode = MODE_M;
                    break;
                default:
                    return MODE_UNKNOWN;
            }
        }
    }

    return s_mode;
}
Exemplo n.º 4
0
DialDrive get_dial_drive(void)
{
    if (is_nx1()) {
        return read_int_from_file(
                "/sys/devices/platform/d5keys-polled/dial_drive");
    }
    return DRIVE_UNKNOWN;
}
Exemplo n.º 5
0
int get_battery_percent(void)
{
    if (is_nx1()) {
        return read_int_from_file(
                "/sys/devices/platform/micom-ctrl/body_bat_soc");
    }
    return -1;
}
Exemplo n.º 6
0
void MainWindow::setup_ui() {
    // Battery Charge
    if (check_file(SONY_BATTERY_HIGHSPEED_CHRG)) {
        ui->chk_battery_fast_charge->setChecked(read_int_from_file(SONY_BATTERY_HIGHSPEED_CHRG));

        connect(ui->chk_battery_fast_charge, SIGNAL(stateChanged(int)), this, SLOT(chk_battery_fast_charge_changed(int)));
    }
    else ui->chk_battery_fast_charge->setEnabled(false);
Exemplo n.º 7
0
void Date_::deserialize(ifstream& reader)
{
	int size = read_int_from_file(reader);
	char* to_read = new char[size + 1];
	reader.read(to_read, size);
	to_read[size] = '\0';
	field_name = to_read;
	current_date->deserialize(reader);
	set_content(current_date->to_string());
}
Exemplo n.º 8
0
/**
 * Reads keys in keyfile if group GN_CLIENT is in that keyfile and fills
 * options_t *opt structure accordingly.
 * @param[in,out] opt : options_t * structure to store options read from the
 *                configuration file "filename".
 * @param keyfile is the GKeyFile structure that is used by glib to read
 *        groups and keys from.
 * @param filename : the filename of the configuration file to read from
 */
static void read_from_group_client(options_t *opt, GKeyFile *keyfile, gchar *filename)
{
    gchar *dircache = NULL;
    gint cmptype = 0;

    if (keyfile != NULL && filename != NULL && g_key_file_has_group(keyfile, GN_CLIENT) == TRUE)
        {
            /* Reading the directory list */
            opt->dirname_list = read_list_from_file(keyfile, filename, GN_CLIENT, KN_DIR_LIST, _("Could not load directory list from file"));
            opt->exclude_list = read_list_from_file(keyfile, filename, GN_CLIENT, KN_EXC_LIST, _("Could not load exclude file list from file"));

            /* Reading blocksize */
            opt->blocksize = read_int64_from_file(keyfile, filename, GN_CLIENT, KN_BLOCK_SIZE, _("Could not load blocksize from file"), CLIENT_BLOCK_SIZE);

            /* Reading the cache directory if any */
            dircache = read_string_from_file(keyfile, filename, GN_CLIENT, KN_CACHE_DIR, _("Could not load directory name"));
            opt->dircache = normalize_directory(dircache);
            free_variable(dircache);

            /* Reading filename of the database if any */
            opt->dbname = read_string_from_file(keyfile, filename, GN_CLIENT, KN_DB_NAME, _("Could not load cache database name"));

            /* Adaptative mode for blocksize ? */
            opt->adaptive = read_boolean_from_file(keyfile, filename, GN_CLIENT, KN_ADAPTIVE, _("Could not load adaptive configuration from file."));

            /* Scanning option */
            opt->noscan = read_boolean_from_file(keyfile, filename, GN_CLIENT, KN_NOSCAN, _("Could not load scan configuration from file."));

            /* Buffer size to be used to send data to server */
            opt->buffersize = read_int_from_file(keyfile, filename, GN_CLIENT, KN_BUFFER_SIZE, _("Could not load buffersize from file"), CLIENT_MIN_BUFFER);

            /* Compression type if any */
            cmptype = read_int_from_file(keyfile, filename, GN_CLIENT, KN_COMPRESSION_TYPE, _("Compression type not defined in configuration file"), opt->cmptype);
            set_compression_type(opt, cmptype);
        }

}
Exemplo n.º 9
0
static unsigned int
get_optmem_max(void)
{
	static int optmem_max;

	if (!optmem_max) {
		if (read_int_from_file("/proc/sys/net/core/optmem_max",
				       &optmem_max) || optmem_max <= 0) {
			optmem_max = sizeof(long long) * (2 * IOV_MAX + 512);
		} else {
			optmem_max = (optmem_max + sizeof(long long) - 1)
				     & ~(sizeof(long long) - 1);
		}
	}

	return optmem_max;
}
Exemplo n.º 10
0
/**
 * Reads keys in keyfile if groupname is in that keyfile and fills
 * options_t *opt structure accordingly.
 * @param[in,out] opt : options_t * structure to store options read from the
 *                configuration file "filename".
 * @param keyfile is the GKeyFile structure that is used by glib to read
 *        groups and keys from.
 * @param filename : the filename of the configuration file to read from
 */
static void read_from_group_server(options_t *opt, GKeyFile *keyfile, gchar *filename)
{
    gint port = 0;

    if (opt != NULL && keyfile != NULL && filename != NULL && g_key_file_has_group(keyfile, GN_SERVER) == TRUE)
    {
        /* Reading the port number if any */
        port = read_int_from_file(keyfile, filename, GN_SERVER, KN_SERVER_PORT, _("Could not load server port number from file."), SERVER_PORT);

        if (port > 1024 && port < 65535)
        {
            opt->port = port;
        }

        /* Reading IP address of server's host if any */
        opt->ip = read_string_from_file(keyfile, filename, GN_SERVER, KN_SERVER_IP, _("Could not load cache database name"));
    }
}
void healthd_board_mode_charger_init()
{
    int ret;
    char buff[40] = "\0";
    char *pos;
    int charging_enabled = 0;
    int bms_ready = 0;
    int wait_count = 0;
    int fd;
    bool usb_type_is_sdp = false, typec_default_src = false;

    /* check the charging is enabled or not */
    ret = read_int_from_file(CHARGING_ENABLED_PATH, &charging_enabled);
    if (ret >= 0) {
         LOGW(CHGR_TAG, "android charging is %s\n",
                 !!charging_enabled ? "enabled" : "disabled");
         /* if charging is disabled, reboot and exit power off charging */
         if (!charging_enabled)
             reboot(RB_AUTOBOOT);
    }
    ret = read_file(CHARGER_TYPE_PATH, buff, sizeof(buff));
    if (ret >= 0) {
        /* get rid of the new line charcter */
        buff[strcspn(buff, "\n")] = '\0';
        if (!strcmp(buff, "USB"))
            usb_type_is_sdp = true;
    }
    memset(buff, 0, sizeof(buff));
    ret = read_file(USB_TYPEC_MODE_PATH, buff, sizeof(buff));
    if (ret >= 0) {
        if (strcmp(buff, "Source attached (default current)"))
            typec_default_src = true;
    }
    if (usb_type_is_sdp && typec_default_src) {
        /*
         * Request 500mA input current when a SDP is connected and it's
         * acting as a default source.
         * PD capable source which could charge the device with USB_PD
         * charger type is not included here.
         */
        ret = write_file_int(USB_MAX_CURRENT_PATH, USB500_UA);
        if (ret == 0)
            LOGW(CHGR_TAG, "Force input current to 500mA with SDP inserted!\n");
    }
    fd = open(BMS_READY_PATH, O_RDONLY);
    if (fd < 0)
            return;
    while (1) {
        ret = read(fd, buff, (sizeof(buff) - 1));
        if (ret > 0) {
            buff[ret] = '\0';
            sscanf(buff, "%d\n", &bms_ready);
        } else {
            LOGE(CHGR_TAG, "read soc-ready failed, ret=%d\n", ret);
            break;
        }
        if ((bms_ready > 0) || (wait_count++ > WAIT_BMS_READY_TIMES_MAX))
            break;
        usleep(WAIT_BMS_READY_INTERVAL_USEC);
        lseek(fd, 0, SEEK_SET);
    }
    close(fd);
    LOGV(CHGR_TAG, "Checking BMS SoC ready done %d!\n", bms_ready);
}
Exemplo n.º 12
0
int main(int argc, char **argv){
    FILE *query_file = NULL, *test_hits_file = NULL;
    struct cb_database_r *db = NULL;
    struct opt_config *conf;
    struct opt_args *args;
    struct DSVector *iterations = NULL, *expanded_hits = NULL, *queries = NULL,
                    *oseqs = ds_vector_create();
    struct fasta_seq *query = NULL;
    xmlDoc *doc = NULL;
    xmlNode *root = NULL;
    uint64_t dbsize = 0;
    int i = 0, j = 0;

    conf = load_search_args();
    args = opt_config_parse(conf, argc, argv);

    if (args->nargs < 2) {
        fprintf(stderr, 
                "Usage: %s [flags] database-dir fasta-file "
                "[ --blast_args BLASTN_ARGUMENTS ]\n", argv[0]);
        opt_config_print_usage(conf);
        exit(1);
    }

    system("rm CaBLAST_results.xml");

    if (!search_flags.hide_progress)
        fprintf(stderr, "Loading database data\n\n");


    db = cb_database_r_init(args->args[0],
                            (search_flags.load_coarse_db ||
                             search_flags.load_coarse_residues),
                            (search_flags.load_coarse_db ||
                             search_flags.load_coarse_links),
                            search_flags.load_compressed_db,
                            search_flags.link_block_size);
    dbsize = read_int_from_file(8, db->coarse_db->db->file_params);

    if (!search_flags.hide_progress)
        fprintf(stderr, "Running coarse BLAST\n\n");
    blast_coarse(args, dbsize);

    if (NULL == (query_file = fopen(args->args[1], "r"))) {
        fprintf(stderr, "fopen: 'fopen %s' failed: %s\n",
                args->args[1], strerror(errno));
        exit(1);
    }

    queries = ds_vector_create();
    query = fasta_read_next(query_file, "");
    while (query) {
        ds_vector_append(queries, (void *)query);
        query = fasta_read_next(query_file, "");
    }

    fclose(query_file);

    if (!search_flags.hide_progress)
        fprintf(stderr, "Processing coarse BLAST hits for fine BLAST\n\n");
    if (search_flags.show_hit_info)
        if (NULL == (test_hits_file = fopen("CaBLAST_hits.txt", "w"))) {
            fprintf(stderr, "fopen: 'fopen %s' failed: %s\n",
                    "CaBLAST_hits.txt", strerror(errno));
            exit(1);
        }

    //Parse the XML file generated from coarse BLAST and get its iterations.
    doc = xmlReadFile("CaBLAST_temp_blast_results.xml", NULL, 0);
    if (doc == NULL) {
        fprintf(stderr, "Could not parse CaBLAST_temp_blast_results.xml\n");
        return 0;
    }
    root = xmlDocGetRootElement(doc);
    iterations = get_blast_iterations(root);

    for (i = 0; i < iterations->size; i++) {
        if (!search_flags.hide_progress) {
            int32_t digits_full = floor(log10((double)iterations->size)),
                    digits_i    = floor(log10((double)i)), spaces;
            char *bar = progress_bar(i, iterations->size);
            spaces = digits_full - digits_i;
            fprintf(stderr, "\r");
            fprintf(stderr, "iteration: %d/%d", i+1, iterations->size);
            for (j = 0; j < spaces; j++)
                putc(' ', stderr);
            fprintf(stderr, " %s ", bar);
            free(bar);
        }

        /*Expand any BLAST hits we got from the current query sequence during
          coarse BLAST.*/
        expanded_hits = expand_blast_hits(iterations, i, db);

        for (j = 0; j < expanded_hits->size; j++)
            ds_vector_append(oseqs, ds_vector_get(expanded_hits, j));
        ds_vector_free_no_data(expanded_hits);
    }

    write_fine_fasta(oseqs);

    for (i = 0; i < oseqs->size; i++)
        cb_hit_expansion_free(
          (struct cb_hit_expansion *)ds_vector_get(oseqs, i));
    ds_vector_free_no_data(oseqs);

    blast_fine(args, dbsize);

    if (!search_flags.hide_progress)
        fprintf(stderr, "\n"); //Make a newline after the progress bar

    for (i = 0; i < queries->size; i++)
        fasta_free_seq((struct fasta_seq *)ds_vector_get(queries, i));
    ds_vector_free_no_data(queries);

    if (search_flags.show_hit_info)
        fclose(test_hits_file);

    //Free the XML data and expanded hits
    for (i = 0; i < iterations->size; i++) {
        struct DSVector *iteration =
          (struct DSVector *)ds_vector_get(iterations, i);
        for (j = 0; j < iteration->size; j++) {
            struct hit *h = (struct hit *)ds_vector_get(iteration, j);
            ds_vector_free(h->hsps);
            free(h);
        }
    }
    ds_vector_free_no_data(iterations);

    cb_database_r_free(db);
    xmlFreeDoc(doc);

    /*Free the coarse BLAST results file if the --no-cleanup flag is not being
      used.*/
    if (!search_flags.no_cleanup)
        system("rm CaBLAST_temp_blast_results.xml");

    opt_args_free(args);
    opt_config_free(conf);

    return 0;
}