Find the answer to your Linux question:
Results 1 to 2 of 2
Alright, so when it comes to actually coding in general, I'm pretty much a noob (I've always understood the concept behind it though... just a matter of continuous practice and ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2012
    Posts
    1

    Exclamation Need help with C++ programming on Linux platform! Please help.


    Alright, so when it comes to actually coding in general, I'm pretty much a noob (I've always understood the concept behind it though... just a matter of continuous practice and syntax memorization) but here's my situation... I've been given a project as an intern and I must develop a protocol that will allow two mesh routers to switch communication channels whenever interference is encountered between them... say they are using channel 2 and then out of nowhere interference is encountered so they need to switch to another channel. After this encounter, they would communicate and agree to switch to another channel. My major problem in writing this is I don't know how to access Linux system resources (such as the router's kernel to ping, determine the channel number, determine how many active sessions are established, etc,) so that I can pass the proper data in my code. Anyways, all-in-all, I would greatly appreciate any help that would allow me to access Linux environment (especially networking) resources so that I can actually develop/design my protocol.

    Here is my "pseudo code (very English)" for this protocol. This is just a very simple general idea of how my code would flow throughout execution...

    Code:
    "Pseudo-Code" for PCC Protocol
    
    #include <iostream>
    using namespace std;
    
    //whatever is inserted between "*" refers where the code should go and what it should do 
    
    bool& result;
    
    void analyseRTT()
    {
    	*send ping packets to other network node*;
    	if (*total round-trip-time is significantly delayed* && *numberOfSession is the same*)
    		{
    			result = TRUE;
    		}
    	else
    		{
    			result = FALSE;
    		}
    }
    
    int changeChannel(bool& r)
    {
    	if (r == true)
    		{
    			*start channel change negotiation*;
    			*try int channel !== this.channel*
    			*wait for ack*;
    			return channel;
    		}
    	else
    		{
    			return 0;
    		}
    	
    }
    
    void applyChange(int& c)
    {
    	*send channel number to other node to confirm the coming change*;
    	*wait for ack*;
    	*send ack to confirm*;
    	*change current channel to channel number*;
    }
    
    void waitForAnalyse()
    {
    	*wait for suggested channel number*;
    	*chech if channel is available/unused*;
    	*send ack*;
    }
    
    void waitForChange()
    {
    	*wait for confirmed channel number to switch to*;
    	*send ack*;
    	*wait for final ack*;
    	*change channel to chosen channel number*;
    }
    
    int main()
    {
    
    int channel;
    	
    	while(*routers are operational*)
    	{
    		if(*this.node receives change channel negotiation)
    			{
    				receiverSide:
    				waitForAnalyse();
    				waitForChange();
    			}
    		else
    			{
    				wait(1 minute);
    				if(*this.node receives change channel negotiation*)
    					{
    						goto receiverSide;
    					}
    				else
    					{
    						analyseRTT();
    						changeChannel(result);
    						applyChange(channel);
    					}
    			}
    	}	
    	return 0;
    }
    Cheers, thank you and any is help is greatly appreciated.

    J33ZER

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,755
    Well, your pseudo-code is pretty clear, so you understand what you need to do. You just don't know what to do to implement it in C/C++ code. Time to do some reading! There are way too many issues here for simple answers. Linux man pages will help a lot. As far as I can tell, this is more a C than a C++ problem - most low-level application code is in C. If you want to implement this in C++, then start with a model of the data and its behaviors (classes) before you start.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •