Exemple #1
0
void sendCommand4(BYTE PECommand, BYTE PEData, BYTE SSCommand, BYTE SSData)
{
    unsigned short PESend = WRITE | (PECommand << 8) | PEData;
    unsigned short SSSend = SSCommand | SSData;

    sendCommand2(PESend, SSSend);
}
/* Function: 	This function checks if the GPS position is fixed or not
 * Returns 		0 if timeout
 * 				1 if position is fixed
 * 				2 if not fixed
*/
int8_t WaspGPRS_SIM928A::checkGPS()
{
	
	strcpy_P(str_aux1, (char*)pgm_read_word(&(table_GPS[1])));	//GNSS_INFO
	snprintf(str_aux2, sizeof(str_aux2), "%s: 1,1", str_aux1);
	snprintf(str_aux3, sizeof(str_aux3), "%s: 1,0", str_aux1);
	return sendCommand2(str_aux1, str_aux2, str_aux3);
	
}
/* Function: 	This function reads the data from satellites
 * Parameters:	parse.	0 to return the data string in buffer_GPRS
 * 						1 to parse data and update GPS variables
 * Returns 		1 if success
 * 				-1 if timeout
 * 				-2 if error
*/
int8_t WaspGPRS_SIM928A::getGPSData(bool parse)
{

	int8_t answer;
	int aux, counter;
	long previous;
	char aux_str[25];
	int8_t x;
	char* aux_ptr;
	
	serialFlush(_socket);
	
	strcpy_P(str_aux1, (char*)pgm_read_word(&(table_GPS[1])));		//GNSS_INFO
	snprintf(str_aux2, sizeof(str_aux2), "%s: ", str_aux1);
	answer = sendCommand2(str_aux1, str_aux2, ERROR);	
	
	if (answer == 1)
	{
		previous = millis();
		answer = 0;
		counter = 0;
		do{
			// Gets number of available bytes 
			do{
				aux = serialAvailable(_socket);
				
				//avoid millis overflow problem
				if( millis() < previous ) previous = millis(); 
				
			}while((aux == 0) && ((millis()-previous) < 3000));
			
			#if GPRS_debug_mode>0
				USB.print(F("Available bytes: "));
				USB.println(aux, DEC);
			#endif
				
			// Gets available bytes
			while (aux > 0){
				
				if (counter < 0)
				{
					// Skips first 2 bytes (\r\n)
					serialRead(_socket);
				}
				else if(counter < BUFFER_SIZE)
				{
					buffer_GPRS[counter] = serialRead(_socket);
				}
				else
				{
					serialRead(_socket);	
				}
				counter++;
				aux--;
			}
			
			buffer_GPRS[counter] = '\0';
			
			// check if the buffer_GPRS contains "OK"
			if (strstr(buffer_GPRS, "OK") != NULL)    
			{
					answer = 1;
			}
			
			//avoid millis overflow problem
			if( millis() < previous ) previous = millis(); 
				
		}while((answer == 0) && ((millis()-previous) < 3000));
		
		
		
	}
	else if (answer == 2)
	{
		return -2;
	}
	else
	{
		return -1;
	}

	buffer_GPRS[counter - 4] = '\0';

	if (parse == 1)
	{			
		#if GPRS_debug_mode>0
			USB.println(buffer_GPRS);
		#endif
		GPS_status = atoi(strtok(buffer_GPRS, ",")); // Gets fix status
		fix_status = atoi(strtok(NULL, ",")); // Gets fix status
		strcpy(aux_str,strtok(NULL, ",")); // Gets date and time
		
		memset(date, '\0', sizeof(date));
		strncpy(date, aux_str, 8);		
		memset(UTC_time, '\0', sizeof(UTC_time));
		strncpy(UTC_time, aux_str+ 8, 6);
		
		latitude = atof(strtok(NULL, ",")); // Gets latitude
		longitude = atof(strtok(NULL, ",")); // Gets longitude
		altitude = atof(strtok(NULL, ",")); // Gets altitude
		speedOG = atof(strtok(NULL, ",")); // Gets speed over ground. Unit is knots.
		courseOG = atof(strtok(NULL, ",")); // Gets course
		
		mode = atoi(strtok(NULL, ",")); // Gets mode
		
		HDOP = atof(strtok(NULL, ",")); // Gets HDOP
		PDOP = atof(strtok(NULL, ",")); // Gets PDOP
		VDOP = atof(strtok(NULL, ",")); // Gets VDOP
		
		sats_in_view = atoi(strtok(NULL, ",")); // Gets sats_in_view
		sats_in_use = atoi(strtok(NULL, ",")); // Gets sats_in_use
		SNR = atoi(strtok(NULL, ",")); // Gets SNR
		
		#if GPRS_debug_mode>0
			USB.print(F("GPS_status: "));
			USB.println(GPS_status, DEC);
			USB.print(F("fix_status: "));
			USB.println(fix_status, DEC);
		
			USB.print(F("Latitude (in degrees): "));
			USB.println(latitude);
			USB.print(F("Longitude (in degrees): "));
			USB.println(longitude);
			USB.print(F("Date: "));
			USB.print(date);
			USB.print(F("   UTC_time: "));
			USB.println(UTC_time);
			USB.print(F("Altitude: "));
			USB.println(altitude);
			USB.print(F("SpeedOG: "));
			USB.println(speedOG);
			USB.print(F("Course: "));
			USB.println(courseOG);

			USB.print(F("Satellites in view: "));
			USB.println(sats_in_view, DEC); 
			USB.print(F("Satellites in use: "));
			USB.println(sats_in_use, DEC);


			USB.print(F("Mode: "));
			USB.println(mode,DEC);   
			USB.print(F("SNR: "));
			USB.println(SNR,DEC);      


			USB.print("PDOP: ");
			USB.println(PDOP);
			USB.print("HDOP: ");
			USB.println(HDOP);
			USB.print("VDOP: ");
			USB.println(VDOP);
		#endif
	}
	
	return 1;	
}
Exemple #4
0
void writeHex(BYTE digit, BYTE value)
{
    ssCommand = getPECommand1(digit, value);
    sendCommand2(NOOP, ssCommand);
}
Exemple #5
0
void initLEDBoard()
{
    //Initialize the port expander

    //Switches as inputs
    peCommand = getPECommand4(P12_15_CONFIG, INPUT, INPUT, INPUT, INPUT);
    //Test mode off
    ssCommand = getPECommand1(TEST, 0);
    sendCommand2(peCommand, ssCommand);

    peCommand = getPECommand4(P16_19_CONFIG, CONST_CUR, CONST_CUR, CONST_CUR, CONST_CUR);
    ssCommand = getPECommand1(INTENSITY, 8);
    sendCommand2(peCommand, ssCommand);

    peCommand = getPECommand4(P20_23_CONFIG, CONST_CUR, CONST_CUR, CONST_CUR, CONST_CUR);
    ssCommand = getPECommand1(SCANLIMIT, 7);
    sendCommand2(peCommand, ssCommand);

    peCommand = getPECommand4(P24_27_CONFIG, CONST_CUR, CONST_CUR, CONST_CUR, CONST_CUR);
    ssCommand = getPECommand1(DECODE, 0);
    sendCommand2(peCommand, ssCommand);

    peCommand = getPECommand4(P28_31_CONFIG, CONST_CUR, CONST_CUR, CONST_CUR, CONST_CUR);
    ssCommand = getPECommand1(SSSHUTDOWN, 1);
    sendCommand2(peCommand, ssCommand);

    peCommand = getPECommand2(P16_17_CURRENT, LED_CURRENT_5, LED_CURRENT_5);
    ssCommand = getPECommand1(TEST, 1);
    sendCommand2(peCommand, LED_NOOP);

    peCommand = getPECommand2(P18_19_CURRENT, LED_CURRENT_5, LED_CURRENT_5);
    sendCommand2(peCommand, LED_NOOP);

    peCommand = getPECommand2(P20_21_CURRENT, LED_CURRENT_5, LED_CURRENT_5);
    sendCommand2(peCommand, LED_NOOP);

    peCommand = getPECommand2(P22_23_CURRENT, LED_CURRENT_5, LED_CURRENT_5);
    sendCommand2(peCommand, LED_NOOP);

    peCommand = getPECommand2(P24_25_CURRENT, LED_CURRENT_5, LED_CURRENT_5);
    sendCommand2(peCommand, LED_NOOP);

    peCommand = getPECommand2(P26_27_CURRENT, LED_CURRENT_5, LED_CURRENT_5);
    sendCommand2(peCommand, LED_NOOP);

    peCommand = getPECommand2(P28_29_CURRENT, LED_CURRENT_5, LED_CURRENT_5);
    sendCommand2(peCommand, LED_NOOP);

    peCommand = getPECommand2(P30_31_CURRENT, LED_CURRENT_5, LED_CURRENT_5);
    sendCommand2(peCommand, LED_NOOP);

    peCommand = getPECommand1(CONFIGURATION, NORMAL | INDIVIDUAL);
    sendCommand2(peCommand, LED_NOOP);

    peCommand = getPECommand1(RW_BYTE_16,0xFF);
    sendCommand2(peCommand, LED_NOOP);

    peCommand = getPECommand1(RW_BYTE_24,0xFF);
    sendCommand2(peCommand, LED_NOOP);

    //Clear the hex
    int i;
    for(i=1; i<=NUM_DIGITS; i++){
        writeHex(i, 0);
    }
}