Ejemplo n.º 1
0
//////////////////////////////////////////////////////////////////////////////
/// \brief nav_getWaypoint
///			returns the waypoint with the given id
/// \param id
///			ID of the desired waypoint
/// \return Pointer to waypoint with the given ID
///
nav_waypoint_t *nav_getWaypoint(int16_t id)
{
	nav_waypoint_t *get_el = nav_wpStart; //Element to find (index)

	if(nav_wpStart != NULL) //Are elements in the List?
	{
		for(u_int16_t i = 0; i < WP_STACKSIZE; i++)
		{
			if(get_el->id == id)
			{
				return get_el;
			}
			else
			{
				get_el = get_el->next;
				if(get_el == NULL) //End of list - stop loop (Element not found).
					return NULL;
			}
		}
	}
	else
	{
		foutf(&debug,"No waypoints available to return!\n");
		//To do: Debug...
	}

	return NULL;
}
Ejemplo n.º 2
0
////////////////////////////////////////////////////////////////
/// \brief nav_deleteWaypoint
///			Deletes waypoint with the given id from the list
/// \param id
///			ID of the waypoint to delete
void nav_deleteWaypoint(int16_t id)
{
	nav_waypoint_t *del_el; //Element to delete

	if(nav_wpStart != NULL) //Are elements in the List?
	{
		if(nav_wpStart->id == id) //Is the start id the element we want to delete?
		{
			if(nav_wpStart->next == NULL) //Are not more than one elements in the list?
			{
				nav_stackFree(nav_wpStart);
				nav_wpStart = NULL;
				nav_wpEnd = NULL;
			}
			else
			{
				nav_wpStart->next->previous = NULL;
				nav_stackFree(nav_wpStart);
				nav_wpStart = nav_wpStart->next;
			}
		}
		else if(nav_wpEnd->id == id) //Do we want to delete the last element?
		{
			nav_wpEnd->previous->next=NULL;
			nav_stackFree(nav_wpEnd);
			nav_wpEnd = nav_wpEnd->previous;
		}
		else //We want to delete an element between end and start.
		{
			del_el = nav_wpStart;

			for(u_int16_t i = 0; i < WP_STACKSIZE; i++)
			{
				if(del_el->id == id)
				{
					del_el->previous->next = del_el->next;
					del_el->next->previous = del_el->previous;

					nav_stackFree(del_el);
					break; //Found ID - stop for-loop
				}
				else
				{
					del_el = del_el->next;
					if(del_el == NULL) //End of list - stop loop (Element not found).
						break;
				}
			}
		}
	}
	else
	{
		foutf(&debug,"No waypoints available to delete!\n");
		//To do: Debug...
	}
}
Ejemplo n.º 3
0
void SaveCache(
               __in IPAddressMap const & f_cache,
               __in_z char const * const f_szFileName )
{
    std::cout << "Saving cache to " << f_szFileName << "..." << std::endl;

    std::ofstream foutf( f_szFileName);
    if( foutf.bad() )
    {
        // some error, abort
        return;
    }

    foutf << "# Copyright (c) 1993-1999 Microsoft Corp." << std::endl
          << std::endl
          << "# This is a sample HOSTS file used by Microsoft TCP/IP for Windows." << std::endl
          << std::endl
          << "# This file contains the mappings of IP addresses to host names. Each" << std::endl
          << "# entry should be kept on an individual line. The IP address should" << std::endl
          << "# be placed in the first column followed by the corresponding host name." << std::endl
          << "# The IP address and the host name should be separated by at least one" << std::endl
          << "# space." << std::endl
          << "#" << std::endl
          << "#" << std::endl
          << "# This file was generated by HostsMergeCmd." << std::endl
          << "#" << std::endl
          << "#" << std::endl
          << "# Additionally, comments (such as these) may be inserted on individual" << std::endl
          << "# lines or following the machine name denoted by a '#' symbol." << std::endl
          << std::endl
          << "# For example:" << std::endl
          << "#" << std::endl
          << "#      102.54.94.97     rhino.acme.com          # source server" << std::endl
          << "#       38.25.63.10     x.acme.com              # x client host" << std::endl
          << std::endl
          << "127.0.0.1\tlocalhost" << std::endl
          << std::endl;

    foutf << "# BEGIN Local network\\Specific hosts" << std::endl;

    OutputLocalNetwork( f_cache, foutf );

    foutf << "# END Local network\\Specific hosts" << std::endl
          << std::endl
          << std::endl;

    foutf << "# BEGIN Block List" << std::endl;

    OutputBlockList( f_cache, foutf );

    foutf << "# END Block List" << std::endl
          << std::endl;
}
Ejemplo n.º 4
0
void nav_attachWaypoint(nav_waypoint_t *wp)
{
	nav_waypoint_t *penultimate_el; //Pointer to acces penultimate element in the list

	if(nav_wpStart == NULL) //There are no elements in the list, because the start pointer points to NULL
	{
		nav_wpStart = nav_stackFindEmptyElement(); //Reserve first element from stack
		if(nav_wpStart == NULL) //couldn’t reserve element. Stack too small?
		{
			foutf(&debug,"Couldn’t reserve start waypoint from stack!\n");
		}
		else
		{
			attWp_copy(wp, nav_wpStart); //Copy data from given waypoint

			nav_wpStart->next = NULL; //Next pointer points to next element in list, but the start element is now the first and last element, so it points to NULL
			nav_wpEnd = nav_wpStart; //The first element is also the last element
			nav_wpEnd->previous = NULL; //Just like start->next
		}
	}
	else //There is at least one element in the list
	{
		nav_wpEnd->next = nav_stackFindEmptyElement(); //Reserve element from stack for the element after end
		if(nav_wpEnd->next == NULL)
		{
			foutf(&debug,"Couldn’t reserve waypoint from stack!\n");
		}
		else
		{
			penultimate_el = nav_wpEnd; //Now, the last element became the penultimate element (because we attached one more element to the end of the list)
			nav_wpEnd = nav_wpEnd->next; //And the ultimate element points to the just reserved stack element
			nav_wpEnd->next = NULL; //The next pointer of the ultimate element (end element) has to point to NULL again
			nav_wpEnd->previous = penultimate_el; //The previous pointer of the last element has to point to the penultimate element
			penultimate_el->next = nav_wpEnd; //And inversed...

			attWp_copy(wp, nav_wpEnd); //Copy data from given waypoint
		}
	}
}
Ejemplo n.º 5
0
void SavePdnsdNeg(
        __in IPAddressMap const & f_cache,
        __in_z char const * const f_szFileName )
{
    std::cout << "Saving bind pdnsd neg file to " << f_szFileName << "..." << std::endl;

    std::ofstream foutf( f_szFileName );
    if( foutf.bad() )
    {
        // some error, abort
        return;
    }

    foutf << "neg" << std::endl;
    foutf << "{" << std::endl;
    
    DomainNames const setDomainNames( ExtractUniqueDomainNames( f_cache ) );
    DomainNames::const_iterator const itEndDomain( setDomainNames.end() );

    // Banned stuff: Domain names
    for( DomainNames::const_iterator itDomain( setDomainNames.begin() );
        itEndDomain != itDomain;
        ++itDomain )
    {
        std::string domain(*itDomain);
        
        // contains bad chars
        if( std::string::npos != domain.find('\"'))
        {
            continue;
        }
        
        // Too Short
        if(domain.size() < 3)
        {
            continue;
        }
        
        std::stringstream ss;

		foutf << "\tname " << domain << ";" << std::endl;
    }

    foutf << "\ttypes = domain;" << std::endl;
    foutf << "}" << std::endl;
    foutf << std::endl;
}
Ejemplo n.º 6
0
	virtual int main()
	{
		CStreamFile* pOutFile = NULL;
		CFilePath fcurdir;
		CFilePath fziparchive(__FILE__LINE__ m_sZipArchive);
		CFilePath foutf(__FILE__LINE__ m_sOutputFile);
		int result = 0;

		if ( m_help )
		{
			CStringBuffer tmp;

			usage(tmp);
			CERR << tmp;
			return 0;
		}
		if ( !m_AnyZipOption )
		{
			m_AnyZipOption = true;
			m_bAddFiles = true;
		}
		if (m_bInputDir)
		{
			CFilePath finputdir(__FILE__LINE__ m_sInputDir);

			if (CWinDirectoryIterator::FileExists(finputdir))
				finputdir.set_Filename(NULL);
			finputdir.MakeDirectory();
			if (CWinDirectoryIterator::DirectoryExists(finputdir) < 0)
			{
				CERR << finputdir.get_Path() << _T(" does not exist.") << endl;
				return -4;
			}
			CDirectoryIterator::GetCurrentDirectory(fcurdir);
			fziparchive.MakeAbsolute();
			if (m_bOutputFile)
				foutf.MakeAbsolute();
			CDirectoryIterator::SetCurrentDirectory(finputdir);
		}
		if (m_bOutputFile) 
		{
			if (CDirectoryIterator::FileExists(foutf))
				CDirectoryIterator::RemoveFile(foutf);
			else if (foutf.is_File())
			{
				CFilePath tmp(foutf);

				tmp.set_Filename(NULL);
				CDirectoryIterator::MakeDirectory(tmp);
			}
			else
			{
				CDateTime now;
				CStringBuffer tmp;

				now.Now();
				tmp.FormatString(__FILE__LINE__ _T("XZip%04hd%02hd%02hd%02hd%02hd%02hd.log"),
					now.GetYears(), now.GetMonths(), now.GetDays(),
					now.GetHours(), now.GetMinutes(), now.GetSeconds());
				foutf.set_Filename(tmp);
			}
			pOutFile = OK_NEW_OPERATOR CStreamFile;
			pOutFile->ReOpen(foutf, stdout);
		}
		if ( m_bAddFiles )
		{
			if (!m_bZipFileSpec)
			{
				CERR << _T("No FileSpec given. Do not know, what to do.") << endl;
				result = -4;
			}
			else
				XZipAddFiles(fziparchive, m_bRecurseFolders, m_sZipFileSpec, m_sExclude);
		}
		if ( m_bViewFiles )
		{
			if ( !m_bZipFileSpec )
				m_sZipFileSpec.Append(_T("*.*"));
			XZipViewFiles(fziparchive, m_sZipFileSpec, m_sExclude, m_sViewFiles);
		}
		if ( m_bFreshenFiles )
		{
			if ( !m_bZipFileSpec )
				m_sZipFileSpec.Append(_T("*.*"));
			XZipFreshenFiles(fziparchive, m_sZipFileSpec, m_sExclude);
		}
		if ( m_bUpdateFiles )
		{
			if ( !m_bZipFileSpec )
			{
				CERR << _T("No FileSpec given. Do not know, what to do.") << endl;
				result = -4;
			}
			else
				XZipUpdateFiles(fziparchive, m_bRecurseFolders, m_sZipFileSpec, m_sExclude);
		}
		if (pOutFile)
		{
			pOutFile->Close();
			pOutFile->release();
		}
		if (m_bInputDir)
			CDirectoryIterator::SetCurrentDirectory(fcurdir);
		return result;
	}
Ejemplo n.º 7
0
void SaveWpadDat(
        __in IPAddressMap const & f_cache,
        __in_z char const * const f_szFileName,
        __in_z_opt char const * const proxyUrl )
{
    std::cout << "Saving wpad.dat file to " << f_szFileName << "..." << std::endl;

    std::ofstream foutf( f_szFileName );
    if( foutf.bad() )
    {
        // some error, abort
        return;
    }
    
    std::string proxy = "DIRECT";
    if( proxyUrl && *proxyUrl)
    {
        proxy = "PROXY ";
        proxy += proxyUrl;
    }

    DomainNames const setDomainNames( ExtractUniqueDomainNames( f_cache ) );
    DomainNames::const_iterator const itEndDomain( setDomainNames.end() );

    foutf << "//////////////////////////////////////////////////////////////////////////////" << std::endl
          << "//" << std::endl
          << "// Hosts file Based proxy auto configuration script" << std::endl
          << "//" << std::endl
          << "//////////////////////////////////////////////////////////////////////////////" << std::endl
          << std::endl;

    foutf << "function IsHostOrDomain(host, candidate)" << std::endl
          << "{" << std::endl
          << "  return shExpMatch(host, \"*.\" + candidate) || dnsDomainIs(host, candidate);" << std::endl
          << "}" << std::endl
          << std::endl;
    
    
    foutf << "function FindProxyForURL(url, host)" << std::endl
          << "{" << std::endl
          << std::endl  
          << "  // WARNING: all shExpMatch rules following MUST be lowercase!" << std::endl
          << "  url = url.toLowerCase();" << std::endl
          << "  host = host.toLowerCase();" << std::endl
          << std::endl;

    // Local network
    foutf << "  if( isInNet(host, \"10.0.0.0\", \"255.0.0.0\")" << std::endl
          << "   || isInNet(host, \"127.0.0.1\", \"255.255.255.255\")" << std::endl
		  << "   || isInNet(host, \"172.16.0.0\", \"255.240.0.0\")" << std::endl
		  << "   || isInNet(host, \"192.168.0.0\", \"255.255.0.0\"))"
          << "  {" << std::endl
          << "    return \"DIRECT\";" << std::endl
          << "  }" << std::endl
          << std::endl;

    // Banned stuff: Hard coded networks
    foutf << "  if(isInNet(host, \"205.180.85.0\", \"255.255.255.0\")) return \"PROXY 0.0.0.0:3421\";" << std::endl // one whole class C full of ad servers (fastclick)
          << "  if(isInNet(host, \"67.215.65.130\", \"255.255.255.255\")) return \"PROXY 0.0.0.0:3421\";" << std::endl; // hit-adult.opendns.com

    // Banned stuff: Domain names
    for( DomainNames::const_iterator itDomain( setDomainNames.begin() );
        itEndDomain != itDomain;
        ++itDomain )
    {
        std::string domain(*itDomain);
        
        // contains bad chars
        if( std::string::npos != domain.find('\"'))
        {
            continue;
        }
        
        // Too Short
        if(domain.size() < 3)
        {
            continue;
        }
        
        std::stringstream ss;

        foutf << "  if(IsHostOrDomain(host, \"" << domain << "\")) return \"PROXY 0.0.0.0:3421\";" << std::endl;
    }
    foutf << std::endl;
    
    // FTP and HTTP should be proxied    
    foutf << "  if((url.substring(0, 5) == \"http:\")" << std::endl
          << "   ||(url.substring(0, 4) == \"ftp:\")" << std::endl
          << "  )" << std::endl
          << "  {" << std::endl
          << "    return \"" << proxy << "\";" << std::endl
          << "  }" << std::endl
          << std::endl;

    // Everything else direct
    foutf << "  return \"DIRECT\";" << std::endl
          << std::endl
          << "}" << std::endl
          << std::endl;
}
Ejemplo n.º 8
0
portTASK_FUNCTION( vGUITask, pvParameters )
{
	portTickType xLastWakeTime;

	foutf(&debugOS, "xTask GUI started.\n");

	xLastWakeTime = xTaskGetTickCount();

	u8 timer_drawMap = 0;

	for(;;)
	{
		//foutf(&debugOS, "Watermark gui: %i\n", uxTaskGetStackHighWaterMark( NULL ));

		gui_handler(gui_element);

		if(STM_EVAL_PBGetState(BUTTON_USER))
		{
			menu = MENU_CALIBRATION;
		}

		if(battery.percent != batt_percent_old) //Redraw statusbar if battery value changes
		{
			gui_drawAREAstatusbar(&gui_element[GUI_EL_AREA_STATUSBAR_TOP]);
			batt_percent_old = battery.percent;
		}

		switch (menu) {
		case MENU_INIT:
			LCD_Fill(LCD_COLOR_WHITE);
			gui_drawAREAstatusbar(&gui_element[GUI_EL_AREA_STATUSBAR_TOP]);
			gui_drawMBTN(&gui_element[GUI_EL_MBTN_MAP]);
			gui_drawMBTN(&gui_element[GUI_EL_MBTN_VIEW]);
			gui_drawMBTN(&gui_element[GUI_EL_MBTN_SETTINGS]);

			menu = MENU_INIT_IDLE;

		case MENU_INIT_IDLE: //Wait for events...

			if(gui_element[GUI_EL_MBTN_MAP].state == MBTN_ACTIVE)
				menu = MENU_MAP_INIT;
			else if(gui_element[GUI_EL_MBTN_VIEW].state == MBTN_ACTIVE)
				menu = MENU_VIEW_INIT;
			else if(gui_element[GUI_EL_MBTN_SETTINGS].state == MBTN_ACTIVE)
				menu = MENU_SETTINGS_INIT;

			break;

		case MENU_MAP_INIT:

			//Area Map
			//SW Startmapping
			//SW Show scan
			//BTN Clear map
			//BTN Set waypoint

			gui_element[GUI_EL_AREA_MAP].state = GUI_EL_INTOUCHABLE;
			gui_element[GUI_EL_SW_STARTMAPPING].state =		mapping			? SW_ON : SW_OFF;
			gui_element[GUI_EL_SW_SHOWSCAN].state =			show_scan		? SW_ON : SW_OFF;
			gui_element[GUI_EL_SW_PROCESSEDVIEW].state =	processedView	? SW_ON : SW_OFF;

			gui_element[GUI_EL_AREA_MAP].state = MAP_ACTIVE;

			gui_element[GUI_EL_BTN_CLEARMAP].state = BTN_NOT_ACTIVE;

			if(setWaypoints)	gui_element[GUI_EL_BTN_SETWP].state = BTN_ACTIVE;
			else				gui_element[GUI_EL_BTN_SETWP].state = BTN_NOT_ACTIVE;

			gui_drawSW(&gui_element[GUI_EL_SW_STARTMAPPING]);
			gui_drawSW(&gui_element[GUI_EL_SW_SHOWSCAN]);
			gui_drawSW(&gui_element[GUI_EL_SW_PROCESSEDVIEW]);
			gui_drawBTN(&gui_element[GUI_EL_BTN_CLEARMAP]);
			gui_drawBTN(&gui_element[GUI_EL_BTN_SETWP]);

			timer_drawMap = 0;

			menu = MENU_MAP_IDLE;

		case MENU_MAP_IDLE:

			if(timer_drawMap == 0)
			{
				gui_drawAREAmap(&gui_element[GUI_EL_AREA_MAP]);
				timer_drawMap = MAP_REFRESHTIME;
			}
			timer_drawMap --;

			break; //Map idle (waiting for touch events)

		case MENU_VIEW_INIT:
			//Draw View
			menu = MENU_VIEW_IDLE;

		case MENU_VIEW_IDLE:
			break; //View idle (waiting for touch events)
		case MENU_SETTINGS_INIT: //Settings active

			switch (xv11_state(XV11_GETSTATE)) { //Lidar state?
			case XV11_OFF:		gui_element[GUI_EL_SW_LIDAR].state = SW_OFF;	break;
			case XV11_STARTING:	gui_element[GUI_EL_SW_LIDAR].state = SW_BUSY;	break;
			case XV11_ON:		gui_element[GUI_EL_SW_LIDAR].state = SW_ON;		break;
			default:															break;
			}
			gui_drawSW(&gui_element[GUI_EL_SW_LIDAR]);

			gui_element[GUI_EL_SW_STRLIDAR].state =		strlidar.active	? SW_ON : SW_OFF; //Streams on/off?
			gui_drawSW(&gui_element[GUI_EL_SW_STRLIDAR]);
			gui_element[GUI_EL_SW_STRDEBUG].state =		debug.active	? SW_ON : SW_OFF;
			gui_drawSW(&gui_element[GUI_EL_SW_STRDEBUG]);
			gui_element[GUI_EL_SW_STRDEBUGOS].state =	debugOS.active	? SW_ON : SW_OFF;
			gui_drawSW(&gui_element[GUI_EL_SW_STRDEBUGOS]);
			gui_element[GUI_EL_SW_STRERR].state =		error.active	? SW_ON : SW_OFF;
			gui_drawSW(&gui_element[GUI_EL_SW_STRERR]);
			gui_element[GUI_EL_SW_STRSLAMUI].state =	slamUI.active	? SW_ON : SW_OFF;
			gui_drawSW(&gui_element[GUI_EL_SW_STRSLAMUI]);

			gui_element[GUI_EL_BTN_CALTOUCH].state = BTN_NOT_ACTIVE; //Calibrate Touchscreen?
			gui_drawBTN(&gui_element[GUI_EL_BTN_CALTOUCH]);

			gui_element[GUI_EL_BTN_RESET].state = BTN_NOT_ACTIVE; //Reset system!
			gui_drawBTN(&gui_element[GUI_EL_BTN_RESET]);

			menu = MENU_SETTINGS_IDLE;

		case MENU_SETTINGS_IDLE:

			if(gui_element[GUI_EL_SW_LIDAR].state != GUI_EL_INVISIBLE)
			{
				if(xv11_state(XV11_GETSTATE) == XV11_STARTING)
				{
					if(gui_element[GUI_EL_SW_LIDAR].state != SW_BUSY)
					{
						gui_element[GUI_EL_SW_LIDAR].state = SW_BUSY;
						gui_drawSW(&gui_element[GUI_EL_SW_LIDAR]);
					}
				}
				else if(xv11_state(XV11_GETSTATE) == XV11_ON)
				{
					if(gui_element[GUI_EL_SW_LIDAR].state != SW_ON)
					{
						gui_element[GUI_EL_SW_LIDAR].state = SW_ON;
						gui_drawSW(&gui_element[GUI_EL_SW_LIDAR]);
					}
				}
			}
			break; //Settings idle (waiting for touch events)

		case MENU_CALIBRATION: //Calibration mode:
			if(UB_Touch_Calibrate() == 1)
			{
				menu = MENU_INIT;
			}
			break;

		default: menu = MENU_INIT;
			break;
		}

		vTaskDelayUntil( &xLastWakeTime, ( 50 / portTICK_RATE_MS ) );
	}
}