Пример #1
0
//Генерация узлов
bool Environment::generateNodes(int nodeCount)
{
    const int maxAttemps = 9999;
    int attemps = 0;

    this->nodeCount = nodeCount;

    cout << "Инициализация узлов\n\n";
    cout << "Размер области: " << xSize << " x "<< ySize << "\n\n";
    cout << "Запрет на передачу при приеме ";
    if (Simulator::getInstance().mode == DisableTransmittingMode_RTS) cout <<"RTS\n\n";
    else cout << "CTS\n\n";

    generateNodesAttempt();

    //проверяем связность сети
    while ((!(isNetworkConnected()))&&(attemps < maxAttemps))
    {
        attemps++;
        this->clear();
        Simulator::getInstance().getEventQueue()->clear();
//        cout << "Сеть несвязна, перегенерируем координаты узлов "<<1+attemps<<" раз\n";
        generateNodesAttempt();
    }

     calculateMatrix();

    if (isNetworkConnected())
    {
        for (int nodeMac = 0; nodeMac < nodeCount; nodeMac++)
        {
            BSSNode* node = nodes[nodeMac];
            cout<<"Узел P"<<nodeMac<<" добавлен: X="<<node->getX()<<" Y="<<node->getY()<<", момент включения = "<<node->getTimeOn()<<"\n";
        }
//        printMatrix();
        return true;
    }
    else
        return false;
}
int initCellModem(Serial *serial)
{

    size_t success = 0;
    size_t attempts = 0;
    g_cellmodem_status = CELLMODEM_STATUS_NOT_INIT;

    while (!success && attempts++ < 3) {
        closeNet(serial);

        if (attempts > 1) {
            pr_debug("SIM900: power cycling\r\n");
            if (sendCommandOK(serial, "AT\r") == 1 && attempts > 1) {
                pr_debug("SIM900: powering down\r\n");
                powerCycleCellModem();
            }
            powerCycleCellModem();
        }

        if (sendCommandRetry(serial, "ATZ\r", "OK", 2, 2) != 1) continue;
        if (sendCommandRetry(serial, "ATE0\r", "OK", 2, 2) != 1) continue;
        sendCommand(serial, "AT+CIPSHUT\r", "OK");
        if (isNetworkConnected(serial, 60, 3) != 1) continue;
        getSignalStrength(serial);
        read_subscriber_number(serial);
        read_IMEI(serial);
        if (isDataReady(serial, 30, 2) != 1) continue;
        success = 1;
    }
    if ( success ) {
        g_cellmodem_status = CELLMODEM_STATUS_PROVISIONED;
        return 0;
    } else {
        g_cellmodem_status = CELLMODEM_STATUS_NO_NETWORK;
        return -1;
    }
}