void read_fuse(uint8_t *efuse, uint8_t *hfuse, uint8_t *lfuse)
{
	load_command(appc_read_fuse_n_lock_bits);
	output_enable();
	reset_bs2();
	set_byte_low();
	*lfuse = data_in();
	set_bs2();
	set_byte_high();
	*hfuse = data_in();
	set_bs2();
	set_byte_low();
	*efuse = data_in();
	output_disable();
}
示例#2
0
文件: helper.c 项目: RobertDash/pspp
/* Converts TEXT to a value.

   VAL will be initialised and filled by this function.
   It is the caller's responsibility to destroy VAL when no longer needed.
   VAR must be the variable with which VAL is associated.

   On success, VAL is returned, NULL otherwise.
*/
union value *
text_to_value (const gchar *text,
	       const struct variable *var,
	       union value *val)
{
  const struct fmt_spec *format = var_get_print_format (var);
  int width = var_get_width (var);

  if ( format->type != FMT_A)
    {
      if ( ! text ) return NULL;

      {
	const gchar *s = text;
	while (*s)
	  {
	    if ( !isspace (*s))
	      break;
	    s++;
	  }

	if ( !*s) return NULL;
      }
    }

  value_init (val, width);
  free (data_in (ss_cstr (text), UTF8, format->type, val, width,
                 var_get_encoding (var)));

  return val;
}
示例#3
0
static unsigned char  receive()
{
  BitStatus bit;
  unsigned char data = 0;
  char i;
  for(i = 0;i<4;i++)
  {
    rd(0);
    delay();
    rd(1);
    bit = data_in();
    if(bit == RESET)
    {
      
    }
    else
    {
      data |= 0x01;
    }
    data <<= 1;
    delay();
  }
  return data >> 1;

}
示例#4
0
static void *loop_thread(void *arg)
{
	eplsvr_t *ep = (eplsvr_t *)arg;

	int fds, i;
	struct epoll_event evs[EVENTS];

	while (1) {
		fds = epoll_wait(ep->eplfd, evs, EVENTS, -1);
		if (fds == -1 && errno != EINTR) {
			syslog(LOG_ERR, "epoll_wait(): %s", strerror(errno));
			//continue;
			exit(1);
		}

		for (i = 0; i < fds; i++) {
			if (evs[i].data.fd == ep->lsnfd)  /* client comming */
				client_in(ep);
			else if (evs[i].events & EPOLLIN) /* data comming */
				data_in(ep, evs[i].data.fd);
			else	/* error */
				client_out(ep, evs[i].data.fd);
		}
	}

	return NULL;
}
uint16_t read_pgm_mem_word(uint16_t waddr)
{
	uint16_t word;

	load_command(appc_read_flash);
	load_address_high_byte(waddr >> 8);
	load_address_low_byte(waddr & 0xFF);
	output_enable();
	set_byte_low();
	word = data_in();
	set_byte_high();
	word |= data_in() << 8;
	output_disable();

	return word;
}
示例#6
0
uint8 IEC::In(uint8 *byte)
{
	if (talker_active && (received_cmd == CMD_DATA))
		return data_in(byte);

	*byte = 0;
	return ST_TIMEOUT;
}
void read_lock(uint8_t *lock)
{
	load_command(appc_read_fuse_n_lock_bits);
	output_enable();
	reset_bs2();
	set_byte_high();
	*lock = data_in();
	output_disable();
}
void read_cali(uint8_t *cali)
{
	load_command(appc_read_sig_bytes_n_cali_byte);

	load_address_low_byte(0);
	output_enable();
	set_byte_high();
	*cali = data_in();
	output_disable();
}
示例#9
0
int main( int argc, char *argv[] )
{
	//Individual halos
	struct halo *halos;
	halos = (struct halo *)calloc( MAXHALOS, sizeof( struct halo ) );
	//Halo pairs
	struct pair *pairs;
	pairs = (struct pair *)calloc( MAXPAIRS, sizeof( struct pair ) );
	//Isolated halo pairs
	struct pair *isopair;
	isopair = (struct pair *)calloc( MAXIPAIR, sizeof( struct pair ) );
	
	int i,j;
	
	int k, l;
	
	char filename[NMAX1];
	float p[NMAX1];
	
	struct region regions[NMAX2][NMAX2][NMAX2];
	int index[NMAX1][3];
	
	FILE *script;
	
	
	printf( "\n\n************************ HALO PAIR FINDER ***********************\n" );
	//Load Configuration-----------------------------------------------------------------------
	read_parameters( p, "parameters.conf" );
	
	//Load Processed input datafile------------------------------------------------------------
	  //Input Filename
	sprintf( filename, "%s", argv[1] );
	p[NDAT] = data_in( halos, filename, p[NAXE] );

	//Neighborhood Construction----------------------------------------------------------------
 	make_regions( regions, halos, p[NDAT], p[NAXE], p[LBOX], index );
	printf( "  * Datafile of halos has been sorted in octant regions!\n" );
	printf( "  * Neighborhood construction done!\n" );
	
	//Halo Pair construction-------------------------------------------------------------------
 	pair_finder( halos, pairs, isopair, regions, index, p );
	printf( "  * Halo pairs have been found!\n" );
	printf( "  * %d Halos in Mass Range Found!\n", (int)p[HRMAS] );
	
	//Saving Halo Pairs General Sample --------------------------------------------------------
	data_pair_out( pairs, halos, "Pairs.dat", p[PAIR] );
	printf( "  * %d General Halo Pairs Found!\tData in 'Pairs.dat'\n", (int)p[PAIR] );
	
	//Saving Halo Pairs Isolated Sample --------------------------------------------------------
	data_pair_out( isopair, halos, "IsoPairs.dat", p[ISOPAIR] );
	printf( "  * %d Isolated Halo Pairs Found!\tData in 'IsoPairs.dat'\n", (int)p[ISOPAIR] );
	
    return 0;
}
示例#10
0
/* called after start bit comes */
static uint8_t recv_data(void)
{
    uint8_t data = 0;
    bool parity = true;
    ps2_error = PS2_ERR_NONE;

    /* start bit [1] */
    WAIT(clock_lo, 1, 1);
    WAIT(data_lo, 1, 2);
    WAIT(clock_hi, 50, 3);

    /* data [2-9] */
    for (uint8_t i = 0; i < 8; i++) {
        WAIT(clock_lo, 50, 4);
        if (data_in()) {
            parity = !parity;
            data |= (1<<i);
        }
        WAIT(clock_hi, 50, 5);
    }

    /* parity [10] */
    WAIT(clock_lo, 50, 6);
    if (data_in() != parity) {
        ps2_error = PS2_ERR_PARITY;
        goto ERROR;
    }
    WAIT(clock_hi, 50, 7);

    /* stop bit [11] */
    WAIT(clock_lo, 50, 8);
    WAIT(data_hi, 1, 9);
    WAIT(clock_hi, 50, 10);

    return data;
ERROR:
    return 0;
}
示例#11
0
void read_sign(uint8_t *msb, uint8_t *csb, uint8_t *lsb)
{
	load_command(appc_read_sig_bytes_n_cali_byte);
	//load_address_high_byte(0); // TODO

	load_address_low_byte(0);
	output_enable();
	set_byte_low();
	*msb = data_in();
	output_disable();

	load_address_low_byte(1);
	output_enable();
	set_byte_low();
	*csb = data_in();
	output_disable();

	load_address_low_byte(2);
	output_enable();
	set_byte_low();
	*lsb = data_in();
	output_disable();
}
示例#12
0
////////////////////////////////////////////////////////////////////////////////
// Test boost::simd::transform behavior with unary operation
////////////////////////////////////////////////////////////////////////////////
NT2_TEST_CASE_TPL( transform_unary, BOOST_SIMD_SIMD_TYPES )
{
  std::vector<T> data_in(113);
  for(size_t i=0; i<113; ++i)
    data_in[i] = T(i);

  std::vector<T> data_out1(113);
  boost::simd::transform(&*data_in.begin(), &*data_in.begin()+data_in.size(), &*data_out1.begin(), plus_one());

  std::vector<T> data_out2(113);
  std::transform(&*data_in.begin(), &*data_in.begin()+data_in.size(), &*data_out2.begin(), plus_one());

  NT2_TEST_EQUAL(data_out1, data_out2);
}
示例#13
0
uint8_t read_eeprom(uint16_t addr)
{
	uint8_t data;

	load_command(appc_read_eeprom);
	load_address_high_byte(addr >> 8);
	load_address_low_byte(addr & 0xFF);
	output_enable();
	set_byte_low();
	data = data_in();
	output_disable();

	return data;
}
示例#14
0
////////////////////////////////////////////////////////////////////////////////
// Test boost::simd::accumulate
////////////////////////////////////////////////////////////////////////////////
NT2_TEST_CASE_TPL( accumulate, BOOST_SIMD_SIMD_TYPES )
{
  std::size_t n = 113;

  std::vector<T> data_in(n);
  for(size_t i=0; i<n; ++i)
    data_in[i] = T(i);

  T res1 = boost::simd::accumulate(&*data_in.begin(), &*data_in.begin()+data_in.size(), T(0), plus());
  T res2 = std::accumulate(&*data_in.begin(), &*data_in.begin()+data_in.size(), T(0), plus());

  NT2_TEST_EQUAL(res1, res2);
  NT2_TEST_EQUAL(res1, T((n-1)*n/2));
}
示例#15
0
Control::Control(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Control)
{
    ui->setupUi(this);
    setWindowTitle("GSM管理界面");
    out = new Dataout(0,"0",this);
    in = new DataIn();
    ui->stackedWidget->setCurrentIndex(0);
    ui->stackedWidget_2->setCurrentIndex(0);
    QRegExp regExp("0?[.][0-9]+$");
    ui->lineEdit->setValidator(new QRegExpValidator(regExp,this));
    initTime();
    addBTSname();
    addCellID();
    connect(ui->confirm,SIGNAL(clicked()),this,SLOT(data_in()));
    connect(ui->confirm_2,SIGNAL(clicked()),this,SLOT(data_out()));
    connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(page1()));
    connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(page2()));
    connect(ui->confirm_3,SIGNAL(clicked()),this,SLOT(queryBTS()));
    connect(ui->pushButton_3,SIGNAL(clicked()),this,SLOT(page3()));
    connect(ui->pushButton_4,SIGNAL(clicked()),this,SLOT(page4()));
    connect(ui->confirm_4,SIGNAL(clicked()),this,SLOT(queryCell()));
    connect(ui->pushButton_6,SIGNAL(clicked()),this,SLOT(bulkInsert()));
    connect(ui->pushButton_5,SIGNAL(clicked()),this,SLOT(page5()));
    connect(ui->pushButton_9,SIGNAL(clicked()),this,SLOT(reCalculateDatas()));
    connect(ui->pushButton_7,SIGNAL(clicked()),this,SLOT(page6()));
    connect(ui->pushButton_11,SIGNAL(clicked()),this,SLOT(printNeighbor()));
    connect(ui->pushButton_8,SIGNAL(clicked()),this,SLOT(page7()));
    connect(ui->pushButton_10,SIGNAL(clicked()),this,SLOT(findNeighbor()));
    connect(ui->pushButton_12,SIGNAL(clicked()),this,SLOT(findCellInfo()));


    connect(ui->pushButton_13,SIGNAL(clicked()),this,SLOT(page13()));
    connect(ui->pushButton_14,SIGNAL(clicked()),this,SLOT(page14()));
    connect(ui->pushButton_15,SIGNAL(clicked()),this,SLOT(page15()));
    connect(ui->pushButton_16,SIGNAL(clicked()),this,SLOT(page16()));
    connect(ui->pushButton_17,SIGNAL(clicked()),this,SLOT(page17()));
    connect(ui->pushButton_18,SIGNAL(clicked()),this,SLOT(page18()));

    connect(ui->pushButton_22,SIGNAL(clicked()),this,SLOT(action22()));
    connect(ui->pushButton_23,SIGNAL(clicked()),this,SLOT(action23()));
}
示例#16
0
uint8_t m0110_recv(void)
{
    uint8_t data = 0;
    m0110_error = 0;

    WAIT_MS(clock_lo, 250, 1);  // keyboard may block long time
    for (uint8_t i = 0; i < 8; i++) {
        data <<= 1;
        WAIT_US(clock_lo, 200, 2);
        WAIT_US(clock_hi, 200, 3);
        if (data_in()) {
            data |= 1;
        }
    }
    idle();
    return data;
ERROR:
    print("m0110_recv err: "); phex(m0110_error); print("\n");
    _delay_ms(500);
    idle();
    return 0xFF;
}
示例#17
0
文件: main.cpp 项目: cocoriuse/kodo
  int main()
  {
    // Set the number of symbols (i.e. the generation size in RLNC
    // terminology) and the size of a symbol in bytes
    uint32_t symbols = 42;
    uint32_t symbol_size = 100;

    typedef kodo::full_rlnc_encoder<fifi::binary8> rlnc_encoder;
    typedef kodo::full_rlnc_decoder<fifi::binary8> rlnc_decoder;

    // In the following we will make an encoder/decoder factory.
    // The factories are used to build actual encoders/decoders
    rlnc_encoder::factory encoder_factory(symbols, symbol_size);
    auto encoder = encoder_factory.build();

    rlnc_decoder::factory decoder_factory(symbols, symbol_size);
    auto  decoder = decoder_factory.build();

    std::vector<uint8_t> payload(encoder->payload_size());
    std::vector<uint8_t> data_in(encoder->block_size());

    // Just for fun - fill the data with random data
    for(auto &e: data_in)
        e = rand() % 256;

    // Assign the data buffer to the encoder so that we may start
    // to produce encoded symbols from it
    encoder->set_symbols(sak::storage(data_in));

    while( !decoder->is_complete() )
    {
        // Encode a packet into the payload buffer
        encoder->encode( &payload[0] );

        // Pass that packet to the decoder
        decoder->decode( &payload[0] );
    }
  }
int main()
{
    //! [2]
    // Set the number of symbols (i.e. the generation size in RLNC
    // terminology) and the size of a symbol in bytes
    uint32_t max_symbols = 40;
    uint32_t max_symbol_size = 64;

    uint32_t object_size = 6400;
    //! [3]

    //! [4]
    using storage_encoder = kodo::object::storage_encoder<
        kodo::shallow_full_rlnc_encoder<fifi::binary>,
        kodo::fixed_partitioning_scheme>;

    using storage_decoder = kodo::object::storage_decoder<
        kodo::shallow_full_rlnc_decoder<fifi::binary>,
        kodo::fixed_partitioning_scheme>;
    //! [5]

    storage_encoder::factory encoder_factory(max_symbols, max_symbol_size);
    storage_decoder::factory decoder_factory(max_symbols, max_symbol_size);

    std::vector<uint8_t> data_out(object_size, '\0');
    std::vector<uint8_t> data_in(object_size, 'x');

    encoder_factory.set_storage(sak::storage(data_in));
    decoder_factory.set_storage(sak::storage(data_out));

    auto object_encoder = encoder_factory.build();
    auto object_decoder = decoder_factory.build();

    std::cout << "Object size = " << object_size << std::endl;
    std::cout << "Encoder blocks = " << object_encoder->blocks() << std::endl;
    std::cout << "Decoder blocks = " << object_decoder->blocks() << std::endl;

    //! [6]
    for (uint32_t i = 0; i < object_encoder->blocks(); ++i)
    {
        std::cout << "Block = " << i << " symbols = "
                  << object_encoder->symbols(i) << " symbol size = "
                  << object_encoder->symbol_size(i) << std::endl;
    }
    //! [7]

    for (uint32_t i = 0; i < object_encoder->blocks(); ++i)
    {
        auto e = object_encoder->build(i);
        auto d = object_decoder->build(i);

        std::vector<uint8_t> payload(e->payload_size());

        while (!d->is_complete())
        {
            e->encode( payload.data() );

            // Here we would send and receive the payload over a
            // network. Lets throw away some packet to simulate.
            if (rand() % 2)
            {
                continue;
            }

            d->decode( payload.data() );
        }
    }

    // Check we properly decoded the data
    if (data_in == data_out)
    {
        std::cout << "Data decoded correctly" << std::endl;
    }
    else
    {
        std::cout << "Unexpected failure to decode "
                  << "please file a bug report :)" << std::endl;
    }
}
示例#19
0
void DataLayout::follow_weak_refs(BoolObjectClosure* cl) {
  ResourceMark m;
  data_in()->follow_weak_refs(cl);
}
示例#20
0
//----------------------------------------------------------------------------//
void test(gpuip::GpuEnvironment env, const char * codeA, const char * codeB,
          const char * boilerplateA, const char * boilerplateB)
{
    if (!gpuip::ImageProcessor::CanCreate(env)) {
        return;
    }
    
    const char * gpu[3] = {"OpenCL", "CUDA", "GLSL"};
    std::cout << "Testing " << gpu[env] << "..." << std::endl;
    
    const unsigned int width = 4;
    const unsigned int height = 4;
    const unsigned int N = width * height;
    gpuip::ImageProcessor::Ptr ip(gpuip::ImageProcessor::Create(env));
    ip->SetDimensions(width, height);

    gpuip::Buffer::Ptr b1 = ip->CreateBuffer("b1", gpuip::Buffer::FLOAT, 1);
    gpuip::Buffer::Ptr b2 = ip->CreateBuffer("b2", gpuip::Buffer::FLOAT, 1);
    gpuip::Buffer::Ptr b3 = ip->CreateBuffer("b3", gpuip::Buffer::FLOAT, 1);

    gpuip::Kernel::Ptr kernelA = ip->CreateKernel("my_kernelA");
    assert(kernelA.get() != NULL);
    assert(kernelA->name == std::string("my_kernelA"));
    kernelA->code = codeA;
    kernelA->inBuffers.push_back(gpuip::Kernel::BufferLink(b1,"A"));
    kernelA->outBuffers.push_back(gpuip::Kernel::BufferLink(b2,"B"));
    kernelA->outBuffers.push_back(gpuip::Kernel::BufferLink(b3,"C"));


    const gpuip::Parameter<int> incA("incA", 2);
    const gpuip::Parameter<float> incB("incB", 0.25);
    kernelA->paramsInt.push_back(incA);
    kernelA->paramsFloat.push_back(incB);
    assert(ip->BoilerplateCode(kernelA) == std::string(boilerplateA));
    
    gpuip::Kernel::Ptr kernelB = ip->CreateKernel("my_kernelB");
    assert(kernelB.get() != NULL);
    assert(kernelB->name == std::string("my_kernelB"));
    kernelB->code = codeB;
    kernelB->inBuffers.push_back(gpuip::Kernel::BufferLink(b2,"B"));
    kernelB->inBuffers.push_back(gpuip::Kernel::BufferLink(b3,"C"));
    kernelB->outBuffers.push_back(gpuip::Kernel::BufferLink(b1,"A"));
    assert(ip->BoilerplateCode(kernelB) == std::string(boilerplateB));
    
    std::string err;
    assert(ip->Allocate(&err) >= 0);
    assert(ip->Allocate(&err) >= 0); //reiniting should not break things
    
    std::vector<float> data_in(N);
    for(size_t i = 0; i < data_in.size(); ++i) {
        data_in[i] = i;
    }
    assert(ip->Copy(b1, gpuip::Buffer::WRITE_DATA,
                   data_in.data(), &err) >= 0);

    assert(ip->Build(&err) >= 0);
    assert(ip->Build(&err) >= 0); // rebuilding should not break things
  
    assert(ip->Run(&err) >= 0);
    
    std::vector<float> data_outA(N), data_outB(N), data_outC(N);
    assert(ip->Copy(b1, gpuip::Buffer::READ_DATA,data_outA.data(),&err) >= 0);
    assert(ip->Copy(b2, gpuip::Buffer::READ_DATA,data_outB.data(),&err) >= 0);
    assert(ip->Copy(b3, gpuip::Buffer::READ_DATA,data_outC.data(),&err) >= 0);

    for(unsigned int i = 0; i < N; ++i) {
        // Check first kernel call, where B = A + 0.2, C = A + 0.25
        assert(equal(data_outB[i], data_in[i] + incA.value*0.1));
        assert(equal(data_outC[i], data_in[i] + incB.value));

        // Check second kernel call, where A = B + C
        assert(equal(data_outA[i], data_outB[i] + data_outC[i]));
    }
    std::cout << "Test passed!" << std::endl;
}
示例#21
0
static inline uint16_t wait_data_hi(uint16_t us)
{
    while (!data_in() && us)  { asm(""); _delay_us(1); us--; }
    return us;
}
示例#22
0
int main(void)
{
    // Seed random number generator to produce different results every time
    srand((uint32_t)time(0));

    // Set the number of symbols (i.e. the generation size in RLNC
    // terminology) and the size of a symbol in bytes
    uint32_t max_symbols = 6;
    uint32_t max_symbol_size = 32;

    // Initilization of encoder and decoder
    kodocpp::encoder_factory encoder_factory(
        kodocpp::codec::full_vector,
        kodocpp::field::binary8,
        max_symbols,
        max_symbol_size);

    kodocpp::encoder encoder = encoder_factory.build();

    kodocpp::decoder_factory decoder_factory(
        kodocpp::codec::full_vector,
        kodocpp::field::binary8,
        max_symbols,
        max_symbol_size);

    kodocpp::decoder decoder = decoder_factory.build();

    // Allocate some storage for a "payload" the payload is what we would
    // eventually send over a network
    std::vector<uint8_t> payload(encoder.payload_size());

    // Allocate input and output data buffers
    std::vector<uint8_t> data_in(encoder.block_size());
    std::vector<uint8_t> data_out(decoder.block_size());

    // Fill the input buffer with random data
    std::generate(data_in.begin(), data_in.end(), rand);

    // Set the symbol storage for the encoder and decoder
    encoder.set_const_symbols(data_in.data(), encoder.block_size());
    decoder.set_mutable_symbols(data_out.data(), decoder.block_size());

    // Install the default trace function for encoder (writes to stdout)
    encoder.set_trace_stdout();

    // Install a custom trace function for the decoder
    auto callback = [](const std::string& zone, const std::string& data)
    {
        std::set<std::string> filters =
        {
            "decoder_state", "symbol_coefficients_before_read_symbol",
            "symbol_index_before_read_uncoded_symbol"
        };

        if (filters.count(zone))
        {
            std::cout << zone << ":" << std::endl;
            std::cout << data << std::endl;
        }
    };

    decoder.set_trace_callback(callback);

    while (!decoder.is_complete())
    {
        encoder.write_payload(payload.data());

        // Simulate a lossy channel where we are losing 50% of the packets
        if ((rand() % 2) == 0)
        {
            continue;
        }

        decoder.read_payload(payload.data());
    }

    // Check if we properly decoded the data
    if (std::equal(data_out.begin(), data_out.end(), data_in.begin()))
    {
        std::cout << "Data decoded correctly" << std::endl;
    }
    else
    {
        std::cout << "Unexpected failure to decode, "
                  << "please file a bug report :)" << std::endl;
    }

    return 0;
}
示例#23
0
ENCODED_DATA encode(uint32_t N, uint32_t max_symbols, 
         uint32_t max_symbol_size, kodocpp::field  field_size, char *data_in_char, 
          int data_size) {

    kodocpp::encoder_factory encoder_factory(
        kodocpp::codec::full_vector,
        field_size,
        max_symbols,
        max_symbol_size);

    kodocpp::encoder encoder = encoder_factory.build();

    std::cout << "Payload size : " << encoder.payload_size() << std::endl;
    std::vector<uint8_t> payload(encoder.payload_size());
    // Allocate input and output data buffers
    std::vector<uint8_t> data_in(encoder.block_size());

    char *data = data_in_char; 
    uint32_t data_encoded=0;
    uint32_t block_size = max_symbols*max_symbol_size;

    uint32_t total_num_blocks = ceil(static_cast<float>(data_size)/static_cast<float>(block_size));

    std::vector< std::vector< std::vector<uint8_t> > > *encoded_data = new std::vector< std::vector< std::vector<uint8_t> > >[N];
    std::vector< std::vector<uint8_t> > *striped_data = new std::vector< std::vector<uint8_t> >[N];
    

    int block_num = 0;
    int encoded_symbol_size;
    while( data_encoded < data_size ) {
          std::generate(data_in.begin(), data_in.end(), 
                [&data, &data_encoded,data_size] () ->uint8_t{ 
                      if(data_encoded < data_size) {
                          data_encoded++;
                          return *data++; 
                       }
                          data_encoded++;
                       return 32;
                    }

                 );

         encoder.set_const_symbols(data_in.data(), encoder.block_size());


         for(int i = 0; i < N; i ++ ) {
             std::vector<uint8_t> encoded_symbol; 


             uint32_t bytes_used = encoder.write_payload(payload.data());
            
             for (std::vector<uint8_t>::const_iterator it = payload.begin(); it != payload.end(); ++it){
                encoded_symbol.push_back(*it);
             }
             striped_data[i].push_back(encoded_symbol);
             encoded_symbol_size =  payload.size();
         }
         block_num++;
   }

   for(int i =0; i < N; i++) {
       encoded_data->push_back(striped_data[i]);
   }


    uint8_t *encoded_raw_data = (uint8_t *)malloc(block_num*encoded_symbol_size*N*sizeof(uint8_t));

    uint8_t *p = encoded_raw_data;

    int count=0;
    for(int b =0; b < block_num; b++) {
        for(int s =0; s < N; s++) {
            for(std::vector<uint8_t>::const_iterator it = (*encoded_data)[s][b].begin(); 
                    it != (*encoded_data)[s][b].end(); ++it){
                *p++ = *it;
                 count++;
            }
        }
    }

    std::cout << "done writing to buffer" << std::endl;

   ENCODED_DATA data_info; 

   data_info.encoded_symbol_size = encoded_symbol_size;
   //data_info.vdata = encoded_data;
   data_info.encoded_raw_data = encoded_raw_data;
   data_info.k = max_symbols;
   data_info.N = N;
   data_info.num_blocks = block_num;

   std::cout << "num_blocks " << block_num << std::endl;
   std::cout << "max_symbols " << max_symbols << std::endl;
   std::cout << "max_symbol_size " << max_symbol_size << std::endl;
   std::cout << "encoded max_symbol_size " << encoded_symbol_size << std::endl;
   std::cout << "Total Number of uncoded symbols " << max_symbols*max_symbol_size *block_num << std::endl;
   std::cout << "Total Number of coded symbols " << block_num*(max_symbol_size+6)*N << std::endl;
   std::cout << "Total Number of coded symbols " << block_num*encoded_symbol_size*N << std::endl;
   std::cout << "======================================\n";

   return data_info;

}
bool CClientUDPSocket::ProcessPacket(const BYTE* packet, uint16 size, uint8 opcode, uint32 ip, uint16 port)
{
	switch(opcode)
	{
		case OP_REASKCALLBACKUDP:
		{
			if (thePrefs.GetDebugClientUDPLevel() > 0)
				DebugRecv("OP_ReaskCallbackUDP", NULL, NULL, ip);
			theStats.AddDownDataOverheadOther(size);
			CUpDownClient* buddy = theApp.clientlist->GetBuddy();
			if( buddy )
			{
				if( size < 17 || buddy->socket == NULL )
					break;
				if (!md4cmp(packet, buddy->GetBuddyID()))
				{
					PokeUInt32(const_cast<BYTE*>(packet)+10, ip);
					PokeUInt16(const_cast<BYTE*>(packet)+14, port);
					Packet* response = new Packet(OP_EMULEPROT);
					response->opcode = OP_REASKCALLBACKTCP;
					response->pBuffer = new char[size];
					memcpy(response->pBuffer, packet+10, size-10);
					response->size = size-10;
					if (thePrefs.GetDebugClientTCPLevel() > 0)
						DebugSend("OP__ReaskCallbackTCP", buddy);
					theStats.AddUpDataOverheadFileRequest(response->size);
					buddy->socket->SendPacket(response);
				}
			}
			break;
		}
		case OP_REASKFILEPING:
		{
			theStats.AddDownDataOverheadFileRequest(size);
			CSafeMemFile data_in(packet, size);
			uchar reqfilehash[16];
			data_in.ReadHash16(reqfilehash);
			CKnownFile* reqfile = theApp.sharedfiles->GetFileByID(reqfilehash);
			if (!reqfile)
			{
				if (thePrefs.GetDebugClientUDPLevel() > 0) {
					DebugRecv("OP_ReaskFilePing", NULL, reqfilehash, ip);
					DebugSend("OP__FileNotFound", NULL);
				}

				Packet* response = new Packet(OP_FILENOTFOUND,0,OP_EMULEPROT);
				theStats.AddUpDataOverheadFileRequest(response->size);
				SendPacket(response, ip, port);
				break;
			}
			CUpDownClient* sender = theApp.uploadqueue->GetWaitingClientByIP_UDP(ip, port);
			if (sender)
			{
				if (thePrefs.GetDebugClientUDPLevel() > 0)
					DebugRecv("OP_ReaskFilePing", sender, reqfilehash);

				//Make sure we are still thinking about the same file
				if (md4cmp(reqfilehash, sender->GetUploadFileID()) == 0)
				{
					sender->AddAskedCount();
					sender->SetLastUpRequest();
					//I messed up when I first added extended info to UDP
					//I should have originally used the entire ProcessExtenedInfo the first time.
					//So now I am forced to check UDPVersion to see if we are sending all the extended info.
					//For now on, we should not have to change anything here if we change
					//anything to the extended info data as this will be taken care of in ProcessExtendedInfo()
					//Update extended info. 
					if (sender->GetUDPVersion() > 3)
					{
						sender->ProcessExtendedInfo(&data_in, reqfile);
					}
					//Update our complete source counts.
					else if (sender->GetUDPVersion() > 2)
					{
						uint16 nCompleteCountLast= sender->GetUpCompleteSourcesCount();
						uint16 nCompleteCountNew = data_in.ReadUInt16();
						sender->SetUpCompleteSourcesCount(nCompleteCountNew);
						if (nCompleteCountLast != nCompleteCountNew)
						{
							reqfile->UpdatePartsInfo();
						}
					}
					CSafeMemFile data_out(128);
					if(sender->GetUDPVersion() > 3)
					{
						if (reqfile->IsPartFile())
							((CPartFile*)reqfile)->WritePartStatus(&data_out);
						else
							data_out.WriteUInt16(0);
					}
					data_out.WriteUInt16(theApp.uploadqueue->GetWaitingPosition(sender));
					if (thePrefs.GetDebugClientUDPLevel() > 0)
						DebugSend("OP__ReaskAck", sender);
					Packet* response = new Packet(&data_out, OP_EMULEPROT);
					response->opcode = OP_REASKACK;
					theStats.AddUpDataOverheadFileRequest(response->size);
					theApp.clientudp->SendPacket(response, ip, port);
				}
				else
				{
					DebugLogError(_T("Client UDP socket; ReaskFilePing; reqfile does not match"));
					TRACE(_T("reqfile:         %s\n"), DbgGetFileInfo(reqfile->GetFileHash()));
					TRACE(_T("sender->GetRequestFile(): %s\n"), sender->GetRequestFile() ? DbgGetFileInfo(sender->GetRequestFile()->GetFileHash()) : _T("(null)"));
				}
			}
			else
			{
				if (thePrefs.GetDebugClientUDPLevel() > 0)
					DebugRecv("OP_ReaskFilePing", NULL, reqfilehash, ip);

				if (((uint32)theApp.uploadqueue->GetWaitingUserCount() + 50) > thePrefs.GetQueueSize())
				{
					if (thePrefs.GetDebugClientUDPLevel() > 0)
						DebugSend("OP__QueueFull", NULL);
					Packet* response = new Packet(OP_QUEUEFULL,0,OP_EMULEPROT);
					theStats.AddUpDataOverheadFileRequest(response->size);
					SendPacket(response, ip, port);
				}
			}
			break;
		}
		case OP_QUEUEFULL:
		{
			theStats.AddDownDataOverheadFileRequest(size);
			CUpDownClient* sender = theApp.downloadqueue->GetDownloadClientByIP_UDP(ip, port);
			if (thePrefs.GetDebugClientUDPLevel() > 0)
				DebugRecv("OP_QueueFull", sender, NULL, ip);
			if (sender){
				sender->SetRemoteQueueFull(true);
				sender->UDPReaskACK(0);
			}
			break;
		}
		case OP_REASKACK:
		{
			theStats.AddDownDataOverheadFileRequest(size);
			CUpDownClient* sender = theApp.downloadqueue->GetDownloadClientByIP_UDP(ip, port);
			if (thePrefs.GetDebugClientUDPLevel() > 0)
				DebugRecv("OP_ReaskAck", sender, NULL, ip);
			if (sender){
				CSafeMemFile data_in(packet, size);
				if ( sender->GetUDPVersion() > 3 )
				{
					sender->ProcessFileStatus(true, &data_in, sender->GetRequestFile());
				}
				uint16 nRank = data_in.ReadUInt16();
				sender->SetRemoteQueueFull(false);
				sender->UDPReaskACK(nRank);
				sender->AddAskedCountDown();
			}
			break;
		}
		case OP_FILENOTFOUND:
		{
			theStats.AddDownDataOverheadFileRequest(size);
			CUpDownClient* sender = theApp.downloadqueue->GetDownloadClientByIP_UDP(ip, port);
			if (thePrefs.GetDebugClientUDPLevel() > 0)
				DebugRecv("OP_FileNotFound", sender, NULL, ip);
			if (sender){
				sender->UDPReaskFNF(); // may delete 'sender'!
				sender = NULL;
			}
			break;
		}
		case OP_PORTTEST:
		{
			if (thePrefs.GetDebugClientUDPLevel() > 0)
				DebugRecv("OP_PortTest", NULL, NULL, ip);
			theStats.AddDownDataOverheadOther(size);
			if (size == 1){
				if (packet[0] == 0x12){
					bool ret = theApp.listensocket->SendPortTestReply('1', true);
					AddDebugLogLine(true, _T("UDP Portcheck packet arrived - ACK sent back (status=%i)"), ret);
				}
			}
			break;
		}
		default:
			theStats.AddDownDataOverheadOther(size);
			if (thePrefs.GetDebugClientUDPLevel() > 0)
			{
				CUpDownClient* sender = theApp.downloadqueue->GetDownloadClientByIP_UDP(ip, port);
				Debug(_T("Unknown client UDP packet: host=%s:%u (%s) opcode=0x%02x  size=%u\n"), ipstr(ip), port, sender ? sender->DbgGetClientInfo() : _T(""), opcode, size);
			}
			return false;
	}
	return true;
}
示例#25
0
文件: fvcd.cpp 项目: Surtr04/CPD_PI
int main(int argc, char *argv[])
{
if (argc < 4) 
        {
        cout<<"Wrong format"<<endl;    
        cout<<"PLEASE use Convert data gmsh->xml: fvcd mesh.xml data.xml data.msh (-c/v) "<<endl;
        exit(0);
        }        
FVVect<double> x=0,y=0,z=0; 
string    file_mesh=argv[1];
string    file_in=argv[2];
string    file_out=argv[3];    
string    type_name,name;
double    time=0;
size_t nbv=0,type=0;
if(argc==5) type_name=argv[4]; else type_name="-c"; // default data on cell
if(type_name.compare("-v")) type=CELL; else type=VERTEX;
//cout<<file_mesh<<" "<<file_in<<" "<<file_out<<" "<<dim<<" "<<type<<endl;
size_t l;
l=file_mesh.length();
string label_mesh;label_mesh.insert(0,file_mesh,l-4,4);
l=file_in.length();
string label_in;label_in.insert(0,file_in,l-4,4);
l=file_out.length();
string label_out;label_out.insert(0,file_out,l-4,4);
if(label_mesh.compare(".xml"))  {cout<<"Wrong Mesh format, .xml label required"<<endl; exit(0);}
if(label_in.compare(".xml"))  {cout<<"Wrong input file format, .xml label required"<<endl; exit(0);}
if(label_out.compare(".msh")) {cout<<"Wrong output file format, .msh label required"<<endl; exit(0);} 
//
FVMesh1D m1;
FVMesh2D m2;
FVMesh3D m3;
Gmsh mg;
//cout<<"reading the xml mesh file"<<endl;fflush(NULL);
if(m3.read(file_mesh.c_str())==FVOK) mg.FVMesh2Gmsh(m3);
if(m2.read(file_mesh.c_str())==FVOK) mg.FVMesh2Gmsh(m2);      
if(m1.read(file_mesh.c_str())==FVOK) mg.FVMesh2Gmsh(m1);
//cout<<"read ok, now we write the msh mesh"<<endl;
mg.writeMesh(file_out.c_str());
FVio data_in(file_in.c_str(),FVREAD);
// convert the data
size_t result=FVOK;
while (result==FVOK)
    {
     result=data_in.get(x, y, z, time, name);
     nbv=data_in.getNbVect();
     if(result==FVOK) 
         {
         switch(nbv)
              {
              case 0:
              cout<<"  nbvec not found in the file"<<endl;    
              result=FVERROR;
              break;    
              case 1:
              mg.writeVector(x,type,name.c_str(),time);    
              break;
              case 2:
              mg.writeVector(x,y,type,name.c_str(),time);              
              break;
              case 3:
              mg.writeVector(x,y,z,type,name.c_str(),time); 
              break;
              }
          }    
     }  
mg.close();   
}
/// @example use_cached_symbol_decoder.cpp
///
/// This example shows how to use the cached symbol decoder to "extract"
/// the symbol coding coefficients and the encoded symbol data from an
/// incoming symbol.
int main()
{
    // The finite field we will use in the example. You can try
    // with other fields by specifying e.g. fifi::binary8 for the
    // extension field 2^8
    typedef fifi::binary finite_field;

    // Set the number of symbols (i.e. the generation size in RLNC
    // terminology) and the size of a symbol in bytes
    uint32_t symbols = 8;
    uint32_t symbol_size = 160;

    // Typdefs for the encoder/decoder type we wish to use
    typedef kodo::full_rlnc_encoder<finite_field> rlnc_encoder;
    typedef kodo::full_rlnc_decoder<finite_field> rlnc_decoder;

    typedef kodo::symbol_info_decoder<finite_field> rlnc_info_decoder;

    // In the following we will make an encoder/decoder factory.
    // The factories are used to build actual encoders/decoders.
    // Each stack we use have their own factories.
    rlnc_encoder::factory encoder_factory(symbols, symbol_size);
    auto encoder = encoder_factory.build();

    rlnc_decoder::factory decoder_factory(symbols, symbol_size);
    auto decoder = decoder_factory.build();

    rlnc_info_decoder::factory info_decoder_factory(symbols, symbol_size);
    auto info_decoder = info_decoder_factory.build();

    // Allocate some storage for a "payload" the payload is what we would
    // eventually send over a network
    std::vector<uint8_t> payload(encoder->payload_size());

    // Allocate some data to encode. In this case we make a buffer
    // with the same size as the encoder's block size (the max.
    // amount a single encoder can encode)
    std::vector<uint8_t> data_in(encoder->block_size());

    // Just for fun - fill the data with random data
    for(auto &e: data_in)
        e = rand() % 256;

    // Assign the data buffer to the encoder so that we may start
    // to produce encoded symbols from it
    encoder->set_symbols(sak::storage(data_in));

    while( !decoder->is_complete())
    {
        // Encode a packet into the payload buffer
        encoder->encode( &payload[0] );

        // Here we "simulate" a packet loss of approximately 50%
        // by dropping half of the encoded packets.
        // When running this example you will notice that the initial
        // symbols are received systematically (i.e. uncoded). After
        // sending all symbols once uncoded, the encoder will switch
        // to full coding, in which case you will see the full encoding
        // vectors being sent and received.
        if((rand() % 2) == 0)
            continue;

        // Pass the encoded packet to the info decoder. After this
        // information about the coded symbol can be fetched using the
        // cached_symbol_decoder API
        info_decoder->decode( &payload[0] );

        if(!info_decoder->cached_symbol_coded())
        {
            // The symbol was uncoded so we may ask the cache which of the
            // original symbols we have received.

            std::cout << "Symbol was uncoded, index = "
                      << info_decoder->cached_symbol_index() << std::endl;

            // Now we pass the data directly into our actual decoder. This is
            // done using the "Codec API" directly, and not through the "Payload
            // API" as we would typically do.
            decoder->decode_symbol( info_decoder->cached_symbol_data(),
                                    info_decoder->cached_symbol_index());

        }
        else
        {
            // The symbol was coded so we may ask the cache to return
            // the coding coefficients used to create the encoded symbol.

            std::cout << "Symbol was coded, encoding vector = ";

            const uint8_t* c = info_decoder->cached_symbol_coefficients();

            // We loop through the coefficient buffer and print the coefficients
            for(uint32_t i = 0; i < info_decoder->symbols(); ++i)
            {
                std::cout << (uint32_t) fifi::get_value<finite_field>(c, i)
                          << " ";
            }

            std::cout << std::endl;

            // Pass that packet to the decoder, as with the uncoded symbols
            // above we pass it directly to the "Codec API"
            decoder->decode_symbol(info_decoder->cached_symbol_data(),
                                   info_decoder->cached_symbol_coefficients());

        }
    }

    // The decoder is complete, now copy the symbols from the decoder
    std::vector<uint8_t> data_out(decoder->block_size());
    decoder->copy_symbols(sak::storage(data_out));

    // Check we properly decoded the data
    if (std::equal(data_out.begin(), data_out.end(), data_in.begin()))
    {
        std::cout << "Data decoded correctly" << std::endl;
    }
    else
    {
        std::cout << "Unexpected failure to decode "
                  << "please file a bug report :)" << std::endl;
    }
}
示例#27
0
void DataLayout::clean_weak_klass_links(BoolObjectClosure* cl) {
  ResourceMark m;
  data_in()->clean_weak_klass_links(cl);
}
示例#28
0
int main()
{
    // Seed the random number generator to produce different data every time
    srand((uint32_t)time(0));

    // Set the number of symbols and the symbol size
    uint32_t max_symbols = 10;
    uint32_t max_symbol_size = 100;

    // Create encoder/decoder factories that we will use to build the actual
    // encoder and decoder
    kodocpp::encoder_factory encoder_factory(
        kodocpp::codec::sparse_seed,
        kodocpp::field::binary8,
        max_symbols,
        max_symbol_size);

    kodocpp::encoder encoder = encoder_factory.build();

    kodocpp::decoder_factory decoder_factory(
        kodocpp::codec::sparse_seed,
        kodocpp::field::binary8,
        max_symbols,
        max_symbol_size);

    kodocpp::decoder decoder = decoder_factory.build();

    // The coding vector density on the encoder can be set with set_density().
    // Note: the density can be adjusted at any time. This feature can be used
    // to adapt to changing network conditions.
    std::cout << "The density defaults to: " << encoder.density() << std::endl;
    encoder.set_density(0.4);
    std::cout << "The density was set to: " << encoder.density() << std::endl;
    // A low density setting can lead to a large number of redundant symbols.
    // In practice, the value should be tuned to the specific scenario.

    // Allocate some storage for a "payload" the payload is what we would
    // eventually send over a network
    std::vector<uint8_t> payload(encoder.payload_size());

    // Allocate input and output data buffers
    std::vector<uint8_t> data_in(encoder.block_size());
    std::vector<uint8_t> data_out(decoder.block_size());

    // Fill the input buffer with random data
    std::generate(data_in.begin(), data_in.end(), rand);

    // Set the symbol storage for the encoder and decoder
    encoder.set_const_symbols(data_in.data(), encoder.block_size());
    decoder.set_mutable_symbols(data_out.data(), decoder.block_size());

    // Install a custom trace function for the decoder
    auto callback = [](const std::string& zone, const std::string& data)
    {
        std::set<std::string> filters =
            {
                "decoder_state", "symbol_coefficients_before_read_symbol"
            };

        if (filters.count(zone))
        {
            std::cout << zone << ":" << std::endl;
            std::cout << data << std::endl;
        }
    };
    decoder.set_trace_callback(callback);

    uint32_t lost_payloads = 0;
    uint32_t received_payloads = 0;

    while (!decoder.is_complete())
    {
        // The encoder will use a certain amount of bytes of the payload buffer
        uint32_t bytes_used = encoder.write_payload(payload.data());
        std::cout << "Payload generated by encoder, bytes used = "
                  << bytes_used << std::endl;

        // Simulate a channel with a 50% loss rate
        if ((rand() % 2) == 0)
        {
            lost_payloads++;
            continue;
        }

        // Pass the generated packet to the decoder
        received_payloads++;
        decoder.read_payload(payload.data());
        std::cout << "Payload processed by decoder, current rank = "
                  << decoder.rank() << std::endl << std::endl;
    }

    std::cout << "Number of lost payloads: " << lost_payloads << std::endl;
    std::cout << "Number of received payloads: " << received_payloads
              << std::endl;

    // Check if we properly decoded the data
    if (data_in == data_out)
    {
        std::cout << "Data decoded correctly" << std::endl;
    }
    else
    {
        std::cout << "Unexpected failure to decode, "
                  << "please file a bug report :)" << std::endl;
    }

    return 0;
}
示例#29
0
inline void
invoke_reuse_incomplete(uint32_t symbols, uint32_t symbol_size)
{

    bool do_complete;

    typename Encoder::factory encoder_factory(symbols, symbol_size);
    typename Decoder::factory decoder_factory(symbols, symbol_size);

    // Use factory a lot of times
    for (uint32_t i = 0; i < 100; ++i)
    {
        // Build coders
        auto encoder = encoder_factory.build();
        auto decoder = decoder_factory.build();

        // Prepare buffers
        std::vector<uint8_t> payload(encoder->payload_size());
        std::vector<uint8_t> data_in(encoder->block_size());

        // Fill with random data
        for (auto &e: data_in)
            e = rand() % 256;

        // Put data in encoder
        encoder->set_symbols(sak::storage(data_in));

        if (rand() % 100 > 90)
        {
            do_complete = false;
        }
        else
        {
            do_complete = true;
        }

        // Start encoding/decoding
        while (!decoder->is_complete())
        {
            encoder->encode(&payload[0]);

            // Loose a packet with probability
            if (rand() % 100 > 90)
                continue;

            decoder->decode(&payload[0]);

            // Stop decoding after a while with probability
            if (!do_complete && decoder->rank() == symbols - 2)
                break;
        }

        // Check if completed decoders are correct
        if (decoder->is_complete())
        {
            std::vector<uint8_t> data_out(decoder->block_size());
            decoder->copy_symbols(sak::storage(data_out));

            ASSERT_TRUE(sak::equal(sak::storage(data_out),
                                   sak::storage(data_in)));
        }
    }

}
示例#30
0
int main()
{
    // Seed the random number generator to produce different data every time
    srand((uint32_t)time(0));

    // Set the number of symbols (i.e. the generation size in RLNC
    // terminology) and the size of a symbol in bytes
    uint32_t max_symbols = 16;
    uint32_t max_symbol_size = 1400;

    //! [0]
    // In the following we will make an encoder/decoder factory.
    // The factories are used to build actual encoders/decoders
    kodocpp::encoder_factory encoder_factory(
        kodocpp::codec::full_vector,
        kodocpp::field::binary8,
        max_symbols,
        max_symbol_size);

    kodocpp::encoder encoder = encoder_factory.build();

    kodocpp::decoder_factory decoder_factory(
        kodocpp::codec::full_vector,
        kodocpp::field::binary8,
        max_symbols,
        max_symbol_size);

    kodocpp::decoder decoder1 = decoder_factory.build();
    kodocpp::decoder decoder2 = decoder_factory.build();
    //! [1]

    std::vector<uint8_t> payload(encoder.payload_size());
    std::vector<uint8_t> data_in(encoder.block_size());
    // Just for fun - fill the data with random data
    std::generate(data_in.begin(), data_in.end(), rand);
    // Assign the data buffer to the encoder so that we may start
    // to produce encoded symbols from it
    encoder.set_const_symbols(data_in.data(), encoder.block_size());
    // Create a buffer which will contain the decoded data, and we assign
    // that buffer to the decoder
    std::vector<uint8_t> data_out1(decoder1.block_size());
    std::vector<uint8_t> data_out2(decoder2.block_size());
    decoder1.set_mutable_symbols(data_out1.data(), decoder1.block_size());
    decoder2.set_mutable_symbols(data_out2.data(), decoder2.block_size());

    uint32_t encoded_count = 0;
    uint32_t dropped_count = 0;

    // We switch any systematic operations off so the encoder produces
    // coded symbols from the beginning
    if (encoder.is_systematic_on())
        encoder.set_systematic_off();

    //! [2]
    while (!decoder2.is_complete())
    {
        // Encode a packet into the payload buffer
        encoder.write_payload(payload.data());

        ++encoded_count;

        if (rand() % 2)
        {
            ++dropped_count;
        }
        else
        {
            // Pass that packet to the decoder1
            decoder1.read_payload(payload.data());
        }

        // Create a recoded packet from decoder1
        decoder1.write_payload(payload.data());

        if (rand() % 2)
        {
            ++dropped_count;
        }
        else
        {
            // Pass the recoded packet to decoder two
            decoder2.read_payload(payload.data());
        }
    }
    //! [3]
    std::cout << "Encoded count = " << encoded_count << std::endl;
    std::cout << "Dropped count = " << dropped_count << std::endl;

    // Check if we properly decoded the data
    if (data_in == data_out2)
    {
        std::cout << "Data decoded correctly" << std::endl;
    }

    return 0;
}