Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of GA-Test_copy by
Revision 3:8bee1711d186, committed 2018-02-28
- Comitter:
- aungriah
- Date:
- Wed Feb 28 16:10:21 2018 +0000
- Parent:
- 2:5adf0b785944
- Commit message:
- ILBE
Changed in this revision
--- a/PC/PC.cpp Wed Jan 10 16:14:49 2018 +0000
+++ b/PC/PC.cpp Wed Feb 28 16:10:21 2018 +0000
@@ -25,28 +25,34 @@
void PC::readcommand(void (*executer)(char*))
{
-
- /*char input = getc(); // get the character from serial bus
+ //printf("Reads");
+ //while(1){
+ char input = getc();
+ //printf("%c", input); // get the character from serial bus
//printf("\x1B[1K");
//printf("-");
- if(input == 'r') { // if return was pressed, the command must be executed
- command[command_char_count] = '\0';
+
+ if(input == '\r') {
+ // if return was pressed, the command must be executed
+ this->command[command_char_count] = '\0';
executer(&command[0]);
- command_char_count = 0; // reset command
- command[command_char_count] = '\0';
+ this->command_char_count = 0; // reset command
+ this->command[command_char_count] = '\0';
+ // break;
} else if (command_char_count < COMMAND_MAX_LENGHT) {
// printf("Debug Point 4");
- command[command_char_count] = input;
+ this->command[command_char_count] = input;
//printf(command);
- command_char_count++;
+ this->command_char_count++;
+
}
+//}
-*/
- while (1)
+/* while (1)
{
if (readable())
@@ -61,7 +67,7 @@
executer(&command[0]);
command_char_count = 0; // reset command
-
+ */
--- a/PC/PC.h Wed Jan 10 16:14:49 2018 +0000
+++ b/PC/PC.h Wed Feb 28 16:10:21 2018 +0000
@@ -12,10 +12,10 @@
void cls(); // to clear the display
void locate(int column, int row); // to relocate the cursor
void readcommand(void (*executer)(char*)); // to read a char from the pc to the command string
+ int command_char_count;
char command[COMMAND_MAX_LENGHT];
private:
- int command_char_count;
};
#endif
--- a/main_minimal.cpp Wed Jan 10 16:14:49 2018 +0000
+++ b/main_minimal.cpp Wed Feb 28 16:10:21 2018 +0000
@@ -19,6 +19,7 @@
void rangeAndDisplayOne(uint8_t addr);
void rangeAndDisplayAll();
void executeOrder(char* command);
+void rangeAndDisplayInt(uint8_t from, uint8_t to);
// PA_7 MOSI, PA_6 MISO, PA_5 SCLK, PB_6 CS, PB_9 IRQ
@@ -114,6 +115,9 @@
break;
case RANGE_ONE: rangeAndDisplayOne(beaconNode.getDestination());
break;
+ case RANGE_INT: rangeAndDisplayInt(beaconNode.getRepetitions(), beaconNode.getDestination());
+
+ break;
default: break;
}
beaconNode.decreaseRepetitions();
@@ -128,9 +132,7 @@
// EXECUTE THIS IF A BASE STATION
pc.readcommand(executeOrder);
- wait_ms(10);
-
- wdt.kick();
+ //wdt.kick();
}
else { // All Anchor Action is in the Interrupt functions!
// EXECUTE THIS IF AN ANCHOR
@@ -173,7 +175,10 @@
pc.printf("Base Station is RESETTED \r\n\r\n");
}
-
+ else if (strncmp(command,"int",3)==0){
+ baseStationNode.sendOrder(0,dest1,RANGE_INT,repetitions, Node::BASE_ORDER);
+ // pc.print("Mode: Range interval \r\n");
+ }
else if (strncmp(command, "all", 3) == 0){
baseStationNode.sendOrder(0, NOT_USED, RANGE_ALL, repetitions, Node::BASE_ORDER);
// pc.printf("Mode: Range all \r\n");
@@ -246,6 +251,9 @@
baseStationNode.sendOrder(dest3, NOT_USED, BECOME_ANCHOR, NOT_USED, Node::SWITCH_TYPE);
}
+ else{
+ pc.printf("test");
+ }
}
@@ -322,7 +330,9 @@
pc.printf("%f(%f) \r\n", beaconNode.getDistance(addr), beaconNode.getSignalStrength(addr));
}
-
+void rangeAndDisplayInt(uint8_t from,uint8_t to){
+ beaconNode.requestRangingInt(from,to);
+ }
void rangeAndDisplayAll(){
beaconNode.requestRangingAll();
--- a/nodes/nodes.cpp Wed Jan 10 16:14:49 2018 +0000
+++ b/nodes/nodes.cpp Wed Feb 28 16:10:21 2018 +0000
@@ -42,6 +42,7 @@
void BeaconNode::callbackRX(uint64_t RxTime) {
//pc.printf("Got a frame, adress: %d source: %d \r\n", receivedFrame.destination, receivedFrame.source);
if (receivedFrame.destination == address){
+
switch (receivedFrame.type) {
case SWITCH_TYPE:
sendBaseAck();
@@ -84,9 +85,10 @@
float level = dw.getRXLevel(&diagnostic2);
if(level < signalStrength[receivedFrame.source])
signalStrength[receivedFrame.source] = level;
+
acknowledgement[1] = true;
-
+
// dw.turnonrx(); // start listening again
break;
}
@@ -120,7 +122,8 @@
if(acknowledgement[1] == true){
acknowledgement[2] = true;
// pc.printf("Ack edited %d \r\n", acknowledgement[2]);
- }
+ }
+
}
@@ -135,7 +138,7 @@
pc.printf(" max try %d\n\r",MAX_TRIES);
float time_before = LocalTimer.read();
- while(!acknowledgement[2] && LocalTimer.read() < time_before + 0.001f); // Wait until previous StreamFrame is sent
+ while(!acknowledgement[2] && LocalTimer.read() < time_before + 0.0025f); // Wait until previous StreamFrame is sent
acknowledgement[0] = false;
acknowledgement[1] = false;
@@ -144,7 +147,7 @@
sendPingFrame(destination);
- while(!acknowledgement[1] && (LocalTimer.read() < time_before + 0.001f + 0.003f*acknowledgement[0])); // One Ranging normaly takes less than 1.5 miliseconds
+ while(!acknowledgement[1] && (LocalTimer.read() < time_before + 0.0025f + 0.003f*acknowledgement[0])); // One Ranging normaly takes less than 1.5 miliseconds
if(acknowledgement[1]){
distances[destination] = calibratedDistance(destination);
@@ -152,7 +155,7 @@
// Stream Data to Basestation
sendStreamFrame(destination);
} else {
- acknowledgement[1]=1;
+ //acknowledgement[1]=1;
distances[destination] = -10;
noRec[destination] = 0;
sendStreamFrame(destination);
@@ -172,16 +175,16 @@
//if(rawDistance <= 8.458)
// rawDistance -= 0.0541*rawDistance; // Correction Term 22-03-2017
//else
- if(rawDistance >= 22.7)
- rawDistance += -0.0004*rawDistance - 0.3971;
- else if (rawDistance >= 14.3)
- rawDistance += -0.0015*rawDistance - 0.372;
- else if (rawDistance >= 8)
- rawDistance += -0.0029*rawDistance - 0.352;
- else if (rawDistance >= 3.93)
- rawDistance += 0.001*rawDistance - 0.370;
- else
- rawDistance += -0.0235*rawDistance - 0.273;
+ //if(rawDistance >= 22.7)
+ // rawDistance += -0.0004*rawDistance - 0.3971;
+ //else if (rawDistance >= 14.3)
+ // rawDistance += -0.0015*rawDistance - 0.372;
+ //else if (rawDistance >= 8)
+ // rawDistance += -0.0029*rawDistance - 0.352;
+ //else if (rawDistance >= 3.93)
+ // rawDistance += 0.001*rawDistance - 0.370;
+ //else
+ // rawDistance += -0.0235*rawDistance - 0.273;
//else if (rawDistance >= 3)
// rawDistance += 0.0004*rawDistance - 0.5556
@@ -209,7 +212,7 @@
// }
return rawDistance;
-
+ //return tofs[destination];
}
#pragma Otime // Compiler optimize Runtime at the cost of image size
@@ -222,7 +225,15 @@
distances[i] = -10;
}
}
-
+void BeaconNode::requestRangingInt(uint8_t from,uint8_t to) {
+ for (int i=from; i <= to; i++){
+ if (i!= address) {
+ requestRanging(i);
+ }
+ else
+ distances[i] = -10;
+ }
+}
#pragma Otime // Compiler optimize Runtime at the cost of image size
void BeaconNode::sendPingFrame(uint8_t destination) {
rangingFrame.source = address;
@@ -339,6 +350,7 @@
case PING:
sendAnswer(receivedFrame.source, ANCHOR_RESPONSE);
receiverTimestamps[receivedFrame.source][0] = RxTime; //Save the first timestamp on the receiving node/anchor (T_rp)
+ //dw.turnonrx();
break;
case BEACON_RESPONSE:
{
@@ -348,9 +360,12 @@
//if(timediffRec < 0)
// timediffRec = 0;
sendTransferFrame(receivedFrame.source, receiverTimestamps[receivedFrame.source][0] + receiverTimestamps[receivedFrame.source][2] - 2*receiverTimestamps[receivedFrame.source][1]);
+ //dw.turnonrx();
break;
}
- default : break;
+ default :
+ dw.turnonrx();
+ break;
}
}
else{
@@ -463,7 +478,10 @@
ack = true;
break;
-
+
+ default:
+ //dw.turnonrx();
+ break;
@@ -481,6 +499,8 @@
dw.turnonrx(); // start listening again
}
+
+
#pragma Otime // Compiler optimize Runtime at the cost of image size
void BaseStationNode::sendOrder(uint8_t beacon_destination, uint8_t anchor_destination, uint8_t action, uint16_t repetitions, uint8_t type) {
ExtendedRangingFrame orderFrame;
@@ -489,7 +509,11 @@
orderFrame.source = address;
orderFrame.destination = beacon_destination;
orderFrame.type = type;
- orderFrame.signedTime = action << 24 | anchor_destination << 16 | repetitions;
+ if(action == 1){
+ orderFrame.signedTime = action << 24 | anchor_destination << 16 | 1;
+ }
+ else
+ orderFrame.signedTime = action << 24 | anchor_destination << 16 | repetitions;
int i = 0;
for(i = 0; i < 3 && !ack; i++){
@@ -500,12 +524,13 @@
if(!ack)
{
pc.printf("ERROR: Tag #%d did not respond \r\n", beacon_destination);
+
}
else
{
// pc.printf("Order sent, %d tries \r\n", i);
}
-
+
}
--- a/nodes/nodes.h Wed Jan 10 16:14:49 2018 +0000
+++ b/nodes/nodes.h Wed Feb 28 16:10:21 2018 +0000
@@ -21,8 +21,9 @@
#define BASE_STATION_ADDR 15 // Defines the Adress of the Base Station (reserved Adress)
// Constants for Base_Orders
-#define RANGE_ALL 1
-#define RANGE_ONE 0
+#define RANGE_ALL 2
+#define RANGE_ONE 0
+#define RANGE_INT 1
#define NOT_USED 0xff
// Constant for Switch Types Orders
@@ -118,6 +119,7 @@
virtual void requestRanging(uint8_t destination);
virtual void requestRangingAll();
+ virtual void requestRangingInt(uint8_t from, uint8_t to);
float getDistance(uint8_t index);
float getSignalStrength(uint8_t index);
