Skip to content

Commit

Permalink
temp while loop catch removed, added i2c requesting to payload and re…
Browse files Browse the repository at this point in the history
…sponse.
  • Loading branch information
Richard Bamford committed Aug 7, 2018
1 parent eebf3fc commit 274a09a
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 12 deletions.
25 changes: 25 additions & 0 deletions Code/Beacon/BeaconTest1.ino
Expand Up @@ -8,6 +8,7 @@ Author: Richad Bamford (FOSSA Systems)
#include <EEPROM.h>
#include <string.h>
#include <LoRaLib.h>
#include <Wire.h>

#include "configuration.h"
#include "state_machine_declerations.h"
Expand All @@ -30,6 +31,7 @@ int POWER_INFO_TIMER = 0;

void setup()
{
Wire.begin();
Serial.begin(9600);

if (Pin_Interface_ShouldReset())
Expand Down Expand Up @@ -184,5 +186,28 @@ void loop()
Debugging_Utilities_DebugLog("End listening for function id '8'");
}

// delay(200);

Debugging_Utilities_DebugLog("Checking I2C input for data.");

Wire.requestFrom(8, 32); // request 32 bytes from slave device #8

String payloadTransmissionMessage = String("");

while (Wire.available())
{ // slave may send less than requested
char c = Wire.read(); // receive a byte as character
payloadTransmissionMessage += String(c);
}

if (payloadTransmissionMessage != "")
{
Communication_SX1278TransmitPayloadMessage(payloadTransmissionMessage);
}
else
{
// Debugging_Utilities_DebugLog("No message to send");
}

delay(200);
}
14 changes: 13 additions & 1 deletion Code/Beacon/communication.cpp
Expand Up @@ -57,7 +57,19 @@ void Communication_SX1278Transmit(String inFuncId, String inMessage) // this is
}
}
}


/*
* @brief an abstraction layer for the payload transmissions.
*/
void Communication_SX1278TransmitPayloadMessage(String inPayloadMessage)
{
int indexOfSeperator = inPayloadMessage.indexOf(';'); // first ; is the seperator between funcid and message data.
String message = inPayloadMessage.substring(indexOfSeperator + 1); // from after the first ; to the end
String functionId = inPayloadMessage.substring(0, indexOfSeperator); // from the start to the first ; (exluding);

Communication_SX1278Transmit(functionId, message);
}

/**
* @brief satellite's Setup() function is called..
*
Expand Down
2 changes: 2 additions & 0 deletions Code/Beacon/communication.h
Expand Up @@ -3,6 +3,8 @@

void Communication_SX1278Transmit(String inFuncId, String inMessage);

void Communication_SX1278TransmitPayloadMessage(String inPayloadMessage);

//////////////////////////////
// FOSSA_PROTOCOL FUNCTIONS //
//////////////////////////////
Expand Down
12 changes: 1 addition & 11 deletions Code/Beacon/system_info.cpp
Expand Up @@ -36,17 +36,7 @@ float System_Info_GetInternalTemperature()

ADCSRA |= _BV(ADSC);

int max_repetitions = 10000;
int repetition_count = 0;
while (bit_is_set(ADCSRA,ADSC))
{
repetition_count++;

if (repetition_count >= max_repetitions)
{
break;
}
}
while (bit_is_set(ADCSRA,ADSC));

wADC = ADCW;

Expand Down
9 changes: 9 additions & 0 deletions Code/Payload/PayloadSketch.ino
@@ -1,6 +1,15 @@
#include <Wire.h>

void requestEvent()
{
Wire.write("6;");
}

void setup() {
// put your setup code here, to run once:
Wire.begin(8);
Serial.begin(9600);
Wire.onRequest(requestEvent);
}

void loop() {
Expand Down

0 comments on commit 274a09a

Please sign in to comment.