Changeset - 2406c449316b
[Not reviewed]
default
0 5 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-02-26 16:34:24
ethanzonca@CL-ENS241-08.cedarville.edu
Added buzzer on touchdown support with altitude and failsafe cutoff time. Failsafe is tested and functional, altitude is untested.
5 files changed with 67 insertions and 4 deletions:
0 comments (0 inline, 0 general)
master/master/config.h
Show inline comments
 
@@ -20,24 +20,31 @@
 
// --------------------------------------------------------------------------
 
 
//#define DEBUG_OUTPUT
 
 
#define BLACKOUT_ENABLE
 
 
#define F_CPU 11059200
 
#define MODULE_ID '1'
 
#define BOARDTEMP_ADDR 0x90
 
 
#define HEATER_THRESHOLD 60
 
 
// Touchdown buzzer settings
 
#define BUZZER_RATE 3000
 
#define BUZZER_DURATION 1
 
 
#define BUZZER_FAILSAFE_DURATION 600000
 
#define BUZZER_TRIGGER_MINDURATION 1
 
#define BUZZER_TRIGGER_MAXALTITUDE 1
 
 
// --------------------------------------------------------------------------
 
// Error Codes config (led.c, used throughout code)
 
// --------------------------------------------------------------------------
 
 
// SD Card
 
#define ERROR_SLAVETIMEOUT 0
 
#define ERROR_SD_INIT 1
 
#define ERROR_SD_PARTITION 2
 
#define ERROR_SD_FILE 3
 
 
#define ERROR_XBEETIMEOUT 4
master/master/lib/led.c
Show inline comments
 
@@ -34,40 +34,40 @@ void led_setup()
 
	_delay_ms(1);
 
	led_off(LED_BUZZ);
 
}
 
 
void led_power_toggle() 
 
{
 
	OCR0B ^= 30;
 
}
 
 
// Turn the specified LED on
 
void led_on(uint8_t led) 
 
{
 
	if(blackout && led != LED_ERROR)
 
	if(blackout && led != LED_ERROR && led != LED_BUZZ)
 
	{
 
		return;
 
	}		
 
	*(ledList[led].port) |= (1<<ledList[led].pin);
 
}
 
 
// Turn the specified LED off
 
void led_off(uint8_t led) 
 
{
 
	*(ledList[led].port) &= ~(1<<ledList[led].pin);
 
}
 
 
void led_toggle(uint8_t led)
 
{
 
	if(blackout && led != LED_ERROR)
 
	if(blackout && led != LED_ERROR && led != LED_BUZZ)
 
	{
 
		return;
 
	}
 
	*(ledList[led].port) ^= (1<<ledList[led].pin);
 
}
 
 
void led_blackout() {
 
	if(!blackout) 
 
	{	
 
		blackout = true;
 
		for(int i=0; i<NUM_LEDS; i++)
 
		{
master/master/lib/sensordata.c
Show inline comments
 
@@ -195,13 +195,54 @@ void sensordata_logvalues()
 
				if(tmp != -2111111111) 
 
				{
 
					snprintf(logbuf + strlen(logbuf),CSV_LOGLINE_SIZE-strlen(logbuf)," %ld,", tmp);
 
				}
 
			
 
			}
 
		}
 
		
 
		// End line and write to log
 
		snprintf(logbuf + strlen(logbuf),CSV_LOGLINE_SIZE-strlen(logbuf),"\r\n");
 
		logger_log(logbuf);
 
	}
 
}
 

	
 
bool isTouchdown = false;
 
bool sensordata_isTouchdown()
 
{
 
	return isTouchdown;
 
}
 

	
 
int32_t sensordata_getSensorValue(uint8_t sensorID) 
 
{
 
	// Loop through all slaves
 
	for(int i=0; i<MAX_NUM_SLAVES; i++)
 
	{
 
		uint32_t val = sensordata_get(i, sensorID);
 
		if(val != -2111111111) {
 
			return val;
 
		}
 
	}		
 
	return -2111111111;
 
}
 

	
 
void sensordata_checkTouchdown()
 
{
 
	// If we have reached touchdown, never get out of this state
 
	if(isTouchdown)
 
	{
 
		return;
 
	}
 
	
 
	if(time_millis() > BUZZER_FAILSAFE_DURATION)
 
	{
 
		isTouchdown = true;
 
	}
 
	else
 
	{
 
		int32_t altitude = sensordata_getSensorValue(SENSOR_ALTITUDE);
 
		if(altitude != -2111111111 && altitude < BUZZER_TRIGGER_MAXALTITUDE && time_millis() > BUZZER_TRIGGER_MINDURATION)
 
		{
 
			isTouchdown = true;
 
		}			
 
	}
 
}
 
\ No newline at end of file
master/master/lib/sensordata.h
Show inline comments
 
@@ -12,14 +12,16 @@
 
 
 
#ifndef SENSORDATA_H_
 
#define SENSORDATA_H_
 
 
#include "slavesensors.h"
 
 
void sensordata_setup();
 
void sensordata_set(uint8_t nodeID, uint8_t type, int32_t value);
 
int32_t sensordata_get(uint8_t nodeID, uint8_t type);
 
char* slavesensors_getAPRScomment();
 
void sensordata_logvalues();
 
bool sensordata_isTouchdown();
 
void sensordata_checkTouchdown();
 
 
#endif /* SENSORDATA_H_ */
 
\ No newline at end of file
master/master/master.c
Show inline comments
 
@@ -55,34 +55,34 @@ int main(void)
 
	afsk_setup();
 
	
 
	serial0_sendString("\r\nHello.\r\n\r\n");
 
	
 
	// Blocking ZigBee node discovery
 
	slavesensors_network_scan();
 
	
 
	// Software timers	
 
	uint32_t lastAprsBroadcast = 0;
 
	uint32_t lastLog = 0;
 
	uint32_t lastLedCycle = 0;
 
	uint32_t lastDataReq = 0;
 
	uint32_t lastBuzz = 0;
 
	
 
	// Result of last parser run
 
	int parseResult = PARSERESULT_NODATA;
 
	
 
	// FIXME: Probably don't need this.
 
	serial1_ioff();
 
	
 
	while(1)
 
    {
 
		
 
		// Periodic: LED execution indicator
 
		if(time_millis() - lastLedCycle > LEDCYCLE_RATE) 
 
		{
 
			led_power_toggle();
 
			led_spin();
 
			
 
			// Enable GPS serial interrupts if we aren't doing AFSK
 
			if(!afsk_busy())
 
				serial1_ion();
 
				
 
			lastLedCycle = time_millis();	
 
		}
 
@@ -104,46 +104,59 @@ int main(void)
 
				led_off(LED_SIDEBOARD);
 
			}
 
			
 
			sensors_readBoardTemp();
 
		
 
			// Write CSV header and log data values
 
			sensordata_logvalues();			
 
			
 
			led_off(LED_CYCLE);
 
			lastLog = time_millis();
 
		}		
 
		
 
		// Periodic: Buzzer
 
		if(time_millis() - lastBuzz > BUZZER_RATE) {
 
			if(sensordata_isTouchdown())
 
			{
 
				led_on(LED_BUZZ);
 
				_delay_ms(BUZZER_DURATION);
 
				led_off(LED_BUZZ);
 
			}			
 
			lastBuzz = time_millis();
 
		}
 
		
 
		// Periodic: Data Request
 
		if(time_millis() - lastDataReq > DATAREQUEST_RATE)  
 
		{
 
			
 
			// Start getting values for next transmission
 
			if(slavesensors_isrequesting())
 
			{
 
				// TODO: something is terribly wrong. Timeout?
 
			}
 
			else
 
			{
 
				slavesensors_startprocess();
 
			}
 
			
 
			lastDataReq = time_millis();
 
		}
 
		
 
		
 
		// Periodic: APRS transmission
 
		if(time_millis() - lastAprsBroadcast > APRS_TRANSMIT_PERIOD) 
 
		{
 
			// Check for touchdown
 
			sensordata_checkTouchdown();
 
			
 
			// LED blackout
 
			#ifdef BLACKOUT_ENABLE
 
			led_blackout();
 
			#endif
 
			
 
			// Ensure we aren't already transmitting
 
			while(afsk_busy());
 
			
 
			// Turn off interrupts and transmit APRS sentence
 
			serial1_ioff();
 
			aprs_send(); // non-blocking
 
			
 
			lastAprsBroadcast = time_millis();
0 comments (0 inline, 0 general)