Changeset - b6a1b8d502cc
[Not reviewed]
default
0 22 0
ethanzonca@CL-SEC241-08.cedarville.edu - 12 years ago 2012-11-28 21:54:02
ethanzonca@CL-SEC241-08.cedarville.edu
Significant commenting and reformatting of documents, no functional changes. [reindented APRS generator]
22 files changed with 306 insertions and 173 deletions:
0 comments (0 inline, 0 general)
master/master/config.h
Show inline comments
 
/*
 
 * config.h
 
 *
 
 * Created: 10/25/2012 3:28:22 PM
 
 *  Author: ethanzonca
 
 */ 
 
 
/*
 
 * Master Firmware: Configuration
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 * 
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
#ifndef CONFIG_H_
 
#define CONFIG_H_
 
 
// --------------------------------------------------------------------------
 
// Module config (master.c)
 
// --------------------------------------------------------------------------
 
 
#define F_CPU 11059200
 
#define MODULE_ID '1'
 
 
 
// --------------------------------------------------------------------------
 
// Error Codes config (led.c)
 
// --------------------------------------------------------------------------
 
 
// SD Card
 
#define ERROR_SD_INIT 2
 
#define ERROR_SD_PARTITION 3
 
 
 
// --------------------------------------------------------------------------
 
// Slave Sensors config (slavesensors.c)
 
// --------------------------------------------------------------------------
 
 
#define SLAVE0_SENSORS BOARDTEMP
 
#define SLAVE1_SENSORS BOARDTEMP | HUMIDITY | TEMPERATURE | PRESSURE | AMBIENTLIGHT
 
#define SLAVE2_SENSORS BOARDTEMP | GEIGER
 
#define SLAVE3_SENSORS BOARDTEMP | CAMERA
 
#define SLAVE4_SENSORS NONE
 
#define SLAVE5_SENSORS NONE
 
#define SLAVE6_SENSORS NONE
 
#define SLAVE7_SENSORS NONE
 
 
 
// --------------------------------------------------------------------------
 
// USART config (serial.c)
 
// --------------------------------------------------------------------------
 
 
#define USART0_BAUDRATE 115200
 
#define USART1_BAUDRATE 115200
 
 
 
// --------------------------------------------------------------------------
 
// AX.25 config (ax25.c)
 
// --------------------------------------------------------------------------
 

	
 
// TX delay in milliseconds
 
#define TX_DELAY      300
 

	
 
// Maximum packet delay
 
#define MAX_PACKET_LEN 512  // bytes
 
 

	
 
// --------------------------------------------------------------------------
 
// APRS config (aprs.c)
 
// --------------------------------------------------------------------------
 

	
 
// Set your callsign and SSID here. Common values for the SSID are
 
// (from http://zlhams.wikidot.com/aprs-ssidguide):
 
//
 
// - Balloons:  11
 
// - Cars:       9
 
// - Home:       0
 
// - IGate:      5
 
#define S_CALLSIGN      "MYCALL"
 
#define S_CALLSIGN      "KD8TDF"
 
#define S_CALLSIGN_ID   11
 

	
 
// Destination callsign: APRS (with SSID=0) is usually okay.
 
#define D_CALLSIGN      "APRS"
 
#define D_CALLSIGN_ID   0
 

	
 
// Digipeating paths:
 
// (read more about digipeating paths here: http://wa8lmf.net/DigiPaths/ )
 
// The recommended digi path for a balloon is WIDE2-1 or pathless. The default
 
// is pathless. Uncomment the following two lines for WIDE2-1 path:
 
#define DIGI_PATH1      "WIDE2"
 
#define DIGI_PATH1_TTL  1
 

	
 
// APRS comment: this goes in the comment portion of the APRS message. You
 
// might want to keep this short. The longer the packet, the more vulnerable
 
// it is to noise.
 
#define APRS_COMMENT    "Trackuino reminder: replace callsign with your own"
 
#define APRS_COMMENT    "Custom payload data here, eventually..."
 
 
// Transmit the APRS sentence every X milliseconds
 
#define APRS_TRANSMIT_PERIOD 5000
 

	
 

	
 
// --------------------------------------------------------------------------
 
// Logger config (logger.c)
 
// --------------------------------------------------------------------------
 
 
#define LOGGER_ID_EEPROM_ADDR 0x10
 
 
// Written to the beginning of every log file
 
#define LOGGER_HEADERTEXT "HAB Control Master - 1.0\n"
 
 
// Log to SD card every X milliseconds
 
#define LOGGER_RATE 1000 
 
master/master/lib/afsk.c
Show inline comments
 
/*
 
 * fsk.c
 
 *
 
 * Created: 10/29/2012 7:40:34 PM
 
 *  Author: ethanzonca
 
/*
 
 * Master Firmware: AFSK Generation
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 * 
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 

	
 

	
 
#include "../config.h"
 
#include "afsk.h"
 

	
 
#include <stdint.h>
 
#include <stdbool.h>
 
#include <avr/io.h>
 
#include <avr/interrupt.h> 
 
#include <util/delay.h>
 
#include <avr/pgmspace.h>
 

	
 

	
 
PROGMEM extern const uint8_t afsk_sine_table[512] = {
 
  127, 129, 130, 132, 133, 135, 136, 138, 139, 141, 143, 144, 146, 147, 149, 150, 152, 153, 155, 156, 158, 
 
  159, 161, 163, 164, 166, 167, 168, 170, 171, 173, 174, 176, 177, 179, 180, 182, 183, 184, 186, 187, 188, 
 
@@ -66,87 +72,83 @@ extern const uint16_t TABLE_SIZE = sizeo
 
// phase offset of 1800 gives ~1900 Hz
 
// phase offset of 3300 gives ~2200 Hz
 
#define PHASE_DELTA_1200 1800
 
#define PHASE_DELTA_2200 2200
 

	
 
// Module globals
 
volatile unsigned char current_byte;
 
volatile unsigned char current_sample_in_baud;    // 1 bit = SAMPLES_PER_BAUD samples
 
volatile bool go = false;                 
 

	
 
volatile unsigned int packet_pos;                 // Next bit to be sent out
 

	
 

	
 
volatile unsigned int afsk_packet_size = 10;
 
volatile const uint8_t *afsk_packet;
 

	
 

	
 

	
 

	
 

	
 

	
 
void afsk_ptt_off() {
 
void afsk_ptt_off() 
 
{
 
	// turn ptt off
 
}
 

	
 
void afsk_ptt_on() {
 
void afsk_ptt_on() 
 
{
 
	// turn the ptt on... possibly delay based on spec
 
}
 

	
 

	
 

	
 

	
 

	
 

	
 

	
 
ISR(TIMER2_OVF_vect) 
 
{
 
	if (go) {
 

	
 
		// If done sending packet
 
		if (packet_pos == afsk_packet_size) {
 
		if (packet_pos == afsk_packet_size) 
 
		{
 
			go = false;         // End of transmission
 
			afsk_timer_stop();  // Disable modem
 
			afsk_ptt_off();    // Release PTT
 
			return; // done
 
		}
 

	
 
		// If sent SAMPLES_PER_BAUD already, go to the next bit
 
		if (current_sample_in_baud == 0) {    // Load up next bit
 
			if ((packet_pos & 7) == 0) {          // Load up next byte
 
		if (current_sample_in_baud == 0)  // Load up next bit
 
		{   
 
			if ((packet_pos & 7) == 0) // Load up next byte
 
			{          
 
				current_byte = afsk_packet[packet_pos >> 3];
 
			}				
 
			else {
 
			else 
 
			{
 
				current_byte = current_byte / 2;  // ">>1" forces int conversion
 
			}			
 
			if ((current_byte & 1) == 0) {
 
			if ((current_byte & 1) == 0) 
 
			{
 
				// Toggle tone (1200 <> 2200)
 
				phasedelta ^= (PHASE_DELTA_1200 ^ PHASE_DELTA_2200);
 
			}
 
		}
 
	
 
		phase += phasedelta;
 
		uint8_t s = afsk_read_sample((phase >> 7) & (TABLE_SIZE - 1));
 
		afsk_output_sample(s);
 

	
 
		if(++current_sample_in_baud == SAMPLES_PER_BAUD) {
 
			// sounds fun when this is commented out... but why??!?!
 
		if(++current_sample_in_baud == SAMPLES_PER_BAUD) 
 
		{
 
			current_sample_in_baud = 0;
 
			packet_pos++;
 
		}
 
		
 
	}
 
}	
 

	
 
void afsk_output_sample(uint8_t s) {
 
void afsk_output_sample(uint8_t s) 
 
{
 
	OCR2B = s;
 
}
 

	
 
void afsk_timer_start()
 
{
 
	// Clear the overflow flag, so that the interrupt doesn't go off
 
	// immediately and overrun the next one (p.163).
 
	TIFR2 |= _BV(TOV2);       // Yeah, writing a 1 clears the flag.
 

	
 
	// Enable interrupt when TCNT2 reaches TOP (0xFF) (p.151, 163)
 
	TIMSK2 |= _BV(TOIE2);
 
}
 
@@ -185,25 +187,26 @@ void afsk_start()
 
int afsk_busy()
 
{
 
	return go;
 
}
 

	
 
void afsk_send(const uint8_t *buffer, int len)
 
{
 
	afsk_packet_size = len;
 
	afsk_packet = buffer;
 
}
 

	
 

	
 
void afsk_setup() {
 
void afsk_setup() 
 
{
 
	
 
	// Source timer2 from clkIO (datasheet p.164)
 
	ASSR &= ~(_BV(EXCLK) | _BV(AS2));
 

	
 
	// Set fast PWM mode with TOP = 0xff: WGM22:0 = 3  (p.150)
 
	TCCR2A |= _BV(WGM21) | _BV(WGM20);
 
	TCCR2B &= ~_BV(WGM22);
 

	
 
	// Do non-inverting PWM on pin OC2B (arduino pin 3) (p.159).
 
	// OC2A (arduino pin 11) stays in normal port operation:
 
	// COM2B1=1, COM2B0=0, COM2A1=0, COM2A0=0
 
	TCCR2A = (TCCR2A | _BV(COM2B1)) & ~(_BV(COM2B0) | _BV(COM2A1) | _BV(COM2A0));
master/master/lib/afsk.h
Show inline comments
 
/*
 
 * afsk.h
 
 *
 
 * Created: 10/29/2012 7:43:03 PM
 
 *  Author: ethanzonca
 
 */ 
 
/*
 
 * Master Firmware: AFSK Generation
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 * 
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
 
#ifndef AFSK_H_
 
#define AFSK_H_
 
 
#include <inttypes.h>
 
 
// Private
 
void afsk_output_sample(uint8_t s);
 
void afsk_timer_start();
 
void afsk_timer_stop();
 
 
// Public
 
void afsk_setup();
 
void afsk_test();
 
void afsk_send(const uint8_t *buffer, int len);
 
int afsk_busy();
 
void afsk_start();
 
 
#endif /* AFSK_H_ */
 
\ No newline at end of file
master/master/lib/aprs.c
Show inline comments
 
/*
 
 * aprs.c
 
 *
 
 * Created: 11/8/2012 3:40:57 PM
 
 *  Author: ethanzonca
 
 */ 
 
/*
 
 * Master Firmware: APRS
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 * 
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
#include "../config.h"
 
#include "aprs.h"
 
#include "ax25.h"
 
#include <stdio.h>
 

	
 
const char *gps_aprs_lat = "omgmylatitude";
 
const char *gps_aprs_lon = "omgmylongitude";
 
const char *gps_time = "omgmygpstime";
 
float gps_altitude = 123.5;
 
int gps_course = 5;
 
int gps_speed = 13;
master/master/lib/aprs.h
Show inline comments
 
/*
 
 * aprs.h
 
 *
 
 * Created: 11/8/2012 3:41:04 PM
 
 *  Author: ethanzonca
 
 */ 
 
/*
 
 * Master Firmware: APRS
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 * 
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
 
#ifndef APRS_H_
 
#define APRS_H_
 
 
void aprs_send();
 
 
#endif /* APRS_H_ */
 
\ No newline at end of file
master/master/lib/ax25.c
Show inline comments
 
/*
 
 * ax25.c
 
 *
 
 * Created: 10/30/2012 12:16:41 PM
 
 *  Author: ethanzonca
 
 */ 
 
 
//Licensing: Library from the Trackuino project
 
/*
 
 * Master Firmware: AX25 Protocol
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 * 
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 * Used under the GPL from the Trackuino project
 
 */
 

	
 
#include <inttypes.h>
 
#include "../config.h"
 
#include "ax25.h"
 
#include "afsk.h"
 

	
 
// Module globals
 
static uint16_t crc;
 
static uint8_t ones_in_a_row;
 
static uint8_t packet[MAX_PACKET_LEN];
 
static unsigned int packet_size;
 

	
 
// Module functions
 
void update_crc(uint8_t a_bit)
 
{
 
	crc ^= a_bit;
 
	if (crc & 1)
 
	crc = (crc >> 1) ^ 0x8408;  // X-modem CRC poly
 
	else
 
	crc = crc >> 1;
 
}
 

	
 
void send_byte(uint8_t a_byte)
 
{
 
	uint8_t i = 0;
 
	while (i++ < 8) {
 
	while (i++ < 8) 
 
	{
 
		uint8_t a_bit = a_byte & 1;
 
		a_byte >>= 1;
 
		update_crc(a_bit);
 
		if (a_bit) {
 
		if (a_bit) 
 
		{
 
			// Next bit is a '1'
 
			if (packet_size >= MAX_PACKET_LEN * 8)  // Prevent buffer overrun
 
			return;
 
			packet[packet_size >> 3] |= (1 << (packet_size & 7));
 
			packet_size++;
 
			if (++ones_in_a_row < 5) continue;
 
		}
 
		// Next bit is a '0' or a zero padding after 5 ones in a row
 
		if (packet_size >= MAX_PACKET_LEN * 8)    // Prevent buffer overrun
 
		return;
 
		packet[packet_size >> 3] &= ~(1 << (packet_size & 7));
 
		packet_size++;
 
@@ -53,55 +60,59 @@ void send_byte(uint8_t a_byte)
 

	
 
// Exported functions
 
void ax25_send_byte(uint8_t a_byte)
 
{
 
	// Wrap around send_byte, but prints debug info
 
	send_byte(a_byte);
 
}
 

	
 
void ax25_send_flag()
 
{
 
	uint8_t flag = 0x7e;
 
	int i;
 
	for (i = 0; i < 8; i++, packet_size++) {
 
	for (i = 0; i < 8; i++, packet_size++) 
 
	{
 
		if (packet_size >= MAX_PACKET_LEN * 8)  // Prevent buffer overrun
 
		return;
 
		if ((flag >> i) & 1)
 
		packet[packet_size >> 3] |= (1 << (packet_size & 7));
 
		else
 
		packet[packet_size >> 3] &= ~(1 << (packet_size & 7));
 
	}
 
}
 

	
 
void ax25_send_string(const char *string)
 
{
 
	int i;
 
	for (i = 0; string[i]; i++) {
 
	for (i = 0; string[i]; i++) 
 
	{
 
		ax25_send_byte(string[i]);
 
	}
 
}
 

	
 
void ax25_send_header(const struct s_address *addresses, int num_addresses)
 
{
 
	int i, j;
 
	packet_size = 0;
 
	ones_in_a_row = 0;
 
	crc = 0xffff;
 
	
 
	// Send flags during TX_DELAY milliseconds (8 bit-flag = 8000/1200 ms)
 
	for (i = 0; i < TX_DELAY * 3 / 20; i++) {
 
	for (i = 0; i < TX_DELAY * 3 / 20; i++) 
 
	{
 
		ax25_send_flag();
 
	}
 
	
 
	for (i = 0; i < num_addresses; i++) {
 
	for (i = 0; i < num_addresses; i++) 
 
	{
 
		// Transmit callsign
 
		for (j = 0; addresses[i].callsign[j]; j++)
 
		send_byte(addresses[i].callsign[j] << 1);
 
		// Transmit pad
 
		for ( ; j < 6; j++)
 
		send_byte(' ' << 1);
 
		// Transmit SSID. Termination signaled with last bit = 1
 
		if (i == num_addresses - 1)
 
		send_byte(('0' + addresses[i].ssid) << 1 | 1);
 
		else
 
		send_byte(('0' + addresses[i].ssid) << 1);
 
	}
master/master/lib/ax25.h
Show inline comments
 
/*
 
 * ax25.h
 
 *
 
 * Created: 10/30/2012 12:14:05 PM
 
 *  Author: ethanzonca
 
 */ 
 
/*
 
 * Master Firmware: AX25 Protocol
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 * 
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 * Used under the GPL from the Trackuino project
 
 */
 
 
 
#ifndef AX25_H_
 
#define AX25_H_
 
 
#include <inttypes.h>
 
 
struct s_address {
 
	char callsign[7];
 
	unsigned char ssid;
 
};
 
master/master/lib/led.c
Show inline comments
 
/*
 
 * led.c
 
 *
 
 * Created: 10/25/2012 3:34:03 PM
 
 *  Author: ethanzonca
 
 */ 
 
/*
 
 * Master Firmware: Status and Error LED Handler
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 * 
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
#include "../config.h"
 
#include <avr/io.h>
 
#include <util/delay.h>
 
#include "led.h"
 
 
void led_setup() 
 
{
 
	// Configure ports/pins for LEDs
 
	DDRA = 0xff;
 
	//PORTA = 0x00;
 
}
 
master/master/lib/led.h
Show inline comments
 
/*
 
 * led.h
 
 *
 
 * Created: 10/25/2012 3:34:10 PM
 
 *  Author: ethanzonca
 
 */ 
 
/*
 
 * Master Firmware: Status and Error LED Handler
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 * 
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
 
#ifndef LED_H_
 
#define LED_H_
 
 
#define POWER PB2
 
#define ERROR PB1
 
#define STAT PB0
 
#define OK 2
 
 
void led_setup();
 
void led_on(uint8_t led);
master/master/lib/logger.c
Show inline comments
 
/*
 
 * CFile1.c
 
 *
 
 * Created: 11/7/2012 8:05:44 PM
 
 *  Author: mkanning
 
 */ 
 
/*
 
 * Master Firmware: SD Card Data Logger
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 * 
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
#include "../config.h"
 
#include <util/delay.h>
 
#include <string.h>
 
#include <stdio.h>
 
#include <avr/pgmspace.h>
 
#include <avr/sleep.h>
 
#include <avr/eeprom.h>
 
#include <string.h>
 
#include "sd/fat.h"
 
#include "sd/fat_config.h"
 
#include "sd/partition.h"
 
@@ -101,34 +106,36 @@ void logger_setup()
 
		// Error seeking to file
 
		_delay_ms(10);
 
		fat_close_file(fd);
 
		return;
 
	}
 
		
 
	// Write header information
 
	logger_log(LOGGER_HEADERTEXT);
 
	logger_log("\n-- BEGIN DATA --\n");
 
 
}	
 
 
void logger_log(char *buffer) {
 
void logger_log(char *buffer) 
 
{
 
	uint8_t len = strlen(buffer);
 
	if(fat_write_file(fd, (uint8_t*) buffer, len) != len)
 
	{
 
		// Error writing to file
 
		return;
 
	}
 
}
 
 
void logger_closeLog() {
 
void logger_closeLog() 
 
{
 
	fat_close_file(fd);
 
	fat_close_dir(dd);
 
	fat_close(fs);
 
	partition_close(partition);
 
}
 
 
 
 
 
 
 
// INTERNAL FUNCTIONS
master/master/lib/logger.h
Show inline comments
 
/*
 
 * logger.h
 
 *
 
 * Created: 11/7/2012 8:06:16 PM
 
 *  Author: mkanning
 
 */ 
 
/*
 
 * Master Firmware: Status and Error LED Handler
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 * 
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
 
#ifndef LOGGER_H_
 
#define LOGGER_H_
 
 
void logger_setup();
 
uint8_t logger_writeLine(char* dateLine, uint8_t length);
 
struct fat_file_struct* open_file_in_dir(struct fat_fs_struct* fs, struct fat_dir_struct* dd, const char* name);
 
uint8_t find_file_in_dir(struct fat_fs_struct* fs, struct fat_dir_struct* dd, const char* name, struct fat_dir_entry_struct* dir_entry);
 
 
void logger_log(char *buffer);
 
void logger_closeLog();
master/master/lib/looptime.c
Show inline comments
 
/*
 
 * looptime.c
 
 *
 
 * Created: 11/19/2012 8:56:42 PM
 
 *  Author: ethanzonca
 
 */ 
 
/*
 
 * Master Firmware: Program Timer
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 * 
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
#include "../config.h"
 
#include <avr/io.h>
 
#include <avr/interrupt.h>
 
#include <util/delay.h>
 
volatile uint32_t millis = 0; // Milliseconds since initialization
 

	
 

	
 

	
 
void time_setup() {
 
void time_setup() 
 
{
 
	DDRA = 0xff;
 
	
 
	// Generic microcontroller config options
 
	OCR0A = 173; // Approx 172.7969 ticks per ms with 64 prescaler
 
	
 
	TCCR0A |= (1 << WGM01) | (1 << WGM00); // Count until OCR0A, then overflow (wgm02 in the next line specifies this as well)
 
	TCCR0B |= (1 << CS01) | (1 << CS00) | (1 << WGM02); // clock div by 64
 
	TIFR0 |= ( 1 << TOV0 ); // clear pending interrupts
 
	TIMSK0 |= (1 << TOIE0); // enable overflow interrupt
 
}
 

	
 

	
 
ISR(TIMER0_OVF_vect) {
 
ISR(TIMER0_OVF_vect) 
 
{
 
	millis = millis + 1;
 
}
 

	
 
uint32_t time_millis() {
 
uint32_t time_millis() 
 
{
 
	return millis; // meh accuracy, but that's OK
 
}
master/master/lib/looptime.h
Show inline comments
 
/*
 
 * looptime.h
 
 *
 
 * Created: 11/19/2012 8:56:49 PM
 
 *  Author: ethanzonca
 
 */ 
 
 
/*
 
 * Master Firmware: Program Timer
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 * 
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
#ifndef LOOPTIME_H_
 
#define LOOPTIME_H_
 
 

	
 
void time_setup();
 

	
 
uint32_t time_millis();
 
 
#endif /* LOOPTIME_H_ */
 
\ No newline at end of file
master/master/lib/serial.c
Show inline comments
 
/*
 
 * serial.c
 
 *
 
 * Created: 10/25/2012 3:19:49 PM
 
 *  Author: ethanzonca
 
 */ 
 
/*
 
 * Master Firmware: USART Send/Recieve
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 * 
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
#include "serial.h"
 
#include "../config.h"
 
#include <avr/io.h>
 
 
void serial0_setup() {
 
	/* Set baud rate */
 
	UBRR0H = (unsigned char)(USART0_BAUD_PRESCALE>>8);
 
	UBRR0L = (unsigned char)USART0_BAUD_PRESCALE;
 
	/* Enable receiver and transmitter */
 
	UCSR0B = (1<<RXEN0)|(1<<TXEN0);
 
	/* Set frame format: 8data, 1stop bit */
 
@@ -45,52 +50,56 @@ unsigned char serial0_readChar()
 
{
 
	while(!(UCSR0A &(1<<RXC0)));
 
	return UDR0;
 
}
 
 
unsigned char serial1_readChar()
 
{
 
	while(!(UCSR1A &(1<<RXC1)));
 
	return UDR1;
 
}
 
 
void serial0_sendString(const char* stringPtr){
 
	while(*stringPtr != 0x00){
 
	while(*stringPtr != 0x00)
 
	{
 
		serial0_sendChar(*stringPtr);
 
		stringPtr++;
 
	}
 
}
 
 
void serial1_sendString(const char* stringPtr){
 
	while(*stringPtr != 0x00){
 
	while(*stringPtr != 0x00)
 
	{
 
		serial1_sendChar(*stringPtr);
 
		stringPtr++;
 
	}
 
}
 
 
 
void serial_sendCommand( char moduleID, char sensorID, char* data )
 
{
 
	char checkSum = 0x00; //initialize checksum
 
	
 
	serial0_sendChar('['); //bracket indicates start of command
 
	serial0_sendChar(moduleID);
 
	checkSum+=moduleID;
 
	
 
	serial0_sendChar(sensorID);
 
	checkSum+=sensorID;
 
	
 
	// send data, null-terminated
 
	while(*data != 0x00){
 
	while(*data != 0x00)
 
	{
 
		serial0_sendChar(*data);
 
		checkSum += *data;
 
		data++;
 
	}
 
	
 
	serial0_sendChar(checkSum);
 
	serial0_sendChar(']'); //bracket indicates end of command
 
}
 
 
void serial_sendResponseData(){
 
void serial_sendResponseData()
 
{
 
	
 
}
 
master/master/lib/serial.h
Show inline comments
 
/*
 
 * serial.h
 
 *
 
 * Created: 10/25/2012 3:19:42 PM
 
 *  Author: ethanzonca
 
 */ 
 
/*
 
 * Master Firmware: USART Send/Recieve
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 * 
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
 
#ifndef SERIAL_H_
 
#define SERIAL_H_
 
 
#include <inttypes.h>
 
 
#define USART0_BAUD_PRESCALE (((F_CPU / (USART0_BAUDRATE * 16UL))) -1 )
 
#define USART1_BAUD_PRESCALE (((F_CPU / (USART1_BAUDRATE * 16UL))) -1 )
 
 
void serial0_sendChar( unsigned char byte );
 
void serial1_sendChar( unsigned char byte );
master/master/lib/serparser.c
Show inline comments
 
/*
 
* serparser.c
 
*
 
* Created: 10/25/2012 8:11:43 PM
 
*  Author: ethanzonca
 
*/
 
 
/*
 
 * Master Firmware: Serial Parser
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 * 
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
// ************* Macros ***************
 
#define SERIAL_RX_HASBYTES UCSR0A & _BV(RXC0)
 
#define MAX_CMD_LEN 16
 
#define BROADCAST_ADDR 0 //public address
 
#include <avr/io.h>
 
#include "../config.h"
 
#include "serial.h"
 
//#define DEBUG
 
 
// ************* Command Definitions ***************
 
master/master/lib/serparser.h
Show inline comments
 
/*
 
 * serparser.h
 
 *
 
 * Created: 10/25/2012 8:11:49 PM
 
 *  Author: ethanzonca
 
 */ 
 
/*
 
 * Master Firmware: Serial Parser
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 * 
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
 
#ifndef SERPARSER_H_
 
#define SERPARSER_H_
 
 
// Prototypes
 
int serparser_parse(void);
 
 
#endif /* SERPARSER_H_ */
 
\ No newline at end of file
master/master/lib/slavesensors.c
Show inline comments
 
/*
 
 * slavesensors.c
 
 *
 
 * Created: 11/27/2012 9:02:12 PM
 
 *  Author: ethanzonca
 
 */ 
 
/*
 
 * Master Firmware: Slave Sensor Data Aquisition
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 * 
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
#include <avr/io.h>
 
#include <stdbool.h>
 
#include "../config.h"
 
#include "serial.h"
 
#include "serparser.h"
 

	
 
// Serial Commands
 
enum sensorTypes // CMD ID#
 
{
 
	NONE = 0,
 
	BOARDTEMP = (1<<0),
master/master/lib/slavesensors.h
Show inline comments
 
/*
 
 * slavesensors.h
 
 *
 
 * Created: 11/27/2012 9:05:47 PM
 
 *  Author: ethanzonca
 
 */ 
 
/*
 
 * Master Firmware: Slave Sensor Data Aquisition
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 * 
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
 
#ifndef SLAVESENSORS_H_
 
#define SLAVESENSORS_H_
 
 
#include <stdbool.h>
 
 
void slavesensors_setup();
 
bool slavesensors_process();
 
 
 
#endif /* SLAVESENSORS_H_ */
 
\ No newline at end of file
master/master/lib/watchdog.c
Show inline comments
 
/*
 
 * watchdog.c
 
 *
 
 * Created: 11/19/2012 6:50:51 PM
 
 *  Author: ethanzonca
 
 */ 
 
/*
 
 * Master Firmware: Watchdog Timer
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 * 
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
 
#include <avr/io.h>
 
#include <avr/interrupt.h>
 
#include <avr/wdt.h>
 
 
//initialize watchdog
 
void watchdog_setup(void)
 
{
 
	
 
	cli();
 
	wdt_reset();
master/master/lib/watchdog.h
Show inline comments
 
/*
 
 * watchdog.h
 
 *
 
 * Created: 11/19/2012 6:50:58 PM
 
 *  Author: ethanzonca
 
 */ 
 
/*
 
 * Master Firmware: Watchdog Timer
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 * 
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
 
#ifndef WATCHDOG_H
 
#define WATCHDOG_H
 
 
void watchdog_setup(void);
 
 
#endif
 
\ No newline at end of file
master/master/master.c
Show inline comments
 
@@ -21,25 +21,26 @@
 
#include <stdbool.h>
 

	
 
#include "lib/serial.h"
 
#include "lib/aprs.h"
 
#include "lib/afsk.h"
 
#include "lib/led.h"
 
#include "lib/logger.h"
 
#include "lib/watchdog.h"
 
#include "lib/sd/sd_raw_config.h"
 
#include "lib/looptime.h"
 
#include "lib/slavesensors.h"
 

	
 
void micro_setup() {
 
void micro_setup() 
 
{
 

	
 
}
 

	
 
int main(void)
 
{
 
    
 
	// Initialize libraries
 
	time_setup();
 
	micro_setup();
 
	watchdog_setup();
 
	led_setup();
 
	serial0_setup();
 
@@ -62,45 +63,47 @@ int main(void)
 
	uint32_t lastLog = 0;
 
	
 
	// If we are currently processing sensor data
 
	bool isProcessing = false;
 
	
 
	// Write CSV header to SD card
 
	logger_log("ProgramTime,LastAprsBroadcast,LastLog\n");
 
	
 
	while(1)
 
    {
 
		
 
		// Periodic: Logging
 
		if(time_millis() - lastLog > LOGGER_RATE) {
 
		if(time_millis() - lastLog > LOGGER_RATE) 
 
		{
 
			
 
			// TODO: Acquire data from daughterboards
 
			//       This will be complicated because we need timeouts / unreliable transmission, etc
 
			//
 
			// For each daughterboard...
 
			//   1. Send request to daughterboard for sensor data
 
			//   2. Wait for response from daughterboard (timeout!)
 
			//   3. Put data into local variables for transmission / logging
 
			
 
			led_on(STAT);
 
			snprintf(logbuf, 32, "%lu,%lu,%lu,\r\n", time_millis(), lastAprsBroadcast,lastLog);
 
			logger_log(logbuf);
 
			serial0_sendString("SD Logger: ");
 
			serial0_sendString(logBufPtr);
 
			led_off(STAT);
 
			lastLog = time_millis();
 
		}		
 
		
 
		// Periodic: APRS transmission
 
		if(time_millis() - lastAprsBroadcast > APRS_TRANSMIT_PERIOD) {
 
		if(time_millis() - lastAprsBroadcast > APRS_TRANSMIT_PERIOD) 
 
		{
 
			while(afsk_busy());
 
			aprs_send(); // non-blocking
 
			serial0_sendString("Initiating APRS transmission...\r\n");
 
			
 
			// Start getting values for next transmission
 
			isProcessing = true;
 
			
 
			lastAprsBroadcast = time_millis();
 
		}			
 
		
 
		// keep calling processSensors until it is finished
 
		if(isProcessing) 
0 comments (0 inline, 0 general)