Changeset - 2d1f159689de
[Not reviewed]
default
0 7 0
kripperger@CL-SEC241-09.cedarville.edu - 12 years ago 2013-01-23 21:48:11
kripperger@CL-SEC241-09.cedarville.edu
Work on the Slave to master communications
7 files changed with 82 insertions and 29 deletions:
0 comments (0 inline, 0 general)
slave/slave/config.h
Show inline comments
 
@@ -21,6 +21,11 @@
 
// Maximum payload size of command
 
#define MAX_PAYLOAD_LEN 16
 
 
// Number of datatypes to transmit per module type
 
#define DATATYPES_GENERIC 1
 
#define DATATYPES_SENSOR 6
 
#define DATATYPES_GEIGER 2
 
#define DATATYPES_CAMERA 1
 
 
//Sensors and IO
 
#define SENSOR_LOOP 200				// Frequency of sensor reads (in ms)
slave/slave/lib/inputOutput.c
Show inline comments
 
@@ -11,6 +11,8 @@
 
#include "led.h"
 
#include "sensors.h"
 
 
int8_t	moduleID;	// Slave Module ID from rotary dip switch (or EEPROM)
 
 
 void io_configure()
 
 {
 
	// Configure ports/pins
 
@@ -23,14 +25,14 @@
 
 }
 
 
 
 
 
 uint8_t io_getModuleId()
 
 {
 
	// Get ID from rotary dip and return it. 
 
	uint8_t id;
 
	id = 0;
 
 
	
 
	
 
	
 
 void io_readModuleId()
 
 {
 
	// Get ID from rotary dip and return it. 
 
	moduleID = 0;
 
	
 
	// This method is temporary as the next release will read the module ID from EEPROM
 
	PORTC |= (1 << PC2);	// Pull pins on rotary dip high
 
@@ -38,17 +40,28 @@
 
	PORTC |= (1 << PC4);	// Pull pins on rotary dip high
 
	PORTC |= (1 << PC5);	// Pull pins on rotary dip high
 
	
 
	id = ((PINC & 0b00011100) >> 2);	// Read Dip Encoder
 
	id = ~id;							//Invert Dip reading
 
	id = (id & 0b0111);					//Mask bits
 
	moduleID = ((PINC & 0b00011100) >> 2);		// Read Dip Encoder
 
	moduleID = ~moduleID;						//Invert Dip reading
 
	moduleID = (moduleID & 0b0111);				//Mask bits
 
 
 
	//id = i2c_read(EEPROM_ADDR, 0x04);
 
/*
 
	while(moduleID==0)
 
	{
 
		moduleID = i2c_read(EEPROM_ADDR, 0x04);
 
	}
 
*/
 
 
 
	return id;
 
 }
 
 
 
 
 
 uint8_t io_getModuleId()
 
 {
 
	return moduleID;
 
 }
 
 
 
 
 
 void io_heaterOn()
 
 {		
 
	PORTB |= (1 << PB4);	//ON
slave/slave/lib/inputOutput.h
Show inline comments
 
@@ -10,7 +10,9 @@
 
#define IO_H_
 
 
 
void io_configure();
 
uint8_t io_getModuleId();	// Get ID from rotary dip and return it.
 
 
void io_readModuleId();	// Reads ID from rotary dip (or EEPROM).
 
uint8_t io_getModuleId();	// Gets ID and returns it.
 
 
 
void io_heaterOn();
 
void io_heaterOff();
slave/slave/lib/masterComm.c
Show inline comments
 
@@ -7,15 +7,49 @@
 
 
 
#include <avr/io.h>
 
#include <stdio.h>
 
#include "../config.h"
 
#include "masterComm.h"
 
#include "serial.h"
 
#include "serparser.h"
 
#include "inputOutput.h"
 
 
char buff2[64];
 
 
void masterComm_send()
 
{
 
	//Send stuff
 
	serial0_sendString("[@");
 
	switch(io_getModuleId())
 
	{
 
		case 0:
 
			// Generic
 
			snprintf(buff2,64,"%u",DATATYPES_GENERIC);
 
			break;
 
			
 
		case 1:
 
			// Sensors
 
			snprintf(buff2,64,"%u",DATATYPES_SENSOR);
 
			break;
 
			
 
		case 2:
 
			// Geiger
 
			snprintf(buff2,64,"%u",DATATYPES_GEIGER);
 
			break;
 
			
 
		case 3:
 
			// Camera
 
			snprintf(buff2,64,"%u",DATATYPES_CAMERA);
 
			break;
 
			
 
		default:
 
			snprintf(buff2,64,"%u",DATATYPES_GENERIC);
 
			break;
 
	}
 
	
 
	serial0_sendString(buff2);
 

	
 

	
 
	
 
	serial0_sendString("got data\r\n");
 
}
 
slave/slave/lib/masterComm.h
Show inline comments
 
@@ -5,14 +5,13 @@
 
 *  Author: kripperger
 
 */ 
 
 
 
#ifndef MASTERCOMM_H_
 
#define MASTERCOMM_H_
 
 
 
 
void masterComm_check();
 
void masterComm_send();
 
void masterComm_check();	// Runs parser and checks for data request
 
void masterComm_send();		// Sends data after being requested
 
 
 
slave/slave/slave.c
Show inline comments
 
@@ -53,18 +53,17 @@ int main(void)
 
	i2c_init();				// Setup I2C
 
	serial0_setup();		// Config serial port
 
	
 
	uint8_t moduleID = io_getModuleId();	// Slave Module ID from rotary dip switch
 
	modules_setup(moduleID);				// Run setup functions for specific module
 
	io_readModuleId();
 
	modules_setup(io_getModuleId());				// Run setup functions for specific module
 
	
 
	
 
	//uint8_t test;		//Debug
 
	//uint8_t test2;	//Debug	
 
	
 
	
 
	
 
	// Serial output //DEBUG
 
	char buff[64];							//Buffer for serial output //DEBUG
 
	serial0_sendString("Starting\r\n");
 
	serial0_sendString("Starting Slave\r\n");
 
	
 
	
 
    while(1)
 
@@ -74,17 +73,17 @@ int main(void)
 
		//masterComm_check();
 
 
		
 
		
 
		// Main slave operations
 
		if ((time_millis() % SENSOR_LOOP) == 0)	// Uses program timer to run every so often. Time interval defined in config.h
 
		{
 
			led_toggle(2);
 
//			sensors_readBoardTemp();	// Read board temperature sensor (Common on all slaves) (Data Read)
 
//			modules_run(moduleID);		// Runs specific module functions (like data reading)
 

	
 
			sensors_readBoardTemp();	// Read board temperature sensor (Common on all slaves) (Data Read)
 
			modules_run(io_getModuleId());		// Runs specific module functions (like data reading)
 
			
 
//			io_regulateTemp();			// Gets board temperature and enables heater if below threshold
 
			led_toggle(1);
 
//			snprintf(buff,64,"|ModuleID: %u |BoardTemp: %i |Millis: %lu |Heater: %u\r\n",moduleID,sensors_getBoardTemp(),time_millis(),io_heaterStatus()); //DEBUG
 
//			snprintf(buff,64,"lol%i\r\n",sensors_getBoardTemp());
 
			io_regulateTemp();			// Gets board temperature and enables heater if below threshold
 

	
 
			//snprintf(buff,64,"|ModuleID: %u |BoardTemp: %i |Millis: %lu |Heater: %u\r\n",io_getModuleId(),sensors_getBoardTemp(),time_millis(),io_heaterStatus()); //DEBUG
 
//			serial0_sendString(buff); //DEBUG
 

	
 
			led_toggle(0);		// Toggle LED0(Blue) to show loop running
 
@@ -113,6 +112,7 @@ int main(void)
 
		
 
		PORTA &= ~(1 << PA1);	//OFF
 
		PORTA |= (1 << PA1);	//ON
 
		PORTB ^= (1 << PB0);	//Toggle
 
		
 
		sprintf(buff, "log: %u,%u,%u,%u\r\n", temp,temp2,temp3,temp4);
 
		serial0_sendString(buff);
slave/slave/slave.cproj
Show inline comments
 
@@ -22,7 +22,7 @@
 
    <eraseonlaunchrule>0</eraseonlaunchrule>
 
    <AsfVersion>3.1.3</AsfVersion>
 
    <avrtoolinterface>ISP</avrtoolinterface>
 
    <avrtool>com.atmel.avrdbg.tool.avrdragon</avrtool>
 
    <avrtool>com.atmel.avrdbg.tool.ispmk2</avrtool>
 
    <com_atmel_avrdbg_tool_simulator>
 
      <ToolType xmlns="">com.atmel.avrdbg.tool.simulator</ToolType>
 
      <ToolName xmlns="">AVR Simulator</ToolName>
 
@@ -48,7 +48,7 @@
 
      </OverrideVtorValue>
 
      <Channel>
 
        <host>127.0.0.1</host>
 
        <port>52709</port>
 
        <port>52533</port>
 
        <ssl>False</ssl>
 
      </Channel>
 
      <ToolOptions>
 
@@ -56,7 +56,7 @@
 
        <InterfaceProperties>
 
          <JtagDbgClock>249000</JtagDbgClock>
 
          <JtagProgClock>1000000</JtagProgClock>
 
          <IspClock>250000</IspClock>
 
          <IspClock>1970000</IspClock>
 
          <JtagInChain>false</JtagInChain>
 
          <JtagEnableExtResetOnStartSession>false</JtagEnableExtResetOnStartSession>
 
          <JtagDevicesBefore>0</JtagDevicesBefore>
0 comments (0 inline, 0 general)