Exemple #1
0
/**
 * This function is called when a packet is received by the radio. It will
 * process the packet.
 */
inline void processData(uint32_t len) {
    uint8_t i, packet_len;

    for(i=0; i<len; i++) {
        //finds the end of the packet
        if(data_temp[i] != ']')
            continue;

        //then terminates the string, ignore everything afterwards
        data_temp[i+1] = '\0';

        //Check validity of string
        // 1) is the first position in array a number
        //printf("%d\r\n", data_temp[0]);
        if((int)data_temp[0] <= 48 || (int)data_temp[0] > 57) {
            //printf("Error1\r\n");
            break;
        }

        // 2) is the second position in array a letter
        //      < 'a' or > 'z' then break
        //printf("%d\r\n", data_temp[1]);
        if((int)data_temp[1] < 97 || (int)data_temp[1] > 122) {
            //printf("Error2\r\n");
            break;
        }

#ifdef GATEWAY
        printf("rx: %s|%d\r\n",data_temp, RFM69_lastRssi());
#endif
        //Reduce the repeat value
        data_temp[0] = data_temp[0] - 1;
        //Now add , and end line and let string functions do the rest
        data_temp[i] = ',';
        data_temp[i+1] = '\0';

        if(strstr(data_temp, NODE_ID) != 0)
            break;

        strcat(data_temp, NODE_ID); // Add ID
        strcat(data_temp, "]"); // Add ending

        packet_len = strlen(data_temp);
        mrtDelay(random_output); // Random delay to try and avoid packet collision

        rx_packets++;

        transmitData(packet_len);
        break;
    }
}
Exemple #2
0
int main(int argc, char **argv)
{
	char spin[] = "-\\|/", SequenceCount = 'a';
	char Message[65], Data[100], upload_exclude[200], Command[200], Telemetry[100], *Bracket, *Start;
	int Bytes, Sentence_Count, sc = 0;
	double Latitude, Longitude;
	unsigned int Altitude;
	uint8_t opmode, flags1, flags2, old_opmode = 0, old_flags1 = 0, old_flags2 = 0;
	const char *inifile = "gateway.ini"; // FIXME
	float node_lat, node_lon;
	time_t next_beacon;
	bool bmp085, xap;

	/* load configuration */
	ini_gets("node", "id", "", node_id, sizeof(node_id), inifile);
	node_lat = ini_getf("node", "lat", 999, inifile);
	node_lon = ini_getf("node", "lon", 999, inifile);
	bmp085 = ini_getbool("sensors", "bmp085", false, inifile);
	xap = ini_getbool("xap", "enabled", false, inifile);
	ini_gets("upload", "exclude", "", upload_exclude, sizeof(upload_exclude), inifile);
	
	if (strlen(node_id) == 0) {
		puts("Node ID has not been specified");
		exit(1);
	}

	printf("Upload exclude list is \"%s\"\n", upload_exclude);

	if (xap) {
		xapInit();
	}

	if (node_lat < 900 && node_lon < 900) {
		/* put the gateway on the map */
		sprintf(Message,"0aL%f,%f:%s[%s]", node_lat, node_lon, GIT_VER, node_id);
	} else {
		sprintf(Message,"0a:%s[%s]", GIT_VER, node_id);
	}

	UploadPacket(Message,0);
	if (xap) {
		xapSendPacket(Message, 0);
	}

	if (bmp085) {
		next_beacon = time(NULL) + 10;
		printf("Initialising BMP085\n");
		bmp085_Calibration();
	}

	printf("Initialising RFM69\n");

	setupRFM69();
	
	printf("Starting main loop ...\n");

	Sentence_Count = 0;

	while (1)
	{
		if (rfm69_available())
		{
			Bytes = rfmM69_recv(Message, sizeof(Message));
			printf ("%s Data available - %d bytes\n", Now(), Bytes);
			printf ("rx: %s|%d\n", Message,RFM69_lastRssi());

			if (Bytes > 0)
			{
				if (!excluded(Message, upload_exclude)) {
					// UKHASNet upload
					UploadPacket(Message, RFM69_lastRssi());
				}

				if (xap) {
					// xAP broadcast
					xapSendPacket(Message, RFM69_lastRssi());
				}
#if 0
				// Habitat upload
				// 3dL51.95023,-2.54445,155[DA1]
				if (strstr(Message, "DA1"))
				{
					if (Start = strchr(Message, 'L'))
					{
						// DA1,2,19:35:37,51.95023,-2.54445,160*05%0A

						if (sscanf(Start+1, "%lf,%lf,%u[", &Latitude, &Longitude, &Altitude))
						{
							printf("Altitude = %u\n", Altitude);
							sprintf(Telemetry, "%s,%d,%s,%lf,%lf,%u", "DA1", ++Sentence_Count, Now(), Latitude, Longitude, Altitude);
							sprintf(Command, "wget -O habitat.txt \"http://habitat.habhub.org/transition/payload_telemetry\" --post-data \"callsign=DA0&string=\\$\\$%s*%s%s&string_type=ascii&metadata={}\"",	Telemetry, Checksum(Telemetry), "\%0A");
							printf("%s\n", Command);
							system(Command);
						}
					}
				}
#endif
			}
		}
		else
		{
Exemple #3
0
int main(void)
{
    // Initialise the GPIO block
    gpioInit();
    
	#ifdef GPS
		// Initialise the UART0 block for printf output
		uart0Init(9600);
	#else
		// Initialise the UART0 block for printf output
		uart0Init(115200);
	#endif
    
    // Configure the multi-rate timer for 1ms ticks
    mrtInit(__SYSTEM_CLOCK/1000);
    
    // Configure the switch matrix (setup pins for UART0 and SPI)
    configurePins();
    
    //Seed random number generator, we can use our 'unique' ID
    random_output = NODE_ID[0] + NODE_ID[1] + NODE_ID[2];
    //printf("random: %d\r\n", random_output);
    
    RFM69_init();
    
    #ifdef GPS
		int navmode = 9;
		setupGPS();
    #endif

	#ifdef DEBUG
		printf("Node initialized, version %s\r\n",GIT_VER);
	#endif
    
    while(1) {
        
        #ifdef GPS
			mrtDelay(5000);
			navmode = gps_check_nav();
            if (navmode != 6){
                setupGPS();
            }
        
			mrtDelay(500);
			gps_get_position();
			mrtDelay(500);
			gps_check_lock();
			mrtDelay(500);

			//printf("Data: %d,%d,%d,%d,%d,%d\r\n", lat, lon, alt, navmode, lock, sats);
			//printf("Errors: %d,%d\r\n", GPSerror, serialBuffer_write);
        #endif
        
        incrementPacketCount();
        
        //Clear buffer
        data_temp[0] = '\0';
        uint8_t n;
        
        //Create the packet
        int int_temp = RFM69_readTemp(); // Read transmitter temperature
        rx_rssi = RFM69_lastRssi();
        floor_rssi = RFM69_sampleRssi();
        
        #ifdef GPS
			n = sprintf(data_temp, "%d%cL%d,%d,%dT%dR%d[%s]", NUM_REPEATS, data_count, lat, lon, alt, int_temp, rx_rssi, NODE_ID);
		#else
			if(data_count == 97) {
				n = sprintf(data_temp, "%d%cL%s[%s]", NUM_REPEATS, data_count, LOCATION_STRING, NODE_ID);
			} else {
				n = sprintf(data_temp, "%d%cT%dR%d,%dC%d[%s]", NUM_REPEATS, data_count, int_temp, rx_rssi, floor_rssi, rx_packets, NODE_ID);
			}
        #endif
        
        transmitData(n);
        
        awaitData(TX_GAP);
    }
    
}
Exemple #4
0
int main(void)
{
#ifdef ZOMBIE_MODE
    LPC_SYSCON->BODCTRL = 0x11;  //Should be set to Level 1 (Assertion 2.3V, De-assertion 2.4V) reset
#endif

#if defined(GATEWAY) || defined(DEBUG)
    // Initialise the UART0 block for printf output
    uart0Init(115200);
#endif

    // Configure the multi-rate timer for 1ms ticks
    mrtInit(__SYSTEM_CLOCK/1000);

    /* Enable AHB clock to the Switch Matrix , UART0 , GPIO , IOCON, MRT , ACMP */
    LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 7) | (1 << 14) /*| (1 << 6)*//* | (1 << 18)*/
                                 | (1 << 10) | (1 << 19);

    // Configure the switch matrix (setup pins for UART0 and SPI)
    configurePins();



#ifdef DEBUG
    mrtDelay(100);
    printf("Node Booted\r\n");
    mrtDelay(100);
#endif

    RFM69_init();

#ifdef ZOMBIE_MODE
    //This is to allow the setup to recover from the initial boot and
    // avoid a loop
    RFM69_setMode(RFM69_MODE_SLEEP);
    init_sleep();
    sleepMicro(20000);
#endif

#ifdef DEBUG
    printf("Node initialized, version %s\r\n",GIT_VER);
#endif

    //Seed random number generator, we can use our 'unique' ID
    random_output = NODE_ID[0] + NODE_ID[1] + NODE_ID[2];


    while(1) {

        /*
        #ifdef ZOMBIE_MODE
        adc_result = acmpVccEstimate();
        // Before transmitting if the input V is too low we could sleep again
        if (adc_result < 3100 || adc_result > 10000) {
            sleepRadio();
        }
        #endif
        */



        incrementPacketCount();

        //Clear buffer
        data_temp[0] = '\0';
        uint8_t n;

        //Create the packet
        int int_temp;
#ifdef ZOMBIE_MODE
        //This is to allow the setup to recover from the initial boot and
        // avoid a loop
        RFM69_setMode(RFM69_MODE_SLEEP);
        init_sleep();
        sleepMicro(10000);
#endif

        int_temp = RFM69_readTemp(); // Read transmitter temperature


        rx_rssi = RFM69_lastRssi();
        // read the rssi threshold before re-sampling noise floor which will change it
        rssi_threshold = RFM69_lastRssiThreshold();
        floor_rssi = RFM69_sampleRssi();

#ifdef ZOMBIE_MODE
        //This is to allow the setup to recover from the initial boot and
        // avoid a loop
        RFM69_setMode(RFM69_MODE_SLEEP);
        init_sleep();
        sleepMicro(10000);
#endif

#ifdef ZOMBIE_MODE
        adc_result = acmpVccEstimate();
        //sleepMicro(20000);
#endif

#ifdef DEBUG
        printf("ADC: %d\r\n", adc_result);

#endif
#ifdef ZOMBIE_MODE
        //This is to allow the setup to recover from the initial boot and
        // avoid a loop
        RFM69_setMode(RFM69_MODE_SLEEP);
        init_sleep();
        sleepMicro(10000);
#endif

        if(data_count == 97) {
            n = sprintf(data_temp, "%d%cL%s[%s]", NUM_REPEATS, data_count, LOCATION_STRING, NODE_ID);
        }
        else {

#ifdef DEBUG
            //n = sprintf(data_temp, "%d%cT%dR%d,%dC%dX%d,%dV%d[%s]", NUM_REPEATS, data_count, int_temp, rx_rssi, floor_rssi, rx_packets, rx_restarts, rssi_threshold, adc_result, NODE_ID);
            n = sprintf(data_temp, "%d%cT%dV%d[%s]", NUM_REPEATS, data_count, int_temp, adc_result, NODE_ID);
#elif defined(ZOMBIE_MODE)
            n = sprintf(data_temp, "%d%cT%dV%d[%s]", NUM_REPEATS, data_count, int_temp, adc_result, NODE_ID);
#else
            n = sprintf(data_temp, "%d%cT%dR%d[%s]", NUM_REPEATS, data_count, int_temp, rx_rssi, NODE_ID);
#endif
        }

        transmitData(n);

#ifdef ZOMBIE_MODE
        sleepRadio();
#else
        awaitData(TX_GAP);
#endif

    }

}
Exemple #5
0
int main(void)
{

#if defined(GATEWAY) || defined(DEBUG) || defined(GPS)
    // Initialise the UART0 block for printf output
    uart0Init(115200);
#endif

    // Configure the multi-rate timer for 1ms ticks
    mrtInit(__SYSTEM_CLOCK/1000);

    /* Enable AHB clock to the Switch Matrix , UART0 , GPIO , IOCON, MRT , ACMP */
    LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 7) | (1 << 14) /*| (1 << 6)*//* | (1 << 18)*/
                                 | (1 << 10) | (1 << 19);

    // Configure the switch matrix (setup pins for UART0 and SPI)
    configurePins();

    LPC_GPIO_PORT->DIR0 |= (1 << GSM_PWR);

    RFM69_init();

#if defined(GATEWAY) || defined(DEBUG) || defined(GPS)
    mrtDelay(100);
    printf("Node Booted\r\n");
    mrtDelay(100);
#endif

    uart1Init(115200);

    GSM_On();

    //GSM_AT();


#if defined(GATEWAY) || defined(DEBUG) || defined(GPS)
    printf("Node initialized, version %s\r\n",GIT_VER);
#endif

    //Seed random number generator, we can use our 'unique' ID
    random_output = NODE_ID[0] + NODE_ID[1] + NODE_ID[2];

    mrtDelay(5000);

    GSM_AT();
    mrtDelay(5000);

    GSM_upload();

    while(1) {



        GSM_AT();

        incrementPacketCount();

        //Clear buffer
        data_temp[0] = '\0';
        uint8_t n;

        //Create the packet
        int int_temp;

        int_temp = RFM69_readTemp(); // Read transmitter temperature
        rx_rssi = RFM69_lastRssi();
        // read the rssi threshold before re-sampling noise floor which will change it
        rssi_threshold = RFM69_lastRssiThreshold();
        floor_rssi = RFM69_sampleRssi();

        if(data_count == 97) {
            n = sprintf(data_temp, "%d%cL%s[%s]", NUM_REPEATS, data_count, LOCATION_STRING, NODE_ID);
        }
        else {

#ifdef DEBUG
            n = sprintf(data_temp, "%d%cT%dR%d,%dC%dX%d,%dV%d[%s]", NUM_REPEATS, data_count, int_temp, rx_rssi, floor_rssi, rx_packets, rx_restarts, rssi_threshold, adc_result, NODE_ID);
#else
            n = sprintf(data_temp, "%d%cT%dR%dX%d[%s]", NUM_REPEATS, data_count, int_temp, rx_rssi, rx_packets, NODE_ID);
#endif
        }

        transmitData(n);
        GSM_upload();

        awaitData(TX_GAP);

    }

}