# HG changeset patch # User kripperger@CL-SEC241-09.cedarville.edu # Date 2013-01-23 21:48:11 # Node ID 2d1f159689de8660d5adcdeea41b6f3d63b1b2b2 # Parent 8fb88c0ed65a4bfc0ca909f635c32266cc668cdf Work on the Slave to master communications diff --git a/slave/slave/config.h b/slave/slave/config.h --- a/slave/slave/config.h +++ b/slave/slave/config.h @@ -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) diff --git a/slave/slave/lib/inputOutput.c b/slave/slave/lib/inputOutput.c --- a/slave/slave/lib/inputOutput.c +++ b/slave/slave/lib/inputOutput.c @@ -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() + + + + + void io_readModuleId() { // Get ID from rotary dip and return it. - uint8_t id; - id = 0; - - - + 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 diff --git a/slave/slave/lib/inputOutput.h b/slave/slave/lib/inputOutput.h --- a/slave/slave/lib/inputOutput.h +++ b/slave/slave/lib/inputOutput.h @@ -10,8 +10,10 @@ #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(); uint8_t io_heaterStatus(); diff --git a/slave/slave/lib/masterComm.c b/slave/slave/lib/masterComm.c --- a/slave/slave/lib/masterComm.c +++ b/slave/slave/lib/masterComm.c @@ -7,15 +7,49 @@ #include +#include #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"); } diff --git a/slave/slave/lib/masterComm.h b/slave/slave/lib/masterComm.h --- a/slave/slave/lib/masterComm.h +++ b/slave/slave/lib/masterComm.h @@ -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 diff --git a/slave/slave/slave.c b/slave/slave/slave.c --- a/slave/slave/slave.c +++ b/slave/slave/slave.c @@ -53,39 +53,38 @@ 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) { // Master communication - //masterComm_check(); - + //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()); -// serial0_sendString(buff); //DEBUG + 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 _delay_ms(1); // Delay to prevent the sensor loop from running again before time_millis changes @@ -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); diff --git a/slave/slave/slave.cproj b/slave/slave/slave.cproj --- a/slave/slave/slave.cproj +++ b/slave/slave/slave.cproj @@ -22,7 +22,7 @@ 0 3.1.3 ISP - com.atmel.avrdbg.tool.avrdragon + com.atmel.avrdbg.tool.ispmk2 com.atmel.avrdbg.tool.simulator AVR Simulator @@ -48,7 +48,7 @@ 127.0.0.1 - 52709 + 52533 False @@ -56,7 +56,7 @@ 249000 1000000 - 250000 + 1970000 false false 0