int main(int argc, const char **argv) { set_debug_flags(NULL, D_ALWAYS); set_mySubSystem( "TEST_LOG_READER_STATE", SUBSYSTEM_TYPE_TOOL ); // initialize to read from config file myDistro->Init( argc, argv ); config(); // Set up the dprintf stuff... dprintf_config("TEST_LOG_READER_STATE"); Options opts; if ( CheckArgs( argc, argv, opts ) < 0 ) { fprintf( stderr, "CheckArgs() failed\n" ); exit( 1 ); } ReadUserLog::FileState state; if ( opts.needStateFile() && ( ReadState( opts, state ) < 0 ) ) { fprintf( stderr, "ReadState() failed\n" ); exit( 1 ); } ReadUserLog::FileState state2; if ( opts.needStateFile2() && ( ReadState( opts, state2 ) < 0 ) ) { fprintf( stderr, "ReadState() failed\n" ); exit( 1 ); } int status = 0; switch( opts.getCommand() ) { case CMD_NONE: status = -1; break; case CMD_LIST: opts.dumpFieldList( ); break; case CMD_DUMP: status = DumpState( opts, state ); break; case CMD_DIFF: status = DiffState( opts, state, state2 ); break; case CMD_ACCESS: status = CheckStateAccess( opts, state ); break; case CMD_VERIFY: status = VerifyState( opts, state ); break; } if ( status == 0 ) { exit( 0 ); } else { exit( 2 ); } }
BOOL CDownloads_Deleted::Create(CWnd *pParent) { CRect rc (0, 0, 0, 0); if (FALSE == CListCtrlEx::Create (LVS_REPORT|LVS_OWNERDRAWFIXED|LVS_SHOWSELALWAYS, rc, pParent, 0x5A9)) return FALSE; SetExtendedStyle (LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP|LVS_EX_INFOTIP); m_images.Create (16, 17, ILC_COLOR24 | ILC_MASK, 7, 1); CBitmap bmp; bmp.Attach (SBMP (IDB_DOWNLOADSTASKS)); m_images.Add (&bmp, RGB (255, 0, 255)); SetImageList (&m_images, LVSIL_SMALL); m_selimages.Create (16, 17, ILC_COLOR24 | ILC_MASK, 7, 1); CBitmap bmp2; bmp2.Attach (SBMP (IDB_DOWNLOADSTASKS_SEL)); m_selimages.Add (&bmp2, RGB (255, 0, 255)); SetSelectedImages (&m_selimages); InsertColumn (0, "", LVCFMT_LEFT, 200, 0); InsertColumn (1, "", LVCFMT_LEFT, 50, 0); InsertColumn (2, "", LVCFMT_LEFT, 100, 0); InsertColumn (3, "", LVCFMT_LEFT, 58, 0); InsertColumn (4, "", LVCFMT_LEFT, 200, 0); ReadState ("DownloadsDeleted"); return TRUE; }
COptionsDlg::COptionsDlg(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage) :CPropertySheet(nIDCaption, pParentWnd, iSelectPage), COptionsInfo(m_DefaultState), #pragma warning(push) #pragma warning(disable : 4355) // 'this' used in base member initializer list m_GeneralDlg(*this), // passing reference to our COptionsInfo base class m_DocumentDlg(*this), m_NavigateDlg(*this), m_EngineDlg(*this), m_PaletteDlg(*this), m_NetworkDlg(*this), m_DisplayDlg(*this), m_MidiDlg(*this) #pragma warning(pop) { ReadState(); m_psh.dwFlags |= PSH_NOAPPLYNOW; AddPage(&m_GeneralDlg); AddPage(&m_DocumentDlg); AddPage(&m_NavigateDlg); AddPage(&m_EngineDlg); AddPage(&m_PaletteDlg); AddPage(&m_NetworkDlg); AddPage(&m_DisplayDlg); AddPage(&m_MidiDlg); m_CurPage = 0; }
dev_test_state HVS_B0307::Test(void) { dev_test_state dt = dev_test_to_intermediate( Base::Test() ); int rc=AF(afClearLAM); if (dt!=DEV_TEST_OK) return dt; if (rc&CAMAC_CC_ERRORS) return dfcamac_rc2test(rc); if( (dt=dfcamac_rc2test(SetVoltage(0)|AF(afOff)))!=DEV_TEST_OK ) return dt; bool on; if( (dt=dfcamac_rc2test(AF(afOn)|ReadState(&on)))!=DEV_TEST_OK ) return dt; if ( !on ) { printf("%s: Test error: Channel 0 unable to turn on \n", Type); return DEV_TEST_BROKEN; } if( (dt=dfcamac_rc2test(AF(afOff)|ReadState(&on)))!=DEV_TEST_OK ) return dt; if ( on ) { printf("%s: Test error: Channel 0 unable to turn off \n", Type); return DEV_TEST_BROKEN; } for(__u8 shift=0; shift<nVoltageBits; shift++) { __u16 w, r; w = 1<<shift; if( (dt=dfcamac_rc2test(AF(afWrite,&w)))!=DEV_TEST_OK ) return dt; if( (dt=dfcamac_rc2test(ReadVoltage(&r)))!=DEV_TEST_OK) return dt; if (w!=r) { printf("%s: Test error: Channel 0 W=%2d R=%2d\n", Type, w, r); return DEV_TEST_BROKEN; } } if( (dt=dfcamac_rc2test(SetVoltage(0)|AF(afOn)))!=DEV_TEST_OK ) return dt; rc = AF(afCheckLAM); if ( rc & (CAMAC_CC_ERRORS & ~CAMAC_CC_NOT_Q) ) return dfcamac_rc2test(rc & ~CAMAC_CC_NOT_Q); if ( !(rc & CAMAC_CC_NOT_Q) ) return DEV_TEST_BROKEN; return DEV_TEST_OK; }
// this function makes the button act as a electronic switch // used for road work mode and emergency mode bool ReadSwitch() { if (ReadState() == HIGH && prevState == 0) prevState = 1; if (prevState == 1 && ReadState() == LOW) prevState = 2; if (prevState == 2 && ReadState() == HIGH) prevState = 3; if (prevState == 3 && ReadState() == LOW) prevState = 0; if(prevState == 1 || prevState == 2) return true; else return false; }
BOOL CScheduler_Log::Create(CWnd *pParent) { if (!CWndLog::Create (pParent)) return FALSE; ReadState ("SchedulerLog"); return TRUE; }
BOOL CHFE_Log::Create(CWnd *pParent) { if (!CWndLog::Create (pParent)) return FALSE; ReadState ("HFELog"); return TRUE; }
int qdplusReadStateFile(QDPLUS *handle) { FILE *fp; int status; UINT16 flag; UINT64 serialno; LNKLST_NODE *crnt; QDPLUS_STATE state; QDPLUS_DIGITIZER *digitizer; status = QDPLUS_STATE_BUG; if ((fp = OpenStateFile(handle, "rb", &status)) == NULL) return status; if (fread(&flag, sizeof(UINT16), 1, fp) != 1) { status = feof(fp) ? QDPLUS_STATE_EMPTY : QDPLUS_STATE_IOERR; fclose(fp); return status; } if (flag != QDPLUS_FLAG_CLEAN) { fclose(fp); return QDPLUS_STATE_DIRTY; } while (fread(&serialno, sizeof(UINT64), 1, fp) == 1) { if ((digitizer = qdplusGetDigitizer(handle, serialno)) == NULL) { fclose(fp); return QDPLUS_STATE_BUG; } if (digitizer->state != NULL) listDestroy(digitizer->state); if ((digitizer->state = listCreate()) == NULL) { fclose(fp); return QDPLUS_STATE_NOMEM; } while ((status = ReadState(fp, &state)) == STATE_READ_OK) { if (!listAppend(digitizer->state, &state, sizeof(QDPLUS_STATE))) { fclose(fp); return QDPLUS_STATE_NOMEM; } } if (status != STATE_READ_FINISHED) { fclose(fp); return QDPLUS_STATE_IOERR; } } status = feof(fp) ? QDPLUS_STATE_OK : QDPLUS_STATE_IOERR; fclose(fp); return status; }
/*---------------------------------------------------------------------*/ BOOL OpenStateForWrite(H_ARCHIVE harchive) { _archive[harchive].last_error = ARC_NO_ERROR; _archive_error = ARC_NO_ERROR; /* Create filespec for state file and open for read */ sprintf(_archive[harchive].filespec, "%s%c%s", _archive[harchive].path, PATH_DELIMITER, STATE_FILENAME); if ((_archive[harchive].file = FileOpenForRead(_archive[harchive].filespec)) == VOID_H_FILE) { ArchiveLog(ARC_LOG_ERRORS, "OpenStateForWrite: Error opening state file: %s", _archive[harchive].filespec); _archive[harchive].last_error = ARC_FILE_IO_ERROR; return (FALSE); } /* Read the current state */ if (!ReadState(harchive)) return (FALSE); if (_archive[harchive].state.write) { ArchiveLog(ARC_LOG_ERRORS, "OpenStateForWrite: Archive is open for write by another process: %s", _archive[harchive].path); _archive[harchive].last_error = ARC_PERMISSION_DENIED; return (FALSE); } if (!FileClose(_archive[harchive].file)) { _archive[harchive].last_error = ARC_FILE_IO_ERROR; return (FALSE); } /* Reopen for write */ if ((_archive[harchive].file = FileOpenForWrite(_archive[harchive].filespec)) == VOID_H_FILE) { ArchiveLog(ARC_LOG_ERRORS, "OpenStateForWrite: Error opening state file: %s", _archive[harchive].filespec); _archive[harchive].last_error = ARC_FILE_IO_ERROR; return (FALSE); } /* Mark as open for write */ _archive[harchive].state.write = TRUE; /* Archive is open for read-write access */ _archive[harchive].access = ARC_WRITE; /* Start the update timer */ Timer48Start(&_archive[harchive].update, 0); if (!WriteState(harchive)) return (FALSE); /* Start the update timer */ Timer48Start(&_archive[harchive].update, UPDATE_INTERVAL); ArchiveLog(ARC_LOG_MAXIMUM, "State file opened for write: %s", _archive[harchive].filespec); return (TRUE); }
/*! * This function loads the active page using the base class persist method. * @sa CResizableState::ReadState * * @param pszName String that identifies stored settings * * @return Returns @a TRUE if successful, @a FALSE otherwise */ BOOL CResizableSheetState::LoadPage(LPCTSTR pszName) { // restore active page, zero (the first) if not found CString data, id; id = CString(pszName) + ACTIVEPAGE_ENT; if (!ReadState(id, data)) return FALSE; int page = _ttoi(data); CPropertySheet* pSheet = DYNAMIC_DOWNCAST(CPropertySheet, GetResizableWnd()); if (pSheet != NULL) return pSheet->SetActivePage(page); return FALSE; }
//--------- This is the initializer ---------------------- DPmixGGM::DPmixGGM (Real *data, myInt L_start, myInt n_obs, myInt p_model, Real edgeInclusionProb, ifstream& initfile) { myInt i; X = data; n = n_obs; p = p_model; L = L_start; xi = new myInt[n]; graphlist = new LPGraph[L]; for(i=0; i<L; i++) { graphlist[i] = new Graph(); graphlist[i]->InitGraph(p); }; pll = new Real[L]; //alpha = 20; alpha = 1; #ifdef RANDOMSTART RandomStartAllXi(L); RandomStartAllG(L, edgeInclusionProb); #else ReadState(initfile); #endif plp = partitionlogPrior(L, xi, alpha); for(i=0; i<L; i++) { pll[i] = cluster_k_loglikelihood (i, xi, graphlist[i]); } }
/*! * This function loads and set the current window position and size using * the base class persist method. Minimized and maximized state is also * optionally preserved. * @sa CResizableState::WriteState * @note Window coordinates are in the form used by the system functions * GetWindowPlacement and SetWindowPlacement. * * @param pszName String that identifies stored settings * @param bRectOnly Flag that specifies wether to ignore min/max state * * @return Returns @a TRUE if successful, @a FALSE otherwise */ BOOL CResizableWndState::LoadWindowRect(LPCTSTR pszName, BOOL bRectOnly) { CString data, id; WINDOWPLACEMENT wp; id = CString(pszName) + PLACEMENT_ENT; if (!ReadState(id, data)) // never saved before return FALSE; SecureZeroMemory(&wp, sizeof(WINDOWPLACEMENT)); wp.length = sizeof(WINDOWPLACEMENT); if (!GetResizableWnd()->GetWindowPlacement(&wp)) return FALSE; // use workspace coordinates RECT& rc = wp.rcNormalPosition; long min_width = rc.right - rc.left; long min_height = rc.bottom - rc.top; if (_stscanf(data, PLACEMENT_FMT, &rc.left, &rc.top, &rc.right, &rc.bottom, &wp.showCmd, &wp.flags, &wp.ptMinPosition.x, &wp.ptMinPosition.y) == 8) { if (rc.bottom - rc.top < min_height) rc.bottom = rc.top + min_height; if (rc.right - rc.left < min_width) rc.right = rc.left + min_width; if (bRectOnly) // restore size/pos only { wp.showCmd = SW_SHOWNORMAL; wp.flags = 0; } else // restore also max state { if (wp.showCmd == SW_SHOWMINIMIZED) wp.showCmd = SW_SHOWNORMAL; } return GetResizableWnd()->SetWindowPlacement(&wp); } return FALSE; }
BOOL CTorrents_Tasks::Create(CWnd *pwndParent) { CRect rc (0, 0, 50, 50); if (FALSE == CListCtrlEx::Create (HDS_DRAGDROP | LVS_REPORT | LVS_OWNERDRAWFIXED | LVS_SHOWSELALWAYS | LVS_OWNERDATA | LVS_NOSORTHEADER, rc, pwndParent, 0x56783)) return FALSE; SetExtendedStyle (LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP| LVS_EX_INFOTIP|0x00004000); m_images.Create (16, 17, ILC_COLOR24 | ILC_MASK, 7, 1); CBitmap bmp; bmp.Attach (SBMP (IDB_DOWNLOADSTASKS)); m_images.Add (&bmp, RGB (255, 0, 255)); SetImageList (&m_images, LVSIL_SMALL); m_selimages.Create (16, 17, ILC_COLOR24 | ILC_MASK, 7, 1); CBitmap bmp2; bmp2.Attach (SBMP (IDB_DOWNLOADSTASKS_SEL)); m_selimages.Add (&bmp2, RGB (255, 0, 255)); SetSelectedImages (&m_selimages); InsertColumn (0, "", LVCFMT_LEFT, 200, 0); InsertColumn (1, "", LVCFMT_LEFT, 50, 0); InsertColumn (2, "", LVCFMT_LEFT, 100, 0); InsertColumn (3, "", LVCFMT_LEFT, 60, 0); InsertColumn (4, "", LVCFMT_LEFT, 50, 0); InsertColumn (5, "", LVCFMT_LEFT, 58, 0); InsertColumn (6, "", LVCFMT_LEFT, 70, 0); InsertColumn (7, "", LVCFMT_LEFT, 200, 0); InsertColumn (8, "", LVCFMT_LEFT, 120, 0); ReadState ("TorrentsTasks"); ShowWindow (SW_SHOW); return TRUE; }
/*---------------------------------------------------------------------*/ BOOL ArchiveSync(H_ARCHIVE harchive) { FILE_STAT stat; if (!ValidateHandle(harchive)) return (FALSE); _archive[harchive].last_error = ARC_NO_ERROR; _archive_error = ARC_NO_ERROR; /* If we're open for write and the update timer has expired... */ if (_archive[harchive].access == ARC_WRITE) { if (_archive[harchive].dirty) { if (!Timer48Expired(&_archive[harchive].update)) return (TRUE); ArchiveLog(ARC_LOG_MAXIMUM, "Synchronize state file for write"); if (!WriteState(harchive)) return (FALSE); _archive[harchive].dirty = FALSE; } /* Restart the update timer */ Timer48Restart(&_archive[harchive].update); } /* If we're open for read... */ else if (_archive[harchive].access == ARC_READ) { /* If the state file has changed since we last looked... */ if (!GetFileStat(_archive[harchive].filespec, &stat)) return (FALSE); if (memcmp(&_archive[harchive].stat, &stat, sizeof(FILE_STAT)) != 0) { ArchiveLog(ARC_LOG_VERBOSE, "State file has changed, synchronizing"); if (!ReadState(harchive)) return (FALSE); } } else return (FALSE); return (TRUE); }
/*! * This function loads and set the current window position and size using * the base class persist method. Minimized and maximized state is also * optionally preserved. * @sa CResizableState::WriteState * @note Window coordinates are in the form used by the system functions * GetWindowPlacement and SetWindowPlacement. * * @param pszName String that identifies stored settings * @param bRectOnly Flag that specifies wether to ignore min/max state * * @return Returns @a TRUE if successful, @a FALSE otherwise */ BOOL CResizableWndState::LoadWindowRect(LPCTSTR pszName, BOOL bRectOnly) { CString data, id; WINDOWPLACEMENT wp; id = CString(pszName) + PLACEMENT_ENT; if (!ReadState(id, data)) // never saved before return FALSE; SecureZeroMemory(&wp, sizeof(WINDOWPLACEMENT)); wp.length = sizeof(WINDOWPLACEMENT); if (!GetResizableWnd()->GetWindowPlacement(&wp)) return FALSE; // use workspace coordinates RECT& rc = wp.rcNormalPosition; if (_stscanf(data, PLACEMENT_FMT, &rc.left, &rc.top, &rc.right, &rc.bottom, &wp.showCmd, &wp.flags, &wp.ptMinPosition.x, &wp.ptMinPosition.y) == 8) { if (bRectOnly) // restore size/pos only { wp.showCmd = SW_SHOWNORMAL; wp.flags = 0; return GetResizableWnd()->SetWindowPlacement(&wp); } else // restore minimized window to normal or maximized state { if (wp.showCmd == SW_SHOWMINIMIZED && wp.flags == 0) wp.showCmd = SW_SHOWNORMAL; else if (wp.showCmd == SW_SHOWMINIMIZED && wp.flags == WPF_RESTORETOMAXIMIZED) wp.showCmd = SW_SHOWMAXIMIZED; return GetResizableWnd()->SetWindowPlacement(&wp); } } return FALSE; }
BOOL CDownloads_History::Create(CWnd *pParent) { CRect rc (0, 0, 0, 0); m_mgr = &_DldsMgr.m_histmgr; if (FALSE == CListCtrlEx::Create (LVS_REPORT|LVS_OWNERDRAWFIXED|LVS_SHOWSELALWAYS, rc, pParent, 0x5d9)) return FALSE; SetExtendedStyle (LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP|LVS_EX_INFOTIP); m_images.Create (16, 17, ILC_COLOR24 | ILC_MASK, 7, 1); CBitmap bmp; bmp.Attach (SBMP (IDB_DOWNLOADSTASKS)); m_images.Add (&bmp, RGB (255, 0, 255)); SetImageList (&m_images, LVSIL_SMALL); m_selimages.Create (16, 17, ILC_COLOR24 | ILC_MASK, 7, 1); CBitmap bmp2; bmp2.Attach (SBMP (IDB_DOWNLOADSTASKS_SEL)); m_selimages.Add (&bmp2, RGB (255, 0, 255)); SetSelectedImages (&m_selimages); InsertColumn (0, "file", LVCFMT_LEFT, 100, 0); InsertColumn (1, "url", LVCFMT_LEFT, 100, 0); InsertColumn (2, "added", LVCFMT_LEFT, 80, 0); InsertColumn (3, "dlded", LVCFMT_LEFT, 80, 0); InsertColumn (4, "size", LVCFMT_LEFT, 80, 0); InsertColumn (5, "savedto", LVCFMT_LEFT, 100, 0); InsertColumn (6, "comment", LVCFMT_LEFT, 90, 0); ReadState ("DownloadsHistory"); return TRUE; }
BOOL CSitesWnd::Create(CWnd *pWndParent) { CRect rc (0, 0, 50, 50); if (FALSE == CListCtrlEx::Create (LVS_REPORT|LVS_OWNERDRAWFIXED|LVS_NOSORTHEADER|LVS_SHOWSELALWAYS, rc, pWndParent, 0x53459)) return FALSE; SetExtendedStyle (LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP|LVS_EX_INFOTIP); m_images.Create (16, 17, ILC_COLOR24 | ILC_MASK, 4, 1); CBitmap bmp; bmp.Attach (SBMP (IDB_SITELIST)); m_images.Add (&bmp, RGB (255, 0, 255)); SetImageList (&m_images, LVSIL_SMALL); m_selImages.Create (16, 17, ILC_COLOR24 | ILC_MASK, 4, 1); CBitmap bmp1; bmp1.Attach (SBMP (IDB_SITELIST_SEL)); m_selImages.Add (&bmp1, RGB (255, 0, 255)); SetSelectedImages (&m_selImages); InsertColumn (0, LS (L_SITENAME), LVCFMT_LEFT, 200, 0); InsertColumn (1, LS (L_CONNS), LVCFMT_LEFT, 80, 0); InsertColumn (2, LS (L_LOGIN), LVCFMT_LEFT, 100, 0); InsertColumn (3, LS (L_GROUP2), LVCFMT_LEFT, 100, 0); ReadState ("SitesList"); ShowWindow (SW_SHOW); LoadSites (); return TRUE; }
/*---------------------------------------------------------------------*/ BOOL OpenStateForRead(H_ARCHIVE harchive) { _archive[harchive].last_error = ARC_NO_ERROR; _archive_error = ARC_NO_ERROR; /* Build the state filespec and open */ sprintf(_archive[harchive].filespec, "%s%c%s", _archive[harchive].path, PATH_DELIMITER, STATE_FILENAME); if ((_archive[harchive].file = FileOpenForRead(_archive[harchive].filespec)) == VOID_H_FILE) { ArchiveLog(ARC_LOG_ERRORS, "OpenStateForRead: Error opening state file: %s", _archive[harchive].filespec); _archive[harchive].last_error = ARC_FILE_IO_ERROR; return (FALSE); } /* Read the current state */ if (!ReadState(harchive)) { ArchiveLog(ARC_LOG_ERRORS, "OpenStateForRead: Error trying to retrieve state: %s", _archive[harchive].filespec); FileClose(_archive[harchive].file); return (FALSE); } /* File is open for read access */ _archive[harchive].access = ARC_READ; /* Save file status so we can detect changes to the file */ if (!GetFileStat(_archive[harchive].filespec, &_archive[harchive].stat)) { ArchiveLog(ARC_LOG_ERRORS, "OpenStateForRead: Error retrieving file state: %s", _archive[harchive].filespec); FileClose(_archive[harchive].file); return (FALSE); } ArchiveLog(ARC_LOG_MAXIMUM, "State file opened for read: %s", _archive[harchive].filespec); return (TRUE); }
void DPmixGGM::InformedStart (ifstream& initfile) { ReadState(initfile); plp = partitionlogPrior(L, xi, alpha); for(myInt i=0; i<L; i++) { pll[i] = cluster_k_loglikelihood (i, xi, graphlist[i]); } }
bool WorldSimulation::ReadState(const string& s) { File f; if(!f.OpenData((void*)s.c_str(),s.length(),FILEREAD)) return false; return ReadState(f); }
void MULTIPLAY::ReceiveState() { //check to see if it's time for a state packet int i; float remain; int mult; mult = (int) ((timeindex[1]+FrameTime()/2.0) / STATE_FREQUENCY); remain = (timeindex[1] + FrameTime()/2.0) - (float)(mult * STATE_FREQUENCY); //cout << timeindex[1] << "," << mult << "," << remain << endl; bool found = false; if (remain < FrameTime()) { //cout << "get state" << endl; //search packets for correct time int count = 0; for (i = 0; i < net.GetMaxBuffers(); i++) { if (net.GetBuffer(i)->Valid()) { //ProcessPacket(net.GetBuffer(i)); Uint8 ptype; GetFromData(net.GetBuffer(i)->data, &ptype, sizeof(Uint8), 0); double ptime; GetFromData(net.GetBuffer(i)->data, &ptime, sizeof(double), 1); if (ptype == replay.Get_FuncStateInfo()) { //clean out old state packets if (ptime < timeindex[1] - STATE_FREQUENCY) { net.GetBuffer(i)->Clear(); if (NET_DEBUG) cout << "net: Update: cleaned out old state packet with time " << ptime << endl; } if (ptime > timeindex[1] - FrameTime()/2.0 && ptime < timeindex[1] + FrameTime()/2.0) { //exected time net.GetBuffer(i)->Clear(); if (NET_DEBUG) cout << "net: Update: received state with time " << ptime << endl; loadstates[1].time = ptime; //loadstatevalid[1] = true; ReadState(net.GetBuffer(i)->data, 1); loadstatenow[1] = true; //update funcmem from state for (i = 0; i < fnums[1]; i++) { GetFuncMem(1)[i].oldval = loadstates[1].funcmem[i].oldval; GetFuncMem(1)[i].newval = loadstates[1].funcmem[i].newval; GetFuncMem(1)[i].held = loadstates[1].funcmem[i].held; GetFuncMem(1)[i].active = loadstates[1].funcmem[i].active; GetFuncMem(1)[i].lastupdateat = loadstates[1].funcmem[i].lastupdateat; } if (MP_RECORD && MP_REMOTE_RECORD) { dbgstate[dbgnumstates].CopyFrom(loadstates[1]); dbgnumstates++; } found = true; } else { //cout << "packet " << i << ": " << ptime << "," << timeindex[1] << endl; //increment timeout counter count++; } } //else cout << "i: " << i << ", p: " << ptype << ", t: " << ptime << endl; } } /*//if the state packet is late and we have new packets waiting for us, // give up waiting for the old one if (!found && count >= STATE_TIMEOUT_COUNT) { if (NET_DEBUG) { cout << "net: Update: timeout waiting for state at time " << timeindex[1] << endl; } timeindex[1] += STATE_FREQUENCY; } else if (!found) { if (NET_DEBUG) { cout << "waiting for timeout: " << count << " states in buffer" << endl; } }*/ //if we have new packets waiting for us, // give up waiting for the old one // (moved back into the if (remain < frametime) part because packets can now be timed out) int scount = 0; double highesttime = 0; for (i = 0; i < net.GetMaxBuffers(); i++) { if (net.GetBuffer(i)->Valid()) { //ProcessPacket(net.GetBuffer(i)); Uint8 ptype; GetFromData(net.GetBuffer(i)->data, &ptype, sizeof(Uint8), 0); double ptime; GetFromData(net.GetBuffer(i)->data, &ptime, sizeof(double), 1); if (ptype == replay.Get_FuncStateInfo()) { scount++; if (ptime > highesttime) highesttime = ptime; } } } if (!found && scount >= STATE_TIMEOUT_COUNT) { double newt; newt = (double)((mult+1) * STATE_FREQUENCY); //newt = highesttime; if (NET_DEBUG) { cout << "net: Update: timeout waiting for state at time " << timeindex[1] << " skipping to " << newt << endl; } //timeindex[1] += STATE_FREQUENCY; timeindex[1] = newt; } } }
bool IsPressed() { return ReadState() == HIGH; }
/* ** A "local" function of main(). Handles a #messageType# message arrived on ** #sd# accompanied by #dataSize# bytes of data. */ static void ProcessRequest(Socket *sd, MessageType messageType, size_t dataSize) { char *contents; DataDescriptor contentsDescriptor = SIMPLE_DATA(CHAR_TYPE, 0); AutoFetchInfo *expandedAutoFetches; unsigned long expiration; DataDescriptor expirationDescriptor = SIMPLE_DATA(UNSIGNED_LONG_TYPE, 1); int i; struct state stateDesc; char *stateNames; DataDescriptor stateNamesDescriptor = SIMPLE_DATA(CHAR_TYPE, 0); switch(messageType) { case FETCH_STATE: if(!RecvData(*sd, &stateDesc, stateDescriptor, stateDescriptorLength, PktTimeOut(*sd))) { DROP_SOCKET(sd); ERROR("ProcessRequest: state receive failed\n"); return; } contents = (char *)malloc(stateDesc.rec_count * MAX_RECORD_SIZE); if(contents == NULL) { (void)SendMessage(*sd, MEMORY_FAILED, PktTimeOut(*sd)); ERROR("ProcessRequest: out of memory\n"); } else { if(ReadState(FileOfState(memoryDir, stateDesc.id), contents, stateDesc.rec_count, stateDesc.rec_count * MAX_RECORD_SIZE, stateDesc.seq_no, &stateDesc.time_out, &stateDesc.seq_no, &stateDesc.rec_count, &stateDesc.rec_size)) { if(stateDesc.rec_count > 0) { contentsDescriptor.repetitions = stateDesc.rec_size * stateDesc.rec_count; (void)SendMessageAndDatas(*sd, STATE_FETCHED, &stateDesc, stateDescriptor, stateDescriptorLength, contents, &contentsDescriptor, 1, PktTimeOut(*sd)); } else { (void)SendMessageAndData(*sd, STATE_FETCHED, &stateDesc, stateDescriptor, stateDescriptorLength, PktTimeOut(*sd)); } } else { (void)SendMessage(*sd, MEMORY_FAILED, PktTimeOut(*sd)); if(errno == EMFILE) { CheckConnections(); } } free(contents); } break; case STORE_STATE: if(!RecvData(*sd, &stateDesc, stateDescriptor, stateDescriptorLength, PktTimeOut(*sd))) { DROP_SOCKET(sd); ERROR("ProcessRequest: state receive failed\n"); return; } contentsDescriptor.repetitions = stateDesc.rec_size * stateDesc.rec_count; contents = (char *)malloc(contentsDescriptor.repetitions + 1); if(contents == NULL) { (void)SendMessage(*sd, MEMORY_FAILED, PktTimeOut(*sd)); ERROR("ProcessRequest: out of memory\n"); } else { contents[contentsDescriptor.repetitions] = '\0'; if(!RecvData(*sd, contents, &contentsDescriptor, 1, PktTimeOut(*sd))) { DROP_SOCKET(sd); ERROR("ProcessRequest: data receive failed\n"); } else { (void)SendMessage(*sd, KeepState(&memLogLocation, &stateDesc, contents, contentsDescriptor.repetitions) ? STATE_STORED : MEMORY_FAILED, PktTimeOut(*sd)); for(i = 0; i < autoFetchCount; i++) { if(strstr(autoFetches[i].stateNames, stateDesc.id) != NULL) { if(!SendMessageAndDatas(autoFetches[i].clientSock, STATE_FETCHED, &stateDesc, stateDescriptor, stateDescriptorLength, contents, &contentsDescriptor, 1, PktTimeOut(autoFetches[i].clientSock))) { DROP_SOCKET(&autoFetches[i].clientSock); free(autoFetches[i].stateNames); autoFetches[i] = autoFetches[--autoFetchCount]; } } } } free(contents); } break; case AUTOFETCH_BEGIN: stateNamesDescriptor.repetitions = dataSize; stateNames = (char *)malloc(dataSize); if(stateNames == NULL) { (void)SendMessage(*sd, MEMORY_FAILED, PktTimeOut(*sd)); DROP_SOCKET(sd); ERROR("ProcessRequest: out of memory\n"); } else if(!RecvData(*sd, stateNames, &stateNamesDescriptor, 1, PktTimeOut(*sd))) { (void)SendMessage(*sd, MEMORY_FAILED, PktTimeOut(*sd)); DROP_SOCKET(sd); free(stateNames); ERROR("ProcessRequest: data receive failed\n"); } else if(*stateNames == '\0') { free(stateNames); EndAutoFetch(*sd); (void)SendMessage(*sd, AUTOFETCH_ACK, PktTimeOut(*sd)); } else { for(i=0; (i < autoFetchCount) && (autoFetches[i].clientSock != *sd); i++) ; /* Nothing more to do. */ if(i == autoFetchCount) { expandedAutoFetches = REALLOC(autoFetches, (autoFetchCount + 1) * sizeof(AutoFetchInfo)); if(expandedAutoFetches == NULL) { (void)SendMessage(*sd, MEMORY_FAILED, PktTimeOut(*sd)); DROP_SOCKET(sd); ERROR("ProcessRequest: out of memory\n"); break; } autoFetches = expandedAutoFetches; autoFetches[i].clientSock = *sd; autoFetchCount++; } else { free(autoFetches[i].stateNames); } autoFetches[i].stateNames = stateNames; (void)SendMessage(*sd, AUTOFETCH_ACK, PktTimeOut(*sd)); } break; case MEMORY_CLEAN: if(!RecvData(*sd, &expiration, &expirationDescriptor, 1, PktTimeOut(*sd))) { DROP_SOCKET(sd); ERROR("ProcessRequest: data receive failed\n"); } else { (void)SendMessage(*sd, MEMORY_CLEANED, PktTimeOut(*sd)); (void)DoClean(expiration); } break; #ifdef WITH_NETLOGGER case MEMORY_LOGDEST: /* config message contains log location */ if(!RecvData(*sd, &memLogLocation, loglocationDescriptor, loglocationDescriptorLength, PktTimeOut(*sd))) { DROP_SOCKET(sd); ERROR("ProcessRequest: loglocation receive failed\n"); return; }else { (void)SendMessage(*sd, MEMORY_LOGDEST_ACK, PktTimeOut(*sd)); } LOG2("ProcessRequest: loglocation %d .%s.\n", memLogLocation.loc_type, memLogLocation.path); break; #endif /* WITH_NETLOGGER */ default: DROP_SOCKET(sd); ERROR1("ProcessRequest: unknown message %d\n", messageType); } }
int InitCal() { string data; if (!OPEN_COM) { serial_close(hComm); if ((hComm=serial_open(0, 1, 1)) < 0) { cout<<"Error: cannot connect to Puma"<<endl; return -1; } else OPEN_COM = TRUE; } int MachineState = 0; while(1) { switch (MachineState) { case 0: writeBuffer("cal\n\r"); usleep(100000); switch (ReadState()) { case 0: MachineState = 1; break; case 2: case 3: MachineState = 4; break; case 4: MachineState = 6; break; case -1: printf("Unresolvable statues...\nPlease turn off the controller and reinitilize the program../n"); return -1; break; } break; case 1: switch (ReadState()) { case 0: printf("Turn on the controller....\n"); usleep(3000000); break; case -1: printf("Unresolvable statues...\nPlease turn off the controller and reinitilize the program../n"); return -1; break; default: printf("Initializing....\n"); MachineState = 7; break; } break; case 2: writeBuffer("y\n\r"); switch(ReadState()) { case 2: MachineState = 3; break; } break; case 3: writeBuffer("y\n\r"); usleep(500000); switch(ReadState()) { case 1: case 4: printf("\nInitilization Completed....\n"); MachineState = 0; break; } break; case 4: writeBuffer("y\n\r"); usleep(500000); switch(ReadState()) { case 1: MachineState = 6; break; case 2: MachineState = 3; break; case 4: MachineState = 5; break; } break; case 5: printf("Turn on the arm power....\n"); usleep(500000); MachineState = 0; break; case 6: writeBuffer("do ready\n\r"); switch(ReadState()){ case 1: return 0; case 2: MachineState = 4; break; case 4: MachineState = 5; break; case -1: printf("Unresolvable statues...\nPlease turn off the controller and reinitilize the program../n"); return -1; break; } break; case 7: printf("."); usleep(100000); switch(ReadState()) { case 2: MachineState = 2; break; case -1: printf("Unresolvable statues...\nPlease turn off the controller and reinitilize the program../n"); return -1; break; } break; } } return 0; }