Changeset - fb9fb20b39da
[Not reviewed]
default
0 8 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-01-18 16:53:44
ethanzonca@CL-ENS241-08.cedarville.edu
Fixed issue where timeouts were not functional, number of discovered nodes now displayed on center LEDs.
8 files changed with 69 insertions and 64 deletions:
0 comments (0 inline, 0 general)
master/master/config.h
Show inline comments
 
@@ -14,13 +14,13 @@
 
#define CONFIG_H_
 
 
// --------------------------------------------------------------------------
 
// Module config (master.c)
 
// --------------------------------------------------------------------------
 
 
#define DEBUG_OUTPUT
 
//#define DEBUG_OUTPUT
 
 
#define F_CPU 11059200
 
#define MODULE_ID '1'
 
#define BOARDTEMP_ADDR 0x90
 
 
#define HEATER_THRESHOLD 70
master/master/lib/boardtemp.c
Show inline comments
 
@@ -11,13 +11,13 @@
 
#include <avr/interrupt.h>
 
#include "../config.h"
 
#include <util/delay.h>
 
#include "boardtemp.h"
 
#include "i2c.h"
 
 
int8_t	boardTemp;	// Board Temperature (from i2c)
 
int8_t	boardTemp = 255;	// Board Temperature (from i2c)
 

	
 
void sensors_readBoardTemp()
 
{
 
	boardTemp = i2c_read(BOARDTEMP_ADDR, 0x00);		// Read only the first byte of data (we don't need the resolution here)
 
	boardTemp = ((boardTemp*18)/10) + (32);			// Converting Celsius to Fahrenheit
 
	boardTemp = boardTemp - 3;						// Linear offset
master/master/lib/gps.c
Show inline comments
 
@@ -10,32 +10,21 @@
 
#include <avr/interrupt.h>
 
#include "gps.h"
 
#include "serial.h"
 
#include "../config.h"
 
#include "led.h"
 

	
 

	
 
 
// Circular buffer for incoming data
 
uint8_t nmeaBuffer[NMEABUFFER_SIZE];
 
 
// Location of parser in the buffer
 
uint8_t nmeaBufferParsePosition = 0;
 
 
// Location of receive byte interrupt in the buffer
 
volatile uint16_t nmeaBufferDataPosition = 0;
 
 

	
 
/*
 
volatile uint8_t charTest;
 
ISR(USART1_RX_vect)
 
{
 
	serial0_sendChar(UDR1);
 
	
 
}*/
 

	
 
// holds the byte ALREADY PARSED. includes starting character
 
int bytesReceived = 0;
 

	
 
//data (and checksum) of most recent transmission
 
char data[16];
 

	
 
@@ -98,15 +87,12 @@ char* get_dayofmonth() {
 
}
 

	
 
char variation[9];	//xxx.xb
 
int calculatedChecksum;
 
int receivedChecksum;
 

	
 
char convertBuf1[15];
 
char convertBuf2[15];
 

	
 
// transmission state machine
 
enum decodeState {
 
	//shared fields
 
	INITIALIZE=0,
 
	GET_TYPE,
 
	GPS_CHECKSUM,	//XOR of all the bytes between the $ and the * (not including the delimiters themselves), written in hexadecimal
 
@@ -276,21 +262,12 @@ void parse_gps_transmission(void){
 
			}
 
			else if (byte == ',') //end of this data type
 
			{
 
				
 
				latitude[7] = 0x00; // null terminate
 
				
 
				
 
				// First 2 bytes
 
				//convertBuf1[0] = latitude[0];
 
				//convertBuf1[1] = latitude[1];
 
				//convertBuf1[2] = '\0';
 
				//strncpy(convertBuf2, latitude, 7);
 
				//convertBuf2[7] = '\0';
 
				
 
				
 
				setParserState(GGA_LONGITUDE);
 
				skipBytes = 0; //prep for next phase of parse
 
				numBytes = 0;
 
			}
 
			else //store data
 
			{
master/master/lib/led.c
Show inline comments
 
@@ -33,20 +33,57 @@ void led_on(uint8_t led)
 
	// Turn the specified LED off
 
void led_off(uint8_t led) 
 
{
 
	*(ledList[led].port) &= ~(1<<ledList[led].pin);
 
}
 
 
void led_toggle(uint8_t led)
 
{
 
	*(ledList[led].port) ^= (1<<ledList[led].pin);
 
}
 
 
// Flashes error LED a set amount of times, then leaves it on
 
void led_errorcode(uint8_t code) 
 
{
 
	led_off(LED_ERROR);
 
	_delay_ms(400);
 
	for(int i=0; i<code; i++) 
 
	{
 
		led_on(LED_ERROR);
 
		_delay_ms(150);
 
		led_off(LED_ERROR);
 
		_delay_ms(150);
 
	}
 
	_delay_ms(400);
 
	led_on(LED_ERROR);
 
}
 
 

	
 
uint8_t ctr = 0;
 
void led_spin() {
 
	
 
	if(ctr == 0) {
 
		led_on(LED_ACT0);
 
		led_off(LED_ACT1);
 
		led_off(LED_ACT2);
 
		led_off(LED_ACT3);
 
	}
 
	else if (ctr == 1) {
 
		led_on(LED_ACT1);
 
		led_off(LED_ACT0);
 
		led_off(LED_ACT2);
 
		led_off(LED_ACT3);
 
	}
 
	else if (ctr == 2) {
 
		led_on(LED_ACT2);
 
		led_off(LED_ACT1);
 
		led_off(LED_ACT0);
 
		led_off(LED_ACT3);
 
	}
 
	else if (ctr == 3) {
 
		led_on(LED_ACT3);
 
		led_off(LED_ACT1);
 
		led_off(LED_ACT2);
 
		led_off(LED_ACT0);
 
	}
 
	ctr = (ctr + 1) % 4;
 
}
 
\ No newline at end of file
master/master/lib/led.h
Show inline comments
 
@@ -58,9 +58,11 @@ static led_t ledList[] = {
 
 
#define NUM_LEDS 11
 
 
void led_setup();
 
void led_on(uint8_t led);
 
void led_off(uint8_t led);
 
void led_toggle(uint8_t led);
 
void led_errorcode(uint8_t code);
 
void led_spin();
 
 
#endif /* LED_H_ */
master/master/lib/logger.c
Show inline comments
 
@@ -35,13 +35,16 @@ struct fat_file_struct* fd;
 
void logger_setup()
 
{
 
 
	if(!sd_raw_init())
 
	{
 
		// Initializing SD card failed!
 
		#ifdef DEBUG_OUTPUT
 
		serial0_sendString("SD> Error initializing.\r\n");
 
		#endif
 
		
 
		led_errorcode(ERROR_SD_INIT);
 
		return;
 
	}
 
 
	// TODO: Check SD card switch to see if inserted.
 
	// this was included in the library, but is commented out right now
 
@@ -49,13 +52,16 @@ void logger_setup()
 
	// Open first partition
 
	partition = partition_open(sd_raw_read, sd_raw_read_interval, sd_raw_write, sd_raw_write_interval, 0);
 
	
 
	// Check that partition was created correctly
 
	if(!partition)
 
	{
 
		#ifdef DEBUG_OUTPUT
 
		serial0_sendString("SD> Error opening partition.\r\n");
 
		#endif
 
		
 
		// Error opening partition. MBR might be screwed up.
 
		led_errorcode(ERROR_SD_PARTITION);
 
		return;
 
	}
 
	
 
	
master/master/lib/slavesensors.c
Show inline comments
 
@@ -14,12 +14,13 @@
 
#include <stdbool.h>
 
#include "../config.h"
 
#include "serial.h"
 
#include "serparser.h"
 
#include "slavesensors.h"
 
#include "led.h"
 
#include "looptime.h"
 
#include <util/delay.h>
 
#include <avr/wdt.h>
 

	
 
uint8_t currentSlave = 0;
 
uint8_t currentSlaveSensor = 0;
 
 
@@ -71,42 +72,45 @@ uint8_t loggerIndex = 255;
 

	
 
void slavesensors_network_scan() {
 
	serial0_ioff();
 
	
 
	int atOK;
 
	
 
	#ifdef DEBUG_OUTPUT
 
	serial0_sendString("Beginning network scan...\r\n\r\n");
 
	#endif
 
	
 
	_delay_ms(500); // xbee warmup
 
	wdt_reset();
 
	
 
	led_on(LED_ACTIVITY);
 
	atOK = slavesensors_enterAT();
 
		
 
	char nameString[20] = "NONE";
 
	
 
	char slaveNames[6][16]; // Hold 16-char addresses of max 6 nodes, we only need them for debug so they are local 
 
	
 
	uint8_t nodeCount = 0;
 
	
 
	// wait for OK
 
	//todo
 
	if(atOK == 0)
 
	{
 
		led_on(LED_STATUS);
 
		serial0_sendString("ATND");
 
		serial0_sendChar(0x0D);
 
		
 
		// wait for scan to complete
 
		uint16_t scanStart = time_millis(); 		
 
		while(!serial0_hasChar()) {
 
			if(time_millis() - scanStart > 5000) {
 
				led_errorcode(ERROR_XBEETIMEOUT);
 
				return;
 
			}
 
			wdt_reset();
 
		}
 
		
 
		// Scan data end when newline by itself ("")	
 
		int lineCount = 0;	
 
	
 
		while(1) {
 
			bufPtr = serial0_readLine();
 
			
 
@@ -139,35 +143,43 @@ void slavesensors_network_scan() {
 
		}		
 

	
 
		slavesensors_exitAT();
 

	
 
	}
 
	
 
	// Display number of found nodes on spinning indicator
 
	switch(nodeCount) {
 
		case 0:
 
			break;
 
		case 3:
 
			led_on(LED_ACT2);
 
			_delay_ms(100);
 
		case 2:
 
			led_on(LED_ACT1);
 
			_delay_ms(100);	
 
		case 1:
 
			led_on(LED_ACT0);
 
			_delay_ms(100);
 
	}
 
	
 
	led_on(LED_SIDEBOARD);
 
	_delay_ms(200);
 
	led_off(LED_SIDEBOARD);
 

	
 
	#ifdef DEBUG_NETWORKSCAN
 
	#ifdef DEBUG_OUTPUT
 
	serial0_sendString("Discovered: \r\n");
 
	for(int i=0; i<nodeCount; i++) {
 
		snprintf(debugBuf, 64, "  %s - %s%s\r\n", slaveNames[i],slaveAddressHigh,slaveAddressLow[i]);
 
		serial0_sendString(debugBuf);
 
	}
 
	serial0_sendString("\r\n");
 
	if(atOK != 0) {
 
		serial0_sendString("AT mode failed \r\n");
 
	}
 
	#endif
 
	
 
	
 
	// Wait for response
 
	// will be multiple values separated by <CR>
 
	// 9 data lines per node, <CR> terminated, followed by a new line with only <CR> at the end of all nodes.
 
	
 
	// <CR> followed by another <CR> signifies end of scan data
 
	
 
	for(int i=0; i<nodeCount; i++) 
 
	{
 
		if(strcmp(slaveNames[i], XBEE_LOGDEST_NAME) == 0) 
 
		{
 
			loggerIndex = i;
 
		}
master/master/master.c
Show inline comments
 
@@ -76,50 +76,21 @@ int main(void)
 
	// Result of last parser run
 
	int parseResult = PARSERESULT_NODATA;
 
	
 
	// Write CSV header to SD card
 
	logger_log("ProgramTime,LastAprsBroadcast,LastLog\n");
 
	
 
	uint8_t ctr = 0;
 
	void spin() {
 
		
 
		if(ctr == 0) {
 
			led_on(LED_ACT0);
 
			led_off(LED_ACT1);
 
			led_off(LED_ACT2);
 
			led_off(LED_ACT3);
 
		}			
 
		else if (ctr == 1) {
 
			led_on(LED_ACT1);
 
			led_off(LED_ACT0);
 
			led_off(LED_ACT2);
 
			led_off(LED_ACT3);
 
		}			
 
		else if (ctr == 2) {
 
			led_on(LED_ACT2);
 
			led_off(LED_ACT1);
 
			led_off(LED_ACT0);
 
			led_off(LED_ACT3);
 
		}			
 
		else if (ctr == 3) {
 
			led_on(LED_ACT3);
 
			led_off(LED_ACT1);
 
			led_off(LED_ACT2);
 
			led_off(LED_ACT0);
 
		}			
 
		ctr = (ctr + 1) % 4;
 
	}
 
	
 
	serial1_ioff();
 
	
 
	while(1)
 
    {
 
		
 
		// Periodic: LED execution indicator
 
		if(time_millis() - lastLedCycle > LEDCYCLE_RATE) {
 
			spin();
 
			led_spin();
 
			
 
			if(!afsk_busy())
 
				serial1_ion();
 
			lastLedCycle = time_millis();	
 
		}
 
		
0 comments (0 inline, 0 general)