예제 #1
0
파일: main.cpp 프로젝트: eindacor/utilities
void displayNumber(bigNumber &bn, settings &user, bool exact, bool stats)
{
	if (exact)
		bn.printNumber();

	else
	{
		int actualDigits = bn.getDigitCount() - (PRECISION-bn.getDecimalCount());
		
		if (user.getPercent())
		{
			bn.printPercent(user.getRound());
		}
					
		else 
		{
		    bn.printNumber(user.getRound());
		}

		if (user.getShowDigits() && stats==true)
		{
			cout << endl;
			cout << "Digits: ";
			if (bn<1 && bn > -1 && bn != 0)
				cout << actualDigits - 1;

			else cout << actualDigits;

			cout << "\nDecimal places: " << bn.getDecimalCount();
			cout << "\nBase: " << bn.getBase();
		}
	}
}
예제 #2
0
void validator::validate(const settings& s) {
    if (s.modeling().target().empty()) {
        BOOST_LOG_SEV(lg, error) << missing_target;
        BOOST_THROW_EXCEPTION(configuration_error(missing_target));
    }

    const auto cpp(s.cpp());
    if (cpp.split_project()) {
        if (cpp.include_directory().empty() || cpp.source_directory().empty()) {
            BOOST_LOG_SEV(lg, error) << missing_source_include;
            BOOST_THROW_EXCEPTION(configuration_error(missing_source_include));
        }

        if (!cpp.project_directory().empty()) {
            BOOST_LOG_SEV(lg, error) << unexpected_project_dir;
            BOOST_THROW_EXCEPTION(configuration_error(unexpected_project_dir));
        }
    } else {
        if (!cpp.include_directory().empty() || !cpp.source_directory().empty()) {
            BOOST_LOG_SEV(lg, error) << unexpected_source_include;
            BOOST_THROW_EXCEPTION(configuration_error(unexpected_source_include));
        }

        if (cpp.project_directory().empty()) {
            BOOST_LOG_SEV(lg, error) << missing_project_dir;
            BOOST_THROW_EXCEPTION(configuration_error(missing_project_dir));
        }
    }
}
예제 #3
0
channel::channel(threadpool& pool, asio::socket_ptr socket,
    const settings& settings)
  : proxy(pool, socket, settings.identifier),
    nonce_(0),
    version_({ 0 }),
    located_start_(null_hash),
    located_stop_(null_hash),
    revival_handler_(nullptr),
    expiration_(alarm(pool, pseudo_randomize(settings.channel_expiration()))),
    inactivity_(alarm(pool, settings.channel_inactivity())),
    revival_(alarm(pool, settings.channel_revival())),
    CONSTRUCT_TRACK(channel, LOG_NETWORK)
{
}
예제 #4
0
//
// Loop() - for the NXT-RobotC pesonality, a message is sent out for each
//		loop through the Arduino code.  The message is simply the
//		appropriately formatted BT message with the translation of
//		the Gamepads and inclusion of the button.
//
void Personality_0::Loop(BT *bt, Gamepad *g1, Gamepad *g2)
{
     byte	msgbuff[64];	// max size of a BT message
     int	size;

     // if we're not connected to Bluetooth, then ingore the loop
     if (!bt->connected()) {
          enabled = false;
	  if (isMatchActive()){
	    MatchReset();
	  }
	  return;
     }
       
     // only deal with matchmode when it is active

     if (isMatchActive()){
	     MatchLoopProcess((void *)bt);	// mode is set in the match callback above
     } else {
	     mode = myEEPROM.getMode();		// mode is set by the EEPROM setting
     }

     // first convert the gamepad data and button to the robotC structure
     size = robotcTranslate(msgbuff,enabled,g1,g2, mode);

     // then compose a NXT mailbox message (for BT transport) with that data
     // this routine operates within the given buffer.  Note that the
     // mailbox used is #0.
     size = nxtBTMailboxMsgCompose(0,msgbuff,size);

     // then send it over BT, again, operating on the message buffer
     (void)bt->btWrite(msgbuff,size);
}
예제 #5
0
QString filestuff::mcDir()
{
    QString result = st.read("general", "mcdir", "none").toString();
    if (result == "none")
    {
        QString os = getOS();
        if (os == "Win"){
            result = QDir::homePath() + "/appdata/roaming/.minecraft";
        } else if (os == "Mac") {
            result = QDir::homePath() + "/Library/Application Support/minecraft";
        } else if (os == "Linux") {
            result = QDir::homePath() + "/.minecraft";
        }
    }
    st.write("general", "mcdir", result);
    return result;
}
예제 #6
0
void
ssl_context::init(settings const &s) {

	context_.set_options(asio::ssl::context::default_workarounds);

	std::string cacert = s.ssl_cacert_file_name();
	if (!cacert.empty()) {
		context_.load_verify_file(cacert.c_str());
	}

	std::string cert = s.ssl_cert_file_name();
	if (!cert.empty()) {
		//context_.use_certificate_file(cert.c_str(), asio::ssl::context::pem);
		context_.use_certificate_chain_file(cert.c_str());
		context_.use_private_key_file(cert.c_str(), asio::ssl::context::pem);
	}
}
예제 #7
0
void
threaded_listener::init(settings const &s) {
	if (!empty()) {
		boost::function<void()> f = boost::bind(&threaded_listener::thread_func, this);
		unsigned short threads = s.listener_threads();
		for (unsigned short i = 0; i < threads; ++i) {
			create_thread(f);
		}
	}
}
예제 #8
0
void protocol_ping::start(const settings& settings)
{
    protocol_timer::start(settings.channel_heartbeat(),
        BIND1(send_ping, _1));

    SUBSCRIBE2(ping, handle_receive_ping, _1, _2);

    // Send initial ping message by simulating first heartbeat.
    set_event(error::success);
}
예제 #9
0
QString filestuff::appDir()
{
    QString result = st.read("general", "appdir", "none").toString();
    if (result == "none")
    {
        QString os = getOS();
        if (os == "Win"){
            result = QDir::homePath() + "/appdata/roaming/MCMx";
        } else if (os == "Mac") {
            result = QDir::homePath() + "/Library/Application Support/MCMx";
        } else if (os == "Linux") {
            result = QDir::homePath() + "/.MCMx";
        }
    }
    exMake(result);
    exMake(result + "/backups");
    st.write("general", "appdir", result);
    return result;
}
예제 #10
0
파일: VDIP.cpp 프로젝트: ChapResearch/ChapR
void VDIP::processNXT(portConfig *portConfigBuffer)
{
	  char *name;
	  char *btAddress;
	  long	freeMemory;
          extern BT bt;
          if (myEEPROM.getResetStatus() == (byte) 0){
	    if(nxtQueryDevice(this,portConfigBuffer->usbDev,&name,&btAddress,&freeMemory)){
//	      Serial.print("btAddress: \"");
//	      Serial.print(btAddress);
//	      Serial.print("\"");
              bt.setRemoteAddress(btAddress);
              delay(100);
//	      Serial.print(myEEPROM.getResetStatus());
              myEEPROM.setResetStatus(1); // increments the "status" so that the ChapR knows it has been reset
//	      Serial.print(myEEPROM.getResetStatus());

              delay(1000);
              software_Reset();
            }
          }    
}
예제 #11
0
void
threaded_listener::init(settings const &s) {
    if (!empty()) {
        unsigned short threads = s.listener_threads();
        if (!threads) {
            threads = 1;
        }
        for (unsigned int i = 0; i < threads; ++i) {
            items_.push_back(boost::shared_ptr<queue_type>(new queue_type()));
            boost::function<void()> f = boost::bind(&threaded_listener::thread_func, this, i);
            create_thread(f);
        }
    }
}
예제 #12
0
void protocol_version::start(const settings& settings, size_t height,
                             event_handler handler)
{
    const auto self = template_factory(authority(), settings, nonce(), height);

    // The synchronizer is the only object that is aware of completion.
    const auto handshake_complete =
        BIND2(handle_handshake_complete, _1, handler);

    protocol_timer::start(settings.channel_handshake(),
                          synchronize(handshake_complete, 3, NAME));

    SUBSCRIBE2(version, handle_receive_version, _1, _2);
    SUBSCRIBE2(verack, handle_receive_verack, _1, _2);
    SEND1(self, handle_version_sent, _1);
}
예제 #13
0
파일: menus.cpp 프로젝트: HybridAir/pndt_v1
void menus::doItem() {
    switch(activeItem) {
        case 0:
            mTime.doMenu(currentBtn);
            break;
        case 1:
            setMenu();          //reserved
            break;
        case 2:
            mAbout.doMenu(currentBtn);
            break;
        case 3:
            setMenu();
            set.setMenu();
            break;
    }
}
예제 #14
0
파일: main.cpp 프로젝트: eindacor/utilities
bigNumber numberFromVector(vector<int> &vec, bool neg, int dec, settings &user)
{
	bigNumber temp;
	temp.setBase(user.getBase());

	for (int i=0; i<vec.size(); i++)
	{
		int numberToUse = vec.at(vec.size()-i-1);
		int locationToSet = PRECISION + i;
		temp.setDigit(locationToSet, numberToUse);
	}
	
	if (neg)
		temp.setNegative();

	temp.divideByTen(dec);

	return temp;
}
예제 #15
0
파일: main.cpp 프로젝트: eindacor/utilities
solution solve(string &c, bigNumber previous, settings &user)
{
    c += '$';
    PTYPE pType=ERROR;
    
    vector<int> first;
    vector<int> second;
    bigNumber bn1;
    bigNumber bn2;
    bigNumber temp;
    
    bn1.setBase(user.getBase());
    bn2.setBase(user.getBase());
    temp.setBase(user.getBase());

    int decimalCount1=0;
    int decimalCount2=0;
    int commaNumbers=0;
    int numbers=0;

    bool decimal=false;
	bool comma=false;
	bool negative1=false;
	bool negative2=false;
    bool done=false;
	bool printExact=false;
	bool printStats=false;

    bigNumber* targetBN = &bn1;
    vector<int>* targetVec = &first;
    int* targetDec = &decimalCount1;
	bool* targetNegative = &negative1;
    
    int counter = c.size();
    
    for (int i=0; i<counter; i++)
    {
        if (checkWord(c, i, "pi"))
        {
            if (numbers>0 || comma==true || decimal==true)
            {
                RETURN_ERROR;
            }
            
            else
            {
                string piString(PI);
		
				for (int piMarker=PRECISION; piMarker>=0; piMarker--)
				{
					char piChar = '0';
					int piNum = piString[PRECISION-piMarker] - piChar;
				
					(*targetVec).push_back(piNum);
				}
                
                done=true;
				*targetDec = PRECISION;
                
                numbers += (PRECISION+1);
                counter += 2;
                i += 2;
            }
        }
        
        if (checkWord(c, i, "theta"))
        {
            if (numbers>0 || comma==true || decimal==true)
            {
                RETURN_ERROR;
            }
            
            else
            {
                string thetaString(THETA);
		
				for (int thetaMarker=PRECISION; thetaMarker>=0; thetaMarker--)
				{
					char thetaChar = '0';
					int thetaNum = thetaString[PRECISION-thetaMarker] - thetaChar;
				
					(*targetVec).push_back(thetaNum);
				}
                
                done=true;
				*targetDec = PRECISION;
                
                numbers += (PRECISION+1);
                counter += 5;
                i += 5;
            }
        }
        
		//if it isn't a space, number, symbol, end marker, or decimal point, return error
		if (checkSpace(c[i])==false && 
			isNumber(c[i], user)==false && 
			isSymbol(c[i])==false && 
			c[i] != '$' && 
			c[i] != ',' && 
			c[i] != '.')
		{
			RETURN_ERROR;
		}

		if (c[i]==',')
		{
			if (comma==false)
			{
				if (decimal==true || numbers==0 || numbers > 3 || done==true)
					RETURN_ERROR;

				else comma = true;
			}

			else if (commaNumbers != 3)
			    RETURN_ERROR;
			    
			commaNumbers=0;    
		}
			
		//if it's a space
		else if (checkSpace(c[i])==true)
		{
			//if it's preceeded by a number, number is complete
			if (isNumber(c[i-1], user))
		    {
		        done = true;
		    }
		    
		    //if negative is set, and it is preceeded by a minus symbol, return error
		    else if (checkSymbol(c[i-1]) == SUBTRACT && *targetNegative == true)
		    {
		        RETURN_ERROR;
		    }
		}

        //if it's a number
        else if (isNumber(c[i], user))
        {        
            //if number was complete, return error
            if (done==true)
			{
                RETURN_ERROR;
			}
			
		    if (comma==true)
		        commaNumbers++;
                
            //otherwise add number to target vector, add decimal count if needed
            (*targetVec).push_back(checkNumber(c[i]));
                numbers++;
                
            if (decimal==true)
			{
                (*targetDec)++;
			}
        }
        
        //if it's a minus symbol
        else if (checkSymbol(c[i]) == SUBTRACT)
        {
            //if no numbers have been added
            if (numbers==0)
            {
                //if target isn't negative, make target negative
                if ((*targetNegative)==false)
                {
                    (*targetNegative) = true;
                    (*targetBN).setNegative();
                }
                
                //if target is negative, no numbers have been added, and the target is the first number: 
				//there are two minus symbols, which means the intent is to 
				//subtract a negative number from previous
                else if (targetBN == &bn1)
                {
                    pType = SUBTRACT;
                    targetBN = &bn2;
                    numbers=0;
					commaNumbers=0;
					comma=false;
                    bn2.setNegative(); //sets 2nd number to negative
					negative2=true; //sets 2nd number to negative
                    targetNegative= &negative2;
                    done=false;
                    targetDec = &decimalCount2;
                    targetVec = &second;
                    decimal=false;
                }
                
                else 
				{
					RETURN_ERROR;
				}
            }
            
            //if numbers have been added, and the target is the first number, the problem type is subtraction
            else if (targetBN == &bn1)
            {
                if (comma==true && decimal==false && commaNumbers != 3)
                    RETURN_ERROR;
                
                pType = SUBTRACT;
                numbers=0;
				commaNumbers=0;
				comma=false;
                done=false;
                targetBN = &bn2;
				targetNegative= &negative2;
                targetDec = &decimalCount2;
                targetVec = &second;
                decimal=false;
            }
            
            //if numbers have been added, and the target is the second number, return error
            else 
			{
				RETURN_ERROR;
			}
        }
        
        //if it's a symbol other than minus
        else if (checkSymbol(c[i]) != ERROR && checkSymbol(c[i]) != SUBTRACT)
        {
            //if the type is already established, return error
            if (pType != ERROR)
			{
            	RETURN_ERROR;
			}
                
            //otherwise, set problem type based on symbol and reset figures
            else 
            {
                if (comma==true && decimal==false && commaNumbers != 3)
                    RETURN_ERROR;
                
                pType = checkSymbol(c[i]);
                targetBN = &bn2;
                numbers=0;
				commaNumbers=0;
				comma=false;
                done=false;
				targetNegative = &negative2;
                targetDec = &decimalCount2;
                targetVec = &second;
                decimal=false;
            }
        }
        
        //if it's a decimal point
        else if (c[i]=='.')
        {
            //if there's already been a decimal point, return error
            if (decimal==true)
			{
                RETURN_ERROR;
			}
                
            else decimal = true;
            
            if (comma==true && commaNumbers != 3)
                RETURN_ERROR;
        }
        
        //if it's an endline character
        else if (c[i] == '$')
        {
            if (comma==true && decimal==false && commaNumbers != 3)
                    RETURN_ERROR;
                    
			//if both numbers are empty
			if (first.size()==0 && second.size()==0)
			{
				if (pType==FACTORIAL)
				{
					bn1 = previous;
				}

				else RETURN_ERROR;
			}

			//if first number is empty, set bn1 to previous
			if (first.size()==0)
			{
				bn1 = previous;
			}

			//otherwise create bn1 from entered and print it as is
            else
            {   
				bn1 = numberFromVector(first, negative1, decimalCount1, user);
				printExact=true;
            }
            
            //if second number is empty
            if (second.size()==0)
            {               
                //if first number is negative and pType is undefined, subtract number from previous
                if (negative1==true && pType == ERROR)
                {
					bn1.setPositive();
                    temp = previous - bn1;

					cout << "Entered: "; 
					displayNumber(previous, user, false, false);
					cout << " - "; 
					displayNumber(bn1, user, true, false);

					RETURN_OK(temp);
					//return solution(temp, 0);
                }
                
                //if first number isn't negative and no problem type has been declared, return that number
                else if (pType == ERROR)
                {
					cout << "Entered: "; 
					displayNumber(bn1, user, true, false);
					RETURN_OK(bn1);
                    //return solution(bn1, 0);
                }
               
                else if (pType != FACTORIAL)
                {
                    RETURN_ERROR;
                }
            }
                
            //otherwise take ints from second vector and use to set bigNumber2
            else 
            {
                bn2 = numberFromVector(second, negative2, decimalCount2, user);
            }

			cout << "Entered: ";
			displayNumber(bn1, user, printExact, printStats);
			
			break;
        }
    }
    
    //use problem type to calculate solution, return with no errors if valid
    switch(pType)
    {
        case ERROR: RETURN_ERROR;
        
        case ADD: cout << " + "; bn2.printNumber();
            temp = bn1 + bn2;
			RETURN_OK(temp);
        
        case SUBTRACT: cout << " - "; bn2.printNumber();
			temp = bn1 - bn2;
			RETURN_OK(temp);
                
        case MULTIPLY: cout << " * "; bn2.printNumber();
			temp = bn1 * bn2;
			RETURN_OK(temp);
                
        case DIVIDE: cout << " / "; bn2.printNumber();
            if (bn2==0)
            {
                RETURN_ERROR;
            }
            temp = bn1 / bn2;
			RETURN_OK(temp);
                
        case FACTORIAL: 
			if (bn1<0 || bn1.getDecimalCount() > 0)
            {
				RETURN_ERROR;
            }
            
            else if (bn1==0)
            {
				cout << "!";
				bigNumber fact(1);
				fact.setBase(user.getBase());
				RETURN_OK(fact);
            }
            
            temp = bigNumber::factorial(bn1);
			cout << "!";
			RETURN_OK(temp);    
           
        case EXPONENT: cout << "^"; bn2.printNumber();
			temp = bigNumber::exponent(bn1, bn2);
			RETURN_OK(temp);
        
        case ITERATION: cout << "c"; bn2.printNumber();
			temp = bigNumber::iterations(bn1, bn2);
			RETURN_OK(temp);
        
        default: RETURN_ERROR;
    }

}
예제 #16
0
파일: VDIP.cpp 프로젝트: ChapResearch/ChapR
void VDIP::ejectNXT()
{  
     myEEPROM.setResetStatus(0);
}
예제 #17
0
파일: main.cpp 프로젝트: eindacor/utilities
void modifySettings(settings &user)
{
    cout << endl;
    string setI;
    string setS;
    bool invalid=false;
    int intSet=0;
    
    do
    {
		intSet=0;
        invalid=false;
        setI.clear();
        
        cout << "Enter desired precision: ";
        std::getline(cin, setI);
        
        for (int i=0; i<setI.size(); i++)
        {
			int target = setI.size()-i-1;
			
            if (checkNumber(setI[target]) < 0 || checkNumber(setI[target]) > 9)
            {
                cout << "Invalid entry" << endl << endl;
                invalid=true;
                break;
            }
            
            else intSet += (checkNumber(setI[target]) * pow(10, i));
        }
        
        if (invalid==false)
        {
            if (intSet>PRECISION)
            {
                cout << "Invalid entry (precision must be between 0 and " << PRECISION << ")" << endl << endl;
                invalid=true;
            }
            
            else 
            {
                user.setRound(intSet);
            }
        }
    } while (invalid==true);
    
    do
    {
		intSet=0;
        invalid=false;
        setI.clear();
        
        cout << "Enter desired base: ";
        std::getline(cin, setI);
        
        for (int i=0; i<setI.size(); i++)
        {
			int target = setI.size()-i-1;
			
            if (checkNumber(setI[target]) < 0 || checkNumber(setI[target]) > 9 )
            {
                cout << "Invalid entry" << endl << endl;
                invalid=true;
                break;
            }
            
            else intSet += (checkNumber(setI[target]) * pow(10, i));
        }
    
        
        if (invalid==false)
        {
            if (intSet < 2 || intSet > 36)
            {
                cout << "Invalid entry (base must be between 2 and 36)" << endl << endl;
                invalid=true;
            }
            
            else 
            {
                user.setBase(intSet);
            }
        }
        
    } while (invalid==true);
    
    for (;;)
    {
      
        if (user.getPercent())
        {
            setS.clear();
            cout << "Turn off percentages? ";
            std::getline(cin, setS);
            
            if (setS=="yes" || setS=="y")
            {
                user.percentOff();
                break;
            }
            
            else if (setS=="no" || setS=="n")
            {
                break;
            }
            
            else
            {
                cout << "Invalid entry" << endl << endl;
                continue;
            }
        }
        
        else
        {
            setS.clear();
            cout << "Turn on percentages? ";
            std::getline(cin, setS);
            
            if (setS=="yes" || setS=="y")
            {
                user.percentOn();
                break;
            }
            
            else if (setS=="no" || setS=="n")
            {
                break;
            }
            
            else
            {
                cout << "Invalid entry" << endl << endl;
                continue;
            }
        }
    }

	for (;;)
    {
        setS.clear();
      
        if (user.getShowDigits())
        {
            cout << "Hide number stats? ";
            std::getline(cin, setS);
            
            if (setS=="yes" || setS=="y")
            {
                user.showDigitsOff();
                break;
            }
            
            else if (setS=="no" || setS=="n")
            {
                break;
            }
            
            else
            {
                cout << "Invalid entry" << endl << endl;
                continue;
            }
        }
        
        else
        {
            cout << "Show number stats? ";
            std::getline(cin, setS);
            
            if (setS=="yes" || setS=="y")
            {
                user.showDigitsOn();
                break;
            }
            
            else if (setS=="no" || setS=="n")
            {
                break;
            }
            
            else
            {
                cout << "Invalid entry" << endl << endl;
                continue;
            }
        }
    }
    
    cout << endl << endl;
}
예제 #18
0
파일: VDIP.cpp 프로젝트: ChapResearch/ChapR
//
// processDisk() - called when a disk is discovered and properly located
//                 on P2.  This routine does everything that the Chapr can
//                 do with a flash drive, like update the name of the Chapr.
//
void VDIP::processDisk(portConfig *portConfigBuffer)
{    
     char buf[BIGENOUGH];

     // check that it's in port two (beep annoyingly otherwise)

     if(portConfigBuffer->port == 1) {

       // read through VDIP stuff looking for a text file with the name, personality etc.

       // PLEASE NOTE -- FILE NAMES MUST BE FEWER THAN 8 CHARACTERS

       // get the new name of the ChapR

       if(readFile("name.txt", buf, BIGENOUGH)){
         if (buf[EEPROM_NAMELENGTH - 1] == '\0'){
           myEEPROM.setName(buf);
         }
       }

       // get the new personality

       if(readFile("person.txt", buf, BIGENOUGH)){
         byte newNum = (byte) atoi(buf);
         if (newNum > 0 && newNum <= EEPROM_LASTPERSON){
           myEEPROM.setPersonality(newNum);
         }
       }

       // get the power-down timeout

       if(readFile("timeout.txt", buf, BIGENOUGH)){
         byte newNum = (byte) atoi(buf);
         if (newNum >= 0 && newNum <= EEPROM_MAXTIMEOUT){
         myEEPROM.setTimeout(newNum);
         }
       }

       // get the lag time

       if(readFile("lag.txt", buf, BIGENOUGH)){
         byte newNum = (byte) atoi(buf);
         if (newNum >= 0 && newNum <= EEPROM_MAXLAG){
         myEEPROM.setSpeed(newNum);
         }
       }

       // get the user mode

       if(readFile("mode.txt", buf, BIGENOUGH)){
         byte newNum = (byte) atoi(buf);
         if (newNum >= 0 && newNum <= EEPROM_MAXMODE){
         myEEPROM.setMode(newNum);
         }
       }
       
       // allows user to determine number of seconds in autonomous, teleOp and endgame (ChapR3 of EEPROM)
       // zero for either mode skips the mode

       if(readFile("mConfig.txt",buf, BIGENOUGH)){
	 char *ptr = buf;
	 for (int i = 0; i < 3; i++){
	   switch(i){
	   case 0: myEEPROM.setAutoLen(atoi(ptr));break;
	   case 1: myEEPROM.setTeleLen(atoi(ptr));break;
	   case 2: myEEPROM.setEndLen(atoi(ptr));break;
	   }
	   while (*ptr != '\r' && *ptr != '\0' && *ptr != '\n'){
	     ptr++;
	   }
	   while (*ptr == '\r' && *ptr == '\n'){
	     ptr++;
	   }
	   if (*ptr == '\0'){
	     break;
	   }
	 }
       }
     

       // contains the settings for the digital I/O pins (for FRC, aka ChapR3 of EEPROM)
     
       if (readFile("dgtlIn.txt", buf, BIGENOUGH)){
	 byte newNum = 0;
	 
	 for (int i = 0, ptr = 0; i < 8; i++){
	   byte bit = (buf[ptr] == '1')?1:0;
	   newNum |= bit<<i;
	   while (buf[ptr] != '\r' && buf[ptr] != '\0' && buf[ptr] != '\n'){
	     ptr++;
	   }
	   while (buf[ptr] == '\r' || buf[ptr] == '\n'){
	     ptr++;
	   }
	   if (buf[ptr] == '\0'){
	     break;
	   }
	 }
	 
	 myEEPROM.setDigitalInputs(newNum);
       }

       // contains the 4 analog inputs (for FRC, aka ChapR3 of EEPROM)
       
       if (readFile("analogIn.txt", buf, BIGENOUGH)){
	 char *ptr = buf;
	 for (int i = 0; i < 4; i++){
	   double value = atof(ptr);
	   if (value > 0 && value <= 5) {
	     value = (value*1023)/5;
		// TODO - translate to labview preferences here
		switch(i) {
		case 0:		myEEPROM.setAnalogInput1(value); break;
		case 1:		myEEPROM.setAnalogInput2(value); break;
		case 2:		myEEPROM.setAnalogInput3(value); break;
		case 3:		myEEPROM.setAnalogInput4(value); break;
		}
	   }
	   while (*ptr != '\r' && *ptr != '\0' && *ptr != '\n'){
	     ptr++;
	   }
	   while (*ptr == '\r' || *ptr == '\n'){
	     ptr++;
	   }
	   if (*ptr == '\0'){
	     break;
	   }
	 }
       }

       // get a target bluetooth connection name/ID AND connect if it is there
       // this MAY need to be changed to do the connection AFTER getting
       // done with the flash drive.  Note that this data IS NOT stored in
       // the EEPROM - instead, it is just used as the current paired device
       // and will be reset (like normal) whenever a new pairing is done.

       extern BT bt;

       if(readFile("targetID.txt", buf, BIGENOUGH,true)){
	    if (bt.addressFilter(buf,BIGENOUGH)) {	// useful address?
		 bt.setRemoteAddress(buf);
		 delay(100);
	    }
       }

// TODO: make target.txt work - it should take a NAME and find the BT ID for it

       if(readFile("target.txt", buf, BIGENOUGH,true)){
//	    Serial.print("target: \"");
//	    Serial.print(buf);
//	    Serial.println("\"");
//	    if(bt.nameToAddress(buf)) {
//		 bt.setRemoteAddress(buf);
//		 delay(100);
//	    }
       }

       // the confirm beep indicates that all files that existed were read
       // it doesn't confirm that all data was cool

       beeper.confirm();			 

     } else {

       // the disk was put in the wrong USB port!

       beeper.icky();

     } 
}
예제 #19
0
파일: note_sequence.hpp 프로젝트: bnkr/tune
    note_sequence(settings &set) {
      if (set.note_mode() == settings::note_mode_list) {
        impl_.reset(new detail::listed_sqeuence(
              set.concert_pitch(),
              set.note_list().begin(), set.note_list().end(),
              set.note_list().size()));
      }
      else {
        assert(set.note_mode() == settings::note_mode_start);
        trc("using a start note and distance");
        int start_offset = parse_note(set.start_note().c_str());

        int stop_offset;
        if (! set.end_note().empty()) {
          stop_offset = parse_note(set.end_note().c_str());
        }
        else if (set.num_notes() >= 0) {
          stop_offset = start_offset + set.num_notes() * set.note_distance();
        }
        else {
          stop_offset = start_offset + 12;
        }

        int step = set.note_distance();
        if (start_offset > stop_offset && step > 0) {
          std::cerr << "warning: making the step negative since the end note is lower than the start note." << std::endl;
          step = -step;
        }
        else if (start_offset < stop_offset && step < 0) {
          std::cerr << "warning: making the step positive since the end note is higher than the start note." << std::endl;
          step = -step;
        }

        trc("start: " << start_offset);
        trc("stop:  " << stop_offset);
        trc("step:  " << step);

        impl_.reset(
          new detail::generated_sequence(
            set.concert_pitch(), start_offset, stop_offset, step
          )
        );
        trc("done");
        assert(impl_.get());
      }
    }
예제 #20
0
파일: main.cpp 프로젝트: eindacor/utilities
bool isNumber(char const &c, settings &user)
{
	return (checkNumber(c) >= 0 && checkNumber(c) <= (user.getBase()-1) );
}
예제 #21
0
파일: elector_test.cpp 프로젝트: gsson/koi
#include "nexus.hpp"
#include <boost/uuid/uuid_generators.hpp>

namespace koi {
	struct masterstate;
};

TEST_CASE("elector/promote", "test successful node promotion") {
	using namespace koi;
	using namespace std;
	using namespace boost;
	using namespace boost::posix_time;

	std::vector<std::string> configs;
	configs << "../test/test.conf";
	settings cfg;
	char app[] = "koi";
	char* argv[1] = { app };
	bool ok = cfg.boot(configs, false);
	REQUIRE(ok);

	net::io_service io_service;

	nexus ro(io_service, cfg);

	elector a(ro);
	ok = a.init(microsec_clock::universal_time());
	REQUIRE(ok);

	a.start();
예제 #22
0
파일: main.cpp 프로젝트: eindacor/utilities
bool changeBase(string &c, settings &user)
{
	if (c == "base 2" || c == "base2" || c == "binary")
	{
		user.setBase(2);
		return true;
	}
	
	if (c == "base 3" || c == "base3" || c == "ternary")
	{
		user.setBase(3);
		return true;
	}

	if (c == "base 4" || c == "base4" || c == "quaternary")
	{
		user.setBase(4);
		return true;
	}

	if (c == "base 5" || c == "base5" || c == "quinary")
	{
		user.setBase(5);
		return true;
	}

	if (c == "base 6" || c == "base6" || c == "senary")
	{
		user.setBase(6);
		return true;
	}

	if (c == "base 7" || c == "base7" || c == "septenary")
	{
		user.setBase(7);
		return true;
	}

	if (c == "base 8" || c == "base8" || c == "octonary")
	{
		user.setBase(8);
		return true;
	}

	if (c == "base 9" || c == "base9" || c == "nonary")
	{
		user.setBase(9);
		return true;
	}

	if (c == "base 10" || c == "base10" || c == "decimal")
	{
		user.setBase(10);
		return true;
	}

	if (c == "base 11" || c == "base11" || c == "undenary")
	{
		user.setBase(11);
		return true;
	}

	if (c == "base 12" || c == "base12" || c == "dozenal" || c == "duodecimal")
	{
		user.setBase(12);
		return true;
	}

	if (c == "base 13" || c == "base13" || c == "tridecimal")
	{
		user.setBase(13);
		return true;
	}

	if (c == "base 14" || c == "base14" || c == "quattuordecimal")
	{
		user.setBase(14);
		return true;
	}

	if (c == "base 15" || c == "base15" || c == "quindecimal")
	{
		user.setBase(15);
		return true;
	}

	if (c == "base 16" || c == "base16" || c == "sexadecimal" || c == "hexadecimal")
	{
		user.setBase(16);
		return true;
	}

	if (c == "base 17" || c == "base17" || c == "septendecimal")
	{
		user.setBase(17);
		return true;
	}

	if (c == "base 18" || c == "base18" || c == "octodecimal")
	{
		user.setBase(18);
		return true;
	}

	if (c == "base 19" || c == "base19" || c == "nonadecimal")
	{
		user.setBase(19);
		return true;
	}

	if (c == "base 20" || c == "base20" || c == "vigesimal")
	{
		user.setBase(20);
		return true;
	}

	if (c == "base 21" || c == "base21")
	{
		user.setBase(21);
		return true;
	}

	if (c == "base 22" || c == "base22")
	{
		user.setBase(22);
		return true;
	}

	if (c == "base 23" || c == "base23")
	{
		user.setBase(23);
		return true;
	}

	if (c == "base 24" || c == "base24")
	{
		user.setBase(24);
		return true;
	}

	if (c == "base 25" || c == "base25")
	{
		user.setBase(25);
		return true;
	}

	if (c == "base 26" || c == "base26")
	{
		user.setBase(26);
		return true;
	}

	if (c == "base 27" || c == "base27")
	{
		user.setBase(27);
		return true;
	}

	if (c == "base 28" || c == "base28")
	{
		user.setBase(28);
		return true;
	}

	if (c == "base 29" || c == "base29")
	{
		user.setBase(29);
		return true;
	}

	if (c == "base 30" || c == "base30")
	{
		user.setBase(30);
		return true;
	}

	if (c == "base 31" || c == "base31")
	{
		user.setBase(31);
		return true;
	}

	if (c == "base 32" || c == "base32")
	{
		user.setBase(32);
		return true;
	}

	if (c == "base 33" || c == "base33")
	{
		user.setBase(33);
		return true;
	}

	if (c == "base 34" || c == "base34")
	{
		user.setBase(34);
		return true;
	}

	if (c == "base 35" || c == "base35")
	{
		user.setBase(35);
		return true;
	}

	if (c == "base 36" || c == "base36")
	{
		user.setBase(36);
		return true;
	}

	return false;
}
예제 #23
0
int make_wu_headers(tapeheader_t tapeheader[],workunit wuheader[],
                    buffer_pos_t *start_of_wu) {
  int procid=getpid();
  int i,j,startframe=start_of_wu->frame;
  double receiver_freq;
  int bandno;
  SCOPE_STRING *lastpos;
  FILE *tmpfile;
  char tmpstr[256];
  char buf[64];
  static int HaveConfigTable=0;
  static ReceiverConfig_t ReceiverConfig;   
  static receiver_config r;
  static settings s;

  if(!HaveConfigTable) {
    sprintf(buf,"where s4_id=%d",gregorian?AOGREG_1420:AO_1420);
    r.fetch(std::string(buf));
    ReceiverConfig.ReceiverID=r.s4_id;
    strlcpy(ReceiverConfig.ReceiverName,r.name,
           sizeof(ReceiverConfig.ReceiverName));
    ReceiverConfig.Latitude=r.latitude;
    ReceiverConfig.Longitude=r.longitude;
    ReceiverConfig.WLongitude=-r.longitude;
    ReceiverConfig.Elevation=r.elevation;
    ReceiverConfig.Diameter=r.diameter;
    ReceiverConfig.BeamWidth=r.beam_width;
    ReceiverConfig.CenterFreq=r.center_freq;
    ReceiverConfig.AzOrientation=r.az_orientation;
    for (i=0;i<(sizeof(ReceiverConfig.ZenCorrCoeff)/sizeof(ReceiverConfig.ZenCorrCoeff[0]));i++) {
      ReceiverConfig.ZenCorrCoeff[i]=r.zen_corr_coeff[i];
      ReceiverConfig.AzCorrCoeff[i]=r.az_corr_coeff[i];
    }
    HaveConfigTable=1;
  }
  sprintf(buf,"where active=%d",app.id);
  if (!s.fetch(std::string(buf))) {
    log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"Unable to find active settings for app.id=%d\n",app.id);
    exit(1);
  }
  if (s.receiver_cfg->id != r.id) {
    log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"Receiver config does not match settings (%d != %d)\n",s.receiver_cfg->id, r.id);
    exit(1);
  }
  s.recorder_cfg->fetch();
  s.splitter_cfg->fetch();
  s.analysis_cfg->fetch();
  if (!strncmp(s.splitter_cfg->data_type,"encoded",
     std::min(static_cast<size_t>(7),sizeof(s.splitter_cfg->data_type)))) {
    noencode=0;
  } else {
      noencode=1;
  }

  workunit_grp wugrp;
  sprintf(wugrp.name,"%s.%ld.%d.%ld.%d",tapeheader[startframe].name,
    procid, 
    (current_record-TAPE_RECORDS_IN_BUFFER)*8+startframe,
    start_of_wu->byte,s.id);
  wugrp.receiver_cfg=r;
  wugrp.recorder_cfg=s.recorder_cfg;
  wugrp.splitter_cfg=s.splitter_cfg;
  wugrp.analysis_cfg=s.analysis_cfg;

  wugrp.data_desc.start_ra=tapeheader[startframe+1].telstr.ra;
  wugrp.data_desc.start_dec=tapeheader[startframe+1].telstr.dec;
  wugrp.data_desc.end_ra=tapeheader[startframe+TAPE_FRAMES_PER_WU].telstr.ra;
  wugrp.data_desc.end_dec=tapeheader[startframe+TAPE_FRAMES_PER_WU].telstr.dec;
  wugrp.data_desc.nsamples=NSAMPLES;
  wugrp.data_desc.true_angle_range=0;
  {
    double sample_rate=tapeheader[startframe].samplerate/NSTRIPS;
    /* startframe+1 contains the first valid RA and Dec */
    TIME st=tapeheader[startframe+1].telstr.st;
    TIME et=tapeheader[startframe+TAPE_FRAMES_PER_WU].telstr.st;
    double diff=(et-st).jd*86400.0;
    for (j=2;j<TAPE_FRAMES_PER_WU;j++) {
      wugrp.data_desc.true_angle_range+=angdist(tapeheader[startframe+j-1].telstr,tapeheader[startframe+j].telstr);
    }
    wugrp.data_desc.true_angle_range*=(double)wugrp.data_desc.nsamples/(double)sample_rate/diff;
    if (wugrp.data_desc.true_angle_range==0) wugrp.data_desc.true_angle_range=1e-10;
  }
  // Calculate the number of unique signals that could be found in a workunit.
  // We will use these numbers to calculate thresholds.
  double numgauss=2.36368e+08/wugrp.data_desc.true_angle_range;
  double numpulse=std::min(4.52067e+10/wugrp.data_desc.true_angle_range,2.00382e+11);
  double numtrip=std::min(3.25215e+12/wugrp.data_desc.true_angle_range,1.44774e+13);

  

  // Calculate a unique key to describe this analysis config.
  long keyuniq=floor(std::min(wugrp.data_desc.true_angle_range*100,1000.0)+0.5)+
    s.analysis_cfg.id*1024.0;
  if ((keyuniq>(13*1024)) ||(keyuniq<12*1024)) {
     log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"Invalid keyuniq value!\n");
     log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"%d %d %f\n",keyuniq,s.analysis_cfg.id,wugrp.data_desc.true_angle_range);
     exit(1);
  }

  keyuniq*=-1;
  long save_keyuniq=keyuniq;
  s.analysis_cfg=wugrp.analysis_cfg;
  sprintf(tmpstr,"where keyuniq=%d",keyuniq); 
  // Check if we've already done this analysis_config...
  s.analysis_cfg.id=0;
  s.analysis_cfg->fetch(tmpstr);

  if (s.analysis_cfg->id==0) {
    if (keyuniq != save_keyuniq) {
      log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"keyuniq value changed!\n");
      exit(1);
    }

    // If not calculate the thresholds based upon the input analysis_config
    // Triplets are distributed exponentially...
    wugrp.analysis_cfg->triplet_thresh+=(log(numtrip)-29.0652);

    // Gaussians are based upon chisqr...
    double p_gauss=lcgf(32.0,wugrp.analysis_cfg->gauss_null_chi_sq_thresh*32.0);
    p_gauss-=(log(numgauss)-19.5358);
    wugrp.analysis_cfg->gauss_null_chi_sq_thresh=invert_lcgf(p_gauss,32,1e-4)*0.03125;

    // Pulses thresholds are log of the probability
    wugrp.analysis_cfg->pulse_thresh+=(log(numpulse)-24.7894);

    wugrp.analysis_cfg->keyuniq=keyuniq;
    wugrp.analysis_cfg->insert();
  } else {
    wugrp.analysis_cfg=s.analysis_cfg;
  }

  strlcpy(wugrp.data_desc.time_recorded,
      short_jd_string(tapeheader[startframe+1].telstr.st.jd),
      sizeof(wugrp.data_desc.time_recorded));
  wugrp.data_desc.time_recorded_jd=tapeheader[startframe+1].telstr.st.jd;

  lastpos=&(tapeheader[startframe].telstr);
  coordinate_t tmpcoord;
  tmpcoord.time=tapeheader[startframe].telstr.st.jd;
  tmpcoord.ra=tapeheader[startframe].telstr.ra;
  tmpcoord.dec=tapeheader[startframe].telstr.dec;
  wugrp.data_desc.coords.push_back(tmpcoord);  

  for (j=1;j<TAPE_FRAMES_PER_WU;j++) {
    if ((tapeheader[startframe+j].telstr.st.jd-lastpos->st.jd) > (1.0/86400.0)) 
    {
      lastpos=&(tapeheader[startframe+j].telstr);
      tmpcoord.time=tapeheader[startframe+j].telstr.st.jd;
      tmpcoord.ra=tapeheader[startframe+j].telstr.ra;
      tmpcoord.dec=tapeheader[startframe+j].telstr.dec;
      wugrp.data_desc.coords.push_back(tmpcoord);  
    }
  }

  wugrp.tape_info->id=0;
  wugrp.tape_info->fetch(std::string("where name=\'")+tapeheader[startframe].name+"\'");
  wugrp.tape_info->start_time=tapeheader[startframe].st.jd;
  wugrp.tape_info->last_block_time=tapeheader[startframe].st.jd;
  wugrp.tape_info->last_block_done=tapeheader[startframe].frameseq;

  if (!nodb) {
    if (wugrp.tape_info.id) {
      if (!(wugrp.tape_info->update())) {
        char buf[1024];
        log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"%s",sql_error_message());
	exit(1);
      }
    } else {
      strlcpy(wugrp.tape_info->name,tapeheader[startframe].name,sizeof(wugrp.tape_info->name));
      wugrp.tape_info->insert();
    }
  }

  if (!nodb) wugrp.insert();
  
  for (i=0;i<NSTRIPS;i++) {
    bin_data[i].clear();
    wuheader[i].group_info=wugrp;
    sprintf(wuheader[i].name,"%s.%ld.%d.%ld.%d.%d",tapeheader[startframe].name,
       procid, (current_record-TAPE_RECORDS_IN_BUFFER)*8+startframe,
       start_of_wu->byte,s.id,i);
    wuheader[i].subband_desc.sample_rate=tapeheader[startframe].samplerate/NSTRIPS;
 
    receiver_freq=tapeheader[startframe].centerfreq;

    bandno=((i+NSTRIPS/2)%NSTRIPS)-NSTRIPS/2;

    wuheader[i].subband_desc.base=receiver_freq+
	       (double)(bandno)*wuheader[i].subband_desc.sample_rate;
    wuheader[i].subband_desc.center=receiver_freq+wuheader[i].subband_desc.sample_rate*NSTRIPS*((double)IFFT_LEN*bandno/FFT_LEN+(double)IFFT_LEN/(2*FFT_LEN)-1.0/(2*FFT_LEN));
    wuheader[i].subband_desc.number=i;

    if (!nodb ) {
      if (!(wu_database_id[i]=wuheader[i].insert())) {
        log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"Database error in make_wu_headers()\n");
        exit(EXIT_FAILURE);
      }
    }
	
    sprintf(tmpstr,"./wu_inbox/%s",wuheader[i].name);
    if ((tmpfile=fopen(tmpstr,"w"))) {
      fprintf(tmpfile,"<workunit>\n");
      fprintf(tmpfile,wuheader[i].print_xml().c_str());
      fclose(tmpfile);
    } else {
      log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,"Unable to open file ./wu_inbox/%s, errno=%d\n",wuheader[i].name,errno);
      exit(1);
    }
    bin_data[i].reserve(wuheaders[i].group_info->recorder_cfg->bits_per_sample*
       wuheaders[i].group_info->data_desc.nsamples/8);
  }
  return(1);
}
예제 #24
0
파일: GLHelpers.cpp 프로젝트: KitoHo/rpcs3
	void texture::config(const settings& settings_)
	{
		settings_.apply(*this);
	}
예제 #25
0
 /// Construct object
 /// @param stars A list containing the stars to be put into the tree
 /// @param config A settings object from which all settings will be read
 tree_deflector(const std::vector<star>& stars, const settings& config)
 : _tree(stars, config.get_opening_angle())
 {
 }