Changeset - f859ce69ebdb
[Not reviewed]
default
0 4 0
kripperger@CL-SEC241-09.cedarville.edu - 12 years ago 2013-02-01 17:06:48
kripperger@CL-SEC241-09.cedarville.edu
Master comms
4 files changed with 39 insertions and 3 deletions:
0 comments (0 inline, 0 general)
slave/slave/lib/i2c.h
Show inline comments
 
@@ -39,27 +39,27 @@ void i2c_start_wait(unsigned char addr);
 
	//addr is the address and transfer direction of I2C device
 
 
unsigned char i2c_writeX(unsigned char data);	//Send one byte to I2C device
 
	//data is the byte to be transfered
 
	//Returns   0   write successful
 
	//Returns   1   write failed
 
 
unsigned char i2c_readAck(void);	//read one byte from the I2C device, request more data from device
 
	//Returns byte read from I2C device
 
 
unsigned char i2c_readNak(void);	//read one byte from the I2C device, read is followed by a stop condition
 
	//Returns byte read from I2C device
 
 
unsigned char i2c_readX(unsigned char ack);	//read one byte from the I2C device. Implemented as a macro, which calls either i2c_readAck or i2c_readNak
 
#define i2c_readX(ack)  (ack) ? i2c_readAck() : i2c_readNak(); 
 
	//When ack is 1: send ack, request more data from device
 
	//When ack is 0: send nak, read is followed by a stop condition
 
	//Returns byte read from I2C device
 
 
void i2c_write(unsigned char addr, unsigned char reg, unsigned char data); //Does complete write. Can be used as stand alone function.
 
 
unsigned char i2c_read(unsigned char addr, unsigned char reg);
 
 
/////////////////added for humidity
 
unsigned char i2c_read16(unsigned char addr);
 
uint16_t i2c_read16(unsigned char addr);
 
 
#endif /* I2C_H_ */
 
\ No newline at end of file
slave/slave/lib/masterComm.c
Show inline comments
 
@@ -43,57 +43,89 @@ void masterComm_types()
 
			break;
 
			
 
		case 1:
 
			// Sensors
 
			dataTypes = DATATYPES_SENSOR;
 
			break;
 
			
 
		case 2:
 
			// Geiger
 
			dataTypes = DATATYPES_GEIGER;
 
			break;
 
			
 
		case 3:
 
			// Camera
 
			dataTypes = DATATYPES_CAMERA;
 
			break;
 
			
 
		default:
 
			dataTypes = DATATYPES_GENERIC;
 
			break;
 
	}
 
}
 
 
 
void masterComm_packetSend_unsigned(uint8_t id, uint32_t data)
 
{
 
	serial0_sendChar('[');
 
	snprintf(buff2,64,"%u%u",id,data);
 
	serial0_sendString(buff2);
 
	serial0_sendChar(']');
 
	serial0_sendChar(masterComm_checksum(buff2));
 
}
 
 
void masterComm_packetSend_signed(uint8_t id, int32_t data)
 
{
 
	serial0_sendChar('[');
 
	snprintf(buff2,64,"%u%d",id,data);
 
	serial0_sendString(buff2);
 
	serial0_sendChar(']');
 
	serial0_sendChar(masterComm_checksum(buff2));
 
}
 
 
 
 
void masterComm_modules()
 
{
 
	// Send BoardTemperature (Common for all modules)
 
	masterComm_packetSend_signed(0,sensors_getBoardTemp());
 
 
	
 
	// Send Heater Status (Common for all modules)
 
	serial0_sendChar('[');
 
	snprintf(buff2,64,"0%u",sensors_getBoardTemp());
 
	snprintf(buff2,64,"1%u",/*Heater Status Function Here */2);
 
	serial0_sendString(buff2);
 
	serial0_sendChar(']');	
 
	serial0_sendChar(masterComm_checksum(buff2));	
 
	
 
	// Send Battery Level (Common for all modules)
 
	serial0_sendChar('[');
 
	snprintf(buff2,64,"2%u",/*Heater Status Function Here */2);
 
	serial0_sendString(buff2);
 
	serial0_sendChar(']');	
 
	serial0_sendChar(masterComm_checksum(buff2));	
 
	
 
	
 
	// Send module specific sensor readings
 
	switch(io_getModuleId())
 
	{
 
		case 0:
 
			// Generic
 
			
 
			break;
 
		
 
		case 1:
 
			// Sensors
 
			
 
			// Send SPI Temperature (Air)
 
			serial0_sendChar('[');
 
			snprintf(buff2,64,"2%u",sensors_getSpiTemp());
 
			serial0_sendString(buff2);
 
			serial0_sendChar(']');
 
			serial0_sendChar(masterComm_checksum(buff2));
 
			
 
			// Send Ambient Light (Needs to be formatted)
 
			serial0_sendChar('[');
 
			snprintf(buff2,64,"3%u",geiger_getCpm());		//FIX
 
			serial0_sendString(buff2);
 
			serial0_sendChar(']');
 
			serial0_sendChar(masterComm_checksum(buff2));
slave/slave/lib/masterComm.h
Show inline comments
 
/*
 
 * masterComm.h
 
 *
 
 * Created: 1/22/2013 3:40:43 PM
 
 *  Author: kripperger
 
 */ 
 
 
#ifndef MASTERCOMM_H_
 
#define MASTERCOMM_H_
 
 
char masterComm_checksum(const char* stringPtr);
 
 
void masterComm_types();	// Calculates the number of types the module has
 
 
void masterComm_packetSend_unsigned(uint8_t id, uint32_t data);	//Creates the sensor specific packets and sends them
 
void masterComm_packetSend_signed(uint8_t id, int32_t data);
 
 
void masterComm_modules();	// Sends sensor data depending on module
 
 
void masterComm_checkParser();	// Runs parser and checks for data request
 
void masterComm_send();		// Sends data after being requested
 
 
 
 
 
#endif /* MASTERCOMM_H_ */
 
\ No newline at end of file
slave/slave/lib/sensors.c
Show inline comments
 
@@ -198,33 +198,33 @@ void sensors_readLight()
 

	
 
	// FOR BOTH BYTES:
 
	// light = light << 4;
 
	// light = light | (0x0F & i2c_read(LIGHT_ADDR, 0x04));  //  This can be used to read in the 4 LSBs from the second register
 
	// exponent = 8xE3 + 4xE2 + 2xE1 + E0
 
	// mantissa = 128xM7 + 64xM6 + 32xM5 + 16xM4 + 8xM3 + 4xM2 + 2xM1 + M0
 
	// light = 2^(exponent)*mantissa*0.045
 
}
 

	
 
int16_t sensors_getSpiTemp(void)	// Gets spi temperature from variable
 
{
 
	return spiTemp;
 
}
 
 
int8_t sensors_getBoardTemp(void)	// Gets board temperature from variable
 
{
 
	return boardTemp;
 
}
 
 
int32_t sensors_getPressure(void)	// Gets pressure from variable
 
{
 
	return pressure;
 
}
 
 
int sensors_getHumid(void)			// Gets relative humidity from variable
 
uint16_t sensors_getHumid(void)			// Gets relative humidity from variable
 
{
 
	return humid;
 
}
 
 
uint8_t sensors_getLight(void)		// Gets light from variable
 
{
 
	return light;
 
}
 
\ No newline at end of file
0 comments (0 inline, 0 general)