Files
@ 51e4ad5deebf
Branch filter:
Location: seniordesign-firmware/slave/slave/lib/masterComm.c
51e4ad5deebf
3.4 KiB
text/plain
Finished Master comms format
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | /*
* masterComm.c
*
* Created: 1/22/2013 3:40:53 PM
* Author: kripperger
*/
#include <avr/io.h>
#include <stdio.h>
#include "../config.h"
#include "masterComm.h"
#include "serial.h"
#include "serparser.h"
#include "inputOutput.h"
#include "sensors.h"
#include "geiger.h"
#include "led.h"
uint8_t dataTypes;
char buff2[64];
char masterComm_checksum(const char* stringPtr)
{
char sum = 0;
while(*stringPtr != 0x00)
{
sum += *stringPtr;
stringPtr++;
}
return sum;
}
void masterComm_types()
{
switch(io_getModuleId())
{
case 0:
// Generic
dataTypes = DATATYPES_GENERIC;
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 Board Temperature (Common for all modules)
masterComm_packetSend_signed(0,sensors_getBoardTemp());
// Send Heater Status (Common for all modules)
masterComm_packetSend_unsigned(1,/*Heater Status Get Function Here */0);
// Send Battery Level (Common for all modules)
masterComm_packetSend_unsigned(2,/*Battery Level Get Function Here */0);
// Send module specific sensor readings
switch(io_getModuleId())
{
case 0:
// Generic
break;
case 1:
// Sensors
// Send SPI Temperature (Air)
masterComm_packetSend_unsigned(3,sensors_getSpiTemp());
// Send Ambient Light (Needs to be formatted)
masterComm_packetSend_unsigned(4,/*Ambient Light Get Function Here */0);
// Send Humidity
masterComm_packetSend_unsigned(5,/*Humidity Get Function Here */0);
// Send Pressure
masterComm_packetSend_unsigned(6,/*Pressure Get Function Here */0);
// Send Altitude
masterComm_packetSend_unsigned(7,/*Altitude Get Function Here */0);
break;
case 2:
// Geiger
// Send CPM (radiation)
masterComm_packetSend_unsigned(8,geiger_getCpm());
break;
case 3:
// Camera
break;
default:
break;
}
}
void masterComm_send()
{
masterComm_types(); // Calculates how many data types to send
// Return request with number of data types to be sent
serial0_sendChar('['); // Send opening bracket
snprintf(buff2,64,"@%u",dataTypes); // Send package (@ reply and number of data types)
serial0_sendString(buff2);
serial0_sendChar(']'); // Send closing bracket
serial0_sendChar(masterComm_checksum(buff2)); // Calculate and send checksum
masterComm_modules(); // Send sensor data
}
void masterComm_checkParser()
{
if (serparser_parse() == PARSERESULT_PARSEOK)
{
if (getPayloadType() == ('@'-0x30)) // Request for data recieved
{
led_on(2);
// Send all data
masterComm_send();
//led_off(2);
}
}
}
|