Exemplo n.º 1
0
void SerialPort::do_write(const char msg)
{
    bool write_in_progress = !write_msgs_.empty(); // hay algo que esta escribiendo actualmente?
    write_msgs_.push_back(msg); // guarda en el write buffer
    if (!write_in_progress) // si actualmente nada se esta escribiendo, entonces iniciamos a escribir
        write_start();
}
Exemplo n.º 2
0
uint8_t twi_sync_mt(uint8_t address, uint8_t *req_data, uint8_t req_len) {
	// write start condition
	write_start();
	WAIT_FOR_BUS();

	// write SLA+W
	write_slave_address(address, TW_WRITE);
	WAIT_FOR_BUS();

	if (TW_STATUS != TW_MT_SLA_ACK) {
		write_stop();
		return TWI_ERROR;
	}

	// write request data
	while (req_len--) {
		write_data_byte(*req_data++);
		WAIT_FOR_BUS();

		if (TW_STATUS != TW_MT_DATA_ACK) {
			write_stop();
			return TWI_ERROR;
		}
	}

	// write stop condition
	write_stop();

	while (!(TWCR & (1 << TWSTO)));

	return TWI_OK;
}
Exemplo n.º 3
0
int Cvirtual_binary::load(const std::string& fname)
{
	FILE* f = fopen(fname.c_str(), "rb");
	if (!f)
		return 1;
	struct stat b;
	int error = fstat(fileno(f), &b) ? 1 : fread(write_start(b.st_size), 1, b.st_size, f) != b.st_size;
	fclose(f);
	return error;
}
Exemplo n.º 4
0
 /// write to a connect I2C slave device   
 //
 /// This function writes n bytes of data to the device with address a
 /// that is connected to the I2C bus.
 void write( fast_byte a, const byte data[], fast_byte n ) override {
    write_start();
    write_byte( a << 1 );
    for( fast_byte i = 0; i < n; i++ ){
       read_ack();
       write_byte( data[ i ] );
    }               
    read_ack();
    write_stop();      
 }
Exemplo n.º 5
0
void SerialPort::write_complete(const boost::system::error_code& error)
{
    // La operacion de escritura asyncrona ya termino o fallo y retornara el error
    if (!error)
    { // escritura completada, a continuacion enviamos la siguiente dara para escribir
        write_msgs_.pop_front(); // borra los datos completados
        if (!write_msgs_.empty()) // si queda algo por ser escrito
            write_start(); // entonces inicia la escritura
    }
    else
        do_close(error);
}
Exemplo n.º 6
0
 /// read from a connected I2C slave device
 //
 /// This function reads n bytes of data from the device with address a
 /// that is connected to the I2C bus.
 void read( fast_byte a, byte data[], fast_byte n ) override {
    write_start();
    write_byte( ( a << 1 ) | 0x01 );    
    read_ack();
    for( fast_byte i = 0; i < n; i++ ){
       if( i > 0 ){
          write_ack();
       }   
       data[ i ] = read_byte();
    }               
    write_stop();      
 }      
Exemplo n.º 7
0
/**
 * Asynchronously writes the specified byte sequence to the serial console.
 * @param buffer the data to write from
 * @param nbytes the number of bytes to write
 */
void sio_write(char *buffer, unsigned int nbytes) {
	//c_printf("Writing:%s:%d %d-%d\n", buffer, nbytes, write_buf_start, write_buf_end);
	int spaceleft = WRITE_BUF_LEN - ((write_buf_end - write_buf_start) %
		WRITE_BUF_LEN + WRITE_BUF_LEN) % WRITE_BUF_LEN;
	if (spaceleft < nbytes) {
		__panic("No space left in serial output buffer\n");
	}
	int index = write_buf_end;
	unsigned int count;
	for (count = 0; count < nbytes; ++count) {
		write_buf[index] = buffer[count];
		++write_buf_end;
		write_buf_end %= WRITE_BUF_LEN;
		index = (index + 1) % WRITE_BUF_LEN;
	}
	write_start();
}
int main(int argc, char **argv)
{
	int fd;
	int i, res, desc_size = 0, count = 1;
	char buf[256];
	struct hidraw_report_descriptor rpt_desc;
	struct hidraw_devinfo info;
	memset(&rpt_desc, 0x0, sizeof(rpt_desc));
	memset(&info, 0x0, sizeof(info));
	memset(buf, 0x0, sizeof(buf));
	
	memset(&update_info, 0x0, sizeof(update_info));

	fd = open("/dev/hidraw0", O_RDWR);

	if (fd < 0) {
		perror("Unable to open /dev/hidraw0");
		return 1;
	} else {
		perror("open /dev/hidraw0 success!");
		/* Get Raw Info */
		res = ioctl(fd, HIDIOCGRAWINFO, &info);
		if (res < 0) {
			perror("HIDIOCGRAWINFO");
		} else {
			printf("Raw Info:\n");
			printf("\tbustype: %d (%s)\n",
				info.bustype, bus_str(info.bustype));
			printf("\tvendor: 0x%04hx\n", info.vendor);
			printf("\tproduct: 0x%04hx\n", info.product);
		}
		update_info.write_fd = fd;
		update_info.read_fd = fd;
	}
	init_data();
	write_start();
	update_info.keep_polling = 1;
	poll_event_thread(NULL);
	update_info.keep_polling = -1;
	///update_info.rtkbt_thread_id = rtkbt_create_thread(poll_event_thread, NULL);
	return 0;
}
Exemplo n.º 9
0
 void write_run()
 {
   uint32_t llen;
   char* p;
   while (1)
   {
     if (m_close)/*是否被关闭*/
     {
       m_write_close = true;
       return;
     }
     p = write_start(llen);
     if (m_write_fun(p, llen))
     {
       write_finish(llen);
     }
     else
     {
       break;
     }
   }
 }
Exemplo n.º 10
0
Arquivo: main.c Projeto: bvdberg/code
void* producer(void* ptr)
{
    Buffer* buf = (Buffer*)ptr;
    while (1) {
        int slot = write_start(buf);
        if (slot == -1) {
            printf(ANSI_GREEN"producer: no free space left in queue...waiting"ANSI_NORMAL"\n");
            buffer_print(buf);
            exit(-1);
            usleep(producer_delay);
            continue;
        }
        
        //printf(ANSI_GREEN"producer: slot %d"ANSI_NORMAL"\n", slot);
        buffer_print(buf);
        usleep(produce_duration);
        write_done(buf);
        buffer_print(buf);
    }

    return 0;
}
Exemplo n.º 11
0
uint8_t twi_sync_mtmr(uint8_t address, uint8_t *req_data, uint8_t req_len, uint8_t *res_data, uint8_t res_len) {

	// Master Transmitter

	// write start condition
	write_start();
	WAIT_FOR_BUS();

	// write SLA+W
	write_slave_address(address, TW_WRITE);
	WAIT_FOR_BUS();

	if (TW_STATUS != TW_MT_SLA_ACK) {
		write_stop();
		return TWI_ERROR;
	}

	// write request data
	while (req_len--) {
		write_data_byte(*req_data++);
		WAIT_FOR_BUS();

		if (TW_STATUS != TW_MT_DATA_ACK) {
			write_stop();
			return TWI_ERROR;
		}
	}

	// Master Receiver

	// write repeated start
	write_start();
	WAIT_FOR_BUS();

	if (TW_STATUS != TW_REP_START) {
		write_stop();
		return TWI_ERROR;
	}

	// write SLA+R
	write_slave_address(address, TW_READ);
	WAIT_FOR_BUS();

	if (TW_STATUS != TW_MR_SLA_ACK) {
		write_stop();
		return TWI_ERROR;
	}

	// read data
	while (res_len > 1) {
		read_data_byte(res_data++, 1);
		WAIT_FOR_BUS();

		if (TW_STATUS != TW_MR_DATA_ACK) {
			write_stop();
			return TWI_ERROR;
		}

		res_len--;
	}

	read_data_byte(res_data++, 0);
	WAIT_FOR_BUS();

	if (TW_STATUS != TW_MR_DATA_NACK) {
		write_stop();
		return TWI_ERROR;
	}

	// write stop condition
	write_stop();

	while (!(TWCR & (1 << TWSTO)));

	return TWI_OK;
}
Exemplo n.º 12
0
int delete_files(char *aname, char **files, int count)
{
	struct ar_hdr hdr;
	struct stat info;
	int i, err, fd, bytes, seek;
	long int size;
	char buf[1];

	int a_fd = seek_to_armag(aname);
	if (a_fd == -1)
		return ERR_DELETE;
	
	if (fstat(a_fd, &info) == -1)
		return ERR_STAT;
	
	if (unlink(aname) == -1)
		return ERR_UNLINK;

	fd = open(aname, O_WRONLY | O_CREAT, info.st_mode);
	if (fd == -1)
		return ERR_UNLINK;

	if (write_start(fd) != 0)
		return ERR_DELETE;
	
	while ((bytes = read(a_fd, buf, 1)) != -1) {
		if (bytes == 0)
			return 0;

		if (lseek(a_fd, -1, SEEK_CUR) == -1)
			return ERR_DELETE;

		if (read_hdr(&hdr, a_fd) != 0)
			return ERR_DELETE;

		seek = 1;
		for (i = 0; i < count; i++) {
			if (cmp_hdr_name(&hdr, files[i])) {
				if (seek_to_next(&hdr, a_fd) != 0)
					return ERR_DELETE;
				
				files[i] = "";
				seek = 0;
			}
		}

		size = stoi(hdr.ar_size, 10, 10);
		if (seek) {
			if (write_header(&hdr, fd) != 0)
				return ERR_DELETE;

			if (size%2 == 1)
				size++;

			if (write_file(fd, a_fd, size, 1) != 0)
				return ERR_DELETE;
		}
	}

	return 0;
}
Exemplo n.º 13
0
void Cvirtual_binary::write(const_memory_range d)
{
	memcpy(write_start(d.size()), d, d.size());
}
Exemplo n.º 14
0
void Cvirtual_binary::write(const void* d, size_t cb_d)
{
	memcpy(write_start(cb_d), d, cb_d);
}
Exemplo n.º 15
0
/*
 * jsonwr_start_array_value
 */
void jsonwr_start_array_value(JSONWR_T* jsonwr) {
  write_start(jsonwr, JSON_EMPTY_ARRAY);
  // note we don't write the [ yet
}
Exemplo n.º 16
0
/*
 * jsonwr_start_object_value
 */
void jsonwr_start_object_value(JSONWR_T* jsonwr) {
  write_start(jsonwr, JSON_EMPTY_OBJECT);
  fputc('{', jsonwr->file);
  jsonwr->column += 1;
}
Exemplo n.º 17
0
void	Client::do_write(const char msg) {
  bool write_in_progress = !(this->write_msgs.empty());
  this->write_msgs.push_back(msg);
  if (!write_in_progress)
    write_start();
}