Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added ParkingGarage Mote Source

  • Loading branch information...
commit 61a56094931ffe45749da14bdc820f0b5d2c13c2 1 parent a149e98
@VictoryIsMine VictoryIsMine authored
View
38 src/ParkingGarage/AdcChannel1C.nc
@@ -0,0 +1,38 @@
+#include "Msp430Adc12.h"
+
+module AdcChannel1C {
+ provides {
+ interface AdcConfigure<const msp430adc12_channel_config_t*>;
+ interface Read<uint16_t> as ReadMe;
+ }
+ uses {
+ interface Read<uint16_t>;
+ }
+}
+implementation {
+
+ const msp430adc12_channel_config_t config = {
+ inch: INPUT_CHANNEL_A0,
+ sref: REFERENCE_AVcc_AVss,
+ ref2_5v: REFVOLT_LEVEL_NONE,
+ adc12ssel: SHT_SOURCE_ACLK,
+ adc12div: SHT_CLOCK_DIV_1,
+ sht: SAMPLE_HOLD_4_CYCLES,
+ sampcon_ssel: SAMPCON_SOURCE_SMCLK,
+ sampcon_id: SAMPCON_CLOCK_DIV_1
+ };
+
+ event void Read.readDone( error_t result, uint16_t val )
+ {
+ signal ReadMe.readDone(result, val);
+ }
+
+ command error_t ReadMe.read() {
+ return call Read.read();
+ }
+
+ async command const msp430adc12_channel_config_t* AdcConfigure.getConfiguration()
+ {
+ return &config; // must not be changed
+ }
+}
View
2  src/ParkingGarage/Makefile
@@ -0,0 +1,2 @@
+COMPONENT=ParkingGarageAppC
+include $(MAKERULES)
View
97 src/ParkingGarage/ParkingGarage.h
@@ -0,0 +1,97 @@
+/*
+ * Matt Lindsay
+ * CSE521S project
+ * ParkingGarage is is part of a parking guidance and information system
+ * designed to take advantage of the TelosB and an analog range finder.
+ */
+
+#ifndef PARKING_GARAGE_H
+#define PARKING_GARAGE_H
+
+typedef nx_struct parking_garage_config_msg
+{
+ nx_uint16_t parking_space_id;
+ nx_uint16_t packet_id;
+ nx_uint16_t new_parking_space_id;
+ nx_uint16_t status_interval;
+} parking_garage_config_msg_t;
+
+typedef nx_struct parking_garage_status_msg
+{
+ nx_uint16_t parking_space_id;
+ nx_uint16_t packet_id;
+ nx_uint16_t sensor;
+ nx_uint16_t sensor_value;
+} parking_garage_status_msg_t;
+
+typedef nx_struct parking_garage_status_debug_msg
+{
+ nx_uint16_t parking_space_id;
+ nx_uint16_t packet_id;
+ nx_uint16_t light_sensor;
+ nx_uint16_t passive_ir_sensor;
+ nx_uint16_t temp_sensor;
+ nx_uint16_t humid_sensor;
+ nx_uint16_t active_ir_sensor;
+ nx_uint16_t minutes_occupied;
+} parking_garage_status_debug_msg_t;
+
+typedef nx_struct parking_garage_command_msg
+{
+ nx_uint16_t parking_space_id;
+ nx_uint16_t packet_id;
+ nx_uint16_t online_status;
+ nx_uint16_t data;
+} parking_garage_command_msg_t;
+
+enum
+{
+ // Message Structures
+ PARKING_GARAGE_CONFIG_MSG = 200,
+ PARKING_GARAGE_STATUS_MSG = 201,
+ PARKING_GARAGE_STATUS_DEBUG_MSG = 202,
+ PARKING_GARAGE_COMAND_MSG = 203,
+};
+
+enum
+{
+ // Packets
+ /*
+ * Error Messages 0 - 10
+ * 0 - General Error
+ */
+ ERROR_MESSAGE = 0,
+
+ /*
+ * Config Messages 11 - 20
+ * 11 - Setup Message
+ */
+ CONFIG_SETUP_MESSAGE = 11,
+
+ /*
+ * Sensor Messages 21 - 90
+ * 21 - Sensor Light
+ */
+ SENSOR_LIGHT = 21,
+
+ /*
+ * Debug Messages 91+
+ * 91 - All Sensors
+ */
+ DEBUG_MESSAGE = 91,
+};
+
+enum
+{
+ ADC1 = 0,
+ TEMPERATURE = 1,
+ HUMIDITY = 2,
+ LIGHT = 3,
+ IR_LIGHT = 4,
+ /*
+ * Add new sensors here and increment NUMBER_OF_SENSORS
+ */
+ NUMBER_OF_SENSORS = 5
+};
+
+#endif
View
64 src/ParkingGarage/ParkingGarageAppC.nc
@@ -0,0 +1,64 @@
+/*
+ * Matt Lindsay
+ * CSE521S project
+ * ParkingGarage is is part of a parking guidance and information system
+ * designed to take advantage of the TelosB and an analog range finder.
+ */
+
+#include <Timer.h>
+#include <UserButton.h>
+#include "ParkingGarage.h"
+
+configuration ParkingGarageAppC
+{
+
+}
+implementation
+{
+ components MainC;
+ components ParkingGarageC as App;
+ components LedsC;
+ components ActiveMessageC;
+ components new AMSenderC(PARKING_GARAGE_STATUS_MSG) as StatusSenderC;
+ components new AMSenderC(PARKING_GARAGE_STATUS_DEBUG_MSG) as StatusDebugSenderC;
+ components new AMReceiverC(PARKING_GARAGE_CONFIG_MSG) as ConfigReceiverC;
+ components new AMReceiverC(PARKING_GARAGE_COMAND_MSG) as CommandReceiverC;
+ components new TimerMilliC() as StatusTimerC;
+ components new TimerMilliC() as SensorTimerC;
+ components new TimerMilliC() as LEDTimerC;
+ components new TimerMilliC() as TimeoutTimerC;
+ components UserButtonC;
+ components new AdcReadClientC() as A1_Client;
+ components AdcChannel1C;
+ components new SensirionSht11C() as HumidityTempC;
+ components new HamamatsuS10871TsrC() as TotalSolarC;
+ components new HamamatsuS1087ParC() as PhotoActiveC;
+
+ App.Boot -> MainC.Boot;
+
+ App.ConfigReceive -> ConfigReceiverC;
+ App.CommandReceive -> CommandReceiverC;
+
+ App.StatusSend -> StatusSenderC;
+ App.StatusDebugSend -> StatusDebugSenderC;
+
+ App.RadioControl -> ActiveMessageC;
+ App.Packet -> ActiveMessageC;
+
+ App.Leds -> LedsC;
+
+ App.StatusTimer -> StatusTimerC;
+ App.SensorTimer -> SensorTimerC;
+ App.LEDTimer -> LEDTimerC;
+ App.TimeoutTimer -> TimeoutTimerC;
+
+ A1_Client.AdcConfigure -> AdcChannel1C;
+ AdcChannel1C.Read -> A1_Client;
+ App.AdcC1 -> AdcChannel1C.ReadMe;
+
+ App.ButtonNotify -> UserButtonC;
+ App.Temp -> HumidityTempC.Temperature;
+ App.Humid -> HumidityTempC.Humidity;
+ App.Light -> PhotoActiveC;
+ App.IR -> TotalSolarC;
+}
View
408 src/ParkingGarage/ParkingGarageC.nc
@@ -0,0 +1,408 @@
+/*
+ * Matt Lindsay
+ * CSE521S project
+ * ParkingGarage is is part of a parking guidance and information system
+ * designed to take advantage of the TelosB and an analog range finder.
+ */
+
+module ParkingGarageC {//}@safe(){
+ uses
+ {
+ interface Boot;
+ interface SplitControl as RadioControl;
+ interface Packet;
+ interface Receive as ConfigReceive;
+ interface Receive as CommandReceive;
+ interface AMSend as StatusSend;
+ interface AMSend as StatusDebugSend;
+ interface Leds;
+ interface Timer<TMilli> as StatusTimer;
+ interface Timer<TMilli> as SensorTimer;
+ interface Timer<TMilli> as LEDTimer;
+ interface Timer<TMilli> as TimeoutTimer;
+ interface Read<uint16_t> as AdcC1;
+ interface Read<uint16_t> as Temp;
+ interface Read<uint16_t> as Humid;
+ interface Read<uint16_t> as Light;
+ interface Read<uint16_t> as IR;
+ interface Notify<button_state_t> as ButtonNotify;
+ }
+}
+implementation {
+
+ uint16_t sensor_max = 0;
+ uint16_t sensor_min = 0;
+ uint16_t sensor_config = 0;
+ uint16_t actual_active_ir_sensor = 0;
+ uint16_t carPresentThreshold = 0;
+ uint16_t parkingSpaceID = 0;
+ uint16_t statusPacketID = 0;
+ uint16_t statusDebugPacketID = 0;
+ uint16_t numberOfReads = 10;
+ uint16_t read_count[NUMBER_OF_SENSORS];
+ uint16_t temp_sensor_value[NUMBER_OF_SENSORS];
+ uint16_t sensor_value[NUMBER_OF_SENSORS];
+ message_t buf;
+
+ task void sendStatusMessage();
+ task void sendStatusDebugMessage();
+ task void readAdcC1();
+ task void readTemp();
+ task void readHumid();
+ task void readLight();
+ task void readIR();
+ void ComposeStatusMessage(parking_garage_status_msg_t *msg, uint16_t sensor);
+ void ComposeStatusDebugMessage(parking_garage_status_debug_msg_t *msg);
+ int ReadAllSensors();
+
+ task void sendStatusMessage()
+ {
+ parking_garage_status_msg_t * payload = (parking_garage_status_msg_t *)call Packet.getPayload(&buf, sizeof(parking_garage_status_msg_t));
+
+ // TODO - add a queue of status message sensors
+ ComposeStatusMessage(payload, LIGHT);
+
+ if(call StatusSend.send(AM_BROADCAST_ADDR, &buf, sizeof(parking_garage_status_msg_t)) != SUCCESS)
+ {
+ post sendStatusMessage();
+ }
+ }
+
+ task void sendStatusDebugMessage()
+ {
+ parking_garage_status_debug_msg_t * payload = (parking_garage_status_debug_msg_t *)call Packet.getPayload(&buf, sizeof(parking_garage_status_debug_msg_t));
+
+ ComposeStatusDebugMessage(payload);
+
+ if(call StatusDebugSend.send(AM_BROADCAST_ADDR, &buf, sizeof(parking_garage_status_debug_msg_t)) != SUCCESS)
+ {
+ post sendStatusDebugMessage();
+ }
+ }
+
+ task void readAdcC1()
+ {
+ if(call AdcC1.read() != SUCCESS)
+ post readAdcC1();
+ }
+
+ task void readTemp()
+ {
+ if(call Temp.read() != SUCCESS)
+ post readTemp();
+ }
+
+ task void readHumid()
+ {
+ if(call Humid.read() != SUCCESS)
+ post readHumid();
+ }
+
+ task void readLight()
+ {
+ if(call Light.read() != SUCCESS)
+ post readLight();
+ }
+
+ task void readIR()
+ {
+ if(call IR.read() != SUCCESS)
+ post readIR();
+ }
+
+ void ComposeStatusMessage(parking_garage_status_msg_t *msg, uint16_t sensor)
+ {
+ msg->parking_space_id = parkingSpaceID;
+ msg->packet_id = statusPacketID;
+ msg->sensor = sensor;
+ msg->sensor_value = sensor_value[sensor];
+ if(sensor !=0)
+ {
+ }
+ }
+
+ void ComposeStatusDebugMessage(parking_garage_status_debug_msg_t *msg)
+ {
+ msg->parking_space_id = parkingSpaceID;
+ msg->packet_id = statusDebugPacketID;
+ msg->light_sensor = sensor_value[LIGHT];
+ msg->passive_ir_sensor = sensor_value[IR_LIGHT];
+ msg->temp_sensor = sensor_value[TEMPERATURE];
+ msg->humid_sensor = sensor_value[HUMIDITY];
+ msg->active_ir_sensor = sensor_value[ADC1];
+ msg->minutes_occupied = actual_active_ir_sensor;
+ }
+
+ int ReadAllSensors()
+ {
+ int i = 0;
+ int done = 1;
+
+ if(read_count[ADC1] < numberOfReads)
+ {
+ post readAdcC1();
+ done -= 1;
+ }
+ if(read_count[LIGHT] < numberOfReads)
+ {
+ post readLight();
+ done -= 1;
+ }
+ if(read_count[IR_LIGHT] < numberOfReads)
+ {
+ post readIR();
+ done -= 1;
+ }
+ if(read_count[TEMPERATURE] < numberOfReads)
+ {
+ post readTemp();
+ done -= 1;
+ }
+ if(read_count[HUMIDITY] < numberOfReads)
+ {
+ post readHumid();
+ done -= 1;
+ }
+
+ if(done == 1)
+ {
+ call SensorTimer.stop();
+
+ if(sensor_config == 0)
+ {
+ sensor_max = temp_sensor_value[ADC1]/numberOfReads;
+ sensor_value[ADC1] = temp_sensor_value[ADC1]/numberOfReads;
+ actual_active_ir_sensor = carPresentThreshold;
+ for(i=0; i < NUMBER_OF_SENSORS; i += 1)
+ {
+ temp_sensor_value[i] = 0;
+ read_count[i] = 0;
+ }
+ }
+ else if(sensor_config == 1)
+ {
+ sensor_min = temp_sensor_value[ADC1]/numberOfReads;
+ sensor_value[ADC1] = temp_sensor_value[ADC1]/numberOfReads;
+ carPresentThreshold = ((sensor_max - sensor_min)*.8)+sensor_min;
+ actual_active_ir_sensor = carPresentThreshold;
+ for(i=0; i < NUMBER_OF_SENSORS; i += 1)
+ {
+ temp_sensor_value[i] = 0;
+ read_count[i] = 0;
+ }
+ }
+ else
+ {
+ for(i=0; i < NUMBER_OF_SENSORS; i += 1)
+ {
+ if(i != ADC1)
+ {
+ sensor_value[i] = temp_sensor_value[i]/numberOfReads;
+ }
+ else
+ {
+ actual_active_ir_sensor = temp_sensor_value[i]/numberOfReads;
+
+ if((temp_sensor_value[i]/numberOfReads) < carPresentThreshold)
+ {
+ sensor_value[i] = 1;
+ call Leds.led2On();
+ }
+ else
+ {
+ sensor_value[i] = 0;
+ call Leds.led2Off();
+ }
+ }
+ temp_sensor_value[i] = 0;
+ read_count[i] = 0;
+ }
+ }
+
+ post sendStatusDebugMessage();
+
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+
+ }
+
+ event void Boot.booted()
+ {
+ call RadioControl.start();
+ call ButtonNotify.enable();
+ }
+
+ event void RadioControl.startDone(error_t err)
+ {
+ if (err == SUCCESS)
+ {
+ }
+ }
+
+ event void RadioControl.stopDone(error_t err) {}
+
+ event void ButtonNotify.notify( button_state_t state )
+ {
+ if( state == BUTTON_PRESSED )
+ {
+ if(sensor_config == 0)
+ {
+ call Leds.led1On();
+ parkingSpaceID = 65001;
+ call SensorTimer.startPeriodic(1024);
+ }
+ else if(sensor_config == 1)
+ {
+ call Leds.led1On();
+ parkingSpaceID = 65002;
+ call SensorTimer.startPeriodic(1024);
+ }
+ else if(sensor_config == 2)
+ {
+ parkingSpaceID = 0;
+ post sendStatusDebugMessage();
+ call StatusTimer.startPeriodic(1024);
+ }
+ else
+ {}
+ }
+ else if( state == BUTTON_RELEASED )
+ {
+ /*
+ TODO
+ */
+ }
+ }
+
+ event void StatusTimer.fired()
+ {
+ if(parkingSpaceID != 0)
+ {
+ call StatusTimer.startPeriodic(1024*15);
+ call SensorTimer.startPeriodic(256);
+ }
+ }
+ event void SensorTimer.fired()
+ {
+ ReadAllSensors();
+ }
+ event void LEDTimer.fired()
+ {
+ /*
+ TODO
+ */
+ }
+ event void TimeoutTimer.fired()
+ {
+ /*
+ TODO
+ */
+ }
+
+ event void StatusSend.sendDone(message_t* bufPtr, error_t error)
+ {
+ statusPacketID++;
+ }
+
+ event void StatusDebugSend.sendDone(message_t* bufPtr, error_t error)
+ {
+ statusDebugPacketID++;
+
+ if(sensor_config == 1)
+ {
+ call Leds.led1Off();
+ sensor_config = 2;
+ }
+ else if(sensor_config == 0)
+ {
+ call Leds.led1Off();
+ sensor_config = 1;
+ }
+ }
+
+ event void AdcC1.readDone(error_t result, uint16_t data)
+ {
+ if (result == SUCCESS)
+ {
+ read_count[ADC1] += 1;
+ temp_sensor_value[ADC1] += data;
+ }
+ }
+
+ event void Temp.readDone(error_t result, uint16_t data)
+ {
+ if (result == SUCCESS)
+ {
+ read_count[TEMPERATURE] += 1;
+ temp_sensor_value[TEMPERATURE] += (9/5)*(-38.4 + 0.0098 * data)+32;
+ }
+ }
+
+ event void Humid.readDone(error_t result, uint16_t data)
+ {
+ if (result == SUCCESS)
+ {
+ read_count[HUMIDITY] += 1;
+ temp_sensor_value[HUMIDITY] += -0.0000028*data*data + 0.0405*data-4;
+ }
+ }
+
+ event void Light.readDone(error_t result, uint16_t data)
+ {
+ if (result == SUCCESS)
+ {
+ read_count[LIGHT] += 1;
+ temp_sensor_value[LIGHT] += data;
+ }
+ }
+
+ event void IR.readDone(error_t result, uint16_t data)
+ {
+ if (result == SUCCESS)
+ {
+ read_count[IR_LIGHT] += 1;
+ temp_sensor_value[IR_LIGHT] += data;
+ }
+ }
+
+ event message_t* ConfigReceive.receive(message_t* bufPtr, void* payload, uint8_t len)
+ {
+ if (len != sizeof(parking_garage_config_msg_t))
+ { parking_garage_config_msg_t* pgc = (parking_garage_config_msg_t*)payload;
+
+ parkingSpaceID = pgc->new_parking_space_id;
+
+ call Leds.led0Toggle();
+ return bufPtr;
+ }
+ else
+ {
+ parking_garage_config_msg_t* pgc = (parking_garage_config_msg_t*)payload;
+
+ if(parkingSpaceID == 0)
+ {
+ parkingSpaceID = pgc->new_parking_space_id;
+ }
+
+ call Leds.led0Toggle();
+ }
+ return bufPtr;
+ }
+
+ event message_t* CommandReceive.receive(message_t* bufPtr, void* payload, uint8_t len)
+ {
+ if (len != sizeof(parking_garage_command_msg_t))
+ {
+ return bufPtr;
+ }
+ else
+ {
+ call Leds.led0Toggle();
+ }
+ return bufPtr;
+ }
+}
View
7 src/ParkingGarage/README.txt
@@ -0,0 +1,7 @@
+README for ParkingGarage
+Author/Contact: matthew.scott.lindsay@gmail.com
+
+Description:
+
+ ParkingGarage is is part of a parking guidance and information system
+ designed to take advantage of the TelosB and an analog range finder.

0 comments on commit 61a5609

Please sign in to comment.
Something went wrong with that request. Please try again.