void KeePass2Writer::writeDatabase(QIODevice* device, Database* db)
{
    m_error = false;
    m_errorStr.clear();

    QByteArray masterSeed = randomGen()->randomArray(32);
    QByteArray encryptionIV = randomGen()->randomArray(16);
    QByteArray protectedStreamKey = randomGen()->randomArray(32);
    QByteArray startBytes = randomGen()->randomArray(32);
    QByteArray endOfHeader = "\r\n\r\n";

    CryptoHash hash(CryptoHash::Sha256);
    hash.addData(masterSeed);
    Q_ASSERT(!db->transformedMasterKey().isEmpty());
    hash.addData(db->transformedMasterKey());
    QByteArray finalKey = hash.result();

    QBuffer header;
    header.open(QIODevice::WriteOnly);
    m_device = &header;

    CHECK_RETURN(writeData(Endian::int32ToBytes(KeePass2::SIGNATURE_1, KeePass2::BYTEORDER)));
    CHECK_RETURN(writeData(Endian::int32ToBytes(KeePass2::SIGNATURE_2, KeePass2::BYTEORDER)));
    CHECK_RETURN(writeData(Endian::int32ToBytes(KeePass2::FILE_VERSION, KeePass2::BYTEORDER)));

    CHECK_RETURN(writeHeaderField(KeePass2::CipherID, db->cipher().toByteArray()));
    CHECK_RETURN(writeHeaderField(KeePass2::CompressionFlags,
                                  Endian::int32ToBytes(db->compressionAlgo(),
                                                       KeePass2::BYTEORDER)));
    CHECK_RETURN(writeHeaderField(KeePass2::MasterSeed, masterSeed));
    CHECK_RETURN(writeHeaderField(KeePass2::TransformSeed, db->transformSeed()));
    CHECK_RETURN(writeHeaderField(KeePass2::TransformRounds,
                                  Endian::int64ToBytes(db->transformRounds(),
                                                       KeePass2::BYTEORDER)));
    CHECK_RETURN(writeHeaderField(KeePass2::EncryptionIV, encryptionIV));
    CHECK_RETURN(writeHeaderField(KeePass2::ProtectedStreamKey, protectedStreamKey));
    CHECK_RETURN(writeHeaderField(KeePass2::StreamStartBytes, startBytes));
    CHECK_RETURN(writeHeaderField(KeePass2::InnerRandomStreamID,
                                  Endian::int32ToBytes(KeePass2::Salsa20,
                                                       KeePass2::BYTEORDER)));
    CHECK_RETURN(writeHeaderField(KeePass2::EndOfHeader, endOfHeader));

    header.close();
    m_device = device;
    QByteArray headerHash = CryptoHash::hash(header.data(), CryptoHash::Sha256);
    CHECK_RETURN(writeData(header.data()));

    SymmetricCipherStream cipherStream(device, SymmetricCipher::Aes256, SymmetricCipher::Cbc,
                                       SymmetricCipher::Encrypt, finalKey, encryptionIV);
    cipherStream.open(QIODevice::WriteOnly);
    m_device = &cipherStream;
    CHECK_RETURN(writeData(startBytes));

    HashedBlockStream hashedStream(&cipherStream);
    hashedStream.open(QIODevice::WriteOnly);

    QScopedPointer<QtIOCompressor> ioCompressor;

    if (db->compressionAlgo() == Database::CompressionNone) {
        m_device = &hashedStream;
    }
    else {
        ioCompressor.reset(new QtIOCompressor(&hashedStream));
        ioCompressor->setStreamFormat(QtIOCompressor::GzipFormat);
        ioCompressor->open(QIODevice::WriteOnly);
        m_device = ioCompressor.data();
    }

    KeePass2RandomStream randomStream(protectedStreamKey);

    KeePass2XmlWriter xmlWriter;
    xmlWriter.writeDatabase(m_device, db, &randomStream, headerHash);
}
Ejemplo n.º 2
0
void TestRandom::testUInt()
{
    QByteArray nextBytes;

    nextBytes = Endian::int32ToBytes(42, QSysInfo::ByteOrder);
    m_backend->setNextBytes(nextBytes);
    QCOMPARE(randomGen()->randomUInt(100), 42U);

    nextBytes = Endian::int32ToBytes(117, QSysInfo::ByteOrder);
    m_backend->setNextBytes(nextBytes);
    QCOMPARE(randomGen()->randomUInt(100), 17U);

    nextBytes = Endian::int32ToBytes(1001, QSysInfo::ByteOrder);
    m_backend->setNextBytes(nextBytes);
    QCOMPARE(randomGen()->randomUInt(1), 0U);

    nextBytes.clear();
    nextBytes.append(Endian::int32ToBytes(QUINT32_MAX, QSysInfo::ByteOrder));
    nextBytes.append(Endian::int32ToBytes(QUINT32_MAX - 70000U, QSysInfo::ByteOrder));
    m_backend->setNextBytes(nextBytes);
    QCOMPARE(randomGen()->randomUInt(100000U), (QUINT32_MAX - 70000U) % 100000U);

    nextBytes.clear();
    for (int i = 0; i < 10000; i++) {
        nextBytes.append(Endian::int32ToBytes((QUINT32_MAX / 2U) + 1U + i, QSysInfo::ByteOrder));
    }
    nextBytes.append(Endian::int32ToBytes(QUINT32_MAX / 2U, QSysInfo::ByteOrder));
    m_backend->setNextBytes(nextBytes);
    QCOMPARE(randomGen()->randomUInt((QUINT32_MAX / 2U) + 1U), QUINT32_MAX / 2U);
}
Ejemplo n.º 3
0
void WorldErosion::run(){
    
    std::shared_ptr<Random> randomGen(new Random());
    
    //TileMap *testErode = worldMap->getTileMap(randomGen->rand_crypt(serverConfig->worldX)-1, randomGen->rand_crypt(serverConfig->worldY)-1, randomGen->rand_crypt(serverConfig->worldZ)-1);
    
    
    /*  fileLogger->WorldLog("WorldMap Erosion Started");
     for(int x = 0; x < worldMap->getX(); x++){
     for(int y = 0; y < worldMap->getY(); y++){
     for(int z = 0; z < worldMap->getZ(); z++){
     
     TileMap *testErode = worldMap->getTileMap(x, y, z);
     if(testErode == nullptr)
     break;
     TileMapErode(testErode);
     
     }
     }
     }
     fileLogger->WorldLog("WorldMap Erosion Completed"); */
    
    // Bresenham3D(5, 5, 0, 5, 5, 5, worldMap.get(), " ");
    
    //TileNoiseHeightmap(worldMap->getTileMap(0, 0, 0), 16, 0.50, 256, 2);
    //TileMapErode(worldMap->getTileMap(0, 0, 0), 30);
    WorldMapHeightMap(worldMap.get(), 32, 0.50, 128, 2);
    
    
}
Ejemplo n.º 4
0
void TestRandom::testUIntRange()
{
    QByteArray nextBytes;

    nextBytes = Endian::int32ToBytes(42, QSysInfo::ByteOrder);
    m_backend->setNextBytes(nextBytes);
    QCOMPARE(randomGen()->randomUIntRange(100, 200), 142U);
}
Ejemplo n.º 5
0
Archivo: rwalk.c Proyecto: a4a881d4/oai
void place_rwalk_node(NodePtr node) {

	node->X_pos = (double) ((int) (randomGen(omg_param_list.min_X, omg_param_list.max_X)*100))/ 100;
	node->mob->X_from = node->X_pos;
	node->mob->X_to = node->X_pos;
	node->Y_pos = (double) ((int) (randomGen(omg_param_list.min_Y,omg_param_list.max_Y)*100))/ 100;
	node->mob->Y_from = node->Y_pos;
	node->mob->Y_to = node->Y_pos;

	node->mob->speed = 0.0;
	node->mob->journey_time = 0.0;

	LOG_D(OMG, " INITIALIZE RWALK NODE\n ");
    LOG_I(OMG, "Initial position of node ID: %d type: %d (X = %.2f, Y = %.2f) speed = 0.0\n", node->ID, node->type, node->X_pos, node->Y_pos);   
	Node_Vector[RWALK] = (Node_list) add_entry(node, Node_Vector[RWALK]);
   Node_Vector_len[RWALK]++;
   //Initial_Node_Vector_len[RWALK]++;
}
Ejemplo n.º 6
0
int  main() {
  LinearGenerator linearGen(0,20,2);
  RandomGenerator randomGen(10);
  FibonacciGenerator fibGen(10);
  // MOCK 1
  std::vector<double> myVector;
  myVector.push_back(15);
  myVector.push_back(20);
  myVector.push_back(35);
  myVector.push_back(40);
  myVector.push_back(50);
  MockGenerator mockGen(myVector);
  // MOCK 2
  std::vector<double> myVector2;
  myVector2.push_back(1);
  myVector2.push_back(10);
  myVector2.push_back(50);
  MockGenerator mockGen2(myVector2);

  LinearInterpolationCalculator linInterCalc;
  NearestRankCalculator nearestRankCalc;

  DistributionTester mock0(&mockGen, &nearestRankCalc);
  DistributionTester mock1(&mockGen, &linInterCalc);
  DistributionTester mock2(&mockGen2, &linInterCalc);

  DistributionTester d1(&linearGen, &linInterCalc);
  DistributionTester d2(&linearGen, &nearestRankCalc);
  DistributionTester d3(&randomGen, &linInterCalc);
  DistributionTester d4(&randomGen, &nearestRankCalc);
  DistributionTester d5(&fibGen, &linInterCalc);
  DistributionTester d6(&fibGen, &nearestRankCalc);

  std::cout << "d1: " << d1.getPercentile(50) << std::endl;
  std::cout << "d2: " << d2.getPercentile(50) << std::endl;

  std::cout << "mock0: " << mock0.getPercentile(30) << std::endl;
  std::cout << "mock0: " << mock0.getPercentile(40) << std::endl;
  std::cout << "mock0: " << mock0.getPercentile(50) << std::endl;
  std::cout << "mock0: " << mock0.getPercentile(100) << std::endl;

  std::cout << "mock1: " << mock1.getPercentile(10) << std::endl;
  std::cout << "mock1: " << mock1.getPercentile(30) << std::endl;
  std::cout << "mock1: " << mock1.getPercentile(40) << std::endl;
  std::cout << "mock1: " << mock1.getPercentile(90) << std::endl;

  std::cout << "mock2: " << mock2.getPercentile(10) << std::endl;
  std::cout << "mock2: " << mock2.getPercentile(20) << std::endl;
  std::cout << "mock2: " << mock2.getPercentile(30) << std::endl;
  std::cout << "mock2: " << mock2.getPercentile(40) << std::endl;
  std::cout << "mock2: " << mock2.getPercentile(50) << std::endl;
  std::cout << "mock2: " << mock2.getPercentile(60) << std::endl;
  std::cout << "mock2: " << mock2.getPercentile(70) << std::endl;
  std::cout << "mock2: " << mock2.getPercentile(80) << std::endl;
  std::cout << "mock2: " << mock2.getPercentile(90) << std::endl;
}
Ejemplo n.º 7
0
void Ts2::Link::EndPoint::prepareNegotiation(Link::Protocol::LcpNegotiateSessionData& data)
{
    memset(&data, 0, sizeof(data));
    data.signMode = getSigningCapability();
    data.encMode = getEncryptionCapability();
    data.keyMaterialSize = ARRAY_SIZE_IN_BYTES(data.keyMaterial);

    randomGen(data.iv, CSL_AES_IVSIZE_BYTES, 0);

    if(!isServer) {
        MutexAutoLock lock(&mutex);
        u8 keyMaterial[LCP_NEGOTIATE_SESSION_KEY_MATERIAL_SIZE];
        randomGen(keyMaterial, ARRAY_SIZE_IN_BYTES(keyMaterial), 0);
        const KeysInKeyMaterial *keys = (KeysInKeyMaterial*)keyMaterial;
        signKey.assign((const char*)keys->sign, ARRAY_SIZE_IN_BYTES(keys->sign));
        encKey.assign((const char*)keys->enc, ARRAY_SIZE_IN_BYTES(keys->enc));

        // Encrypt it
        encrypt_data(data.keyMaterial, keyMaterial, ARRAY_SIZE_IN_BYTES(keyMaterial),
                     data.iv, *sessionKey);
    } else {
        randomGen(data.keyMaterial, ARRAY_SIZE_IN_BYTES(data.keyMaterial), 0);
    }
}
Ejemplo n.º 8
0
std::vector<int> IStrategy::initPermutation(unsigned N)
{
	std::vector<int> result;
	int current = 0;
	std::generate_n(
			std::back_inserter(result), 
			N, 
			[&]()->int{ return current++; }
	);

	std::random_device rd;
    std::mt19937 randomGen(rd());
	std::shuffle(result.begin(), result.end(), randomGen);
	
	return result;
}
Ejemplo n.º 9
0
void main() {
    matchString myStr = "123445";
	const unsigned colores = 6, posiciones = 6;
    match aciertos;
  
    cout << "Cadena inicial 123445\n";
    for ( unsigned i = 0; i < 40; i ++ ) {
		string checkStr;
		randomGen( checkStr, posiciones, colores );
		aciertos =  myStr.check(checkStr);
		cout << "Cadena 123445\nCadena " << checkStr <<
			" Plenos " << aciertos.full <<
			" Parciales " << aciertos.color << endl;
	}
	return 0;
      
}
Ejemplo n.º 10
0
Archivo: rwalk.c Proyecto: a4a881d4/oai
Pair sleep_rwalk_node(NodePtr node, double cur_time){
	node->mobile = 0;
	node->mob->speed = 0.0;
	node->mob->X_from = node->mob->X_to;
	node->mob->Y_from = node->mob->Y_to;
	node->X_pos = node->mob->X_to;
	node->Y_pos = node->mob->Y_to;
	Pair pair = malloc(sizeof(Pair)) ;

	node->mob->sleep_duration = (double) ((int) (randomGen(omg_param_list.min_sleep, omg_param_list.max_sleep)*100))/ 100;
	LOG_D(OMG, "node: %d \tsleep duration : %.2f\n",node->ID, node->mob->sleep_duration);

	node->mob->start_journey = cur_time;
	pair->a = node->mob->start_journey + node->mob->sleep_duration; //when to wake up
	LOG_D(OMG, "to wake up at time: cur_time + sleep_duration : %.2f\n", pair->a);
	pair->b = node;

	return pair;
}
int main()
{
    Tree *tree = createTree();
    Hashtable *table5, *table50, *table500;
    FILE *fp50, *fp500, *fp5mil;
    clock_t tstart, tend;
    time_t t;
    srand((unsigned) time(&t));
    double favg;
    int data = 0, i = 0, search, value, found;
    int array50k[50000], *array500k, *array5mil;
    array500k = malloc(500001 * sizeof(int));
    array5mil = malloc(5000001 * sizeof(int));
    if(tree == NULL)
        printf("Memory allocation failed...");
    fp50 = fopen("50tus.txt", "r");
    fp500 = fopen("500tus.txt", "r");
    fp5mil = fopen("5mil.txt", "r");
    if(fp50 == NULL || fp500 == NULL|| fp5mil == NULL)
    {
        fprintf(stderr, "error\n");
        return 1;
    }
    system("color 3");
    table5 = create_table(50000000);
    table50 = create_table(500000);
    table500 = create_table(5000000);

    /*50k*/
    printf("\n50k insert, balance and search!\n");
    printf("Insert: 50k ");
    tstart = clock(); // start
    for(i = 0; i < 50000; ++i)
    {
        fscanf(fp50,"%d\n", &data);
        insert(tree, data);
    }
    tend = clock(); // end
    favg = ((double)(tend - tstart))/CLOCKS_PER_SEC;
    printf("Avg. execution time: %g sec\n",favg);
    tree_to_arr(tree);
    printf("Searching 100x in 50k ");
    tstart = clock(); // start
    find_tree(tree);
    tend = clock(); // end
    favg = ((double)(tend - tstart))/CLOCKS_PER_SEC;
    printf("Avg. execution time: %g sec\n",favg);
    clear_tree(tree);

    /*500k*/
    printf("\n500k insert, balance and search!\n");
    printf("Insert: 500k ");
    tstart = clock(); // start
    for(i = 0; i < 500000; ++i)
    {
        fscanf(fp500,"%d\n", &data);
        insert(tree, data);
    }
    tend = clock(); // end
    favg = ((double)(tend - tstart))/CLOCKS_PER_SEC;
    printf("Avg. execution time: %g sec\n",favg);
    tree_to_arr(tree);
    printf("Searching 100x in 500k ");
    tstart = clock(); // start
    find_tree(tree);
    tend = clock(); // end
    favg = ((double)(tend - tstart))/CLOCKS_PER_SEC;
    printf("Avg. execution time: %g sec\n",favg);
    clear_tree(tree);

    /*5mille*/
    printf("\n5 million insert, balance and search!\n");
    printf("Insert: 5 million ");
    tstart = clock(); // start
    for(i = 0; i < 5000000; ++i)
    {
        fscanf(fp5mil,"%d\n", &data);
        insert(tree, data);
    }
    tend = clock(); // end
    favg = ((double)(tend - tstart))/CLOCKS_PER_SEC;
    printf("Avg. execution time: %g sec\n",favg);
    tree_to_arr(tree);
    printf("Searching 100x in 5 million ");
    tstart = clock(); // start
    find_tree(tree);
    tend = clock(); // end
    favg = ((double)(tend - tstart))/CLOCKS_PER_SEC;
    printf("Avg. execution time: %g sec\n",favg);
    clear_tree(tree);

    /*50k sekvens*/
    printf("\nSekvential insert 50k!\n");
    tstart = clock(); // start
    for(i = 0; i<50000; i++)
    {
        fscanf(fp50, "%d\n", &array50k[i]);
    }
    tend = clock(); // end
    favg = ((double)(tend - tstart))/CLOCKS_PER_SEC;
    printf("Avg. execution time: %g sec\n",favg);
    printf("Sekvential search 50k, 100x!\n");
    tstart = clock(); // start
    for(i = 0; i<100; i++)
    {
        search = randomGen();
        sekvential_search(array50k, search, 50000);
    }
    tend = clock(); // end
    favg = ((double)(tend - tstart))/CLOCKS_PER_SEC;
    printf("Avg. execution time: %g sec\n",favg);
    printf("Sekvential search 50k, 100x(o)!\n");
    tstart = clock(); // start
    for(i = 0; i<100; i++)
    {
        search = randomGen();
        sekvent_search(array50k, search, 50000);
    }
    tend = clock(); // end
    favg = ((double)(tend - tstart))/CLOCKS_PER_SEC;
    printf("Avg. execution time: %g sec\n",favg);

    /*500k sekvens*/
    printf("\nSekvential insert 500k!\n");
    tstart = clock(); // start
    for(i = 0; i<500000; i++)
    {
        fscanf(fp500, "%d\n", &array500k[i]);
    }
    tend = clock(); // end
    favg = ((double)(tend - tstart))/CLOCKS_PER_SEC;
    printf("Avg. execution time: %g sec\n",favg);
    printf("Sekvential search 500k, 100x!\n");
    tstart = clock(); // start
    for(i = 0; i<100; i++)
    {
        search = randomGen();
        sekvential_search(array500k, search, 500000);
    }
    tend = clock(); // end
    favg = ((double)(tend - tstart))/CLOCKS_PER_SEC;
    printf("Avg. execution time: %g sec\n",favg);
    printf("Sekvential search 500k, 100x(o)!\n");
    tstart = clock(); // start
    for(i = 0; i<100; i++)
    {
        search = randomGen();
        sekvent_search(array500k, search, 500000);
    }
    tend = clock(); // end
    favg = ((double)(tend - tstart))/CLOCKS_PER_SEC;
    printf("Avg. execution time: %g sec\n",favg);

    /*5mille seq*/
    printf("\nSekvential insert 5 million!\n");
    tstart = clock(); // start
    for(i = 0; i<5000000; i++)
    {
        fscanf(fp5mil, "%d\n", &array5mil[i]);
    }
    tend = clock(); // end
    favg = ((double)(tend - tstart))/CLOCKS_PER_SEC;
    printf("Avg. execution time: %g sec\n",favg);
    printf("Sekvential search 5 million, 100x!\n");
    tstart = clock(); // start
    for(i = 0; i<100; i++)
    {
        search = randomGen();
        sekvential_search(array5mil, search, 5000000);
    }
    tend = clock(); // end
    favg = ((double)(tend - tstart))/CLOCKS_PER_SEC;
    printf("Avg. execution time: %g sec\n",favg);
    printf("Sekvential search 5 million, 100x(o)!\n");
    tstart = clock(); // start
    for(i = 0; i<100; i++)
    {
        search = randomGen();
        sekvent_search(array5mil, search, 5000000);
    }
    tend = clock(); // end
    favg = ((double)(tend - tstart))/CLOCKS_PER_SEC;
    printf("Avg. execution time: %g sec\n",favg);

    /*Hash 500k*/
    printf("\nHash insert 50k!\n");
    tstart = clock(); // start
    for(i = 0; i<50000; i++){
        fscanf(fp500, "%d\n", &value);
        insert_hash(table50, value);
    }
        tend = clock(); // end
        favg = ((double)(tend - tstart))/CLOCKS_PER_SEC;
        printf("Avg. execution time: %g sec\n",favg);

    /*Hash 500k*/
    printf("\nHash insert 500k!\n");
    tstart = clock(); // start
    for(i = 0; i<500000; i++){
        fscanf(fp500, "%d\n", &value);
        insert_hash(table500, value);
    }
        tend = clock(); // end
        favg = ((double)(tend - tstart))/CLOCKS_PER_SEC;
        printf("Avg. execution time: %g sec\n",favg);

    /*Hash 5 mille*/
    printf("\nHash insert 5 million!\n");
    tstart = clock(); // start
    for(i = 0; i<5000000; i++){
        fscanf(fp5mil, "%d\n", &value);
        insert_hash(table5, value);
    }
        tend = clock(); // end
        favg = ((double)(tend - tstart))/CLOCKS_PER_SEC;
        printf("Avg. execution time: %g sec\n",favg);

    destroy_table(table5);
    destroy_table(table50);
    destroy_table(table500);
    destroyTree(tree);
    return 0;
}
Ejemplo n.º 12
0
void main() {
    srand(time(0));
    int* random = randomGen(20, 13000);
    for (int i = 0; i < 20; i++) {
        random[i] = abs(random[i]) % 4;
    }
    Giraffe Giraffe_array[] = { Giraffe("Edik", 18, 234, 200),
                                Giraffe("Masha", 35, 170, 500),
                                Giraffe("Vasya", 18, 234, 201),
                                Giraffe("Kesha", 18, 240, 195) };

    Array_List<Giraffe>* giraffe_array_list = new Array_List<Giraffe>(4);
    for (int i = 0; i < giraffe_array_list->get_capacity(); i++){
        giraffe_array_list->set(i, Giraffe_array[i]);
    }
    for (int i = 0; i < 20; i++) {
        giraffe_array_list->add(Giraffe_array[random[i]]);
    }

    Hash_Table<Giraffe, int> g_table;
    for (int i = 0; i < giraffe_array_list->get_size(); i++) {
        Giraffe* animal = new Giraffe(giraffe_array_list->get(i));

        int* counter = new int(0);

        if (g_table.contains(animal)) {
            try {
                *counter = *(g_table.get_value(animal));
                (*counter)++;
            }
            catch (Key_Doesnt_Exist_Exception e) {
                printf("Bizzare error appeared, we can't help it\n");
                return;
            }
        }
        else {
            *counter = 1;
        }
        Pair<Giraffe, int> p = { animal, counter };
        g_table.put(p);
    }

    for (int i = 0; i < 4; i++) {
        giraffe_array_list->get(i).print();
        printf("%d\n\n", *(g_table.get_value(&(giraffe_array_list->get(i)))));
    }

    Hash_Table<std::string, int> table;
    std::ifstream File("input.txt");
    while (!File.eof()) {
        std::string* word = new std::string();
        int* counter = new int(0);
        File >> *word;
        if (table.contains(word)) {
            try {
                *counter = *(table.get_value(word));
                (*counter)++;
            }
            catch (Key_Doesnt_Exist_Exception e) {
                printf("Bizzare error appeared, we can't help it\n");
                return;
            }
        }
        else {
            *counter = 1;
        }
        Pair<std::string, int> p = { word, counter };
        table.put(p);
    }

    for (int i = 0; i < 16; i++) {
        int max = table.get(i).get_size();
        for (int j = 0; j < max; j++) {
            std::cout << *(table.get(i).get(j).key);
            printf(" %d\t", *(table.get(i).get(j).value));
        }
        printf("\n\n");
    }
}
Ejemplo n.º 13
0
//michael wander code
//code taken and adapted from http://gamedevelopment.tutsplus.com/tutorials/understanding-steering-behaviors-wander--gamedev-1624
//written by Michael Kong
void Tank::wander(const float& deltaTime){
	float circleDistance = 200.f;
	Ogre::Vector3 circleCenter;
	float radius = 20.f;

	std::random_device rd;
	std::mt19937 random(rd());

	Ogre::Quaternion tankOrientation = mTankBodyNode->getOrientation();
	Ogre::Vector3 currentDirection = tankOrientation * Ogre::Vector3::NEGATIVE_UNIT_X; 
	currentDirection.normalise();
	circleCenter = currentDirection * circleDistance;

	Ogre::Vector3 displacement = Ogre::Vector3::UNIT_Z * radius;

	float length = displacement.length();
	displacement.x = cos(wanderAngle) * length;
   	displacement.z = sin(wanderAngle) * length;
	displacement.y = 13;

   	std::uniform_real_distribution<double> randomGen;

   	wanderAngle += randomGen(random) * ANGLE_CHANGE - ANGLE_CHANGE * 0.5f;

   	Ogre::Vector3 steering = circleCenter + displacement;
	steering.normalise();
	steering *= ms;
	
	circleCenter.y = 13.f;

	mTankBodyNode->lookAt(displacement, Ogre::Node::TransformSpace::TS_WORLD);

	mTankBodyNode->translate(steering * deltaTime);

	/*
	Ogre::Vector3 rayDest;

	rayDest = mTankBodyNode->getOrientation() * Ogre::Vector3(1,0,0);

	bool check = false;
	

			Ogre::Ray shootToCheckWall = Ogre::Ray(mTankBodyNode->getPosition(), rayDest);

			Ogre::RaySceneQuery* mRaySceneQuery = mSceneMgr->createRayQuery(shootToCheckWall, Ogre::SceneManager::ENTITY_TYPE_MASK);
			mRaySceneQuery->setSortByDistance(true);

			// Ray-cast and get first hit
			Ogre::RaySceneQueryResult &result = mRaySceneQuery->execute();
			Ogre::RaySceneQueryResult::iterator itr = result.begin();

			bool hit = false;
			for (itr = result.begin(); itr != result.end(); itr++) 
			{
					
				std::string x = itr->movable->getName();
				printf("Check %s \n", x.c_str());

				if (x[0] == 'C' && itr->distance < 10)
				{
					printf("Too close to %s: %f \n", x.c_str(), (float)itr->distance);
					hit = true;
				}
			}

			if(hit == true)
			{
				mTankBodyNode->yaw(Ogre::Degree(180));
				mTankBodyNode->translate((mTankBodyNode->getPosition() * Ogre::Vector3(-1,0,0)) * deltaTime );
			}
			else if (hit == false)
			{
				
				check = true;
			}
	
	
	*/

			


}
Ejemplo n.º 14
0
Archivo: rwalk.c Proyecto: a4a881d4/oai
Pair move_rwalk_node(NodePtr node, double cur_time) {
	Pair pair = malloc(sizeof(Pair));
	LOG_D(OMG, "MOVE RWALK NODE ID: %d\n",node->ID);

    node->X_pos = node->mob->X_to;
	node->Y_pos = node->mob->Y_to;
	node->mob->X_from = node->X_pos;
	node->mob->Y_from = node->Y_pos;
	node->mobile = 1; 
	double speed_next = randomGen(omg_param_list.min_speed, omg_param_list.max_speed);
	node->mob->speed = speed_next;
    	LOG_D(OMG, "speed_next: %f\n", speed_next); //m/s

	double azimuth_next = randomGen(omg_param_list.min_azimuth, omg_param_list.max_azimuth);
	node->mob->azimuth = azimuth_next;
    	LOG_D(OMG, "azimuth_next: %f\n", node->mob->azimuth); 

	double journeyTime_next = randomGen(omg_param_list.min_journey_time, omg_param_list.max_journey_time);
	node->mob->journey_time = journeyTime_next;
    	LOG_D(OMG, "journey_time_next: %f\n", node->mob->journey_time); 

	double distance = node->mob->speed * node->mob->journey_time;
	LOG_D(OMG, "distance = speed * journey_time: %f\n", distance); 

	double dX = distance * cos(node->mob->azimuth*M_PI/180);
	LOG_D(OMG, "dX = distance * cos(azimuth): %f\n", dX); 
	double dY = distance * sin(node->mob->azimuth*M_PI/180);
	LOG_D(OMG, "dY = distance * sin(azimuth): %f\n", dY); 
	
	LOG_D(OMG, "from: (%.2f, %.2f)\n", node->X_pos, node->Y_pos);
	double X_next = (double) ((int)((node->X_pos + dX) *100))/ 100;
	double Y_next = (double) ((int)((node->X_pos + dY) *100))/ 100;
	LOG_D(OMG, "theoritical_destination: (%f, %f)\n", X_next, Y_next);

	/*if (X_next<param_list.min_X){   // first method
		node->mob->X_to = param_list.min_X;  
	}
	else if (X_next>param_list.max_X){
		node->mob->X_to =  param_list.max_X;
	}
	else {
		node->mob->X_to = X_next;
	}

	if (Y_next<param_list.min_Y){ 
		node->mob->Y_to = param_list.min_Y;  
	}
	else if (Y_next>param_list.max_Y){
		node->mob->Y_to =  param_list.max_Y;
	}
	else {
		node->mob->Y_to = Y_next;
	}*/
   if (X_next < omg_param_list.min_X){
	  while (X_next < omg_param_list.min_X){ 
	   	X_next = X_next + omg_param_list.max_X;  
	  }
    node->mob->X_to = X_next;
   }
	else if (X_next > omg_param_list.max_X){
     while (X_next > omg_param_list.max_X){ 
		 X_next =  X_next - omg_param_list.max_X;
	  }
    node->mob->X_to = X_next;
   }
	else {
		node->mob->X_to = X_next;
	}

	if (Y_next < omg_param_list.min_Y){ 
     while (Y_next < omg_param_list.min_Y){
		Y_next = Y_next + omg_param_list.max_Y;
	  }
     node->mob->Y_to = Y_next;
   }
	else if (Y_next > omg_param_list.max_Y){
     while (Y_next > omg_param_list.max_Y){
		Y_next =  Y_next - omg_param_list.max_Y;
     }
     node->mob->Y_to = Y_next;
	}
	else {
		node->mob->Y_to = Y_next;
	}
	
	LOG_I(OMG, "destination: (%.2f, %.2f)\n", node->mob->X_to, node->mob->Y_to);

	node->mob->start_journey = cur_time;
   	LOG_D(OMG, "start_journey %.2f\n", node->mob->start_journey );
	
	pair->a = (double) ((int) ( (node->mob->start_journey + journeyTime_next) *100))/ 100 ;
	LOG_D(OMG, "pair->a= start journey + journeyTime_next next %.2f\n", pair->a);

	pair->b = node;
	return pair;
	
}
Ejemplo n.º 15
0
Archivo: unit.c Proyecto: a4a881d4/oai
int
main (int argc, char **argv)
{

	 Interface_init();
	 s_t* st2=(s_t*)(Instance[1].gm->mem_ref.pointer);
	 st2->port=38800;

  char c;
  s32 i, j;
  int new_omg_model; // goto ocg in oai_emulation.info.
  // pointers signal buffers (s = transmit, r,r0 = receive)
  double **s_re[NINST], **s_im[NINST], **r_re[NINST], **r_im[NINST], **r_re0, **r_im0;
  double **r_re0_d[8][3], **r_im0_d[8][3], **r_re0_u[3][8],**r_im0_u[3][8];

 // double **s_re, **s_im, **r_re, **r_im, **r_re0, **r_im0;

  double forgetting_factor=0;
  int map1,map2;
  double **ShaF= NULL;

  // Framing variables
  s32 slot, last_slot, next_slot;

  // variables/flags which are set by user on command-line
  double snr_dB, sinr_dB;
  u8 set_snr=0,set_sinr=0;

  u8 cooperation_flag;		// for cooperative communication
  u8 target_dl_mcs = 4;
  u8 target_ul_mcs = 2;
  u8 rate_adaptation_flag;

  u8 abstraction_flag = 0, ethernet_flag = 0;

  u16 Nid_cell = 0;
  s32 UE_id, eNB_id, ret;

  // time calibration for soft realtime mode  
  struct timespec time_spec;
  unsigned long time_last, time_now;
  int td, td_avg, sleep_time_us;

  char *g_log_level = "trace";	// by default global log level is set to trace
  lte_subframe_t direction;

 #ifdef XFORMS
  FD_phy_procedures_sim *form[NUMBER_OF_eNB_MAX][NUMBER_OF_UE_MAX];
  char title[255];
#endif
  LTE_DL_FRAME_PARMS *frame_parms;

  FILE *UE_stats[NUMBER_OF_UE_MAX], *eNB_stats;
  char UE_stats_filename[255];
  int len;
#ifdef ICIC
  remove ("dci.txt");
#endif

  //time_t t0,t1;
  clock_t start, stop;

  // Added for PHY abstraction
  Node_list ue_node_list = NULL;
  Node_list enb_node_list = NULL;
 
  //default parameters
  target_dl_mcs = 0;
  rate_adaptation_flag = 0;
  oai_emulation.info.n_frames = 0xffff;//1024;		//100;
  oai_emulation.info.n_frames_flag = 0;//fixme
  snr_dB = 30;
  cooperation_flag = 0;		// default value 0 for no cooperation, 1 for Delay diversity, 2 for Distributed Alamouti


   init_oai_emulation(); // to initialize everything !!!


   // get command-line options
  while ((c = getopt (argc, argv, "haePToFt:C:N:k:x:m:rn:s:S:f:z:u:b:c:M:p:g:l:d:U:B:R:E:"))
	 != -1) {

    switch (c) {
    case 'F':			// set FDD
      oai_emulation.info.frame_type = 0;
      break;
    case 'C':
      oai_emulation.info.tdd_config = atoi (optarg);
      if (oai_emulation.info.tdd_config > 6) {
	msg ("Illegal tdd_config %d (should be 0-6)\n", oai_emulation.info.tdd_config);
	exit (-1);
      }
      break;
    case 'R':
      oai_emulation.info.N_RB_DL = atoi (optarg);
      if ((oai_emulation.info.N_RB_DL != 6) && (oai_emulation.info.N_RB_DL != 15) && (oai_emulation.info.N_RB_DL != 25)
	  && (oai_emulation.info.N_RB_DL != 50) && (oai_emulation.info.N_RB_DL != 75) && (oai_emulation.info.N_RB_DL != 100)) {
	msg ("Illegal N_RB_DL %d (should be one of 6,15,25,50,75,100)\n", oai_emulation.info.N_RB_DL);
	exit (-1);
      }
    case 'N':
      Nid_cell = atoi (optarg);
      if (Nid_cell > 503) {
	msg ("Illegal Nid_cell %d (should be 0 ... 503)\n", Nid_cell);
	exit(-1);
      }
      break;
    case 'h':
      help ();
      exit (1);
    case 'x':
      oai_emulation.info.transmission_mode = atoi (optarg);
      if ((oai_emulation.info.transmission_mode != 1) &&  (oai_emulation.info.transmission_mode != 2) && (oai_emulation.info.transmission_mode != 5) && (oai_emulation.info.transmission_mode != 6)) {
	msg("Unsupported transmission mode %d\n",oai_emulation.info.transmission_mode);
	exit(-1);
      }
      break;
    case 'm':
      target_dl_mcs = atoi (optarg);
      break;
    case 'r':
      rate_adaptation_flag = 1;
      break;
    case 'n':
      oai_emulation.info.n_frames = atoi (optarg);
      //n_frames = (n_frames >1024) ? 1024: n_frames; // adjust the n_frames if higher that 1024
      oai_emulation.info.n_frames_flag = 1;
      break;
    case 's':
      snr_dB = atoi (optarg);
      set_snr = 1;
      oai_emulation.info.ocm_enabled=0;
      break;
    case 'S':
      sinr_dB = atoi (optarg);
      set_sinr = 1;
      oai_emulation.info.ocm_enabled=0;
      break;
    case 'k':
      //ricean_factor = atof (optarg);
      printf("[SIM] Option k is no longer supported on the command line. Please specify your channel model in the xml template\n"); 
      exit(-1);
      break;
    case 't':
      //Td = atof (optarg);
      printf("[SIM] Option t is no longer supported on the command line. Please specify your channel model in the xml template\n"); 
      exit(-1);
      break;
    case 'f':
      forgetting_factor = atof (optarg);
      break;
    case 'z':
      cooperation_flag = atoi (optarg);
      break;
    case 'u':
      oai_emulation.info.nb_ue_local = atoi (optarg);
      break;
    case 'b':
      oai_emulation.info.nb_enb_local = atoi (optarg);
      break;
    case 'a':
      abstraction_flag = 1;
      break;
    case 'p':
      oai_emulation.info.nb_master = atoi (optarg);
      break;
    case 'M':
      abstraction_flag = 1;
      ethernet_flag = 1;
      oai_emulation.info.ethernet_id = atoi (optarg);
      oai_emulation.info.master_id = oai_emulation.info.ethernet_id;
      oai_emulation.info.ethernet_flag = 1;
      break;
    case 'e':
      oai_emulation.info.extended_prefix_flag = 1;
      break;
    case 'l':
      g_log_level = optarg;
      break;
    case 'c':
      strcpy(oai_emulation.info.local_server, optarg);
      oai_emulation.info.ocg_enabled=1;
      break;
    case 'g':
      oai_emulation.info.multicast_group = atoi (optarg);
      break;
    case 'B':
      oai_emulation.info.omg_model_enb = atoi (optarg);
      break;
    case 'U':
      oai_emulation.info.omg_model_ue = atoi (optarg);
      break;
    case 'T':
      oai_emulation.info.otg_enabled = 1;
      break;
    case 'P':
      oai_emulation.info.opt_enabled = 1;
      break;
    case 'E':
      oai_emulation.info.seed = atoi (optarg);
      break;
    default:
      help ();
      exit (-1);
      break;
    }
  }

  // configure oaisim with OCG
  oaisim_config(g_log_level); // config OMG and OCG, OPT, OTG, OLG

  if (oai_emulation.info.nb_ue_local > NUMBER_OF_UE_MAX ) {
    printf ("Enter fewer than %d UEs for the moment or change the NUMBER_OF_UE_MAX\n", NUMBER_OF_UE_MAX);
    exit (-1);
  }
  if (oai_emulation.info.nb_enb_local > NUMBER_OF_eNB_MAX) {
    printf ("Enter fewer than %d eNBs for the moment or change the NUMBER_OF_UE_MAX\n", NUMBER_OF_eNB_MAX);
    exit (-1);
  }
	
  // fix ethernet and abstraction with RRC_CELLULAR Flag
#ifdef RRC_CELLULAR
  abstraction_flag = 1;
  ethernet_flag = 0;
#endif

  if (set_sinr == 0)
    sinr_dB = snr_dB - 20;

  // setup ntedevice interface (netlink socket)
#ifndef CYGWIN
  ret = netlink_init ();
#endif

  if (ethernet_flag == 1) {
    oai_emulation.info.master[oai_emulation.info.master_id].nb_ue = oai_emulation.info.nb_ue_local;
    oai_emulation.info.master[oai_emulation.info.master_id].nb_enb = oai_emulation.info.nb_enb_local;

    if (!oai_emulation.info.master_id)
      oai_emulation.info.is_primary_master = 1;
    j = 1;
    for (i = 0; i < oai_emulation.info.nb_master; i++) {
      if (i != oai_emulation.info.master_id)
	oai_emulation.info.master_list = oai_emulation.info.master_list + j;
      LOG_I (EMU, "Index of master id i=%d  MASTER_LIST %d\n", i, oai_emulation.info.master_list);
      j *= 2;
    }
    LOG_I (EMU, " Total number of master %d my master id %d\n", oai_emulation.info.nb_master, oai_emulation.info.master_id);
#ifdef LINUX
    init_bypass ();
#endif

    while (emu_tx_status != SYNCED_TRANSPORT) {
      LOG_I (EMU, " Waiting for EMU Transport to be synced\n");
      emu_transport_sync ();	//emulation_tx_rx();
    }
  }				// ethernet flag
  NB_UE_INST = oai_emulation.info.nb_ue_local + oai_emulation.info.nb_ue_remote;
  NB_eNB_INST = oai_emulation.info.nb_enb_local + oai_emulation.info.nb_enb_remote;
#ifndef NAS_NETLINK
  for (UE_id=0;UE_id<NB_UE_INST;UE_id++) {
    sprintf(UE_stats_filename,"UE_stats%d.txt",UE_id);
    UE_stats[UE_id] = fopen (UE_stats_filename, "w");
  }
  eNB_stats = fopen ("eNB_stats.txt", "w");
  printf ("UE_stats=%p, eNB_stats=%p\n", UE_stats, eNB_stats);
#endif
      
  LOG_I(EMU, "total number of UE %d (local %d, remote %d) \n", NB_UE_INST,oai_emulation.info.nb_ue_local,oai_emulation.info.nb_ue_remote);
  LOG_I(EMU, "Total number of eNB %d (local %d, remote %d) \n", NB_eNB_INST,oai_emulation.info.nb_enb_local,oai_emulation.info.nb_enb_remote);
  printf("Running with frame_type %d, Nid_cell %d, N_RB_DL %d, EP %d, mode %d, target dl_mcs %d, rate adaptation %d, nframes %d, abstraction %d\n",
  	 1+oai_emulation.info.frame_type, Nid_cell, oai_emulation.info.N_RB_DL, oai_emulation.info.extended_prefix_flag, oai_emulation.info.transmission_mode,target_dl_mcs,rate_adaptation_flag,oai_emulation.info.n_frames,abstraction_flag);
  

 // init_lte_vars (&frame_parms, oai_emulation.info.frame_type, oai_emulation.info.tdd_config, oai_emulation.info.extended_prefix_flag,oai_emulation.info.N_RB_DL, Nid_cell, cooperation_flag, oai_emulation.info.transmission_mode, abstraction_flag);
  init_frame_params (&frame_parms, oai_emulation.info.frame_type, oai_emulation.info.tdd_config, oai_emulation.info.extended_prefix_flag,oai_emulation.info.N_RB_DL, Nid_cell, cooperation_flag, oai_emulation.info.transmission_mode, abstraction_flag);

  printf ("Nid_cell %d\n", frame_parms->Nid_cell);

  /* Added for PHY abstraction */
  if (abstraction_flag) 
    get_beta_map();

  for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) {
    enb_data[eNB_id] = (node_desc_t *)malloc(sizeof(node_desc_t)); 
    init_enb(enb_data[eNB_id],oai_emulation.environment_system_config.antenna.eNB_antenna);
  }
  
  for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
    ue_data[UE_id] = (node_desc_t *)malloc(sizeof(node_desc_t));
    init_ue(ue_data[UE_id],oai_emulation.environment_system_config.antenna.UE_antenna);
  } 

  // init SF map here!!!
  map1 =(int)oai_emulation.topology_config.area.x_km;
  map2 =(int)oai_emulation.topology_config.area.y_km;
  //ShaF = createMat(map1,map2); -> memory is allocated within init_SF
  ShaF = init_SF(map1,map2,DECOR_DIST,SF_VAR);

  // size of area to generate shadow fading map
  printf("Simulation area x=%f, y=%f\n",
	 oai_emulation.topology_config.area.x_km,
	 oai_emulation.topology_config.area.y_km);
 



  if (abstraction_flag == 0){

	  int ci;
	  int ji=0;
	  for(ci=0;ci<NB_eNB_INST;ci++)
	  {
		  init_channel_mmap_channel(10+ji,frame_parms, &(s_re[ci]), &(s_im[ci]), &(r_re[ci]), &(r_im[ci]), &(r_re0), &(r_im0));
		ji++;
		//printf("ci %d\n",ci);
	  }
	  ji=0;

	  for(ci=NB_eNB_INST;ci<(NB_eNB_INST+NB_UE_INST);ci++)
		  {
		  init_channel_mmap_channel(20+ji,frame_parms, &(s_re[ci]), &(s_im[ci]), &(r_re[ci]), &(r_im[ci]), &(r_re0), &(r_im0));
			ji++;
			//printf("ci %d\n",ci);
		  }


  }

  for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) {
      for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
  init_rre(frame_parms,&(r_re0_u[eNB_id][UE_id]),&(r_im0_u[eNB_id][UE_id]));
  init_rre(frame_parms,&(r_re0_d[UE_id][eNB_id]),&(r_im0_d[UE_id][eNB_id]));
      }
  }

//      printf("r_re0 %lf , r_im0 %lf\n",r_re0_u[0][0][0][0],r_im0_u[0][0][0][0]);
//
//      r_im0_u[0][0][0][0]=100;
//
//      printf("r_re0 %lf , r_im0 %lf\n",r_re0_u[0][0][0][0],r_im0_u[0][0][0][0]);
//
//
//	  clean_param((r_re0_u[0][0]),(r_im0_u[0][0]),frame_parms);
//
//	  printf("r_re0 %lf , r_im0 %lf\n",r_re0_u[0][0][0][0],r_im0_u[0][0][0][0]);



  for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) {
    for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
#ifdef DEBUG_SIM
      printf ("[SIM] Initializing channel from eNB %d to UE %d\n", eNB_id, UE_id);
#endif

     eNB2UE[eNB_id][UE_id] = new_channel_desc_scm(2,
						   2,
						   map_str_to_int(small_scale_names, oai_emulation.environment_system_config.fading.small_scale.selected_option),
						   oai_emulation.environment_system_config.system_bandwidth_MB,
						   forgetting_factor,
						   0,
						   0);
      
      UE2eNB[UE_id][eNB_id] = new_channel_desc_scm(2,
						   2,
						   map_str_to_int(small_scale_names, oai_emulation.environment_system_config.fading.small_scale.selected_option),
						   oai_emulation.environment_system_config.system_bandwidth_MB,
						   forgetting_factor,
						   0,
						   0);
      
    }
  }

  randominit (0);
  set_taus_seed (0);

  number_of_cards = 1;

  openair_daq_vars.rx_rf_mode = 1;
  openair_daq_vars.tdd = 1;
  openair_daq_vars.rx_gain_mode = DAQ_AGC_ON;
  openair_daq_vars.dlsch_transmission_mode = oai_emulation.info.transmission_mode;
  openair_daq_vars.target_ue_dl_mcs = target_dl_mcs;
  openair_daq_vars.target_ue_ul_mcs = target_ul_mcs;
  openair_daq_vars.dlsch_rate_adaptation = rate_adaptation_flag;
  openair_daq_vars.ue_ul_nb_rb = 2;


  
#ifdef XFORMS
  fl_initialize (&argc, argv, NULL, 0, 0);
  for (UE_id = 0; UE_id < NB_UE_INST; UE_id++)
    for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) {
      form[eNB_id][UE_id] = create_form_phy_procedures_sim ();
      sprintf (title, "LTE SIM UE %d eNB %d", UE_id, eNB_id);
      fl_show_form (form[eNB_id][UE_id]->phy_procedures_sim, FL_PLACE_HOTSPOT, FL_FULLBORDER, title);
    }
#endif


  // time calibration for OAI 
  clock_gettime (CLOCK_REALTIME, &time_spec);
  time_now = (unsigned long) time_spec.tv_nsec;
  td_avg = 0;
  sleep_time_us = SLEEP_STEP_US;
  td_avg = TARGET_SF_TIME_NS;


   // s_t* st2=(s_t*)(Instance[1].gm->mem_ref.pointer);
    st2->Exec_FLAG=0;
    int count;


    IntInitAll();
    Soc_t* this  = (Soc_t*)(obj_inst[0].ptr->mem_ref.pointer);
    fd_set read_ibits;
    fd_set write_ibits;
    int n;
    struct timeval tvp ;
    tvp.tv_sec=10;
    tvp.tv_usec=0;

    FD_ZERO(&read_ibits);
	FD_SET(this->m_io_sync.io_sync_entries->fd_read, &read_ibits);

	 ch_thread *e2u_t[NB_eNB_INST][NB_UE_INST];
	 ch_thread *u2e_t[NB_UE_INST][NB_eNB_INST];

	 for(eNB_id=0;eNB_id<NB_eNB_INST;eNB_id++){
	 for(UE_id=0;UE_id<NB_UE_INST;UE_id++){
	 e2u_t[eNB_id][UE_id]=(ch_thread*)calloc(1,sizeof(ch_thread));
	 }}
	 for(UE_id=0;UE_id<NB_UE_INST;UE_id++){
	 for(eNB_id=0;eNB_id<NB_eNB_INST;eNB_id++){
	 u2e_t[UE_id][eNB_id]=(ch_thread*)calloc(1,sizeof(ch_thread));
	 }}

	 pthread_t thread,thread2;
	 pthread_t cthr_u[NB_eNB_INST][NB_UE_INST];
	 pthread_t cthr_d[NB_UE_INST][NB_eNB_INST];


	    for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++){

	  	  for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) {

	  		u2e_t[UE_id][eNB_id]->eNB_id=eNB_id;
	  		u2e_t[UE_id][eNB_id]->UE_id=UE_id;
	  		u2e_t[UE_id][eNB_id]->r_re0=r_re0_d[UE_id][eNB_id];
	  		u2e_t[UE_id][eNB_id]->r_im0=r_im0_d[UE_id][eNB_id];
	  		u2e_t[UE_id][eNB_id]->r_re=r_re[NB_eNB_INST+UE_id];
	  		u2e_t[UE_id][eNB_id]->r_im=r_im[NB_eNB_INST+UE_id];
	  		u2e_t[UE_id][eNB_id]->s_im=s_im[eNB_id];
	  		u2e_t[UE_id][eNB_id]->s_re=s_re[eNB_id];
	  		u2e_t[UE_id][eNB_id]->eNB2UE=eNB2UE[eNB_id][UE_id];
	  		u2e_t[UE_id][eNB_id]->UE2eNB=UE2eNB[UE_id][eNB_id];
	  		u2e_t[UE_id][eNB_id]->enb_data=enb_data[eNB_id];
	  		u2e_t[UE_id][eNB_id]->ue_data=ue_data[UE_id];
	  		u2e_t[UE_id][eNB_id]->next_slot=&next_slot;
	  		u2e_t[UE_id][eNB_id]->abstraction_flag=&abstraction_flag;
	  		u2e_t[UE_id][eNB_id]->frame_parms=frame_parms;

	  	pthread_create (&cthr_d[UE_id][eNB_id], NULL, do_DL_sig_channel_T,(void*)(u2e_t[UE_id][eNB_id]));

	    }
	    }

	    int sock;

	  	int port=(35000+(10+eNB_id)+(20+UE_id));
	  	port=35010;
		sock = openairInetCreateSocket(SOCK_DGRAM,IPPROTO_UDP,"127.0.0.1",port);

		 //  int n;
		  // fd_set read_ibits;
		//   fd_set write_ibits;
		//   struct timeval tvp = { 0, 0 };

		 FD_ZERO(&read_ibits);
		 FD_SET(sock,&read_ibits);
		 n = openairSelect(sock+1, &read_ibits, NULL, NULL, NULL);
		 printf("Waiting is over\n");
		 FD_ISSET(sock, &read_ibits);







	 for (mac_xface->frame=0; mac_xface->frame<oai_emulation.info.n_frames; mac_xface->frame++) {
		  int dir_flag=0;

	      printf("=============== Frame Number %d ============= \n ",mac_xface->frame);


	    /*
	    // Handling the cooperation Flag
	    if (cooperation_flag == 2)
	      {
		if ((PHY_vars_eNB_g[0]->eNB_UE_stats[0].mode == PUSCH) && (PHY_vars_eNB_g[0]->eNB_UE_stats[1].mode == PUSCH))
		  PHY_vars_eNB_g[0]->cooperation_flag = 2;
	      }
	    */
	    // for dubugging the frame counter

	    update_nodes(oai_emulation.info.time);

	    enb_node_list = get_current_positions(oai_emulation.info.omg_model_enb, eNB, oai_emulation.info.time);
	    ue_node_list = get_current_positions(oai_emulation.info.omg_model_ue, UE, oai_emulation.info.time);

	    // update the position of all the nodes (eNB/CH, and UE/MR) every frame
	    if (((int)oai_emulation.info.time % 10) == 0 ) {
	      display_node_list(enb_node_list);
	      display_node_list(ue_node_list);
	      if (oai_emulation.info.omg_model_ue >= MAX_NUM_MOB_TYPES){ // mix mobility model
		for(UE_id=oai_emulation.info.first_ue_local; UE_id<(oai_emulation.info.first_ue_local+oai_emulation.info.nb_ue_local);UE_id++){
		  new_omg_model = randomGen(STATIC, MAX_NUM_MOB_TYPES);
		  LOG_D(OMG, "[UE] Node of ID %d is changing mobility generator ->%d \n", UE_id, new_omg_model);
		  // reset the mobility model for a specific node
		  set_new_mob_type (UE_id, UE, new_omg_model, oai_emulation.info.time);
		}
	      }

	      if (oai_emulation.info.omg_model_enb >= MAX_NUM_MOB_TYPES) {	// mix mobility model
		for (eNB_id = oai_emulation.info.first_enb_local; eNB_id < (oai_emulation.info.first_enb_local + oai_emulation.info.nb_enb_local); eNB_id++) {
		  new_omg_model = randomGen (STATIC, MAX_NUM_MOB_TYPES);
		  LOG_D (OMG, "[eNB] Node of ID %d is changing mobility generator ->%d \n", UE_id, new_omg_model);
		  // reset the mobility model for a specific node
		  set_new_mob_type (eNB_id, eNB, new_omg_model, oai_emulation.info.time);
		}
	      }
	    }

	#ifdef DEBUG_OMG
	    if ((((int) oai_emulation.info.time) % 100) == 0) {
	      for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++) {
		get_node_position (UE, UE_id);
	      }
	    }
	#endif

	    if (oai_emulation.info.n_frames_flag == 0){ // if n_frames not set by the user then let the emulation run to infinity
	      mac_xface->frame %=(oai_emulation.info.n_frames-1);
	      // set the emulation time based on 1ms subframe number
	      oai_emulation.info.time += 0.01; // emu time in s
	    }
	    else { // user set the number of frames for the emulation
	      // let the time go faster to see the effect of mobility
	      oai_emulation.info.time += 0.1;
	    }

	    /* check if the openair channel model is activated used for PHY abstraction */
	    /*    if ((oai_emulation.info.ocm_enabled == 1)&& (ethernet_flag == 0 )) {
	          extract_position(enb_node_list, enb_data, NB_eNB_INST);
	          extract_position(ue_node_list, ue_data, NB_UE_INST);

	          for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) {
	    	for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
	    	  calc_path_loss (enb_data[eNB_id], ue_data[UE_id], eNB2UE[eNB_id][UE_id], oai_emulation.environment_system_config,ShaF[(int)ue_data[UE_id]->x][(int)ue_data[UE_id]->y]);
	    	  UE2eNB[UE_id][eNB_id]->path_loss_dB = eNB2UE[eNB_id][UE_id]->path_loss_dB;
	    	  printf("[CHANNEL_SIM] Pathloss bw enB %d at (%f,%f) and UE%d at (%f,%f) is %f (ShaF %f)\n",
	    		 eNB_id,enb_data[eNB_id]->x,enb_data[eNB_id]->y,UE_id,ue_data[UE_id]->x,ue_data[UE_id]->y,
	    		 eNB2UE[eNB_id][UE_id]->path_loss_dB,
	    		 ShaF[(int)ue_data[UE_id]->x][(int)ue_data[UE_id]->y]);
	    	}
	          }
	        } */

	    //    else {
	          for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) {
	    	for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
	    	  eNB2UE[eNB_id][UE_id]->path_loss_dB = -105 + snr_dB;
	    	  //UE2eNB[UE_id][eNB_id]->path_loss_dB = -105 + snr_dB;
	    	  if (eNB_id == (UE_id % NB_eNB_INST))
	    	    UE2eNB[UE_id][eNB_id]->path_loss_dB = -105 + snr_dB - 10;
	    	  else
	    	    UE2eNB[UE_id][eNB_id]->path_loss_dB = -105 + sinr_dB - 10;
	    #ifdef DEBUG_SIM
	    	  printf("[SIM] Path loss from eNB %d to UE %d => %f dB\n",eNB_id,UE_id,eNB2UE[eNB_id][UE_id]->path_loss_dB);
	    	  printf("[SIM] Path loss from UE %d to eNB %d => %f dB\n",UE_id,eNB_id,UE2eNB[UE_id][eNB_id]->path_loss_dB);
	    #endif
	    	}
	          }
	       // } else



	     st2->EResp_FLAG=0;


	    for (slot=0 ; slot<20 ; slot++) {
	        printf("=============== Frame Number %d , Slot %d ============= \n ",mac_xface->frame,slot);

	      last_slot = (slot - 1)%20;
	      if (last_slot <0)
		last_slot+=20;
	      next_slot = (slot + 1)%20;

	      direction = subframe_select(frame_parms,next_slot>>1);

	      if (direction  == SF_DL) {
	    	  dir_flag=1;
	      }

	      else if (direction  == SF_UL) {
	    	  dir_flag=2;
	      }
	      else {//it must be a special subframe
		if (next_slot%2==0) {//DL part
			dir_flag=1;
		}
		else {// UL part
			dir_flag=2;
		}
	      }
	int count=0;
	if(dir_flag==1)
	{
		  st2->EResp_FLAG=0;
	 	  count=0;
		    for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) {

			  send_exec_msg(next_slot,last_slot,mac_xface->frame,mac_xface->frame,slot,0,38810+eNB_id);

			  printf("Waiting for Exec Msg Complete \n");

			//	n = openairIoSyncCreateThread_2(&this->m_io_sync);

		    } // for loop

			while(count<NB_eNB_INST){
			n=trig_wait((void*)&this->m_io_sync);
			count++;
			}

		    for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++){
		   	  	  for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) {
		   	  //trigger message
			     send_exec_msg(0,0,0,0,0,0,(35000+(10+eNB_id)+(20+UE_id)));
  		   	  	  }
		    }

		    usleep(5);


		   // while(st2->EResp_FLAG<NB_eNB_INST)
			   //   {

/*
	    for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++){

	  	  for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) {

	  		u2e_t[UE_id][eNB_id]->eNB_id=eNB_id;
	  		u2e_t[UE_id][eNB_id]->UE_id=UE_id;
	  		u2e_t[UE_id][eNB_id]->r_re0=r_re0_d[UE_id][eNB_id];
	  		u2e_t[UE_id][eNB_id]->r_im0=r_im0_d[UE_id][eNB_id];
	  		u2e_t[UE_id][eNB_id]->r_re=r_re[NB_eNB_INST+UE_id];
	  		u2e_t[UE_id][eNB_id]->r_im=r_im[NB_eNB_INST+UE_id];
	  		u2e_t[UE_id][eNB_id]->s_im=s_im[eNB_id];
	  		u2e_t[UE_id][eNB_id]->s_re=s_re[eNB_id];
	  		u2e_t[UE_id][eNB_id]->eNB2UE=eNB2UE[eNB_id][UE_id];
	  		u2e_t[UE_id][eNB_id]->UE2eNB=UE2eNB[UE_id][eNB_id];
	  		u2e_t[UE_id][eNB_id]->enb_data=enb_data[eNB_id];
	  		u2e_t[UE_id][eNB_id]->ue_data=ue_data[UE_id];
	  		u2e_t[UE_id][eNB_id]->next_slot=&next_slot;
	  		u2e_t[UE_id][eNB_id]->abstraction_flag=&abstraction_flag;
	  		u2e_t[UE_id][eNB_id]->frame_parms=frame_parms;

	  	 //  pthread_create (&thread[eNB_id][UE_id], NULL, do_DL_sig_channel_T,(void*)cthread);
	  	pthread_create (&cthr_d[UE_id][eNB_id], NULL, do_DL_sig_channel_T,(void*)(u2e_t[UE_id][eNB_id]));
	 // 	pthread_join(cthr_d[UE_id][eNB_id], NULL);

	  //	pthread_join(cthr_d[UE_id][eNB_id], NULL);
	  //	   pthread_join(thread[eNB_id][UE_id], NULL);
	  //  do_DL_sig_channel(eNB_id,UE_id,r_re0,r_im0,r_re[NB_eNB_INST+UE_id],r_im[NB_eNB_INST+UE_id],s_re[eNB_id],s_im[eNB_id],eNB2UE,enb_data, ue_data,next_slot,abstraction_flag,frame_parms);
	  	 //   do_DL_sig_channel(eNB_id,UE_id,r_re0_d[UE_id][eNB_id],r_im0_d[UE_id][eNB_id],r_re[NB_eNB_INST+UE_id],r_im[NB_eNB_INST+UE_id],s_re[eNB_id],s_im[eNB_id],eNB2UE,enb_data, ue_data,next_slot,abstraction_flag,frame_parms);

	    }
	    }
*/


	//
//for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++){
//for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) {
//pthread_join(cthr_d[UE_id][eNB_id], NULL);
//}
//}



	  	for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++){
		  	  clean_param(r_re[NB_eNB_INST+UE_id],r_im[NB_eNB_INST+UE_id],frame_parms);

	  	  	  for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) {

	  	 channel_add(r_re[NB_eNB_INST+UE_id],r_im[NB_eNB_INST+UE_id],r_re0_d[UE_id][eNB_id],r_im0_d[UE_id][eNB_id],frame_parms);

	  	  	  }
	  	}


	//  	if(UE_id==NB_UE_INST)
	//  	pthread_join(thread, NULL);
	    //}

	  	 for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++){

	  	  	  for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) {

	  	  	  	// pthread_join(thread, NULL);
	  	  		  //pthread_join(thread[eNB_id][UE_id], NULL);
	  	  	  }
	  	 }
	  	  	 // }

	    st2->EResp_FLAG=0;
		  count=0;

	    for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++)
	    	if (mac_xface->frame >= (UE_id * 10)) {	// activate UE only after 10*UE_id frames so that different UEs turn on separately

	    	    send_exec_msg(next_slot,last_slot,mac_xface->frame,mac_xface->frame,slot,0,38820+UE_id);

	    	    	printf("Waiting for Exec Msg Complete \n");
	    			//n = openairIoSyncCreateThread_2(&this->m_io_sync);
	    	  	//    n=trig_wait((void*)&this->m_io_sync);

	    }
	    	else{
	    		st2->EResp_FLAG=st2->EResp_FLAG+1;
	    		count++;
	    	}

			while(count<NB_UE_INST){
	    		n=trig_wait((void*)&this->m_io_sync);
	    		count++;
	    		}

	    //while(st2->EResp_FLAG<NB_UE_INST)
	        	// {
	//	    n = select(this->m_io_sync.hfd, &read_ibits, NULL, NULL,NULL);
	//		FD_ISSET(this->m_io_sync.io_sync_entries->fd_read, &read_ibits);

	        	// printf("..");
	        //	 }
	}
	else if(dir_flag==2)
	{
		  st2->EResp_FLAG=0;
	 	  count=0;

		for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++)
			if (mac_xface->frame >= (UE_id * 10)) {	// activate UE only after 10*UE_id frames so that different UEs turn on separately


		    	      	    send_exec_msg(next_slot,last_slot,mac_xface->frame,mac_xface->frame,slot,0,38820+UE_id);

		    	//      	    	printf("Waiting for Exec Msg Complete \n");
		    		//		n = openairIoSyncCreateThread_2(&this->m_io_sync);
		    		  	 //   n=trig_wait((void*)&this->m_io_sync);


		    	        }
			else{
			    		st2->EResp_FLAG=st2->EResp_FLAG+1;
			    		count++;
			}
		while(count<NB_UE_INST){
		    		n=trig_wait((void*)&this->m_io_sync);
		    		count++;
		    		}

		//while(st2->EResp_FLAG<NB_UE_INST)
			    	 //    	    	 {
	//	    n = select(this->m_io_sync.hfd, &read_ibits, NULL, NULL,NULL);
	//		FD_ISSET(this->m_io_sync.io_sync_entries->fd_read, &read_ibits);

			    	      	    	// printf("..");
			    	     // 	    	 }

			 	 // do_UL_sig_channel2(1,0,r_re0,r_im0,r_re,r_im,s_re,s_im,UE2eNB,next_slot,abstraction_flag,frame_parms);
			 	//  do_UL_sig_channel(r_re0,r_im0,r_re,r_im,s_re,s_im,UE2eNB,next_slot,abstraction_flag,frame_parms);



		       	  for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) {

		          for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++){

						e2u_t[eNB_id][UE_id]->eNB_id=eNB_id;
		        		e2u_t[eNB_id][UE_id]->UE_id=UE_id;
		        		e2u_t[eNB_id][UE_id]->r_re=r_re[eNB_id];
		        		e2u_t[eNB_id][UE_id]->r_im=r_im[eNB_id];
		        		e2u_t[eNB_id][UE_id]->r_re0=r_re0_u[eNB_id][UE_id];
		        		e2u_t[eNB_id][UE_id]->r_im0=r_im0_u[eNB_id][UE_id];
		        		e2u_t[eNB_id][UE_id]->s_im=s_im[NB_eNB_INST+UE_id];
		        		e2u_t[eNB_id][UE_id]->s_re=s_re[NB_eNB_INST+UE_id];
		        		e2u_t[eNB_id][UE_id]->eNB2UE=eNB2UE[eNB_id][UE_id];
		        		e2u_t[eNB_id][UE_id]->UE2eNB=UE2eNB[UE_id][eNB_id];
		        		e2u_t[eNB_id][UE_id]->enb_data=enb_data[eNB_id];
		        		e2u_t[eNB_id][UE_id]->ue_data=ue_data[UE_id];
		        		e2u_t[eNB_id][UE_id]->next_slot=&next_slot;
		        		e2u_t[eNB_id][UE_id]->abstraction_flag=&abstraction_flag;
		        		e2u_t[eNB_id][UE_id]->frame_parms=frame_parms;

			        	 pthread_create (&cthr_u[eNB_id][UE_id], NULL, do_UL_sig_channel_T,(void*)e2u_t[eNB_id][UE_id]);
		        	 //  pthread_create (&thread[eNB_id][UE_id], NULL, do_UL_sig_channel_T,(void*)cthread);
		        	//   do_UL_sig_channel(eNB_id,UE_id,r_re0,r_im0,r_re[eNB_id],r_im[eNB_id],s_re[NB_eNB_INST+UE_id],s_im[NB_eNB_INST+UE_id],UE2eNB,next_slot,abstraction_flag,frame_parms);

	// do_UL_sig_channel(eNB_id,UE_id,r_re0_u[eNB_id][UE_id],r_im0_u[eNB_id][UE_id],r_re[eNB_id],r_im[eNB_id],s_re[NB_eNB_INST+UE_id],s_im[NB_eNB_INST+UE_id],UE2eNB,next_slot,abstraction_flag,frame_parms);

		          }

		             }




		       	for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) {
		       	for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++){
		 //      	pthread_join(thread[eNB_id][UE_id], NULL);
	           	     pthread_join(cthr_u[eNB_id][UE_id], NULL);

		       	}
		       	}

		      	for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) {
		           	  clean_param(r_re[eNB_id],r_im[eNB_id],frame_parms);
		      		for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++){
		    				    channel_add(r_re[eNB_id],r_im[eNB_id],r_re0_u[eNB_id][UE_id],r_im0_u[eNB_id][UE_id],frame_parms);

		    		       	}
		    		       	}




		       		     //     }

	 	    	  st2->EResp_FLAG=0;
	 	    	  count=0;
			 	 for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) {


			 	    	  send_exec_msg(next_slot,last_slot,mac_xface->frame,mac_xface->frame,slot,0,38810+eNB_id);

			 		//		n = openairIoSyncCreateThread_2(&this->m_io_sync);
			 		  	//    n=trig_wait((void*)&this->m_io_sync);

			 	//    	  printf("Waiting for Exec Msg Complete \n");

			 	          } // for loop

			 	while(count<NB_eNB_INST){
			 	    		n=trig_wait((void*)&this->m_io_sync);
			 	    		count++;
			 	    		}

			 //	 while(st2->EResp_FLAG<NB_eNB_INST)
			 			 	    //	      {
	//				    n = select(this->m_io_sync.hfd, &read_ibits, NULL, NULL,NULL);
	//					FD_ISSET(this->m_io_sync.io_sync_entries->fd_read, &read_ibits);

			 			 	    //	    	 // printf("..");
			 		//	 	    	      }

	}


	      if ((last_slot == 1) && (mac_xface->frame == 0)
		  && (abstraction_flag == 0) && (oai_emulation.info.n_frames == 1)) {

	//	write_output ("dlchan0.m", "dlch0",
	//		      &(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[0][0][0]),
	//		      (6 * (PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)), 1, 1);
	//	write_output ("dlchan1.m", "dlch1",
	//		      &(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[1][0][0]),
	//		      (6 * (PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)), 1, 1);
	//	write_output ("dlchan2.m", "dlch2",
	//		      &(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[2][0][0]),
	//		      (6 * (PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)), 1, 1);
	//	write_output ("pbch_rxF_comp0.m", "pbch_comp0",
	//		      PHY_vars_UE_g[0]->lte_ue_pbch_vars[0]->rxdataF_comp[0], 6 * 12 * 4, 1, 1);
	//	write_output ("pbch_rxF_llr.m", "pbch_llr",
	//		      PHY_vars_UE_g[0]->lte_ue_pbch_vars[0]->llr, (frame_parms->Ncp == 0) ? 1920 : 1728, 1, 4);
	      }
	      /*
	         if ((last_slot==1) && (mac_xface->frame==1)) {
	         write_output("dlsch_rxF_comp0.m","dlsch0_rxF_comp0",PHY_vars_UE->lte_ue_dlsch_vars[eNB_id]->rxdataF_comp[0],300*(-(PHY_vars_UE->lte_frame_parms.Ncp*2)+14),1,1);
	         write_output("pdcch_rxF_comp0.m","pdcch0_rxF_comp0",PHY_vars_UE->lte_ue_pdcch_vars[eNB_id]->rxdataF_comp[0],4*300,1,1);
	         }
	       */
	      if (next_slot %2 == 0){
		clock_gettime (CLOCK_REALTIME, &time_spec);
		time_last = time_now;
		time_now = (unsigned long) time_spec.tv_nsec;
		td = (int) (time_now - time_last);
		if (td>0) {
		  td_avg = (int)(((K*(long)td) + (((1<<3)-K)*((long)td_avg)))>>3); // in us
		  LOG_I(EMU,"sleep frame %d, average time difference %ldns, CURRENT TIME DIFF %dus, avgerage difference from the target %dus\n",
			mac_xface->frame, td_avg, td/1000,(td_avg-TARGET_SF_TIME_NS)/1000);
		}
		if (td_avg<(TARGET_SF_TIME_NS - SF_DEVIATION_OFFSET_NS)){
		  sleep_time_us += SLEEP_STEP_US;
		}
		else if (td_avg > (TARGET_SF_TIME_NS + SF_DEVIATION_OFFSET_NS)) {
		  sleep_time_us-= SLEEP_STEP_US;
		}
	      }// end if next_slot%2
	    }				//end of slot
Ejemplo n.º 16
0
const std::string UUID::getUUID() {
	return boost::lexical_cast<std::string>(randomGen());
}
Ejemplo n.º 17
0
Uuid Uuid::random()
{
    return Uuid(randomGen()->randomArray(Length));
}