Пример #1
0
void retryToTransmit(char * fname)
{
        FILE * infile;
        char line[1000];
		char dummy[1000];
		if(!fileExists(fname)) return;

		system("rm -f retryStore1.txt");
        if((infile = fopen(fname, "r")) == NULL) {
                printf("File retryStore1.txt does not exists retryStore.txt\n");
                return;
                }

        int isConnected=TRUE;
        FILE * retryStore1=fopen("retryStorex.txt", "w");
        while( fgets(line, sizeof(line), infile) != NULL ) {
                //printf("line x: %s\n",line);
			if( !strstr(line, "echo") && line[0] !=10	)
			{
				if (isConnected ) 
				{ // && strcasecmp(line[0],"e") != 0) { 
					printf("RETR: %s\n",line);
					system(line);
					if ( fileContains("outlogwget.txt","EnterData.aspx") || fileContains("outlogwget.txt","EnterAlert.aspx") )
							{ 
							system("rm -f EnterData.aspx*");
							printf("Transmitted\n");
							//LastTimeConnected_s = CurrentTime_s;

							}
					else if ( fileContains("outlogwget.txt","EnterAlert.aspx") )
							{ 
							system("rm -f EnterAlert.aspx*");
							printf("Transmitted\n");
							//LastTimeConnected_s = CurrentTime_s;
							}
					else
                        { //isConnected=FALSE ;
						  printf("Not transmitted, stored\n");
                          fprintf(retryStore1, "%s\n",line);
						  fflush(retryStore1);
                        }
				}
				else
				     fprintf(retryStore1, "%s\n",line);
					 fflush(retryStore1);
			}
        } 
        fclose(retryStore1);
		fclose(infile);
        if (fileExists("retryStorex.txt"))
			sprintf(dummy,"mv -f retryStorex.txt %s",fname);
			printf("%s\n",dummy);
			system(dummy);
		
        
}
Пример #2
0
Файл: gps.c Проект: annunal/IDSL
void retryToTransmitGPS()
{       return;
        FILE * infile;
        char line[1000];
		char dummy[1000];
		if(!fileExists("retryStoreGPS.txt")) return;
		
		
		system("rm -f retryStoreGPS1.txt");
        if((infile = fopen("retryStoreGPS.txt", "r")) == NULL) {
                printf("File %s does not exists retryStoreGPS.txt\n");
                return;
                }

        int isConnected=TRUE;
        FILE * retryStore1=fopen("retryStoreGPS1.txt", "w");
        while( fgets(line, sizeof(line), infile) != NULL ) {
                //printf("line x: %s\n",line);

                if (isConnected) { 
					printf("RETR: %s\n",line);
					system(line);
					if ( fileContains("outlogGPSwget.txt","EnterData.aspx") || fileContains("outlogGPSwget.txt","EnterAlert.aspx") )
							{ 
							system("rm -f EnterData.aspx*");}
					else if ( fileContains("outlogGPSwget.txt","EnterAlert.aspx") )
							{ 
							system("rm -f EnterAlert.aspx*");}
					else
                        { isConnected=FALSE ;
                          fprintf(retryStore1, "%s\n",line);
                        }
					}
					else
					     fprintf(retryStore1, "%s\n",line);
        }
        fclose(retryStore1);
		fclose(infile);
        if (fileExists("retryStoreGPS1.txt"))
			system("mv retryStoreGPS1.txt retryStoreGPS.txt");
		
        
}
int CommonTools::fileContains(const char* s,std::string name,int n)
{
  return fileContains(s,name.c_str(),n);
}
Пример #4
0
Файл: gps.c Проект: annunal/IDSL
void *readGPSThread(void *args)
{    if (ttyGPS==0) return;
	struct sensorGrid *readings = (struct sensorGrid *)args;
	float measure, average;
	char * buffer[5*BUFFERSIZE];
	int n;
	char *s, *p, *end = reading + BUFFERSIZE;
    char * row;
	char success = 'N';
	si_processed=0;
	LastTimeGPSSave=-1000;
	
	while(1) {
		//for(p=reading;p<end;p++) *p=0;
		//unsigned char poll[10]={0xB5, 0x62, 0x02, 0x10, 0x00, 0x00, 0x12, 0x38, 0x0D, 0x0A};
		//int written=write(ttyGPS->_fileno,poll,10);
		int i;
		n = read(ttyGPS->_fileno, reading, BUFFERSIZE);
		for(i=0;i<n;i++)
		{
			if(reading[i]==0) reading[i]=32 ;//'\n';
			//printf("%c", reading[i]);
		}
		 
		row = strtok(reading,"\n");
		while (row != NULL)
		{   
		    if(row[0]=='$' && strstr(row,"*") !=0 )
			{
				//printf("%s\n",row);
				if(strstr(row,"$GPGGA") !=0)
				{
					char * res[100];
					int nfields;
					//printf("%s\n",row);
					splitString(row,res, &nfields);
					if (nfields>=12)
					{   float latDeg,lonDeg,lonMin,latMin;
						latDeg=(int) (atof(res[2])/100);
						lonDeg=(int) (atof(res[4])/100);
						latMin=(float) ((atof(res[2])/100)-latDeg)*100/60;
						lonMin=(float) ((atof(res[4])/100)-lonDeg)*100/60;
						
						readings->longitude=lonDeg+lonMin;
						if(res[5]=='W') readings->longitude *= (-1);
						
						readings->latitude =latDeg+latMin;
						if(res[3]=='S') readings->latitude *= (-1);
						
						readings->elevation=(float) atof(res[9]);
						readings->gpstime=res[1];
						FILE * gpslog = fopen("gpslog.log", "a");
						fprintf(gpslog, "%s, %s,  %s,  %f, %f, %f \n",readings->gpstime,res[2],res[4],readings->longitude,readings->latitude,readings->elevation);
						fclose(gpslog);
						//printf("lat-lon=%s  %s\n",res[2],res[4]);
						CurrentTime_s=(double) time(NULL);  // seconds from 1/1/1970					printf("elev=%s\n",res[9]);
						if(CurrentTime_s-LastTimeGPSSave>Configuration.gpsDeltaTSave)
						{
							LastTimeGPSSave=CurrentTime_s;
							char gpsURL0[4096];
							char dummy[4096];
							char dummy1[4096],*t;

							success = 'T';
							
							strcpy(gpsURL0,Configuration.gpsURL);
							sprintf(dummy1,"%f",readings->longitude);
							replace(gpsURL0,"$LON", dummy1,dummy); strcpy(gpsURL0, dummy);
							
							sprintf(dummy1, "%f",readings->latitude);
							replace(gpsURL0,"$LAT", dummy1,dummy); strcpy(gpsURL0, dummy);
							
							sprintf(dummy1, "%f",readings->elevation);
							replace(gpsURL0,"$HEI", dummy1,dummy); strcpy(gpsURL0, dummy);

							//printLog(gpsURL0);
							t = ctrim(gpsURL0);
							sprintf(dummy, "wget \"%s\" -T 10 -nv -o outlogGPSwget.txt", t);

							printf("Storing GPS location: %s\n",dummy);
							system(dummy);

							if ( fileContains("outlogGPSwget.txt","EnterData.aspx"))
							{
								system("rm -f outlogGPSwget.txt* EnterData.aspx*");
								retryToTransmitGPS();  // se sono riuscito a trasmettere, provo a ritrasmettere quelli non riusciti
							}
							else
							{  // se non sono riuscito a trasmettere salvo nel file retrysStore.txt i comandi da dare e poi riprovare.
								FILE * retryStore = fopen(RETRY_BUFFER_GPS, "a");
								//printf("string stored %s\n",dummy);
								if(retryStore)
								{
									fprintf(retryStore, "%s\n",dummy);
									fclose(retryStore);
									success = 'S';
								}
							}
						}
					}
				}
			}
			row=strtok(NULL,"\n");
		}
		//printf("----------------\n");
		sleep(1);
		
	}

	return NULL;
}