void CActiveMasternode::ManageStateLocal(CConnman& connman) { LogPrint("masternode", "CActiveMasternode::ManageStateLocal -- status = %s, type = %s, pinger enabled = %d\n", GetStatus(), GetTypeString(), fPingerEnabled); if(nState == ACTIVE_MASTERNODE_STARTED) { return; } // Choose coins to use CPubKey pubKeyCollateral; CKey keyCollateral; if(pwalletMain->GetMasternodeOutpointAndKeys(outpoint, pubKeyCollateral, keyCollateral)) { int nPrevoutAge = GetUTXOConfirmations(outpoint); if(nPrevoutAge < Params().GetConsensus().nMasternodeMinimumConfirmations){ nState = ACTIVE_MASTERNODE_INPUT_TOO_NEW; strNotCapableReason = strprintf(_("%s - %d confirmations"), GetStatus(), nPrevoutAge); LogPrintf("CActiveMasternode::ManageStateLocal -- %s: %s\n", GetStateString(), strNotCapableReason); return; } { LOCK(pwalletMain->cs_wallet); pwalletMain->LockCoin(outpoint); } CMasternodeBroadcast mnb; std::string strError; if(!CMasternodeBroadcast::Create(outpoint, service, keyCollateral, pubKeyCollateral, keyMasternode, pubKeyMasternode, strError, mnb)) { nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = "Error creating mastenode broadcast: " + strError; LogPrintf("CActiveMasternode::ManageStateLocal -- %s: %s\n", GetStateString(), strNotCapableReason); return; } { LOCK(cs_main); // remember the hash of the block where masternode collateral had minimum required confirmations mnb.nCollateralMinConfBlockHash = chainActive[GetUTXOHeight(outpoint) + Params().GetConsensus().nMasternodeMinimumConfirmations - 1]->GetBlockHash(); } fPingerEnabled = true; nState = ACTIVE_MASTERNODE_STARTED; //update to masternode list LogPrintf("CActiveMasternode::ManageStateLocal -- Update Masternode List\n"); mnodeman.UpdateMasternodeList(mnb, connman); mnodeman.NotifyMasternodeUpdates(connman); //send to all peers LogPrintf("CActiveMasternode::ManageStateLocal -- Relay broadcast, collateral=%s\n", outpoint.ToStringShort()); mnb.Relay(connman); } }
bool SetGameState(GameState newState) { if (m_state != newState) { DebuggerPrintf("Changed State from %s to %s", GetStateString(m_state), GetStateString(newState)); m_state = newState; return true; } else { ERROR_RECOVERABLE("State machine was set to the same state."); return false; } }
//----------------------------------------------------------------------------------- void TheGame::Render() { Renderer::instance->ClearScreen(0.3f, 0.3f, 0.3f); Renderer::instance->BeginOrtho(Vector2::ZERO, Vector2(1600, 900)); Renderer::instance->DrawText2D(Vector2(0, 0), GetStateString(GetGameState()), 5.0f, RGBA::VAPORWAVE, true, BitmapFont::CreateOrGetFontFromGlyphSheet("Runescape")); switch (GetGameState()) { case GameState::GENERATION: Renderer::instance->ClearScreen(0.3f, 0.3f, 0.3f); RenderGeneration(); break; case GameState::MAIN_MENU: Renderer::instance->ClearScreen(RGBA::CORNFLOWER_BLUE); RenderMainMenu(); break; case GameState::MAP_SELECTION: Renderer::instance->ClearScreen(RGBA::FOREST_GREEN); RenderMapSelection(); break; case GameState::PLAYING: Renderer::instance->ClearScreen(RGBA::BLACK); RenderPlaying(); break; case GameState::PAUSED: Renderer::instance->ClearScreen(RGBA::CORNFLOWER_BLUE); RenderPaused(); break; } Renderer::instance->EndOrtho(); }
void CActiveMasternode::ManageState(CConnman& connman) { LogPrint("masternode", "CActiveMasternode::ManageState -- Start\n"); if(!fMasterNode) { LogPrint("masternode", "CActiveMasternode::ManageState -- Not a masternode, returning\n"); return; } if(Params().NetworkIDString() != CBaseChainParams::REGTEST && !masternodeSync.IsBlockchainSynced()) { nState = ACTIVE_MASTERNODE_SYNC_IN_PROCESS; LogPrintf("CActiveMasternode::ManageState -- %s: %s\n", GetStateString(), GetStatus()); return; } if(nState == ACTIVE_MASTERNODE_SYNC_IN_PROCESS) { nState = ACTIVE_MASTERNODE_INITIAL; } LogPrint("masternode", "CActiveMasternode::ManageState -- status = %s, type = %s, pinger enabled = %d\n", GetStatus(), GetTypeString(), fPingerEnabled); if(eType == MASTERNODE_UNKNOWN) { ManageStateInitial(connman); } if(eType == MASTERNODE_REMOTE) { ManageStateRemote(); } else if(eType == MASTERNODE_LOCAL) { // Try Remote Start first so the started local masternode can be restarted without recreate masternode broadcast. ManageStateRemote(); if(nState != ACTIVE_MASTERNODE_STARTED) ManageStateLocal(connman); } SendMasternodePing(connman); }
void PowerState::EnterState () { PmSetSystemPowerState_I (GetStateString (), 0, 0, TRUE); m_LastNewState = GetState (); // Point to itself // Initial timeout to Active: m_dwEventArray[PM_SHUTDOWN_EVENT] = m_pPwrStateMgr->GetEventHandle (PM_SHUTDOWN_EVENT); m_dwEventArray[PM_RELOAD_ACTIVITY_TIMEOUTS_EVENT] = m_pPwrStateMgr->GetEventHandle (PM_RELOAD_ACTIVITY_TIMEOUTS_EVENT); m_dwEventArray[PM_MSGQUEUE_EVENT] = m_pPwrStateMgr->GetEventHandle (PM_MSGQUEUE_EVENT); m_dwEventArray[PM_RESTART_TIMER_EVENT] = m_pPwrStateMgr->GetEventHandle (PM_RESTART_TIMER_EVENT); m_dwEventArray[PM_USER_ACTIVITY_EVENT] = m_pPwrStateMgr->GetUserActivityTimer ()->hevAutoReset; m_dwEventArray[PM_SYSTEM_API_EVENT] = m_pPwrStateMgr->GetEventHandle (PM_SYSTEM_API_EVENT); m_dwEventArray[PM_SYSTEM_TIMEIDLE_RESET] = m_pPwrStateMgr->GetEventHandle (PM_SYSTEM_TIMEIDLE_RESET); m_dwEventArray[PM_BOOTPHASE2_EVENT] = m_pPwrStateMgr->GetEventHandle (PM_BOOTPHASE2_EVENT); m_dwNumOfEvent = PM_BASE_TOTAL_EVENT; for (DWORD dwIndex = 0; dwIndex < PM_BASE_TOTAL_EVENT; dwIndex++) { if (m_dwEventArray[dwIndex] == NULL) { // Use dummy event. m_dwEventArray[dwIndex] = m_hUnsignaledHandle; } } m_pPwrStateMgr->ReAdjustTimeOuts (); }
void CActiveLegacyMasternodeManager::ManageState(CConnman& connman) { if (deterministicMNManager->IsDeterministicMNsSporkActive()) return; LogPrint("masternode", "CActiveLegacyMasternodeManager::ManageState -- Start\n"); if (!fMasternodeMode) { LogPrint("masternode", "CActiveLegacyMasternodeManager::ManageState -- Not a masternode, returning\n"); return; } if (Params().NetworkIDString() != CBaseChainParams::REGTEST && !masternodeSync.IsBlockchainSynced()) { nState = ACTIVE_MASTERNODE_SYNC_IN_PROCESS; LogPrintf("CActiveLegacyMasternodeManager::ManageState -- %s: %s\n", GetStateString(), GetStatus()); return; } if (nState == ACTIVE_MASTERNODE_SYNC_IN_PROCESS) { nState = ACTIVE_MASTERNODE_INITIAL; } LogPrint("masternode", "CActiveLegacyMasternodeManager::ManageState -- status = %s, type = %s, pinger enabled = %d\n", GetStatus(), GetTypeString(), fPingerEnabled); if (eType == MASTERNODE_UNKNOWN) { ManageStateInitial(connman); } if (eType == MASTERNODE_REMOTE) { ManageStateRemote(); } SendMasternodePing(connman); }
void CActiveMasternode::ManageStateRemote() { LogPrint("masternode", "CActiveMasternode::ManageStateRemote -- Start status = %s, type = %s, pinger enabled = %d, pubKeyMasternode.GetID() = %s\n", GetStatus(), GetTypeString(), fPingerEnabled, pubKeyMasternode.GetID().ToString()); mnodeman.CheckMasternode(pubKeyMasternode, true); masternode_info_t infoMn; if(mnodeman.GetMasternodeInfo(pubKeyMasternode, infoMn)) { if(infoMn.nProtocolVersion != PROTOCOL_VERSION) { nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = "Invalid protocol version"; LogPrintf("CActiveMasternode::ManageStateRemote -- %s: %s\n", GetStateString(), strNotCapableReason); return; } if(service != infoMn.addr) { nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = "Broadcasted IP doesn't match our external address. Make sure you issued a new broadcast if IP of this masternode changed recently."; LogPrintf("CActiveMasternode::ManageStateRemote -- %s: %s\n", GetStateString(), strNotCapableReason); return; } if(!CMasternode::IsValidStateForAutoStart(infoMn.nActiveState)) { nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = strprintf("Masternode in %s state", CMasternode::StateToString(infoMn.nActiveState)); LogPrintf("CActiveMasternode::ManageStateRemote -- %s: %s\n", GetStateString(), strNotCapableReason); return; } if(nState != ACTIVE_MASTERNODE_STARTED) { LogPrintf("CActiveMasternode::ManageStateRemote -- STARTED!\n"); outpoint = infoMn.vin.prevout; service = infoMn.addr; fPingerEnabled = true; nState = ACTIVE_MASTERNODE_STARTED; } } else { nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = "Masternode not in masternode list"; LogPrintf("CActiveMasternode::ManageStateRemote -- %s: %s\n", GetStateString(), strNotCapableReason); } }
void PowerStateSuspend::EnterState () { PmSetSystemPowerState_I (GetStateString (), 0, 0, TRUE); // Because it wakes up by a wakeup source, automatically enter the Resuming state. m_LastNewState = Resuming; // Point to Resuming. // Initial timeout to Active: m_pPwrStateMgr->ClearUnattendedRefCount (); m_dwEventArray[PM_USER_ACTIVITY_EVENT] = m_pPwrStateMgr->GetUserActivityTimer ()->hevActive; m_pPwrStateMgr->ReInitTimeOuts (FALSE); }
void CActiveLegacyMasternodeManager::ManageStateRemote() { if (deterministicMNManager->IsDeterministicMNsSporkActive()) return; LogPrint("masternode", "CActiveLegacyMasternodeManager::ManageStateRemote -- Start status = %s, type = %s, pinger enabled = %d, keyIDOperator = %s\n", GetStatus(), GetTypeString(), fPingerEnabled, activeMasternodeInfo.legacyKeyIDOperator.ToString()); mnodeman.CheckMasternode(activeMasternodeInfo.legacyKeyIDOperator, true); masternode_info_t infoMn; if (mnodeman.GetMasternodeInfo(activeMasternodeInfo.legacyKeyIDOperator, infoMn)) { if (infoMn.nProtocolVersion != PROTOCOL_VERSION) { nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = "Invalid protocol version"; LogPrintf("CActiveLegacyMasternodeManager::ManageStateRemote -- %s: %s\n", GetStateString(), strNotCapableReason); return; } if (activeMasternodeInfo.service != infoMn.addr) { nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = "Broadcasted IP doesn't match our external address. Make sure you issued a new broadcast if IP of this masternode changed recently."; LogPrintf("CActiveLegacyMasternodeManager::ManageStateRemote -- %s: %s\n", GetStateString(), strNotCapableReason); return; } if (!CMasternode::IsValidStateForAutoStart(infoMn.nActiveState)) { nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = strprintf("Masternode in %s state", CMasternode::StateToString(infoMn.nActiveState)); LogPrintf("CActiveLegacyMasternodeManager::ManageStateRemote -- %s: %s\n", GetStateString(), strNotCapableReason); return; } auto dmn = deterministicMNManager->GetListAtChainTip().GetMNByCollateral(infoMn.outpoint); if (dmn) { if (dmn->pdmnState->addr != infoMn.addr) { nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = strprintf("Masternode collateral is a ProTx and ProTx address does not match local address"); LogPrintf("CActiveLegacyMasternodeManager::ManageStateRemote -- %s: %s\n", GetStateString(), strNotCapableReason); return; } LogPrintf("CActiveLegacyMasternodeManager::ManageStateRemote -- Collateral is a ProTx\n"); } if (nState != ACTIVE_MASTERNODE_STARTED) { LogPrintf("CActiveLegacyMasternodeManager::ManageStateRemote -- STARTED!\n"); activeMasternodeInfo.outpoint = infoMn.outpoint; activeMasternodeInfo.service = infoMn.addr; fPingerEnabled = true; nState = ACTIVE_MASTERNODE_STARTED; } } else { nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = "Masternode not in masternode list"; LogPrintf("CActiveLegacyMasternodeManager::ManageStateRemote -- %s: %s\n", GetStateString(), strNotCapableReason); } }
DWORD PowerState::StateValidateRegistry (DWORD dwDState, DWORD dwFlag) { HKEY hkPM = NULL, hkSubkey; TCHAR pszSubKey[MAX_PATH]; DWORD dwDisposition; SETFNAME (_T ("PowerState::StateValidateRegistry")); // Open the Power Manager registry key: DWORD dwStatus = RegCreateKeyEx (HKEY_LOCAL_MACHINE, PWRMGR_REG_KEY, 0, NULL, 0, 0, NULL, &hkPM, &dwDisposition); if (dwStatus != ERROR_SUCCESS) { PMLOGMSG (ZONE_ERROR, (_T ("%s: can't open '%s', error is %d\r\n"), pszFname, PWRMGR_REG_KEY, dwStatus)); } // Verify the system state: if (dwStatus == ERROR_SUCCESS) { StringCchPrintf (pszSubKey, MAX_PATH, _T ("State\\%s"), GetStateString ()); dwStatus = RegCreateKeyEx (hkPM, pszSubKey, 0, NULL, 0, 0, NULL, &hkSubkey, &dwDisposition); if (dwStatus == ERROR_SUCCESS) { if (dwDisposition == REG_CREATED_NEW_KEY) { // Allow devices to go to any passed-in power level: DWORD dwValue = dwDState; // D State dwStatus = RegSetValueEx (hkSubkey, NULL, 0, REG_DWORD, (LPBYTE) & dwValue, sizeof (dwValue)); // Write the passed flags value: if (dwStatus == ERROR_SUCCESS) { dwValue = dwFlag; dwStatus = RegSetValueEx (hkSubkey, _T ("Flags"), 0, REG_DWORD, (LPBYTE) & dwValue, sizeof (dwValue)); } } RegCloseKey (hkSubkey); } PMLOGMSG (dwStatus != ERROR_SUCCESS && ZONE_ERROR, (_T ("%s: error %d while creating or writing values in '%s\\%s'\r\n"), pszFname, dwStatus, PWRMGR_REG_KEY, pszSubKey)); } // Release resources: if (hkPM != NULL) RegCloseKey (hkPM); return dwStatus; }
bool CActiveLegacyMasternodeManager::SendMasternodePing(CConnman& connman) { if (deterministicMNManager->IsDeterministicMNsSporkActive()) return false; if (!fPingerEnabled) { LogPrint("masternode", "CActiveLegacyMasternodeManager::SendMasternodePing -- %s: masternode ping service is disabled, skipping...\n", GetStateString()); return false; } if (!mnodeman.Has(activeMasternodeInfo.outpoint)) { strNotCapableReason = "Masternode not in masternode list"; nState = ACTIVE_MASTERNODE_NOT_CAPABLE; LogPrintf("CActiveLegacyMasternodeManager::SendMasternodePing -- %s: %s\n", GetStateString(), strNotCapableReason); return false; } CMasternodePing mnp(activeMasternodeInfo.outpoint); mnp.nSentinelVersion = nSentinelVersion; mnp.fSentinelIsCurrent = (abs(GetAdjustedTime() - nSentinelPingTime) < MASTERNODE_SENTINEL_PING_MAX_SECONDS); if (!mnp.Sign(activeMasternodeInfo.legacyKeyOperator, activeMasternodeInfo.legacyKeyIDOperator)) { LogPrintf("CActiveLegacyMasternodeManager::SendMasternodePing -- ERROR: Couldn't sign Masternode Ping\n"); return false; } // Update lastPing for our masternode in Masternode list if (mnodeman.IsMasternodePingedWithin(activeMasternodeInfo.outpoint, MASTERNODE_MIN_MNP_SECONDS, mnp.sigTime)) { LogPrintf("CActiveLegacyMasternodeManager::SendMasternodePing -- Too early to send Masternode Ping\n"); return false; } mnodeman.SetMasternodeLastPing(activeMasternodeInfo.outpoint, mnp); LogPrintf("CActiveLegacyMasternodeManager::SendMasternodePing -- Relaying ping, collateral=%s\n", activeMasternodeInfo.outpoint.ToStringShort()); mnp.Relay(connman); return true; }
bool CActiveMasternode::SendMasternodePing(CConnman& connman) { if(!fPingerEnabled) { LogPrint("masternode", "CActiveMasternode::SendMasternodePing -- %s: masternode ping service is disabled, skipping...\n", GetStateString()); return false; } if(!mnodeman.Has(outpoint)) { strNotCapableReason = "Masternode not in masternode list"; nState = ACTIVE_MASTERNODE_NOT_CAPABLE; LogPrintf("CActiveMasternode::SendMasternodePing -- %s: %s\n", GetStateString(), strNotCapableReason); return false; } CMasternodePing mnp(outpoint); mnp.nSentinelVersion = nSentinelVersion; mnp.fSentinelIsCurrent = (abs(GetAdjustedTime() - nSentinelPingTime) < MASTERNODE_WATCHDOG_MAX_SECONDS); if(!mnp.Sign(keyMasternode, pubKeyMasternode)) { LogPrintf("CActiveMasternode::SendMasternodePing -- ERROR: Couldn't sign Masternode Ping\n"); return false; } // Update lastPing for our masternode in Masternode list if(mnodeman.IsMasternodePingedWithin(outpoint, MASTERNODE_MIN_MNP_SECONDS, mnp.sigTime)) { LogPrintf("CActiveMasternode::SendMasternodePing -- Too early to send Masternode Ping\n"); return false; } mnodeman.SetMasternodeLastPing(outpoint, mnp); LogPrintf("CActiveMasternode::SendMasternodePing -- Relaying ping, collateral=%s\n", outpoint.ToStringShort()); mnp.Relay(connman); return true; }
void CActiveLegacyMasternodeManager::ManageStateInitial(CConnman& connman) { if (deterministicMNManager->IsDeterministicMNsSporkActive()) return; LogPrint("masternode", "CActiveLegacyMasternodeManager::ManageStateInitial -- status = %s, type = %s, pinger enabled = %d\n", GetStatus(), GetTypeString(), fPingerEnabled); // Check that our local network configuration is correct if (!fListen) { // listen option is probably overwritten by smth else, no good nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = "Masternode must accept connections from outside. Make sure listen configuration option is not overwritten by some another parameter."; LogPrintf("CActiveLegacyMasternodeManager::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason); return; } // First try to find whatever local address is specified by externalip option bool fFoundLocal = GetLocal(activeMasternodeInfo.service) && CMasternode::IsValidNetAddr(activeMasternodeInfo.service); if (!fFoundLocal) { bool empty = true; // If we have some peers, let's try to find our local address from one of them connman.ForEachNodeContinueIf(CConnman::AllNodes, [&fFoundLocal, &empty](CNode* pnode) { empty = false; if (pnode->addr.IsIPv4()) fFoundLocal = GetLocal(activeMasternodeInfo.service, &pnode->addr) && CMasternode::IsValidNetAddr(activeMasternodeInfo.service); return !fFoundLocal; }); // nothing and no live connections, can't do anything for now if (empty) { nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = "Can't detect valid external address. Will retry when there are some connections available."; LogPrintf("CActiveLegacyMasternodeManager::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason); return; } } if (!fFoundLocal && Params().NetworkIDString() == CBaseChainParams::REGTEST) { if (Lookup("127.0.0.1", activeMasternodeInfo.service, GetListenPort(), false)) { fFoundLocal = true; } } if (!fFoundLocal) { nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = "Can't detect valid external address. Please consider using the externalip configuration option if problem persists. Make sure to use IPv4 address only."; LogPrintf("CActiveLegacyMasternodeManager::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason); return; } int mainnetDefaultPort = Params(CBaseChainParams::MAIN).GetDefaultPort(); if (Params().NetworkIDString() == CBaseChainParams::MAIN) { if (activeMasternodeInfo.service.GetPort() != mainnetDefaultPort) { nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = strprintf("Invalid port: %u - only %d is supported on mainnet.", activeMasternodeInfo.service.GetPort(), mainnetDefaultPort); LogPrintf("CActiveLegacyMasternodeManager::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason); return; } } else if (activeMasternodeInfo.service.GetPort() == mainnetDefaultPort) { nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = strprintf("Invalid port: %u - %d is only supported on mainnet.", activeMasternodeInfo.service.GetPort(), mainnetDefaultPort); LogPrintf("CActiveLegacyMasternodeManager::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason); return; } if (Params().NetworkIDString() != CBaseChainParams::REGTEST) { // Check socket connectivity LogPrintf("CActiveLegacyMasternodeManager::ManageStateInitial -- Checking inbound connection to '%s'\n", activeMasternodeInfo.service.ToString()); SOCKET hSocket; bool fConnected = ConnectSocket(activeMasternodeInfo.service, hSocket, nConnectTimeout) && IsSelectableSocket(hSocket); CloseSocket(hSocket); if (!fConnected) { nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = "Could not connect to " + activeMasternodeInfo.service.ToString(); LogPrintf("CActiveLegacyMasternodeManager::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason); return; } } // Default to REMOTE eType = MASTERNODE_REMOTE; LogPrint("masternode", "CActiveLegacyMasternodeManager::ManageStateInitial -- End status = %s, type = %s, pinger enabled = %d\n", GetStatus(), GetTypeString(), fPingerEnabled); }
void CMasternode::Check(bool fForce) { AssertLockHeld(cs_main); LOCK(cs); if (ShutdownRequested()) return; if (!fForce && (GetTime() - nTimeLastChecked < MASTERNODE_CHECK_SECONDS)) return; nTimeLastChecked = GetTime(); LogPrint(MCLog::MN, "CMasternode::Check -- Masternode %s is in %s state\n", outpoint.ToStringShort(), GetStateString()); //once spent, stop doing the checks if (IsOutpointSpent()) return; int nHeight = 0; if (!fUnitTest) { Coin coin; if (!GetUTXOCoin(outpoint, coin)) { nActiveState = MASTERNODE_OUTPOINT_SPENT; LogPrint(MCLog::MN, "CMasternode::Check -- Failed to find Masternode UTXO, masternode=%s\n", outpoint.ToStringShort()); return; } nHeight = chainActive.Height(); } if (IsPoSeBanned()) { if (nHeight < nPoSeBanHeight) return; // too early? // Otherwise give it a chance to proceed further to do all the usual checks and to change its state. // Masternode still will be on the edge and can be banned back easily if it keeps ignoring mnverify // or connect attempts. Will require few mnverify messages to strengthen its position in mn list. LogPrint(MCLog::MN, "CMasternode::Check -- Masternode %s is unbanned and back in list now\n", outpoint.ToStringShort()); DecreasePoSeBanScore(); } else if (nPoSeBanScore >= MASTERNODE_POSE_BAN_MAX_SCORE) { nActiveState = MASTERNODE_POSE_BAN; // ban for the whole payment cycle nPoSeBanHeight = nHeight + mnodeman.size(); LogPrint(MCLog::MN, "CMasternode::Check -- Masternode %s is banned till block %d now\n", outpoint.ToStringShort(), nPoSeBanHeight); return; } int nActiveStatePrev = nActiveState; bool fOurMasternode = fMasternodeMode && activeMasternode.pubKeyMasternode == pubKeyMasternode; // masternode doesn't meet payment protocol requirements ... bool fRequireUpdate = nProtocolVersion < mnpayments.GetMinMasternodePaymentsProto() || // or it's our own node and we just updated it to the new protocol but we are still waiting for activation ... (fOurMasternode && nProtocolVersion < PROTOCOL_VERSION); if (fRequireUpdate) { nActiveState = MASTERNODE_UPDATE_REQUIRED; if (nActiveStatePrev != nActiveState) { LogPrint(MCLog::MN, "CMasternode::Check -- Masternode %s is in %s state now\n", outpoint.ToStringShort(), GetStateString()); } return; } // keep old masternodes on start, give them a chance to receive updates... bool fWaitForPing = !masternodeSync.IsMasternodeListSynced() && !IsPingedWithin(MASTERNODE_MIN_MNP_SECONDS); if (fWaitForPing && !fOurMasternode) { // ...but if it was already expired before the initial check - return right away if (IsExpired() || IsSentinelPingExpired() || IsNewStartRequired()) { LogPrint(MCLog::MN, "CMasternode::Check -- Masternode %s is in %s state, waiting for ping\n", outpoint.ToStringShort(), GetStateString()); return; } } // don't expire if we are still in "waiting for ping" mode unless it's our own masternode if (!fWaitForPing || fOurMasternode) { if (!IsPingedWithin(MASTERNODE_NEW_START_REQUIRED_SECONDS)) { nActiveState = MASTERNODE_NEW_START_REQUIRED; if (nActiveStatePrev != nActiveState) { LogPrint(MCLog::MN, "CMasternode::Check -- Masternode %s is in %s state now\n", outpoint.ToStringShort(), GetStateString()); } return; } if (!IsPingedWithin(MASTERNODE_EXPIRATION_SECONDS)) { nActiveState = MASTERNODE_EXPIRED; if (nActiveStatePrev != nActiveState) { LogPrint(MCLog::MN, "CMasternode::Check -- Masternode %s is in %s state now\n", outpoint.ToStringShort(), GetStateString()); } return; } // part 1: expire based on machinecoind ping bool fSentinelPingActive = masternodeSync.IsSynced() && mnodeman.IsSentinelPingActive(); bool fSentinelPingExpired = fSentinelPingActive && !IsPingedWithin(MASTERNODE_SENTINEL_PING_MAX_SECONDS); LogPrint(MCLog::MN, "CMasternode::Check -- outpoint=%s, GetAdjustedTime()=%d, fSentinelPingExpired=%d\n", outpoint.ToStringShort(), GetAdjustedTime(), fSentinelPingExpired); if (fSentinelPingExpired) { nActiveState = MASTERNODE_SENTINEL_PING_EXPIRED; if (nActiveStatePrev != nActiveState) { LogPrint(MCLog::MN, "CMasternode::Check -- Masternode %s is in %s state now\n", outpoint.ToStringShort(), GetStateString()); } return; } } // We require MNs to be in PRE_ENABLED until they either start to expire or receive a ping and go into ENABLED state // Works on mainnet/testnet only and not the case on regtest. if (Params().NetworkIDString() != CBaseChainParams::REGTEST) { if (lastPing.sigTime - sigTime < MASTERNODE_MIN_MNP_SECONDS) { nActiveState = MASTERNODE_PRE_ENABLED; if (nActiveStatePrev != nActiveState) { LogPrint(MCLog::MN, "CMasternode::Check -- Masternode %s is in %s state now\n", outpoint.ToStringShort(), GetStateString()); } return; } } if (!fWaitForPing || fOurMasternode) { // part 2: expire based on sentinel info bool fSentinelPingActive = masternodeSync.IsSynced() && mnodeman.IsSentinelPingActive(); bool fSentinelPingExpired = fSentinelPingActive && !lastPing.fSentinelIsCurrent; LogPrint(MCLog::MN, "CMasternode::Check -- outpoint=%s, GetAdjustedTime()=%d, fSentinelPingExpired=%d\n", outpoint.ToStringShort(), GetAdjustedTime(), fSentinelPingExpired); if (fSentinelPingExpired) { nActiveState = MASTERNODE_SENTINEL_PING_EXPIRED; if (nActiveStatePrev != nActiveState) { LogPrint(MCLog::MN, "CMasternode::Check -- Masternode %s is in %s state now\n", outpoint.ToStringShort(), GetStateString()); } return; } } nActiveState = MASTERNODE_ENABLED; // OK if (nActiveStatePrev != nActiveState) { LogPrint(MCLog::MN, "CMasternode::Check -- Masternode %s is in %s state now\n", outpoint.ToStringShort(), GetStateString()); } }
void CActiveMasternode::ManageStateInitial(CConnman& connman) { LogPrint("masternode", "CActiveMasternode::ManageStateInitial -- status = %s, type = %s, pinger enabled = %d\n", GetStatus(), GetTypeString(), fPingerEnabled); // Check that our local network configuration is correct if (!fListen) { // listen option is probably overwritten by smth else, no good nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = "Masternode must accept connections from outside. Make sure listen configuration option is not overwritten by some another parameter."; LogPrintf("CActiveMasternode::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason); return; } // First try to find whatever local address is specified by externalip option bool fFoundLocal = GetLocal(service) && CMasternode::IsValidNetAddr(service); if(!fFoundLocal) { bool empty = true; // If we have some peers, let's try to find our local address from one of them connman.ForEachNodeContinueIf(CConnman::AllNodes, [&fFoundLocal, &empty, this](CNode* pnode) { empty = false; if (pnode->addr.IsIPv4()) fFoundLocal = GetLocal(service, &pnode->addr) && CMasternode::IsValidNetAddr(service); return !fFoundLocal; }); // nothing and no live connections, can't do anything for now if (empty) { nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = "Can't detect valid external address. Will retry when there are some connections available."; LogPrintf("CActiveMasternode::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason); return; } } if(!fFoundLocal) { nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = "Can't detect valid external address. Please consider using the externalip configuration option if problem persists. Make sure to use IPv4 address only."; LogPrintf("CActiveMasternode::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason); return; } int mainnetDefaultPort = Params(CBaseChainParams::MAIN).GetDefaultPort(); if(Params().NetworkIDString() == CBaseChainParams::MAIN) { if(service.GetPort() != mainnetDefaultPort) { nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = strprintf("Invalid port: %u - only %d is supported on mainnet.", service.GetPort(), mainnetDefaultPort); LogPrintf("CActiveMasternode::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason); return; } } else if(service.GetPort() == mainnetDefaultPort) { nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = strprintf("Invalid port: %u - %d is only supported on mainnet.", service.GetPort(), mainnetDefaultPort); LogPrintf("CActiveMasternode::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason); return; } LogPrintf("CActiveMasternode::ManageStateInitial -- Checking inbound connection to '%s'\n", service.ToString()); if(!connman.ConnectNode(CAddress(service, NODE_NETWORK), NULL, true)) { nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = "Could not connect to " + service.ToString(); LogPrintf("CActiveMasternode::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason); return; } // Default to REMOTE eType = MASTERNODE_REMOTE; // Check if wallet funds are available if(!pwalletMain) { LogPrintf("CActiveMasternode::ManageStateInitial -- %s: Wallet not available\n", GetStateString()); return; } if(pwalletMain->IsLocked()) { LogPrintf("CActiveMasternode::ManageStateInitial -- %s: Wallet is locked\n", GetStateString()); return; } if(pwalletMain->GetBalance() < 1000*COIN) { LogPrintf("CActiveMasternode::ManageStateInitial -- %s: Wallet balance is < 1000 TINCOIN\n", GetStateString()); return; } // Choose coins to use CPubKey pubKeyCollateral; CKey keyCollateral; // If collateral is found switch to LOCAL mode if(pwalletMain->GetMasternodeOutpointAndKeys(outpoint, pubKeyCollateral, keyCollateral)) { eType = MASTERNODE_LOCAL; } LogPrint("masternode", "CActiveMasternode::ManageStateInitial -- End status = %s, type = %s, pinger enabled = %d\n", GetStatus(), GetTypeString(), fPingerEnabled); }
std::string CMasternode::GetStatus() const { // TODO: return smth a bit more human readable here return GetStateString(); }
void CMasternode::Check(bool fForce) { LOCK(cs); if(ShutdownRequested()) return; if(!fForce && (GetTime() - nTimeLastChecked < MASTERNODE_CHECK_SECONDS)) return; nTimeLastChecked = GetTime(); LogPrint("masternode", "CMasternode::Check -- Masternode %s is in %s state\n", vin.prevout.ToStringShort(), GetStateString()); //once spent, stop doing the checks if(IsOutpointSpent()) return; int nHeight = 0; if(!fUnitTest) { TRY_LOCK(cs_main, lockMain); if(!lockMain) return; CCoins coins; if(!pcoinsTip->GetCoins(vin.prevout.hash, coins) || (unsigned int)vin.prevout.n>=coins.vout.size() || coins.vout[vin.prevout.n].IsNull()) { nActiveState = MASTERNODE_OUTPOINT_SPENT; LogPrint("masternode", "CMasternode::Check -- Failed to find Masternode UTXO, masternode=%s\n", vin.prevout.ToStringShort()); return; } nHeight = chainActive.Height(); } if(IsPoSeBanned()) { if(nHeight < nPoSeBanHeight) return; // too early? // Otherwise give it a chance to proceed further to do all the usual checks and to change its state. // Masternode still will be on the edge and can be banned back easily if it keeps ignoring mnverify // or connect attempts. Will require few mnverify messages to strengthen its position in mn list. LogPrintf("CMasternode::Check -- Masternode %s is unbanned and back in list now\n", vin.prevout.ToStringShort()); DecreasePoSeBanScore(); } else if(nPoSeBanScore >= MASTERNODE_POSE_BAN_MAX_SCORE) { nActiveState = MASTERNODE_POSE_BAN; // ban for the whole payment cycle nPoSeBanHeight = nHeight + mnodeman.size(); LogPrintf("CMasternode::Check -- Masternode %s is banned till block %d now\n", vin.prevout.ToStringShort(), nPoSeBanHeight); return; } int nActiveStatePrev = nActiveState; bool fOurMasternode = fMasterNode && activeMasternode.pubKeyMasternode == pubKeyMasternode; // masternode doesn't meet payment protocol requirements ... bool fRequireUpdate = nProtocolVersion < mnpayments.GetMinMasternodePaymentsProto() || // or it's our own node and we just updated it to the new protocol but we are still waiting for activation ... (fOurMasternode && nProtocolVersion < PROTOCOL_VERSION); if(fRequireUpdate) { nActiveState = MASTERNODE_UPDATE_REQUIRED; if(nActiveStatePrev != nActiveState) { LogPrint("masternode", "CMasternode::Check -- Masternode %s is in %s state now\n", vin.prevout.ToStringShort(), GetStateString()); } return; } // keep old masternodes on start, give them a chance to receive updates... bool fWaitForPing = !masternodeSync.IsMasternodeListSynced() && !IsPingedWithin(MASTERNODE_MIN_MNP_SECONDS); if(fWaitForPing && !fOurMasternode) { // ...but if it was already expired before the initial check - return right away if(IsExpired() || IsWatchdogExpired() || IsNewStartRequired()) { LogPrint("masternode", "CMasternode::Check -- Masternode %s is in %s state, waiting for ping\n", vin.prevout.ToStringShort(), GetStateString()); return; } } // don't expire if we are still in "waiting for ping" mode unless it's our own masternode if(!fWaitForPing || fOurMasternode) { if(!IsPingedWithin(MASTERNODE_NEW_START_REQUIRED_SECONDS)) { nActiveState = MASTERNODE_NEW_START_REQUIRED; if(nActiveStatePrev != nActiveState) { LogPrint("masternode", "CMasternode::Check -- Masternode %s is in %s state now\n", vin.prevout.ToStringShort(), GetStateString()); } return; } bool fWatchdogActive = masternodeSync.IsSynced() && mnodeman.IsWatchdogActive(); bool fWatchdogExpired = (fWatchdogActive && ((GetTime() - nTimeLastWatchdogVote) > MASTERNODE_WATCHDOG_MAX_SECONDS)); LogPrint("masternode", "CMasternode::Check -- outpoint=%s, nTimeLastWatchdogVote=%d, GetTime()=%d, fWatchdogExpired=%d\n", vin.prevout.ToStringShort(), nTimeLastWatchdogVote, GetTime(), fWatchdogExpired); if(fWatchdogExpired) { nActiveState = MASTERNODE_WATCHDOG_EXPIRED; if(nActiveStatePrev != nActiveState) { LogPrint("masternode", "CMasternode::Check -- Masternode %s is in %s state now\n", vin.prevout.ToStringShort(), GetStateString()); } return; } if(!IsPingedWithin(MASTERNODE_EXPIRATION_SECONDS)) { nActiveState = MASTERNODE_EXPIRED; if(nActiveStatePrev != nActiveState) { LogPrint("masternode", "CMasternode::Check -- Masternode %s is in %s state now\n", vin.prevout.ToStringShort(), GetStateString()); } return; } } if(lastPing.sigTime - sigTime < MASTERNODE_MIN_MNP_SECONDS) { nActiveState = MASTERNODE_PRE_ENABLED; if(nActiveStatePrev != nActiveState) { LogPrint("masternode", "CMasternode::Check -- Masternode %s is in %s state now\n", vin.prevout.ToStringShort(), GetStateString()); } return; } nActiveState = MASTERNODE_ENABLED; // OK if(nActiveStatePrev != nActiveState) { LogPrint("masternode", "CMasternode::Check -- Masternode %s is in %s state now\n", vin.prevout.ToStringShort(), GetStateString()); } }
bool openavbAvdeccMsgSrvrHndlChangeNotificationFromClient(int avdeccMsgHandle, openavbAvdeccMsgStateType_t currentState) { AVB_TRACE_ENTRY(AVB_TRACE_AVDECC_MSG); avdecc_msg_state_t *pState = AvdeccMsgStateListGet(avdeccMsgHandle); if (!pState) { AVB_LOGF_ERROR("avdeccMsgHandle %d not valid", avdeccMsgHandle); AVB_TRACE_EXIT(AVB_TRACE_AVDECC_MSG); return false; } // Save the updated state. if (currentState != pState->lastReportedState) { openavbAvdeccMsgStateType_t previousState = pState->lastReportedState; pState->lastReportedState = currentState; AVB_LOGF_INFO("Notified of client %d state change from %s to %s (Last requested: %s)", avdeccMsgHandle, GetStateString(previousState), GetStateString(currentState), GetStateString(pState->lastRequestedState)); // If AVDECC did not yet set the client state, set the client state to the desired state. if (pState->lastRequestedState == OPENAVB_AVDECC_MSG_UNKNOWN) { if (pState->stream->initial_state == TL_INIT_STATE_RUNNING && pState->lastReportedState != OPENAVB_AVDECC_MSG_RUNNING) { // Have the client be running if the user explicitly requested it to be running. openavbAvdeccMsgSrvrChangeRequest(avdeccMsgHandle, OPENAVB_AVDECC_MSG_RUNNING); } else if (pState->stream->initial_state != TL_INIT_STATE_RUNNING && pState->lastReportedState == OPENAVB_AVDECC_MSG_RUNNING) { // Have the client not be running if the user didn't explicitly request it to be running. openavbAvdeccMsgSrvrChangeRequest(avdeccMsgHandle, OPENAVB_AVDECC_MSG_STOPPED); } else if (gAvdeccCfg.bFastConnectSupported && !(pState->bTalker) && pState->lastReportedState == OPENAVB_AVDECC_MSG_STOPPED) { // Listener started as not running, and is not configured to start in the running state. // See if we should do a fast connect using the saved state. openavb_tl_data_cfg_t *pCfg = pState->stream; if (pCfg) { U16 flags, talker_unique_id; U8 talker_entity_id[8], controller_entity_id[8]; bool bAvailable = openavbAvdeccGetSaveStateInfo(pCfg, &flags, &talker_unique_id, &talker_entity_id, &controller_entity_id); if (bAvailable) { openavbAcmpSMListenerSet_doFastConnect(pCfg, flags, talker_unique_id, talker_entity_id, controller_entity_id); } } } } else if (currentState == OPENAVB_AVDECC_MSG_STOPPED_UNEXPECTEDLY) { if (previousState != OPENAVB_AVDECC_MSG_STOPPED_UNEXPECTEDLY && pState->lastRequestedState == OPENAVB_AVDECC_MSG_RUNNING && gAvdeccCfg.bFastConnectSupported) { // The Talker disappeared. Use fast connect to assist with reconnecting if it reappears. openavb_tl_data_cfg_t *pCfg = pState->stream; if (pCfg) { U16 flags, talker_unique_id; U8 talker_entity_id[8], controller_entity_id[8]; bool bAvailable = openavbAvdeccGetSaveStateInfo(pCfg, &flags, &talker_unique_id, &talker_entity_id, &controller_entity_id); if (bAvailable) { // Set the timed-out status for the Listener's descriptor. // The next time the Talker advertises itself, openavbAcmpSMListenerSet_talkerTestFastConnect() should try to reconnect. openavb_aem_descriptor_stream_io_t *pDescriptor; U16 listenerUniqueId; for (listenerUniqueId = 0; listenerUniqueId < 0xFFFF; ++listenerUniqueId) { pDescriptor = openavbAemGetDescriptor(openavbAemGetConfigIdx(), OPENAVB_AEM_DESCRIPTOR_STREAM_INPUT, listenerUniqueId); if (pDescriptor && pDescriptor->stream && strcmp(pDescriptor->stream->friendly_name, pCfg->friendly_name) == 0) { // We found a match. AVB_LOGF_INFO("Listener %s waiting to fast connect to flags=0x%04x, talker_unique_id=0x%04x, talker_entity_id=" ENTITYID_FORMAT ", controller_entity_id=" ENTITYID_FORMAT, pCfg->friendly_name, flags, talker_unique_id, ENTITYID_ARGS(talker_entity_id), ENTITYID_ARGS(controller_entity_id)); pDescriptor->fast_connect_status = OPENAVB_FAST_CONNECT_STATUS_TIMED_OUT; memcpy(pDescriptor->fast_connect_talker_entity_id, talker_entity_id, sizeof(pDescriptor->fast_connect_talker_entity_id)); CLOCK_GETTIME(OPENAVB_CLOCK_REALTIME, &pDescriptor->fast_connect_start_time); pDescriptor->fast_connect_start_time.tv_sec += 5; // Give the Talker some time to shutdown or stabilize break; } } } } } // Now that we have handled this, treat this state as a normal stop. pState->lastReportedState = OPENAVB_AVDECC_MSG_STOPPED; } } AVB_TRACE_EXIT(AVB_TRACE_AVDECC_MSG); return true; }
void ShooterControl::PIDShooter() {//Shooting Using Encoder Count and PIDControl bool isRTHeld = xbox->isRightTriggerHeld(); bool isYPressed = xbox->isYPressed(); bool isLTHeld = xbox->isLeftTriggerHeld(); bool isUpperLimit = upperLimit->Get() == 0; bool isLowerLimit = lowerLimit->Get() == 0; bool isRBHeld = xbox->isRBumperHeld(); bool isXPressed = xbox->isXPressed(); bool isBPressed = xbox->isBPressed(); //for ramping double timeChange = (shooterTimer.Get() - previousTime); previousTime = shooterTimer.Get(); int count = shooterEncoder->Get(); if (maxEncoderValue < count) { maxEncoderValue = count; } switch (fireState) { case Init: //Starts The Robot In This State if (isLowerLimit) { pIDControlOutput->PIDWrite(STOPPEDSPEED); shooterEncoder->Reset(); controller->Enable(); controller->SetSetpoint(HOME); fireState = Home; } else { if (canIFire()) { pIDControlOutput->PIDWrite(ARMINGSPEED); } } break; case Home: //Default State For Shooter Arm if (isRBHeld) { fireState = ReadyToFire; //pneumaticsControl->compressorDisable(); } if (isLTHeld) { fireState = Arming; } if (isRTHeld) { fireState = Passing; } break; case Arming: //If LTHeld if (isLowerLimit) { pIDControlOutput->PIDWrite(STOPPEDSPEED); shooterEncoder->Reset(); controller->Enable(); controller->SetSetpoint(ARMING); } else { pIDControlOutput->PIDWrite(ARMINGSPEED); } if (!isLTHeld) { pIDControlOutput->PIDWrite(STOPPEDSPEED); controller->Enable(); controller->SetSetpoint(HOME); fireState = Home; } break; case ReadyToFire: //ready to fire. Lift up until a value is reached if (!isRBHeld) { controller->SetSetpoint(shooterEncoder->Get()); fireState = Retracting; } else if ((count > READYTOFIRE - 6) && (count < READYTOFIRE + 6)) { if (isRTHeld) { if (isXPressed && canIFire()) {//twoStageFire Shoot. Originally used to be RT Held and X twoStageSetupPosition = 5; twoStagePidSetup = -0.08; twoStageEndPosition = 250; twoStagePidFire = 0.95; fireState = StageTwoFire; pIDControlOutput->PIDOverideEnable(twoStagePidFire); maxEncoderValue = 0; } if (isYPressed && canIFire()) {//twoStageFire Shoot. Originally used to be RT Held and X twoStageSetupPosition = 5; twoStagePidSetup = -0.08; twoStageEndPosition = 250; twoStagePidFire = 0.90; fireState = StageTwoFire; pIDControlOutput->PIDOverideEnable(twoStagePidFire); maxEncoderValue = 0; } if (isBPressed && canIFire()) {//twoStageFire Shoot. Jim's Favorite shoot. Shoots the ball insanely high twoStageSetupPosition = 15; twoStagePidSetup = -0.3; twoStageEndPosition = 110; twoStagePidFire = 1.00; fireState = StageOneFire; pIDControlOutput->PIDOverideEnable(twoStagePidSetup); maxEncoderValue = 0; } } else { if (isYPressed && canIFire()) {//Regular Shoot fireState = Firing; pIDControlOutput->PIDOverideEnable(MANUALPIDFIRE); maxEncoderValue = 0; } if (isXPressed && canIFire()) {//twoStageFire Shoot. Originally used to be RT Held and X twoStageSetupPosition = 5; twoStagePidSetup = -0.08; twoStageEndPosition = 250; twoStagePidFire = 1.00; fireState = StageTwoFire; pIDControlOutput->PIDOverideEnable(twoStagePidFire); maxEncoderValue = 0; } /* if (isBPressed && canIFire()) {//twoStageFire Shoot. Originally used to be RT Held and Y twoStagePidFire = 1.00; twoStageEndPosition = 225; fireState = StageTwoFire; pIDControlOutput->PIDOverideEnable(twoStagePidFire); maxEncoderValue = 0; } */ if (isBPressed && canIFire()) { twoStagePidFire = 1.00; twoStageEndPosition = 85; twoStageSetupPosition = 20; fireState = StageOneFire; pIDControlOutput->PIDOverideEnable(-0.1); maxEncoderValue = 0; } } } else { if (pneumaticsControl->ballGrabberIsExtended()) { double positionChange = loadRampProfile(timeChange); double newSetpoint = controller->GetSetpoint() + positionChange; if (newSetpoint >= READYTOFIRE) { newSetpoint = READYTOFIRE; } controller->SetSetpoint(newSetpoint); } } break; case StageOneFire: if (shooterEncoder->Get() <= twoStageSetupPosition) { fireState = StageTwoFire; pIDControlOutput->PIDOverideEnable(twoStagePidFire); maxEncoderValue = 0; } else { double countChange = shootRampProfile(timeChange); double newSetpoint = controller->GetSetpoint() + countChange; if (newSetpoint >= twoStageSetupPosition) { newSetpoint = twoStageSetupPosition; } controller->SetSetpoint(newSetpoint); } break; case StageTwoFire: if (isUpperLimit || shooterEncoder->Get() >= twoStageEndPosition) { controller->SetSetpoint(twoStageEndPosition); pIDControlOutput->PIDOverideDisable(); fireState = Retracting; } else { double countChange = shootRampProfile(timeChange); double newSetpoint = controller->GetSetpoint() + countChange; if (newSetpoint >= twoStageEndPosition) { newSetpoint = twoStageEndPosition; } controller->SetSetpoint(newSetpoint); } break; case TrussSetup: if (shooterEncoder->Get() <= TRUSSSETUP) { fireState = TrussShot; pIDControlOutput->PIDOverideEnable(TRUSSPIDFIRE); maxEncoderValue = 0; } else { double countChange = shootRampProfile(timeChange); double newSetpoint = controller->GetSetpoint() + countChange; if (newSetpoint >= TRUSSSETUP) { newSetpoint = TRUSSSETUP; } controller->SetSetpoint(newSetpoint); } break; case TrussShot://A higher shoot, with lower release point. X must be held. if (isUpperLimit || shooterEncoder->Get() >= TRUSS) { controller->SetSetpoint(TRUSS); pIDControlOutput->PIDOverideDisable(); fireState = Retracting; } else { double countChange = shootRampProfile(timeChange); double newSetpoint = controller->GetSetpoint() + countChange; if (newSetpoint >= TRUSS) { newSetpoint = TRUSS; } controller->SetSetpoint(newSetpoint); } break; case Passing://Starts the ballgrabberMotors in reverse. See BallGrabber Method. if (!isRTHeld) { fireState = Home; } break; case Firing://While RTHeld, shooter moves using pIDController. Stops when upperLimit or encoder count is reached //if (!isRTHeld) { if (false) { if (canIFire()) { fireState = Retracting; controller->SetSetpoint(shooterEncoder->Get()); } else { controller->SetSetpoint(shooterEncoder->Get()); fireState = Fired; } } else { if (isUpperLimit || shooterEncoder->Get() >= FIRE) { controller->SetSetpoint(FIRE); //fireState = Fired; pIDControlOutput->PIDOverideDisable(); fireState = Retracting; } else { //pIDControlOutput->PIDWrite(SHOOTINGSPEED); double countChange = shootRampProfile(timeChange); double newSetpoint = controller->GetSetpoint() + countChange; if (newSetpoint >= FIRE) { newSetpoint = FIRE; } controller->SetSetpoint(newSetpoint); } } break; case Fired://Moves to Retracting if RTHeld is released and ballgrabber is extended if (!isRTHeld && canIFire()) { fireState = Retracting; } break; case Retracting:// Returns to Home. Using downRampProfile. if (this->shooterEncoder->Get() <= HOME + 5) { controller->SetSetpoint(HOME); //pneumaticsControl->compressorEnable(); fireState = Home; } double positionChange = downRampProfile(timeChange); double newSetpoint = controller->GetSetpoint() + positionChange; if (newSetpoint <= HOME) { newSetpoint = HOME; } controller->SetSetpoint(newSetpoint); break; default: break; } dsLCD->PrintfLine(DriverStationLCD::kUser_Line1, "S: %s C: %i E: %i", GetStateString(), count, maxEncoderValue); dsLCD->PrintfLine(DriverStationLCD::kUser_Line3, "E: %i", maxEncoderValue); //dsLCD->PrintfLine(DriverStationLCD::kUser_Line5, "Reed Val: %i", //Code to display REED value. // pneumaticsControl->ReadSwitch()); }
void PowerStateOff::EnterState () { PmSetSystemPowerState_I (GetStateString (), 0, 0, TRUE); }