uint8_t BayGPRSInterface::begin(long baud,uint8_t unlock_only){ _baud=baud; i_begin(_baud); skipChars(); printP("AT"); //Will autoconfigure BAUD-Rate - Auto BAUD-Rate did not work with Sleep-Mode! delay(100); println(); printP("AT+IPR="); println(_baud); wait_forOK(200); return init(unlock_only); }
int32_t IndexInput::readString(TCHAR* buffer, const int32_t maxLength){ int32_t len = readVInt(); int32_t ml=maxLength-1; if ( len >= ml ){ readChars(buffer, 0, ml); buffer[ml] = 0; //we have to finish reading all the data for this string! if ( len-ml > 0 ){ //seek(getFilePointer()+(len-ml)); <- that was the wrong way to "finish reading" skipChars(len-ml); } return ml; }else{ readChars(buffer, 0, len); buffer[len] = 0; return len; } }
uint8_t BayGPRSInterface::changeIPR(long baud) { _baud = baud; long t_baud[] = { baud, 9600, 38400, 57600 }; for (uint8_t i = 0; i < 4; i++) { i_begin(t_baud[i]); skipChars(); printP("AT"); //Will autoconfigure BAUD-Rate - Auto BAUD-Rate did not work with Sleep-Mode! delay(100); println(); printP("AT+IPR="); println(_baud); if (!wait_forOK(200)) { i_end(); i_begin(_baud); return 0; } i_end(); } return 1; }
/** * Find and optionally copy the next token from a string. * The next token is composed of characters from rp_hh_boudChars. Copies the * token into dest if not NULL. * * @param len On entry, *len indicates the max length of a token (without the * terminating \0), on exit it is set to the actual length. * @param dest destination for the token. May be null. If not null * it is the responsibility of the caller to provide a buffer of at least * len chars. * @param str The source string where to get the token from. * @return Returns the start of the token, and sets *len to its actual * length. */ char * getNextToken( int *len, char *dest, char *str) { int max_len = *len; char *end = NULL; str = skipBlanks(str); end = ('\0' == *str) ? str : skipChars(str, rp_hh_boundChars); *len = end - str; if (*len > max_len) *len = max_len; if (NULL != dest) { if ( end != str) { strncpy(dest, str, *len); } *(dest+*len) = '\0'; } return str; }
uint8_t BayGPRSInterface::init(uint8_t unlock_only){ uint8_t count=0; init_start: uint8_t i=0; printP("AT"); //Wake up delay(200); println(); wait_forOK(1000); printlnP("AT"); //Check communication if(! wait_forOK(200)){ //communication ok! printlnP("ATE0"); //Command echo off wait_forOK(500); printlnP("AT+CSCLK=2"); //Auto-Sleepmode wait_forOK(500); //Check PIN printlnP("AT+CPIN?"); while(wait_forPGM(PSTR("+CPIN: "),5000,7,_base64buffer)){ printlnP("AT"); wait_forOK(200); printlnP("AT+CFUN=0"); //Disable wait_forOK(10000); printlnP("AT+CFUN=1"); //delay(2000); //Enable wait_forOK(10000); printlnP("AT"); wait_forOK(200); printlnP("AT+CPIN?"); i++; if(i>2) return 6; } if(_base64buffer[5]=='U') return 3; //SIM PUK if(_base64buffer[5]=='I'){ //SIM PIN printlnP("AT"); wait_forOK(200); printP("AT+CPIN=\""); print(_pin); println("\""); if(wait_forOK(30000)) { return 2; //Wrong PIN } wait_for("SMS Ready",(unlock_only?5000:60000)); } //Return here - Moden will try to connect and attach in the background! if(unlock_only) return 0; // Waiting for Modem to Connect for(i=0;i<127;i++){ if(isRegistered()) break; delay(500); } if(i==127) return 4; for(i=0;i<127;i++){ if(isAttached()) break; delay(500); } if(i==127) return 5; return 0; } softReset(); softSwitch(); i_begin(_baud); skipChars(); printP("AT"); //Will autoconfigure BAUD-Rate - Auto BAUD-Rate did not work with Sleep-Mode! delay(100); println(); printP("AT+IPR="); println(_baud); wait_forOK(200); count++; if(count>1) return 1; goto init_start; }
bool LoadBmpFile( const char* filename, int &NumRows, int &NumCols, GLubyte* &ImagePtr ) { FILE* infile = fopen( filename, "rb" ); // Open for reading binary data if ( !infile ) { fprintf( stderr, "LoadBmpFile(): unable to open file: %s\n", filename ); return false; } bool fileFormatOK = false; int bChar = fgetc( infile ); int mChar = fgetc( infile ); if ( bChar == 'B' && mChar == 'M' ) { // If starts with "BM" for "BitMap" skipChars( infile, 4 + 2 + 2 + 4 + 4 ); // Skip 4 fields we don't care about NumCols = readLong( infile ); NumRows = readLong( infile ); skipChars( infile, 2 ); // Skip one field int bitsPerPixel = readShort( infile ); skipChars( infile, 4 + 4 + 4 + 4 + 4 + 4 ); // Skip 6 more fields if ( NumCols > 0 && NumCols <= 100000 && NumRows > 0 && NumRows <= 100000 && bitsPerPixel == 24 && !feof( infile ) ) { fileFormatOK = true; } } if ( !fileFormatOK ) { fclose ( infile ); fprintf( stderr, "Not a valid 24-bit bitmap file: %s.\n", filename ); return false; } // Allocate memory ImagePtr = new unsigned char[ NumRows * GetNumBytesPerRow( NumCols ) ]; if ( !ImagePtr ) { fclose ( infile ); fprintf( stderr, "Unable to allocate memory for %i x %i bitmap: %s.\n", NumRows, NumCols, filename ); return false; } unsigned char* cPtr = ImagePtr; for ( int i = 0; i < NumRows; i++ ) { int j; for ( j = 0; j < NumCols; j++ ) { *( cPtr + 2 ) = fgetc( infile ); // Blue color value *( cPtr + 1 ) = fgetc( infile ); // Green color value *cPtr = fgetc( infile ); // Red color value cPtr += 3; } int k = 3 * NumCols; // Num bytes already read for ( ; k < GetNumBytesPerRow( NumCols ); k++ ) { fgetc( infile ); // Read and ignore padding; *( cPtr++ ) = 0; } } if ( feof( infile ) ) { fclose ( infile ); fprintf( stderr, "Premature end of file: %s.\n", filename ); return false; } fclose( infile ); // Close the file return true; }
void StringParser::skipEOL() { skipChars("\n\r"); }
void StringParser::skipSpace() { skipChars(" \t\n"); }