Example #1
0
u8 modem_attachtest( u8 *ucBuffer )
{
    PYGMYCOMMAND pygmyCmd;
    u8 *ucParams[ 3 ], ucLen; // *ucSubString1, *ucSubString2, *ucSubString;
    
    ucLen = getAllSubStrings( ucBuffer, ucParams, 3, WHITESPACE|PUNCT|NEWLINE );
    
    if( ucLen >= 3 ){
        if( isStringSame( ucParams[ 0 ], (u8*)AT_SGACT ) && 
            convertStringToInt( ucParams[ 1 ] ) == 1 ){
            if( convertStringToInt( ucParams[ 2 ] ) == 1 ){
                print( MODEM_DEBUG, "\rAttached" );
                return( TRUE ); 
            }else{
                pygmyCmd.Name = (u8*)AT_SGACT;
                pygmyCmd.PrintHandler = print_SGACT1;
                pygmyCmd.EventHandler = handler_ATSGACT;
                pygmyCmd.Expire = 5;
                pygmyCmd.Retry = 1;
                cmdReplace( &globalModemQueue, &pygmyCmd );
                return( 1 ); 
            } // if
        } // else
    } // if

    return( FALSE );
}
Example #2
0
int IP::checkIP(string ipadress) {
	size_t pos = 0, posBefore = 0;
	int tal;

	pos = ipadress.find(".");
	posBefore = pos + 1;
	tal = convertStringToInt(ipadress.substr(0, pos)); //talet i första delen
	if (pos == string::npos || pos > 3 || pos == 0 || tal > 223) // kollar att det finns en punkt och att första delen har en storlek mellan 1-3 (192.168.1.1) OK! (.168.1.1) INTE OK!
		return 0;

	pos = ipadress.find(".", pos + 1);
	tal = convertStringToInt(ipadress.substr(posBefore, pos)); // talet i andra delen
	posBefore = pos + 1;
	if (pos == string::npos || pos > 7 || pos < 3 || tal > 255) // kollar att den finns en andra punkt och att den delen har en storlek mellan 1-3
		return 0;

	tal = convertStringToInt(ipadress.substr(posBefore, pos)); // talet i tredje delen
	pos = ipadress.find(".", pos + 1);
	if (pos == string::npos || pos > 11 || pos < 5 || tal > 255) // kollar att den finns en tredje punkt och att den delen har en storlek mellan 1-3
		return 0;

	tal = convertStringToInt(ipadress.substr(pos + 1)); // talet i fjärde delen
	if (tal > 255)
		return 0;

	pos = ipadress.find(".", pos + 1);
	if (pos != string::npos) // kollar om det finns en fjärde punkt.
		return 0;

	return 1;
}
Example #3
0
int IP::checkMask(string mask) {
	size_t pos = 0, posBefore = 0;
	int tal;
	string binary;
	bool correct = true;

	pos = mask.find(".");
	posBefore = pos + 1;
	tal = convertStringToInt(mask.substr(0, pos)); //talet i första delen
	if (pos == string::npos || pos > 3 || pos == 0 || tal > 255) // kollar att det finns en punkt och att första delen har en storlek mellan 1-3 (192.168.1.1) OK! (.168.1.1) INTE OK!
		return 0;
	binary = decimalToBinary(tal);

	pos = mask.find(".", pos + 1);
	tal = convertStringToInt(mask.substr(posBefore, pos)); // talet i andra delen
	posBefore = pos + 1;
	if (pos == string::npos || pos > 7 || pos < 3 || tal > 255) // kollar att den finns en andra punkt och att den delen har en storlek mellan 1-3
		return 0;

	tal = convertStringToInt(mask.substr(posBefore, pos)); // talet i tredje delen
	pos = mask.find(".", pos + 1);
	if (pos == string::npos || pos > 11 || pos < 5 || tal > 255) // kollar att den finns en tredje punkt och att den delen har en storlek mellan 1-3
		return 0;

	tal = convertStringToInt(mask.substr(pos + 1)); // talet i fjärde delen
	if (tal > 255)
		return 0;

	return 1;
}
Example #4
0
u8 modem_flow( u8 *ucBuffer )
{
    u8 *ucParams[ 2 ], ucLen;

    ucLen = getAllSubStrings( ucBuffer, ucParams, 2, WHITESPACE|PUNCT|NEWLINE );
    if( ucLen > 1 ){
        print( MODEM_COM, "AT+IFC=%d,%d\r", convertStringToInt( ucParams[ 0 ] ), 
            convertStringToInt( ucParams[ 1 ] ) );
        return( TRUE );
    } // if

    return( FALSE );
}
Example #5
0
int compare(string op1, string op2) {
	int a = convertStringToInt(op1);
	int b = convertStringToInt(op2);
	if(a > b) {
		return 1;
	}
	if(a == b) {
		return 0;
	}
	if(a < b) {
		return -1;
	}
	
}
Example #6
0
u8 convertStringToPin( u8 *ucBuffer )
{
    // This function is constant string safe
    u8 i, ucPin;

    #ifdef __PYGMYNEBULA
        for( i = 0; i < PYGMYMAXPINS; i++ ){
            if( isStringSame( PYGMYNEBULAPINS[ i ].String, ucBuffer ) ){
                return( PYGMYNEBULAPINS[ i ].Value );
            } // if     
        } // for
    #endif // __PYGMYNEBULA
    // Pin isn't an alias, check for port letter and pin number
    if( replaceChars( ucBuffer, "pP", ' ' ) ){
        if( replaceChars( ucBuffer, "aA", ' ' ) ){
            ucPin = 0;
        } else if( replaceChars( ucBuffer, "bB", ' ' ) ){
            ucPin = 16;
        } else if( replaceChars( ucBuffer, "cC", ' ' ) ){
            ucPin = 32;
        } else if( replaceChars( ucBuffer, "dD", ' ' ) ){
            ucPin = 48;
        } else if( replaceChars( ucBuffer, "eE", ' ' ) ){
            ucPin = 64;
        } else if( replaceChars( ucBuffer, "fF", ' ' ) ){
            ucPin = 80;
        } else{
            return( 0xFF );
        } // else
        return( ucPin + convertStringToInt( ucBuffer ) );
    } // if

    return( 0xFF );
}
Example #7
0
int getIndex(char *c) {

	int len = getStringLength(c);
	//printf("%s %s\n", "string ", c);
	if(*(c + len - 1) =='\n') {
		len--;
	}
	int counter = 0;
	int currentIndex = len - 1;

	while(*(c + currentIndex) != ' ') {
		currentIndex--;
		counter++;
	}
	currentIndex++;
	//printf("%s %d\n", "size of countr ", counter);
	char *substring = (char *)malloc((counter + 1) * sizeof(char));

	for(int i = 0; i < counter; i++) {
		*(substring + i) =  *(c + currentIndex + i); 
	}
	*(substring + counter) = '\0';

	//printf("%s %s\n", "substring", substring);
	int resultIndex = convertStringToInt(substring);
	//printf("%d\n", resultIndex);


	free(substring);
	return resultIndex;
}
Example #8
0
u8 modem_pftp( u8 *ucBuffer )
{
    u8 *ucParams[ 3 ], ucLen, *ucCommand, *ucFileName, *ucSubString, ucCMD;

    ucLen = getAllSubStrings( ucBuffer, ucParams, 3, WHITESPACE|NEWLINE );
    ucCommand = ucParams[ 0 ];
    ucFileName = ucParams[ 1 ];
    ucSubString = ucParams[ 2 ];
    
    if( ucCommand ){
        if( isStringSame( ucCommand, "get" ) ){
            ucCMD = 0; 
        } else if( isStringSame( ucCommand, "put" ) ){
            ucCMD = 1;
        } else{
            return( FALSE );
        } // else
    }// if
    
    if( ucFileName ){
        copyString( ucFileName, globalModemPFTP.File.Name );
    } else{
        return( FALSE );
    } // else
    
    // Next test for pcmp tag, if used the file will be decompressed with PCMP as it's saved
    globalModemPFTP.CurrentChunk = 1; // 0 is reserved for error
    if ( ucSubString ){ // Second optional parameter is start chunk for resume
        globalModemPFTP.CurrentChunk = convertStringToInt( ucSubString );
        if( globalModemPFTP.CurrentChunk < 1 ){
            globalModemPFTP.CurrentChunk = 1;
        } // if
    } // if
    
    globalModemTCPPort = 80; // HTTP Port
    globalModemStatus &= ~( MODEM_HTTPINPROGRESS|MODEM_PFTPINPROGRESS|MODEM_SMSINPROGRESS|MODEM_EMAILINPROGRESS);
    globalModemStatus |= MODEM_BUSY;
    globalModemPFTP.ChunkSize = 256; // 256 is default, no sz parameter will be sent, saves bandwidth
    modem_close( "" ); // Clear command queue
    modem_close( "" ); // close any open connections
    modem_portal( "" );//Configure internet portal ( APN )
    modem_attach( "" );//Attach, always to default context 1
    modem_sd( "" ); // Socket dial

    if( ucCMD ){
        if( !fileOpen( &globalModemPFTP.File, globalModemPFTP.File.Name, READ ) ){
            return( FALSE );
        } // if
        globalModemStatus |= MODEM_PFTPPUT;
        pftp_put( "" ); // connection will be closed by server
    } else{
        globalModemStatus &= ~MODEM_PFTPPUT;
        pftp_get( "" ); // connection will be closed by server
    } // else
    
    return( TRUE );
} 
Example #9
0
void LoadCommand::Execute()
{
	statsStruct stats;
	stats = LoadPlayer();
	int i;

	GetGame()->GetPlayer().SetName(stats.statsArray[0]);
	GetGame()->GetPlayer().SetRace(stats.statsArray[1]);
	i = convertStringToInt(stats.statsArray[2]);
	GetGame()->GetPlayer().SetAge(i);
	i = convertStringToInt(stats.statsArray[3]);
	GetGame()->GetPlayer().SetGender((i == 1 ? Male : Female));
	i = convertStringToInt(stats.statsArray[4]);
	GetGame()->GetPlayer().SetClass((Class)i);
	i = convertStringToInt(stats.statsArray[5]);
	GetGame()->GetPlayer().SetExperience(i);
	i = convertStringToInt(stats.statsArray[6]);
	GetGame()->GetPlayer().SetHitpoints(i);

	std::cout<<"Game Loaded!\n";
}
Example #10
0
u8 handler_ATCSQ( u8 *ucBuffer )
{
    // +CSQ is the AT response for Signal Quality, 0-31, 99 = no service or unknown
    u8 *ucParams[ 2 ], ucSignal;
    
    getAllSubStrings( ucBuffer, ucParams, 2, WHITESPACE|PUNCT );
    if( isStringSame( ucParams[ 0 ], (u8*)AT_CSQ ) ){
        ucSignal = convertStringToInt( ucParams[ 1 ] );
        // ToDo: Do something with signal strength        
    } // if

    return( TRUE );
}
Example #11
0
u8 modem_smsdel( u8 *ucBuffer )
{
    u8 *ucParams[ 2 ], ucLen;

    ucLen = getAllSubStrings( ucBuffer, ucParams, 2, WHITESPACE|PUNCT|NEWLINE );
    if( ucLen > 1 ){
        print( MODEM_COM, "AT+CMGD=%d,%d\r", convertStringToInt( ucParams[ 0 ] ), convertStringToInt( ucParams[ 1 ] ) );
        
        return( TRUE );
    } // if
    /*PYGMYCOMMAND pygmyCmd;

    pygmyCmd.Name = "smsdel";
    pygmyCmd.PrintHandler = print_ATCMGD;
    pygmyCmd.EventHandler = handler_ATCMGD;
    pygmyCmd.Expire = 15;
    pygmyCmd.Retry = 1;
    cmdQueue( &globalModemQueue, &pygmyCmd );
    */

    return( FALSE );
}
Example #12
0
u8 handler_ATQSS( u8 *ucBuffer )
{
    u8 *ucParams[ 4 ];
 
    getAllSubStrings( ucBuffer, ucParams, 4, WHITESPACE|PUNCT );
    if( !isStringSame( ucParams[ 0 ], (u8*)AT_QSS ) ){
        return( FALSE );
    } // if

    if( convertStringToInt( ucParams[ 2 ] ) ){
       // ToDo: Add code to do something with QSS value
    } // if

    return( TRUE );
}
Example #13
0
u32 convertDateStringToSeconds( u8 *Buffer )
{
    // This function converts a Date/Time string to seconds
    //"11/20/2003 12:48:00"
    //u16 Year;
    //u8 Month;
    //u8 Day;
    //u8 Hour;
    //u8 Minute;
    //u8 Second;
    PYGMYTIME Time;
    u32 Seconds;
    u8 *TmpString, TmpBuffer[8];

    TmpString = TmpBuffer;
    TmpString = (u8*)strtok ( Buffer, ": /" );
    if( !TmpString ){
        return( FALSE );
    } // if
    Time.Month = convertStringToInt( TmpString );
    TmpString = strtok ( NULL, ": /" );
    if( !TmpString ){
        return( FALSE );
    } // if
    Time.Day = convertStringToInt( TmpString );
    TmpString = strtok ( NULL, ": /" );
    if( !TmpString ){
        return( FALSE );
    } // if
    Time.Year = convertStringToInt( TmpString );
    TmpString = strtok ( NULL, ": /" );
    if( !TmpString ){
        return( FALSE );
    } // if
    Time.Hour = convertStringToInt( TmpString );
    TmpString = strtok ( NULL, ": /" );
    if( !TmpString ){
        return( FALSE );
    } // if
    Time.Minute = convertStringToInt( TmpString );
    TmpString = strtok ( NULL, ": /" );
    if( !TmpString ){
        return( FALSE );
    } // if
    Time.Second = convertStringToInt( TmpString );

    Seconds = convertSystemTimeToSeconds( &Time );
    
    return( Seconds );
}
Example #14
0
u8 pftp_handler( u8 *ucBuffer )
{
    u8 *ucParams[ 5 ], ucLen, *ucSubString, *ucPayload;
    u16 uiCRC, uiLen, uiChunk;
    u32 i, ulPDIA;

    ucLen = getAllSubStrings( ucBuffer, ucParams, 5, WHITESPACE|PUNCT|SEPARATORS );
    
    if( isStringSame( ucParams[ 0 ], "PFTP" ) ){
        if( isStringSame( ucParams[ 1 ], (u8*)AT_ERROR ) ){
            // ERROR is returned when resource is unavailable, such as incorrect filename
            globalModemStatus &= ~(MODEM_PFTPINPROGRESS|MODEM_BUSY);
            modem_close( "now" ); // Clear command queue
            return( TRUE ); // was 0, must test, but 1 cancels
        }else if( !isStringSame( ucSubString, "EOF" ) ){
            uiChunk = convertStringToInt( ucParams[ 1 ] );
            print( MODEM_DEBUG, "\rChunkReq: %d", globalModemPFTP.CurrentChunk );
            print( MODEM_DEBUG, "\rChunkRcv: %d", uiChunk );
            uiLen = convertStringToInt( ucParams[ 2 ] );
                
            ucPayload = ucParams[ 3 ]; //getNextSubString( "", PYGMY_STRING_WHITE|PYGMY_STRING_SEPARATORS );
            print( MODEM_DEBUG, "\rPayLen: %d", ucParams[ 3 ] );
            if( convertHexEncodedStringToBuffer( ucPayload, ucPayload ) != uiLen ){
                print( MODEM_DEBUG, "\rLEN Fail!" );
                return( FALSE );
            } // if
                // Updated to 32bit PDIA, single frame in HEX n 03/17/2011
            pdiaEncode( 0, PDIA_NEW, 0 );
            for( i = 0, ulPDIA = 0, uiCRC = 0; i < uiLen; i++ ){
                pdiaEncode( ucPayload[ i ], PDIA_ADD, (u32*)&ulPDIA );
            } // for
            pdiaEncode( 0, PDIA_END, (u32*)&ulPDIA );
            //Next append h to mark string as hexadecimal
            i = len( ucParams[ 4 ] );
            ucParams[ 4 ][ i++ ] = 'h';
            ucParams[ 4 ][ i ] = '\0';
            // Then convert hexadecimal string to integer
            // Now compare integer against that produced by PDIA encoder
            if( ulPDIA != convertStringToInt( ucParams[ 4 ] ) ){ // Contains CRC
                print( MODEM_DEBUG, "\rData Corrupt!" );
                return( FALSE );
            } // if
            if( uiChunk == globalModemPFTP.CurrentChunk ){
                if( globalModemPFTP.CurrentChunk == 1 ){
                    //if( !Pygmy_PCMP_DecompressStreamToFile( ucPayload, uiLen, PYGMY_PCMP_START, 
                    //    backlinkData.PFTP_Compressed, backlinkData.PFTP_File.Name ) ){
                    //    return( 0 );
                    //}
                    ++globalModemPFTP.CurrentChunk;
                    pftp_get( "" );
                    return( TRUE );
                } else{
                    //if( !Pygmy_PCMP_DecompressStreamToFile( ucPayload, uiLen, PYGMY_PCMP_DATA, 
                    //    backlinkData.PFTP_Compressed, "" ) ){
                    //    return( FALSE );
                    //}
                    ++globalModemPFTP.CurrentChunk;
                    pftp_get( "" );
                    return( TRUE );
                } // else
                print( MODEM_DEBUG, "." );
            }
            return( FALSE );
        } else{
            //Pygmy_PCMP_DecompressStreamToFile( "", uiLen, PYGMY_PCMP_STOP, backlinkData.PFTP_Compressed, "" );
            globalModemStatus &= ~(MODEM_PFTPINPROGRESS|MODEM_BUSY);
            modem_close( "now" ); // Clear command queue
        } // else
            
        return( TRUE ); 
    } // if

    return( FALSE );
}
Example #15
0
int convertSizeTtoInt(size_t val) {
    std::string str = convert_SizeT_toString(val);
    return convertStringToInt(str);   //should check for min/max values
}