Ejemplo n.º 1
0
 /** Matrix with back track of alignment.
 \see Track
 */
 int& track(int row0, int col0) const {
     ASSERT_MSG(in(row0, col0),
                (TO_S(row0) + " " + TO_S(col0)).c_str());
     int row = row0 + 1, col = col0 + 1;
     int index = row * cols_1() + col;
     return matrix_[index * MATRICES_NUMBER + 1];
 }
Ejemplo n.º 2
0
void EtagStoreResource::handleRequest(const Http::Request& request,
                                      Http::Response& response) {
    handle_etag(request, response);
    response.setMimeType("image/gif");
    response.addHeader("Content-Length", TO_S(EMPTY_GIF_SIZE));
    response.out().write(EMPTY_GIF, EMPTY_GIF_SIZE);
}
Ejemplo n.º 3
0
/*
 * Sets the address for the i2c device file.
 *
 * @param mpl115a2 sensor
 */
int mpl115a2_set_addr(void *_s) {
	mpl115a2_t* s = TO_S(_s);
	int error;

	if((error = ioctl(s->file, I2C_SLAVE, s->address)) < 0)
		DEBUG("error: ioctl() failed\n");

	return error;
}
Ejemplo n.º 4
0
/*
 * Frees allocated memory in the init function.
 *
 * @param mpl115a2 sensor
 */
void mpl115a2_init_error_cleanup(void *_s) {
	mpl115a2_t* s = TO_S(_s);

	if(s->i2c_device != NULL) {
		free(s->i2c_device);
		s->i2c_device = NULL;
	}

	free(s);
	s = NULL;
}
Ejemplo n.º 5
0
VALUE db_sqlite3_statement_initialize(VALUE self, VALUE adapter, VALUE sql) {
    Statement *s = db_sqlite3_statement_handle(self);

    sql        = TO_S(sql);
    s->s       = 0;
    s->c       = db_sqlite3_adapter_handle_safe(adapter)->connection;
    s->adapter = adapter;

    if (sqlite3_prepare_v2(s->c, RSTRING_PTR(sql), RSTRING_LEN(sql), &(s->s), 0) != SQLITE_OK)
        rb_raise(eSwiftRuntimeError, "%s\nSQL: %s", sqlite3_errmsg(s->c), RSTRING_PTR(sql));

    return self;
}
Ejemplo n.º 6
0
void ExternalAligner::align_file(const std::string& input,
                                 const std::string& output) const {
    TimeIncrementer ti(this);
    std::string input_esc = escape_backslash(input);
    std::string output_esc = escape_backslash(output);
    std::string cmd = opt_value("aligner-cmd").as<std::string>();
    std::string cmd_string = str(boost::format(cmd) %
                                 input_esc % output_esc);
    int r = system(cmd_string.c_str());
    if (r) {
        throw Exception("external aligner failed with code " +
                        TO_S(r) + ". Command: " + cmd_string);
    }
}
Ejemplo n.º 7
0
/**
 * Closes a MPL115A2 object.
 *
 * @param mpl115a2 sensor
 */
void mpl115a2_close(void *_s) {
	if(_s == NULL) {
		return;
	}
	
	DEBUG("close device\n");
	mpl115a2_t *s = TO_S(_s);

	if(close(s->file) < 0)
		DEBUG("error: %s close() failed\n", s->i2c_device);

	free(s->i2c_device); // free string
	s->i2c_device = NULL;
	free(s); // free structure
	_s = NULL;
}
Ejemplo n.º 8
0
/*
 * Reads the calibration coefficients from the MPL115A2 sensor.
 *
 * @param mpl115a2 sensor
 */
void mpl115a2_read_coeff(void *_s) {
	mpl115a2_t *s = TO_S(_s);

	uint8_t a0_msb = (uint8_t) i2c_smbus_read_byte_data(s->file, MPL115A2_REG_A0_MSB);
	uint8_t a0_lsb = (uint8_t) i2c_smbus_read_byte_data(s->file, MPL115A2_REG_A0_MSB + 1);

	uint8_t b1_msb = (uint8_t) i2c_smbus_read_byte_data(s->file, MPL115A2_REG_B1_MSB);
	uint8_t b1_lsb = (uint8_t) i2c_smbus_read_byte_data(s->file, MPL115A2_REG_B1_MSB + 1);

	uint8_t b2_msb = (uint8_t) i2c_smbus_read_word_data(s->file, MPL115A2_REG_B2_MSB);
	uint8_t b2_lsb = (uint8_t) i2c_smbus_read_word_data(s->file, MPL115A2_REG_B2_MSB + 1);

	uint8_t c12_msb = (uint8_t) i2c_smbus_read_byte_data(s->file, MPL115A2_REG_C12_MSB);
	uint8_t c12_lsb = (uint8_t) i2c_smbus_read_byte_data(s->file, MPL115A2_REG_C12_MSB + 1);

	// signs of the coeffs. are correct because we use int16_t ints.
	int16_t a0, b1, b2, c12;

	// convert to integers
	a0 = (a0_msb<<8) + a0_lsb;
	b1 = (b1_msb<<8) + b1_lsb;
	b2 = (b2_msb<<8) + b2_lsb;
	c12 = (c12_msb<<8) + c12_lsb;


	// convert integers to floats and store them
	s->a0 = a0 / 8.0f; 			// 2^-3
	s->b1 = b1/ 8192.0f; 		// 2^-13
	s->b2 = b2 / 16384.0f; 		// 2^-14
	s->c12 = c12 / 16777216.0f; // 2^-24

	DEBUG("c12: %#x, c12{1:0} %#x\n", c12_lsb, c12_lsb & 0x03);
	DEBUG("a0_msb: %#x, a0_lsb: %#x\n ", a0_msb, a0_lsb);
	DEBUG("b1_msb: %#x, b1_lsb: %#x\n ", b1_msb, b1_lsb);
	DEBUG("b2_msb: %#x, b2_lsb: %#x\n ", b2_msb, b2_lsb);
	DEBUG("c12_msb: %#x,c12_lsb: %#x\n ", c12_msb, c12_lsb);

	DEBUG("a1: %f\n ", s->a0);
	DEBUG("b1: %f\n ", s->b1);
	DEBUG("b2: %f\n ", s->b2);
	DEBUG("c12: %f\n ", s->c12);
}
Ejemplo n.º 9
0
void ExternalAligner::align_seqs_impl(Strings& seqs) const {
    std::string input = tmp_file();
    ASSERT_FALSE(input.empty());
    std::string output = tmp_file();
    ASSERT_FALSE(output.empty());
    {
        boost::shared_ptr<std::ostream> file = name_to_ostream(input);
        std::ostream& out = *file;
        for (int i = 0; i < seqs.size(); i++) {
            write_fasta(out, TO_S(i), "", seqs[i], 60);
        }
    }
    align_file(input, output);
    Strings rows;
    read_alignment(rows, output);
    ASSERT_EQ(rows.size(), seqs.size());
    seqs.swap(rows);
    if (!go("NPGE_DEBUG").as<bool>()) {
        remove_file(input);
        remove_file(output);
    }
}
Ejemplo n.º 10
0
/**
 * Creates a MPL115A2 sensor object.
 *
 * @param i2c device address
 * @param i2c device file path
 * @return mpl115a2 sensor
 */
void *mpl115a2_init(int address, const char* i2c_device_filepath) {
	DEBUG("device: init using address %#x and i2cbus %s\n", address, i2c_device_filepath);

	void *_s = malloc(sizeof(mpl115a2_t));
	if(_s == NULL)  {
		DEBUG("error: malloc returns NULL pointer\n");
		return NULL;
	}

	mpl115a2_t *s = TO_S(_s);
	s->address = address;

	s->i2c_device = (char*) malloc(strlen(i2c_device_filepath) * sizeof(char));
	if(s->i2c_device == NULL) {
		DEBUG("error: malloc returns NULL pointer!\n");
		mpl115a2_init_error_cleanup(s);
		return NULL;
	}

	// copy string
	strcpy(s->i2c_device, i2c_device_filepath);

	// open i2c device
	int file;
	if((file = open(s->i2c_device, O_RDWR)) < 0) {
		DEBUG("error: %s open() failed\n", s->i2c_device);
		mpl115a2_init_error_cleanup(s);
		return NULL;
	}
	s->file = file;
	if(mpl115a2_set_addr(s) < 0) {
		mpl115a2_init_error_cleanup(s);
		return NULL;
	}
	mpl115a2_read_coeff(s);

	DEBUG("device: open ok\n");
	return _s;
}
Ejemplo n.º 11
0
/**
 * Read temperature and pressure value from the MPL115A2 sensor.
 *
 * @param mpl115a2 sensor
 * @param temperature
 * @param pressure
 */
void mpl115a2_read_data(void *_s, float *temperature, float *pressure) {
	mpl115a2_t *s = TO_S(_s);

	if(i2c_smbus_write_byte_data(s->file, MPL115A2_CMD_CONVERSION, 0x00) < 0) {
		DEBUG("error: i2c_smbus_write_byte\n");
	}

	usleep(5 * 1000); // 5 ms

	uint8_t pressure_msb, pressure_lsb, temperature_msb, temperature_lsb;

	uint16_t temperature_word = i2c_smbus_read_word_data(s->file, MPL115A2_REG_TEMPERATURE_MSB);
	uint16_t pressure_word = i2c_smbus_read_word_data(s->file, MPL115A2_REG_PRESSURE_MSB);

	// note: arm uses big endian, but i2c_smbus_x functions assume little endian.
	// word  = 0,1,2,3,4,5,6,7, 8,9,10,11,12,13,14,15
	//        [     lsb       ][         msb         ]
	temperature_msb = (temperature_word & 0x00FF); // extract msb byte
	temperature_lsb = (temperature_word & 0xFF00) >> 8;

	pressure_msb = (pressure_word & 0x00FF); // extract lsb byte
	pressure_lsb = (pressure_word & 0xFF00) >> 8;

	uint16_t raw_temperature = ((temperature_msb << 8) + temperature_lsb) >> 6;
	uint16_t raw_pressure = ((pressure_msb << 8) + pressure_lsb) >> 6;

	float pressure_comp = s->a0 + (s->b1 + s->c12 * raw_temperature) * raw_pressure + s->b2 * raw_temperature;

	// black magic temperature formula: http://forums.adafruit.com/viewtopic.php?f=25&t=34787
	// thx @park
	*temperature = ((float) raw_temperature) * -0.1707f + 112.27f;
	*pressure =  ((pressure_comp / 15.737f) + 50.0f)*1000;

	DEBUG("tmp: %f ,tmp_msb: %#x, tmp_lsb: %#x\n ", *temperature, temperature_msb, temperature_lsb);
	DEBUG("pre: %f ,pre_msb: %#x, pre_lsb: %#x, raw: %#x\n ", *pressure, pressure_msb, pressure_lsb, raw_pressure);
}