void
MapManager::Initialize()
{
    int num_threads(sWorld.getConfig(CONFIG_UINT32_NUMTHREADS));
    // Start mtmaps if needed.
    if (num_threads > 0 && m_updater.activate(num_threads) == -1)
        abort();

    InitStateMachine();
}
Esempio n. 2
0
void
MapManager::Initialize()
{
    int num_threads(sWorld.getConfig(CONFIG_UINT32_NUMTHREADS));

    if (num_threads > 0 && m_updater.activate(num_threads) == -1)
      {  abort(); }

    InitStateMachine();
    InitMaxInstanceId();
}
Esempio n. 3
0
void InitStateMachineList(
  struct TStateMachineList *ptList)
/****************************************************************************/
/* Initialises _all_ statemachines in the indicated list.                   */
/****************************************************************************/
{
  while (ptList != NULL)
  {
    if (ptList->ptThis != NULL)
      InitStateMachine(ptList->ptThis);
    ptList = ptList->ptNext;
  }
}
Esempio n. 4
0
void
MapManager::Initialize()
{
    m_threadsCount = sWorld.getConfig(CONFIG_BOOL_THREADS_DYNAMIC) ? 1 : sWorld.getConfig(CONFIG_UINT32_NUMTHREADS);
    m_threadsCountPreferred = m_threadsCount;

    // Start mtmaps if needed.
    if (m_threadsCount > 0 && m_updater.activate(m_threadsCount) == -1)
        abort();

    InitStateMachine();

    i_balanceTimer.SetInterval(sWorld.getConfig(CONFIG_UINT32_INTERVAL_MAPUPDATE)*100);
    m_previewTimeStamp = WorldTimer::getMSTime();
    m_workTimeStorage = 0;
    m_sleepTimeStorage = 0;
    m_tickCount = 0;
}
Esempio n. 5
0
void
MapManager::Initialize()
{
    InitStateMachine();
    InitMaxInstanceId();
}
void
MapManager::Initialize()
{
    InitStateMachine();
}
Esempio n. 7
0
int PNode :: Init(const Options & oOptions, NetWork *& poNetWork)
{
    int ret = CheckOptions(oOptions);
    if (ret != 0)
    {
        PLErr("CheckOptions fail, ret %d", ret);
        return ret;
    }

    m_iMyNodeID = oOptions.oMyNode.GetNodeID();

    //step1 init logstorage
    LogStorage * poLogStorage = nullptr;
    ret = InitLogStorage(oOptions, poLogStorage);
    if (ret != 0)
    {
        return ret;
    }

    //step2 init network
    ret = InitNetWork(oOptions, poNetWork);
    if (ret != 0)
    {
        return ret;
    }

    //step3 build masterlist
    for (int iGroupIdx = 0; iGroupIdx < oOptions.iGroupCount; iGroupIdx++)
    {
        MasterMgr * poMaster = new MasterMgr(this, iGroupIdx, poLogStorage, oOptions.pMasterChangeCallback);
        assert(poMaster != nullptr);
        m_vecMasterList.push_back(poMaster);

        ret = poMaster->Init();
        if (ret != 0)
        {
            return ret;
        }
    }

    //step4 build grouplist
    for (int iGroupIdx = 0; iGroupIdx < oOptions.iGroupCount; iGroupIdx++)
    {
        Group * poGroup = new Group(poLogStorage, poNetWork, m_vecMasterList[iGroupIdx]->GetMasterSM(), iGroupIdx, oOptions);
        assert(poGroup != nullptr);
        m_vecGroupList.push_back(poGroup);
    }

    //step5 build batchpropose
    if (oOptions.bUseBatchPropose)
    {
        for (int iGroupIdx = 0; iGroupIdx < oOptions.iGroupCount; iGroupIdx++)
        {
            ProposeBatch * poProposeBatch = new ProposeBatch(iGroupIdx, this, &m_oNotifierPool);
            assert(poProposeBatch != nullptr);
            m_vecProposeBatch.push_back(poProposeBatch);
        }
    }

    //step6 init statemachine
    InitStateMachine(oOptions);    

    //step7 parallel init group
    for (auto & poGroup : m_vecGroupList)
    {
        poGroup->StartInit();
    }

    for (auto & poGroup : m_vecGroupList)
    {
        int initret = poGroup->GetInitRet();
        if (initret != 0)
        {
            ret = initret;
        }
    }

    if (ret != 0)
    {
        return ret;
    }

    //last step. must init ok, then should start threads.
    //because that stop threads is slower, if init fail, we need much time to stop many threads.
    //so we put start threads in the last step.
    for (auto & poGroup : m_vecGroupList)
    {
        //start group's thread first.
        poGroup->Start();
    }
    RunMaster(oOptions);
    RunProposeBatch();

    PLHead("OK");

    return 0;
}
Esempio n. 8
0
void
MapManager::Initialize()
{
    InitStateMachine();
    CreateContinents();
}
Esempio n. 9
0
/*
** Function: PBX_Demo
**
** Description:
** PBX State Machine
**
** Input Parameters:
**
** Return:
** none
*/
uInt16 si3210_init (void) {
    ctrl_S spiGciObj; //spi interface object
    systemTimer_S timerObj;    //timer object
    controlInterfaceType *ProHWIntf; //hw interface
    ProslicDeviceType *ProSLICDevices[NUMBER_OF_PROSLIC]; //proslic device object
    proslicChanType_ptr arrayOfProslicChans[NUMBER_OF_CHAN]; //used for initialization only
    chanState ports[NUMBER_OF_CHAN];  //declare channel state structures
    uInt8 i=0;
    BOOLEAN keepRunning = TRUE;
    proslicChanType *pSlic;

#if (PRINTF_IS_OK)
    printf("Hang up phone!\n");
#endif
    //initialize timer
    TimerInit(&timerObj);
    ProSLIC_createControlInterface(&ProHWIntf);
    for (i=0; i<NUMBER_OF_PROSLIC; i++)
        ProSLIC_createDevice (&(ProSLICDevices[i]));
    for (i=0; i<NUMBER_OF_CHAN; i++) {
        widebandEn[i]=0;
        ProSLIC_createChannel(&(ports[i].ProObj));
        ProSLIC_SWInitChan (ports[i].ProObj,i,SI321X_TYPE, ProSLICDevices[i], ProHWIntf);
    }
    ProSLIC_setControlInterfaceCtrlObj (ProHWIntf, &spiGciObj);
    ProSLIC_setControlInterfaceReset (ProHWIntf, ctrl_ResetWrapper);
    ProSLIC_setControlInterfaceWriteRegister (ProHWIntf, ctrl_WriteRegisterWrapper);
    ProSLIC_setControlInterfaceReadRegister (ProHWIntf, ctrl_ReadRegisterWrapper);
    ProSLIC_setControlInterfaceWriteRAM (ProHWIntf, ctrl_WriteRAMWrapper);
    ProSLIC_setControlInterfaceReadRAM (ProHWIntf, ctrl_ReadRAMWrapper);
    ProSLIC_setControlInterfaceTimerObj (ProHWIntf, &timerObj);
    ProSLIC_setControlInterfaceDelay (ProHWIntf, time_DelayWrapper);
    ProSLIC_setControlInterfaceTimeElapsed (ProHWIntf, time_TimeElapsedWrapper);
    ProSLIC_setControlInterfaceGetTime (ProHWIntf, time_GetTimeWrapper);


#if (PRINTF_IS_OK)
    printf ("-------Si321x Rev ");
    printf (VERSIONSTR);
    printf (" PBX Demo Program------\n\n");
#endif


    ProSLIC_Reset((ports[0].ProObj));	//Reset the ProSLIC(s) before we begin

    //initialize SPI interface
    if (SPI_Init (&spiGciObj) ==  FALSE) {
#if (PRINTF_IS_OK)
        printf ("Cannot connect\n");
#endif
        return 0;
    }

    //Initialize the channel state for each channel
    for (i=0; i<NUMBER_OF_CHAN; i++) {
        arrayOfProslicChans[i] = (ports[i].ProObj); //create array of channel pointers (for broadcast init)
        ProSLIC_setSWDebugMode (ports[i].ProObj, 1);
    }
    ProSLIC_Init(arrayOfProslicChans,NUMBER_OF_CHAN);
    ProSLIC_RingSetup(ports[0].ProObj,USA_DEFAULT_RING);
    ProSLIC_SetLinefeedStatus(ports[0].ProObj,LF_FWD_ACTIVE);
    ProSLIC_EnableInterrupts(ports[0].ProObj);
    pSlic = (ports[0].ProObj);
    printChipDetails(pSlic);

    for (i=0; i<NUMBER_OF_CHAN; i++) {
        pSlic = (ports[i].ProObj);
        InitStateMachine(&(ports[i])); //initialize the call state machine
        ProSLIC_InitializeDialPulseDetect(&(ports[i].pulseDialData),&(ports[i].offHookTime),&(ports[i].onHookTime));
        if(pSlic->error==SPIFAIL)
            return 0;
        pSlic->deviceId->ctrlInterface->getTime_fptr(pSlic->deviceId->ctrlInterface->hTimer,&(ports[i].offHookTime));
        pSlic->deviceId->ctrlInterface->getTime_fptr(pSlic->deviceId->ctrlInterface->hTimer,&(ports[i].onHookTime));
    }


    //printMenu();
    callDoRinging (&(ports[0]));
    {
        int nTry = 20;
        uInt8 hkStat;
        do {
            ProSLIC_ReadHookStatus(ports[0].ProObj,&hkStat);
            if (hkStat != ONHOOK) {
                ProSLIC_ToneGenStop(ports[0].ProObj);
                break;
            }
            else {
                printf ("Waiting OnHOOK Event..%d\n", nTry);
            }
            nTry--;
            mdelay(300);
        } while(nTry>0);
    }


    ProSLIC_PCMTimeSlotSetup(ports[0].ProObj,ppcm_config->ts_start[0],ppcm_config->ts_start[0]);

#if	defined(PCM_LINEAR)
    callDoWideband(&(ports[0]));
#else
    callDoNarrowband(&(ports[0]));
#endif
    ProSLIC_PCMStart(ports[0].ProObj);
    ProSLIC_SetLinefeedStatus(ports[0].ProObj,LF_FWD_ACTIVE);
    //start the demo
    /*
    	while (keepRunning){
    		for (i=0;i<NUMBER_OF_CHAN;i++){
    			if (ports[i].ProObj->channelEnable){
    				channelDemo(&(ports[i]),&timerObj,&keepRunning);
    				if (ports[i].connectionWith != NOCONNECT)
    					connectionManager(&(ports[i]),&(ports[ports[i].connectionWith]));
    			}
    		}
    	}
    */
    return 1;
}
Esempio n. 10
0
void TestMgr::RunWithPid(void) {

	bool doExit = false;
	float pwmDutyCycle = 0.0;

	// Initialize the state machine that runs the worker bees
	InitStateMachine();

	// Initialize the PID Loop
	// PidConstants_t pidConstants;
	// m_PidRange.ChangeRangeId(0);
	// m_PidRange.GetRangeConstants(pidConstants);
	// m_PidLoop.InitLoopUsingConstants(pidConstants, m_PidRange.GetRangeEndTemp());
	// p->m_PidLoop.SetLoopOnOff(PID_LOOP_ON);

	while (!doExit) {

		if (m_AbortFlag) {
			doExit = true;
			break;
		}

		// Get the elapsed time since the PID loop was run last
		m_PidLoopElapsedTime = m_PidLoopRunTimer.GetElapsedMillisec();

		// Run the PID loop at the specified interval
		if (m_PidLoopElapsedTime >= (m_PidLoopUpdateTimeInMs - 10)) {

			// Restart PID loop timer
			m_PidLoopRunTimer.ResetStartTimestamp();

			// Safety check
			if (m_PlateTempDegreesC > 100.0) {
				m_Sub20.HeaterPwmUpdate(0.0);
				m_Sub20.TurnOffHeater();
				std::cout << "Temperature exceeds max allowed. Turning off heater and exiting."  << std::endl;
				doExit = true;
			}

			// Read the plate temperature
			if (ReadTemp()) {

				// Run the state machine
				state_machine_run(&m_StateMachine, (uint32_t *)this, (uint32_t *)NULL);

				// Re-read the elapsed time since loop was run
				// uint64_t elapsedTimeInMs = m_PidLoopRunTimer.GetElapsedMillisec();

				// Run the PID loop
				pwmDutyCycle = m_PidLoop.Compute(m_PlateTempDegreesC, (m_PidLoopElapsedTime / ((float)1000.0)));
				if (m_PidLoop.IsLoopOn()) {
					// Update either the heater or the cooler PWM
					PidDirection_t pidDirection = m_PidLoop.GetDirection();
                    assert (pidDirection == PID_DIR_DIRECT || pidDirection == PID_DIR_REVERSE);
                    if (pidDirection == PID_DIR_DIRECT) {
						m_Sub20.HeaterPwmUpdate(pwmDutyCycle);
					} else {
						m_Sub20.CoolerPwmUpdate(pwmDutyCycle);
					}
				}
			}
		}

		// Get the elapsed time since the last voltage was logged
		m_LogVoltageElapsedTime = m_LogVoltageTimer.GetElapsedMillisec();

		// Log voltage at the specified interval.
		if (m_LogVoltageElapsedTime >= (m_VoltageLogUpdateTimeInMs - 10)) {

			// Restart Log Voltage timer
			m_LogVoltageTimer.ResetStartTimestamp();

			if (0 && m_FlukeSerial.ReadAcVoltage(m_AcVoltage)) {
				std::cout << "[" << std::dec << std::setfill('0') << std::setw(6) << m_LogVoltageElapsedTime << "] ";
				std::cout << "DC Voltage: ";
				std::cout << std::fixed << std::setw(11) << std::setprecision(6) << m_AcVoltage << std::endl;
				VoltageLogWriteData(m_RunTimer.GetElapsedMillisec());
			}
		}

		// Run the main loop at a 10ms rate
		QThread::msleep(10);
	}
}