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 71 insertions and 66 deletions:
0 comments (0 inline, 0 general)
master/master/config.h
Show inline comments
 
@@ -8,25 +8,25 @@
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
#ifndef CONFIG_H_
 
#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
 
 
// --------------------------------------------------------------------------
 
// Error Codes config (led.c, used throughout code)
 
// --------------------------------------------------------------------------
 
 
// SD Card
master/master/lib/boardtemp.c
Show inline comments
 
@@ -5,25 +5,25 @@
 
 *  Author: kripperger
 
 */ 
 
 
 
#include <inttypes.h>
 
#include <avr/io.h>
 
#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
 
}
 

	
 
int8_t sensors_getBoardTemp(void)
 
{
 
	return boardTemp;
 
}
master/master/lib/gps.c
Show inline comments
 
@@ -3,44 +3,33 @@
 
*
 
* Created: 11/15/2012 12:02:38 PM
 
*  Author: mkanning
 
*/
 
 
#include <stdbool.h>
 
#include <avr/io.h>
 
#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];
 

	
 
//used to skip over bytes during parse
 
int skipBytes = 0;
 

	
 
//used to index data arrays during data collection
 
int numBytes = 0;
 
@@ -92,27 +81,24 @@ char* get_course() {
 
	return course;
 
}
 
	
 
char dayofmonth[9];	//ddmmyy
 
char* get_dayofmonth() {
 
	return 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
 
	//GGA data fields
 
	GGA_TIME,
 
	GGA_LATITUDE,
 
	GGA_LONGITUDE,
 
	GGA_QUALITY,
 
	GGA_SATELLITES,
 
@@ -270,33 +256,24 @@ void parse_gps_transmission(void){
 
				#ifdef DEBUG_NMEA
 
				serial0_sendString("found lat skip byte\r\n");
 
				#endif
 
				
 
				skipBytes = 1;
 
				setParserState(GGA_LATITUDE);
 
			}
 
			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
 
			{
 
				#ifdef DEBUG_NMEA
 
				serial0_sendString("found lat byte\r\n");
 
				#endif
 
				
 
				latitude[numBytes] = byte; //adjust number of bytes to fit array
 
				numBytes++;
master/master/lib/led.c
Show inline comments
 
@@ -27,26 +27,63 @@ void led_setup()
 
// Turn the specified LED on
 
void led_on(uint8_t led) 
 
{
 
	*(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)
 
{
 
	*(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
 
@@ -52,15 +52,17 @@ static led_t ledList[] = {
 
 
	{&DDRD, &PORTD, PD6}, // SIDEBOARD
 
	{&DDRD, &PORTD, PD5}, // ACTIVITY
 
	{&DDRD, &PORTD, PD4}, // CYCLE
 
	{&DDRA, &PORTA, PD6}, // HEAT
 
};
 
 
#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
 
@@ -29,39 +29,45 @@
 
struct partition_struct* partition;
 
struct fat_fs_struct* fs;
 
struct fat_dir_entry_struct directory;
 
struct fat_dir_struct* dd;
 
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
 
	
 
	// 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;
 
	}
 
	
 
	
 
	// Open FAT filesystem
 
	fs = fat_open(partition);
 
	if(!fs)
 
	{
 
		// opening filesystem failed
 
		led_errorcode(ERROR_SD_PARTITION);
master/master/lib/slavesensors.c
Show inline comments
 
@@ -8,24 +8,25 @@
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
#include <avr/io.h>
 
#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;
 
 
uint16_t slaves[MAX_SLAVES][MAX_SLAVE_SENSORS];
 
 
bool requesting = false;
 
 
void slavesensors_setup() 
 
{
 
@@ -65,60 +66,63 @@ void slavesensors_setup()
 
 
char* bufPtr = 0x00;
 
char debugBuf[64];
 
char slaveAddressLow[6][9];
 
char slaveAddressHigh[6][9];
 
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();
 
			
 

	
 
			// If we're starting a new block but got a newline instead, we're done!
 
			if(lineCount == 0 && strcmp(bufPtr, "") == 0) {
 
				break;			
 
			}
 
			
 
			if(lineCount == 1) {
 
				strcpy(slaveAddressHigh[nodeCount], bufPtr);
 
			}
 
			else if(lineCount == 2) {
 
				strcpy(slaveAddressLow[nodeCount], bufPtr);
 
			}
 
			else if(lineCount == 3) {
 
@@ -133,47 +137,55 @@ void slavesensors_network_scan() {
 
				lineCount = 0;
 
			}
 
			else {
 
				lineCount++;
 
			}
 

	
 
		}		
 

	
 
		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;
 
		}
 
	}
 
	
 
	slavesensors_loggerdest();
 
	
 
	serial0_ion();
 
}
master/master/master.c
Show inline comments
 
@@ -70,62 +70,33 @@ int main(void)
 
	
 
	// Software timers	
 
	uint32_t lastAprsBroadcast = 0;
 
	uint32_t lastLog = 0;
 
	uint32_t lastLedCycle = 0;
 
	
 
	// 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();	
 
		}
 
		
 
		// Periodic: Logging
 
		if(time_millis() - lastLog > LOGGER_RATE) 
 
		{
 
			led_on(LED_CYCLE);
 
			
 
			heater_regulateTemp();
0 comments (0 inline, 0 general)