Example #1
0
bool Printer::Idle( void ) {
    string str;
    bool is_connected;

    while ( ( str = ReadResponse() ) != "" )
        ParseResponse( str );

    if ( m_view ) {
        while ( ( str = ReadLog() ) != "" )
            m_view->comm_log( str );

        while ( ( str = ReadErrorLog() ) != "" ) {
            alert( str.c_str() );
        }
    }

    if ( ( is_connected = IsConnected() ) != was_connected ) {
        was_connected = is_connected;
        signal_serial_state_changed.emit( is_connected ? SERIAL_CONNECTED : SERIAL_DISCONNECTED );
    }

    if ( waiting_temp && --temp_countdown == 0 &&
            m_model && m_model->settings.get_boolean("Misc","TempReadingEnabled") ) {
        UpdateTemperatureMonitor();
        temp_countdown = 100;
        waiting_temp = false;
    }

    return true;
}
Example #2
0
int main(int argc, char **argv)
{
  Initialize(argc, argv);

  ReadLog();

  Terminate();

  return(1);
}
Example #3
0
bool UploadCurrentLog(LogUploadResult &result)
{
    String data;
    ReadLog(data);
    if (data.IsEmpty()) {
        result.errors << Str("LogUpload.EmptyLog");
        return false;
    }

    AppendGameCaptureLog(data);

    String filename = CurrentLogFilename();

    return UploadLogGitHub(GetPathFileName(filename.FindReplace(L"\\", L"/").Array(), true), data, result);
}
Example #4
0
	/** 
	open, write, close the file rather than hold it forever so it can handle having
	the file deleted from underneath it without failing. 
	*/
	void LogToFile :: PushItemsToFile()
	{
		try {				
			std::ofstream file(mFileName.c_str(), std::ios::app | std::ios::out);
			if(!file.is_open()) std::cerr << "Failure to open: " << mFileName << std::endl;
			
			LogEntry le;
			while(ReadLog(le)) file << le.LogString() << std::endl;
			
			file << std::flush;
			if(file.bad()) std::cerr << "Failure during writing log file: " << file.rdstate() << std::endl;				
			file.close();					
		}
		catch(std::exception e){
			std::cerr << "Error during LogToFile: " << e.what() << std::endl;
		}
	}
Example #5
0
/**
open, write, close the file rather than hold it forever so it can handle having
the file deleted from underneath it without failing.
*/
void LogToFile :: PushItemsToFile()
{
	try {
		// we need to open file in append mode first time only
		std::ofstream file(mFileName.c_str(), mOverwriteFile ? (std::ios::out) : (std::ios::app | std::ios::out));
		if(!file.is_open()) std::cerr << "Failure to open: " << mFileName << std::endl;

		mOverwriteFile = false;

		LogEntry le;
		while(ReadLog(le)) file << le.LogString() << std::endl;

		file << std::flush;
		if(file.bad()) std::cerr << "Failure during writing log file: " << file.rdstate() << std::endl;
		file.close();
	}
	catch(std::exception e) {
		std::cerr << "Error during LogToFile: " << e.what() << std::endl;
	}
}
Example #6
0
/**
 * @brief	file manager initialization
 * @param	ShareMem [O ]Pointer to share memory where system information will
 be stored.
 * @return	error code : SUCCESS(0) or FAIL(-1)
 */
int FileMngInit(void *ShareMem)
{
	int ret;
	DBG("Global value size:%d\n", SYS_ENV_SIZE);
	ret = ReadGlobal(ShareMem);
	if(ret == FAIL){
		ret = create_sys_file(SYS_FILE, &SysInfoDefault);
		if(ret == SUCCESS)
			memcpy(ShareMem, &SysInfoDefault, SYS_ENV_SIZE);
		else
			ERROR("Initialize fail (FileMgnInit)\n");
	}
	if(ret == SUCCESS){
		ret = ReadLog();
		if(ret == FAIL)
			ret = create_log_file(LOG_FILE, NULL);
#ifdef __FILE_DEBUG
		else
			ShowAllLog();
#endif
	}
	return ret;
}
Example #7
0
int main(int argc, char **argv) {
	size_t bytes; /* Set by the ReadLog subroutine */
	char* data = 0; /* Allocated and set by the ReadLog subroutine */
	char* outputfilename;
	const char* optstring = "hv";
	int blockno = 0;
	FILE* outputfile;

	while (getopt(argc, argv, optstring) >0) {
	}

	outputfilename = (char *) malloc(2048);
	data = (char *) malloc(INITIAL_BUFFER_SIZE);

	while (ReadLog(stdin, &bytes, data)) {
		printf("Block[%.4d]: %x %x\n", blockno, data[0], data[1]);
		/* Write out the buffer */
		sprintf(outputfilename,"%s_%.4d.raw", argv[1], blockno);
		outputfile = fopen(outputfilename,"w");
		fwrite(data,1,bytes,outputfile);
		blockno++;
	}
	return 0;
}
Example #8
0
int main()
{
	// 启动时即创建看门狗线程,一直喂狗,直到主线程通知退出
	pthread_t pthreadDog;
	pthread_create(&pthreadDog, NULL, G_ThreadClearDog, NULL);
	
	g_objDog.DogInit(); // 确保第一次判断看门狗清除标志能成功
	
	int i, j;
	int	iCnt = 0;		// 连续多少次未清狗的次数
	DWORD	dwFlag = 0;
	
	char *szAppInPart2[APP_IN_PART2] = {"/SockServExe", "/IOExe", "/UpdateExe", "/ComuExe", "/QianExe"};
	char *szAppInPart5[APP_IN_PART5] = {"/mnt/Flash/part5/DvrExe", "/mnt/Flash/part5/SockServExe", "/mnt/Flash/part5/IOExe", "/mnt/Flash/part5/UpdateExe", "/mnt/Flash/part5/QianExe", "/mnt/Flash/part5/ComuExe"};
	
	pid_t RunPid[6] = {0};
	int EndStatus = 0;
	int EndSucc = 0;

	char szPart, szError, szUpdate;
	int iAppInPartx;
	char **pszAppInPartx;
	
	CreateLog();
	
	// 如果ErrLog损坏,则默认运行分区2程序
	if(ReadLog(szPart, szError, szUpdate) == -1)
	{
		PRTMSG(MSG_DBG, "ErrLog damage, use default part2\n");
		
		szPart = '2'; szError = '0'; szUpdate = '0';
	}
	
	// 如果ErrLog误码,则默认运行分区5程序
	if((szPart != '2' && szPart != '5') || (szError < '0' || szError > '5') || (szUpdate < '0' || szUpdate > '5'))
	{
		PRTMSG(MSG_DBG, "ErrLog error, use default part5\n");
		
		szPart = '5';	szError = '0'; szUpdate = '0';
		if(WriteLog(szPart, szError, szUpdate) == -1)
		{
			PRTMSG(MSG_DBG, "write errlog fail\n");
			DeleteLog();
			goto EXIT;
		}
	}

ENTRY:
	PRTMSG(MSG_DBG, "Part:%c Error:%c Update:%c\n", szPart, szError, szUpdate);

	// 如果程序齐全且运行出错次数未达最大次数
	if(AllAppExist(szPart) == true && szError <= '8')
	{
		if(szPart == '2')
		{
			PRTMSG(MSG_DBG, "begin to run in part2\n");
			
			DOG_RSTVAL = 0XFFFFFFFF & ~DOG_QIAN & ~DOG_COMU & ~DOG_SOCK & ~DOG_IO & ~DOG_UPGD;// & ~DOG_DVR_T1 & ~DOG_DVR_T2 & ~DOG_DVR_T3;
			iAppInPartx = APP_IN_PART2;
			pszAppInPartx = szAppInPart2;
		}
		else if(szPart == '5')
		{
			PRTMSG(MSG_DBG, "begin to run in part5\n");
			
			DOG_RSTVAL = 0XFFFFFFFF & ~DOG_QIAN & ~DOG_COMU & ~DOG_SOCK & ~DOG_IO & ~DOG_UPGD & ~DOG_DVR & ~DOG_DVR_T1 & ~DOG_DVR_T2 & ~DOG_DVR_T3;
			iAppInPartx = APP_IN_PART5;
			pszAppInPartx = szAppInPart5;
		}
	}
	else
	{
		// 如果升级成功次数大于5次,则切换到分区2运行
		if(szUpdate == '5')
		{
			PRTMSG(MSG_DBG, "update too many times, switch to part2\n");
			
			szPart = '2';	szError = '0'; szUpdate = '0';
			if(WriteLog(szPart, szError, szUpdate) == -1)
			{
				PRTMSG(MSG_DBG, "write errlog fail\n");
				DeleteLog();
				goto EXIT;
			}
	
			goto ENTRY;
		}
		// 否则进行升级操作
		else
		{
			PRTMSG(MSG_DBG, "begin to update from part3\n");
						
			for(i = 0; i < 3; i++)
			{
				if(AllAppExist('3') == true)
				{
					if(G_ExeUpdate("/mnt/Flash/part3/Down/exe.bin", 0))
					{
						PRTMSG(MSG_DBG, "update succ, switch to part5\n");
						
						// 如果升级成功,切换到分区5,出错次数清零,升级次数递增
						szPart = '5';	szError = '0'; szUpdate++;
						if(WriteLog(szPart, szError, szUpdate) == -1)
						{
							PRTMSG(MSG_DBG, "write errlog fail\n");
							DeleteLog();
							goto EXIT;
						}
	
						goto ENTRY;
					}
				}
							
				sleep(1);
			}
			
			PRTMSG(MSG_DBG, "update fail, switch to part2\n");
			
			// 如果升级失败,切换到分区2,出错次数清零,升级次数清零
			szPart = '2';	szError = '0'; szUpdate = '0';
			if(WriteLog(szPart, szError, szUpdate) == -1)
			{
				PRTMSG(MSG_DBG, "write errlog fail\n");
				DeleteLog();
				goto EXIT;
			}
	
			goto ENTRY;
		}
	}

	// 创建进程, 加载程序
	for(i = 0; i < iAppInPartx; i++)
	{
		chmod(pszAppInPartx[i], S_IRWXU|S_IRWXG|S_IRWXO);

		if((RunPid[i] = fork()) == -1)
		{
			PRTMSG(MSG_DBG, "fork process %s fail, exit\n", pszAppInPartx[i]);
			
			// 如果创建子进程失败,递增出错次数
			szError++;
			if(WriteLog(szPart, szError, szUpdate) == -1)
			{
				DeleteLog();
			}
			goto EXIT;
		}
		else if(RunPid[i] == 0)
		{
			if(-1 == execl(pszAppInPartx[i], NULL))
			{
				// 如果子进程加载程序失败,则阻塞
				PRTMSG(MSG_DBG, "execl program %s fail, sleep\n", pszAppInPartx[i]);
				sleep(3600*48); 
			}
		}
	}
	
	while(!g_bProgExit)
	{
		sleep(8);

		dwFlag = g_objDog.DogQuery();

		if(dwFlag == 0xffffffff)
		{
			iCnt = 0;

			// 若持续正常运行时间超过20分钟(即1200秒,即150个循环),则将失败次数清零,升级次数清零
			static DWORD dwRunTime = 0;
			if(++dwRunTime > 150)
			{
				szError = '0'; szUpdate = '0';
				if(WriteLog(szPart, szError, szUpdate) == -1)
				{
					PRTMSG(MSG_DBG, "write errlog fail\n");
					DeleteLog();
					goto EXIT;
				}
			}
		}
		else
		{
			PRTMSG(MSG_DBG, "dwFlag = %08x\n", dwFlag);

			// 若连续5次未有效清狗(一次判断间隔为8秒,5次即为32秒)
			if(++iCnt > 5)
			{
				// 检查是否有子进程退出
				for(i = 0; i < iAppInPartx; i++)
				{
					if(waitpid(RunPid[i], &EndStatus, WNOHANG) == RunPid[i])
					{
						//子进程正常退出
						if(WIFEXITED(EndStatus) != 0)
						{
							EndSucc++;
						}
					}
				}
				
				// 如果所有子进程都正常退出,出错次数清零
				if(EndSucc == iAppInPartx)
				{
					szError = '0';
				}
				// 否则递增出错次数
				else
				{
					szError++;
				}
				
				PRTMSG(MSG_DBG, "%d/%d program end normally\n", EndSucc, iAppInPartx);
				
				if(WriteLog(szPart, szError, szUpdate) == -1)
				{
					DeleteLog();
				}
				goto EXIT;
			}
		}
	}
		
EXIT:
	g_bProgExit = true;
	sleep(3);
	return 0;
}
Example #9
0
void InterpretCommand(MenuInstanceData * pMenuData, const char *pszScript) {
  char szCmd[31], szParam1[51], szParam2[51];
  char szTempScript[ 255 ];
  memset(szTempScript, 0, sizeof(szTempScript));
  strncpy(szTempScript, pszScript, 250);

  if (pszScript[0] == 0) {
    return;
  }

  char* pszScriptPointer = szTempScript;
  while (pszScriptPointer && !hangup) {
    pszScriptPointer = MenuParseLine(pszScriptPointer, szCmd, szParam1, szParam2);

    if (szCmd[0] == 0) {    // || !pszScriptPointer || !*pszScriptPointer
      break;
    }

    // -------------------------
    // Run a new menu instance

    int nCmdID = GetMenuIndex(szCmd);
    switch (nCmdID) {
    case 0: {
      // "MENU"
      // Spawn a new menu
      MenuInstanceData *pNewMenuData = static_cast<MenuInstanceData *>(malloc(sizeof(MenuInstanceData)));

      memset(pNewMenuData, 0, sizeof(MenuInstanceData));
      pNewMenuData->nFinished = 0;
      pNewMenuData->nReload = 0;

      Menus(pNewMenuData, pMenuData->szPath, szParam1);
      free(pNewMenuData);
    }
    break;
    case 1: {
      // -------------------------
      // Exit out of this instance
      // of the menu
      // -------------------------
      // "ReturnFromMenu"
      InterpretCommand(pMenuData, pMenuData->header.szExitScript);
      pMenuData->nFinished = 1;
    }
    break;
    case 2: {
      // "EditMenuSet"
      EditMenus();           // flag if we are editing this menu
      pMenuData->nFinished = 1;
      pMenuData->nReload = 1;
    }
    break;
    case 3: {
      // "DLFreeFile"
      align(szParam2);
      MenuDownload(szParam1, szParam2, true, true);
    }
    break;
    case 4: {
      // "DLFile"
      align(szParam2);
      MenuDownload(szParam1, szParam2, false, true);
    }
    break;
    case 5: {
      // "RunDoor"
      MenuRunDoorName(szParam1, false);
    }
    break;
    case 6: {
      // "RunDoorFree"
      MenuRunDoorName(szParam1, true);
    }
    break;
    case 7: {
      // "RunDoorNumber"
      int nTemp = atoi(szParam1);
      MenuRunDoorNumber(nTemp, false);
    }
    break;
    case 8: {
      // "RunDoorNumberFree"
      int nTemp = atoi(szParam1);
      MenuRunDoorNumber(nTemp, true);
    }
    break;
    case 9: {
      // "PrintFile"
      printfile(szParam1, true);
    }
    break;
    case 10: {
      // "PrintFileNA"
      printfile(szParam1, false);
    }
    break;
    case 11: {
      // "SetSubNumber"
      SetSubNumber(szParam1);
    }
    break;
    case 12: {
      // "SetDirNumber"
      SetDirNumber(szParam1);
    }
    break;
    case 13: {
      // "SetMsgConf"
      SetMsgConf(szParam1[0]);
    }
    break;
    case 14: {
      // "SetDirConf"
      SetDirConf(szParam1[0]);
    }
    break;
    case 15: {
      // "EnableConf"
      EnableConf();
    }
    break;
    case 16: {
      // "DisableConf"
      DisableConf();
    }
    break;
    case 17: {
      // "Pause"
      pausescr();
    }
    break;
    case 18: {
      // "ConfigUserMenuSet"
      ConfigUserMenuSet();
      pMenuData->nFinished = 1;
      pMenuData->nReload = 1;
    }
    break;
    case 19: {
      // "DisplayHelp"
      if (GetSession()->GetCurrentUser()->IsExpert()) {
        AMDisplayHelp(pMenuData);
      }
    }
    break;
    case 20: {
      // "SelectSub"
      ChangeSubNumber();
    }
    break;
    case 21: {
      // "SelectDir"
      ChangeDirNumber();
    }
    break;
    case 22: {
      // "SubList"
      SubList();
    }
    break;
    case 23: {
      // "UpSubConf"
      UpSubConf();
    }
    break;
    case 24: {
      // "DownSubConf"
      DownSubConf();
    }
    break;
    case 25: {
      // "UpSub"
      UpSub();
    }
    break;
    case 26: {
      // "DownSub"
      DownSub();
    }
    break;
    case 27: {
      // "ValidateUser"
      ValidateUser();
    }
    break;
    case 28: {
      // "Doors"
      Chains();
    }
    break;
    case 29: {
      // "TimeBank"
      TimeBank();
    }
    break;
    case 30: {
      // "AutoMessage"
      AutoMessage();
    }
    break;
    case 31: {
      // "BBSList"
      BBSList();
    }
    break;
    case 32: {
      // "RequestChat"
      RequestChat();
    }
    break;
    case 33: {
      // "Defaults"
      Defaults(pMenuData);
    }
    break;
    case 34: {
      // "SendEMail"
      SendEMail();
    }
    break;
    case 35: {
      // "Feedback"
      FeedBack();
    }
    break;
    case 36: {
      // "Bulletins"
      Bulletins();
    }
    break;
    case 37: {
      // "HopSub"
      HopSub();
    }
    break;
    case 38: {
      // "SystemInfo"
      SystemInfo();
    }
    break;
    case 39: {
      // "JumpSubConf"
      JumpSubConf();
    }
    break;
    case 40: {
      // "KillEMail"
      KillEMail();
    }
    break;
    case 41: {
      // "LastCallers"
      LastCallers();
    }
    break;
    case 42: {
      // "ReadEMail"
      ReadEMail();
    }
    break;
    case 43: {
      // "NewMessageScan"
      NewMessageScan();
    }
    break;
    case 44: {
      // "Goodbye"
      GoodBye();
    }
    break;
    case 45: {
      // "PostMessage"
      WWIV_PostMessage();
    }
    break;
    case 46: {
      // "NewMsgScanCurSub"
      ScanSub();
    }
    break;
    case 47: {
      // "RemovePost"
      RemovePost();
    }
    break;
    case 48: {
      // "TitleScan"
      TitleScan();
    }
    break;
    case 49: {
      // "ListUsers"
      ListUsers();
    }
    break;
    case 50: {
      // "Vote"
      Vote();
    }
    break;
    case 51: {
      // "ToggleExpert"
      ToggleExpert();
    }
    break;
    case 52: {
      // "YourInfo"
      YourInfo();
    }
    break;
    case 53: {
      // "ExpressScan"
      ExpressScan();
    }
    break;
    case 54: {
      // "WWIVVer"
      WWIVVersion();
    }
    break;
    case 55: {
      // "InstanceEdit"
      InstanceEdit();
    }
    break;
    case 56: {
      // "ConferenceEdit"
      JumpEdit();
    }
    break;
    case 57: {
      // "SubEdit"
      BoardEdit();
    }
    break;
    case 58: {
      // "ChainEdit"
      ChainEdit();
    }
    break;
    case 59: {
      // "ToggleAvailable"
      ToggleChat();
    }
    break;
    case 60: {
      // "ChangeUser"
      ChangeUser();
    }
    break;
    case 61: {
      // "CLOUT"
      CallOut();
    }
    break;
    case 62: {
      // "Debug"
      Debug();
    }
    break;
    case 63: {
      // "DirEdit"
      DirEdit();
    }
    break;
    case 65: {
      // "Edit"
      EditText();
    }
    break;
    case 66: {
      // "BulletinEdit"
      EditBulletins();
    }
    break;
    case 67: {
      // "LoadText"
      // LoadText and LoadTextFile are the same, so they are now merged.
      LoadTextFile();
    }
    break;
    case 68: {
      // "ReadAllMail"
      ReadAllMail();
    }
    break;
    case 69: {
      // "Reboot"
      RebootComputer();
    }
    break;
    case 70: {
      // "ReloadMenus"
      ReloadMenus();
    }
    break;
    case 71: {
      // "ResetUserIndex"
      ResetFiles();
    }
    break;
    case 72: {
      // "ResetQScan"
      ResetQscan();
    }
    break;
    case 73: {
      // "MemStat"
      MemoryStatus();
    }
    break;
    case 74: {
      // "PackMsgs"
      PackMessages();
    }
    break;
    case 75: {
      // "VoteEdit"
      InitVotes();
    }
    break;
    case 76: {
      // "Log"
      ReadLog();
    }
    break;
    case 77: {
      // "NetLog"
      ReadNetLog();
    }
    break;
    case 78: {
      // "Pending"
      PrintPending();
    }
    break;
    case 79: {
      // "Status"
      PrintStatus();
    }
    break;
    case 80: {
      // "TextEdit"
      TextEdit();
    }
    break;
    case 81: {
      // "UserEdit"
      UserEdit();
    }
    break;
    case 82: {
      // "VotePrint"
      VotePrint();
    }
    break;
    case 83: {
      // "YLog"
      YesturdaysLog();
    }
    break;
    case 84: {
      // "ZLog"
      ZLog();
    }
    break;
    case 85: {
      // "ViewNetDataLog"
      ViewNetDataLog();
    }
    break;
    case 86: {
      // "UploadPost"
      UploadPost();
    }
    break;
    case 87: {
      // "ClearScreen"
      GetSession()->bout.ClearScreen();
    }
    break;
    case 88: {
      // "NetListing"
      NetListing();
    }
    break;
    case 89: {
      // "WHO"
      WhoIsOnline();
    }
    break;
    case 90: {
      // /A "NewMsgsAllConfs"
      NewMsgsAllConfs();
    }
    break;
    case 91: {
      // /E "MultiEMail"
      MultiEmail();
    }
    break;
    case 92: {
      // "NewMsgScanFromHere"
      NewMsgScanFromHere();
    }
    break;
    case 93: {
      // "ValidatePosts"
      ValidateScan();
    }
    break;
    case 94: {
      // "ChatRoom"
      ChatRoom();
    }
    break;
    case 95: {
      // "DownloadPosts"
      DownloadPosts();
    }
    break;
    case 96: {
      // "DownloadFileList"
      DownloadFileList();
    }
    break;
    case 97: {
      // "ClearQScan"
      ClearQScan();
    }
    break;
    case 98: {
      // "FastGoodBye"
      FastGoodBye();
    }
    break;
    case 99: {
      // "NewFilesAllConfs"
      NewFilesAllConfs();
    }
    break;
    case 100: {
      // "ReadIDZ"
      ReadIDZ();
    }
    break;
    case 101: {
      // "UploadAllDirs"
      UploadAllDirs();
    }
    break;
    case 102: {
      // "UploadCurDir"
      UploadCurDir();
    }
    break;
    case 103: {
      // "RenameFiles"
      RenameFiles();
    }
    break;
    case 104: {
      // "MoveFiles"
      MoveFiles();
    }
    break;
    case 105: {
      // "SortDirs"
      SortDirs();
    }
    break;
    case 106: {
      // "ReverseSortDirs"
      ReverseSort();
    }
    break;
    case 107: {
      // "AllowEdit"
      AllowEdit();
    }
    break;
    case 109: {
      // "UploadFilesBBS"
      UploadFilesBBS();
    }
    break;
    case 110: {
      // "DirList"
      DirList();
    }
    break;
    case 111: {
      // "UpDirConf"
      UpDirConf();
    }
    break;
    case 112: {
      // "UpDir"
      UpDir();
    }
    break;
    case 113: {
      // "DownDirConf"
      DownDirConf();
    }
    break;
    case 114: {
      // "DownDir"
      DownDir();
    }
    break;
    case 115: {
      // "ListUsersDL"
      ListUsersDL();
    }
    break;
    case 116: {
      // "PrintDSZLog"
      PrintDSZLog();
    }
    break;
    case 117: {
      // "PrintDevices"
      PrintDevices();
    }
    break;
    case 118: {
      // "ViewArchive"
      ViewArchive();
    }
    break;
    case 119: {
      // "BatchMenu"
      BatchMenu();
    }
    break;
    case 120: {
      // "Download"
      Download();
    }
    break;
    case 121: {
      // "TempExtract"
      TempExtract();
    }
    break;
    case 122: {
      // "FindDescription"
      FindDescription();
    }
    break;
    case 123: {
      // "ArchiveMenu"
      TemporaryStuff();
    }
    break;
    case 124: {
      // "HopDir"
      HopDir();
    }
    break;
    case 125: {
      // "JumpDirConf"
      JumpDirConf();
    }
    break;
    case 126: {
      // "ListFiles"
      ListFiles();
    }
    break;
    case 127: {
      // "NewFileScan"
      NewFileScan();
    }
    break;
    case 128: {
      // "SetNewFileScanDate"
      SetNewFileScanDate();
    }
    break;
    case 129: {
      // "RemoveFiles"
      RemoveFiles();
    }
    break;
    case 130: {
      // "SearchAllFiles"
      SearchAllFiles();
    }
    break;
    case 131: {
      // "XferDefaults"
      XferDefaults();
    }
    break;
    case 132: {
      // "Upload"
      Upload();
    }
    break;
    case 133: {
      // "YourInfoDL"
      YourInfoDL();
    }
    break;
    case 134: {
      // "UploadToSysop"
      UploadToSysop();
    }
    break;
    case 135: {
      // "ReadAutoMessage"
      ReadAutoMessage();
    }
    break;
    case 136: {
      // "SetNewScanMsg"
      SetNewScanMsg();
    }
    break;
    case 137: {
      // "ReadMessages"
      ReadMessages();
    }
    break;
    /*
    case 138:
    { // "RUN"
    ExecuteBasic(szParam1);
    } break;
    */
    case 139: {
      // "EventEdit"
      EventEdit();
    }
    break;
    case 140: {
      // "LoadTextFile"
      LoadTextFile();
    }
    break;
    case 141: {
      // "GuestApply"
      GuestApply();
    }
    break;
    case 142: {
      // "ConfigFileList"
      ConfigFileList();
    }
    break;
    case 143: {
      // "ListAllColors"
      ListAllColors();
    }
    break;
#ifdef QUESTIONS
    case 144: {
      // "EditQuestions"
      EditQuestions();
    }
    break;
    case 145: {
      // "Questions"
      Questions();
    }
    break;
#endif
    case 146: {
      // "RemoveNotThere"
      RemoveNotThere();
    }
    break;
    case 147: {
      // "AttachFile"
      AttachFile();
    }
    break;
    case 148: {
      // "InternetEmail"
      InternetEmail();
    }
    break;
    case 149: {
      // "UnQScan"
      UnQScan();
    }
    break;
    // ppMenuStringsIndex[150] thru ppMenuStringsIndex[153] not used.....
    case 154: {
      // "Packers"
      Packers();
    }
    break;
    case 155: {
      // Color_Config
      color_config();
    }
    break;
    //------------------------------------------------------------------
    //  ppMenuStringsIndex[156] and [157] are reserved for SDS Systems and systems
    //  that distribute modifications.  DO NOT reuse these strings for
    //  other menu options.
    //------------------------------------------------------------------
    //    case 156:
    //    { // ModAccess
    //        ModsAccess();
    //    } break;
    //    case 157:
    //    { // SDSAccess
    //        SDSAccess();
    //      } break;
    //------------------------------------------------------------------
    case 158: {
      // InitVotes
      InitVotes();
    }
    break;
    case 161: {
      // TurnMCIOn
      TurnMCIOn();
    }
    break;
    case 162: {
      // TurnMCIOff
      TurnMCIOff();
    }
    break;
    default: {
      MenuSysopLog("The following command was not recognized");
      MenuSysopLog(szCmd);
    }
    break;
    }
  }
}
Example #10
0
void main() {
	ReadLog();
}
Example #11
0
//
// The main function for performing SLAM at the low level. The first argument will return 
// whether there is still information to be processed by SLAM (set to 1). The second and third
// arguments return the corrected odometry for the time steps, and the corresponding list of
// observations. This can be used for the higher level SLAM process when using hierarchical SLAM.
//
void LowSlam(TPath **path, TSenseLog **obs)
{
  int cnt;
  int i, j, overflow = 0;
  char name[32];
  TPath *tempPath;
  TSenseLog *tempObs;
  TAncestor *lineage;

  // Initialize the worldMap
  LowInitializeWorldMap();

  // Initialize the ancestry and particles
  cleanID = ID_NUMBER - 2;    // ID_NUMBER-1 is being used as the root of the ancestry tree.

  // Initialize all of our unused ancestor particles to look unused.
  for (i = 0; i < ID_NUMBER; i++) {
    availableID[i] = i;

    l_particleID[i].generation = -1;
    l_particleID[i].numChildren = 0;
    l_particleID[i].ID = -1;
    l_particleID[i].parent = NULL;
    l_particleID[i].mapEntries = NULL;
    l_particleID[i].path = NULL;
    l_particleID[i].seen = 0;
    l_particleID[i].total = 0;
    l_particleID[i].size = 0;
  }

  // Initialize the root of our ancestry tree.
  l_particleID[ID_NUMBER-1].generation = 0;
  l_particleID[ID_NUMBER-1].numChildren = 1;
  l_particleID[ID_NUMBER-1].size = 0;
  l_particleID[ID_NUMBER-1].total = 0;
  l_particleID[ID_NUMBER-1].ID = ID_NUMBER-1;
  l_particleID[ID_NUMBER-1].parent = NULL;
  l_particleID[ID_NUMBER-1].mapEntries = NULL;

  // Create all of our starting particles at the center of the map.
  for (i = 0; i < PARTICLE_NUMBER; i++) {
    l_particle[i].ancestryNode = &(l_particleID[ID_NUMBER-1]);
    l_particle[i].x = MAP_WIDTH / 2;
    l_particle[i].y = MAP_HEIGHT / 2;
    l_particle[i].theta = 0.001;
    l_particle[i].probability = 0;
    children[i] = 0;
  }
  // We really only use the first particle, since they are all essentially the same.
  l_particle[0].probability = 1;
  l_cur_particles_used = 1;
  children[0] = SAMPLE_NUMBER;

  // We don't need to initialize the savedParticles, since Localization will create them for us, and they first are used in 
  // UpdateAncestry, which is called after Localization. This statement isn't necessary, then, but serves as a sort of placeholder 
  // when reading the code.
  cur_saved_particles_used = 0;

  overflow = 1;

  for (i=0; i < START_ITERATION; i++)
    ReadLog(readFile, logfile_index, sense);

  curGeneration = 0;
  // Add the first thing that you see to the worldMap at the center. This gives us something to localize off of.
  ReadLog(readFile, logfile_index, sense);
  AddToWorldModel(sense, 0);
  curGeneration = 1;

  // Make a record of what the first odometry readings were, so that we can compute relative movement across time steps.
  lastX = odometry.x;
  lastY = odometry.y;
  lastTheta = odometry.theta;


  // Get our observation log started.
  (*obs) = (TSenseLog *)malloc(sizeof(TSenseLog));
  for (i=0; i < SENSE_NUMBER; i++) {
    (*obs)->sense[i].distance = sense[i].distance;
    (*obs)->sense[i].theta = sense[i].theta;
  }
  (*obs)->next = NULL;

  cnt = 0;
  while (curGeneration < LEARN_DURATION) {
    // Collect information from the data log. If either reading returns 1, we've run out of log data, and
    // we need to stop now.
    if (ReadLog(readFile, logfile_index, sense) == 1)
      overflow = 0;
    else 
      overflow = 1;

    // We don't necessarily want to use every last reading that comes in. This allows us to make certain that the 
    // robot has moved at least a minimal amount (in terms of meters and radians) before we try to localize and update.
    if ((sqrt(SQUARE(odometry.x - lastX) + SQUARE(odometry.y - lastY)) < 0.10) && (fabs(odometry.theta - lastTheta) < 0.04))
      overflow = 0;

    if (overflow > 0) {
      overflow--;

      // Wipe the slate clean 
      LowInitializeFlags();

      // Apply the localization procedure, which will give us the N best particles
      Localize(sense);

      // Add these maintained particles to the FamilyTree, so that ancestry can be determined, and then prune dead lineages
      UpdateAncestry(sense, l_particleID);

      // Update the observation log (used only by hierarchical SLAM)
      tempObs = (*obs);
      while (tempObs->next != NULL)
	tempObs = tempObs->next;
      tempObs->next = (TSenseLog *)malloc(sizeof(TSenseLog));
      if (tempObs->next == NULL) fprintf(stderr, "Malloc failed in making a new observation!\n");
      for (i=0; i < SENSE_NUMBER; i++) {
	tempObs->next->sense[i].distance = sense[i].distance;
	tempObs->next->sense[i].theta = sense[i].theta;
      }
      tempObs->next->next = NULL;

      curGeneration++;

      // Remember these odometry readings for next time. This is what lets us know the incremental motion.
      lastX = odometry.x;
      lastY = odometry.y;
      lastTheta = odometry.theta;
    }
  }


  // Find the most likely particle. Return its path
  j = 0;
  for (i=0; i < l_cur_particles_used; i++) 
    if (l_particle[i].probability > l_particle[j].probability)
      j = i;

  (*path) = NULL;
  i = 0;
  lineage = l_particle[j].ancestryNode;
  while ((lineage != NULL) && (lineage->ID != ID_NUMBER-1)) {
    tempPath = lineage->path;
    i++;
    while (tempPath->next != NULL) {
      i++;
      tempPath = tempPath->next;
    }
    tempPath->next = (*path);

    (*path) = lineage->path;
    lineage->path = NULL;
    lineage = lineage->parent;
  }

  // Print out the map.
  sprintf(name, "map");
  j = 0;
  for (i = 0; i < l_cur_particles_used; i++)
    if (l_particle[i].probability > l_particle[j].probability)
      j = i;
  PrintMap(name, l_particle[j].ancestryNode, FALSE, -1, -1, -1);
  sprintf(name, "rm map.ppm");
  system(name);

  // Clean up the memory being used.
  DisposeAncestry(l_particleID);
  LowDestroyMap();
}