Skip to content
Snippets Groups Projects
Commit 2bf32ba9 authored by Julia Wichmann's avatar Julia Wichmann
Browse files

Added Layer 3

parent c14453cb
No related branches found
No related tags found
No related merge requests found
......@@ -12,10 +12,12 @@
#include "julart.h" // Uart Functions
#include "crc.h" //crc implementation
#include "lay3.h"
//typedef unsigned char byte;
#define MAXFRAMESIZE 261 //in byte
#define MAXFRAMESIZE 256 //in byte
#define SELF 205
// Init of Send-/Receive-Buffer
byte send[MAXFRAMESIZE]= {0}; // 0xB3, 0x10 = 10110011, 00010000
......@@ -50,15 +52,10 @@ void fillSend (byte* payload, byte size){
}
send[5] = size;
for(byte i = 6; i < size+6; i++){
for(byte i = 6; i < size+8; i++){ // für layer3 muss das noch um 2 erhöht werden!
send[i]= payload[i-6];
}
/* printf("Preambel = %d, CRC-Checksum = %d%d%d%d, Payload-Length = %d\nPayload= ", send[0], send[1], send[2], send[3], send[4], send[5]);
for(byte i = 0; i < size; i++){
printf("%d ", send[i+6]);
}
puts("");
*/
readyToSend = 1;
}
......@@ -86,20 +83,24 @@ int main(void){
uint16_t receiveIndex = 0;
byte* receivedFrame = malloc(MAXFRAMESIZE*sizeof(byte));
uint16_t sizeToReceive = MAXFRAMESIZE;
while(1){
if(!readyToSend){
puts("Getting ready to send.");
byte action; // 0 - broadcast successful, to layer 4; 1 - receive, to layer 4; 2 - relay
puts("Getting ready to send.");
byte sizeToSend = 2;
byte* payload = malloc(sizeToSend*sizeof(byte));
payload[0] = 0xB3;
payload[1] = 0x10;
byte* payload = malloc((sizeToSend+2)*sizeof(byte));
payload[0] = 0x00; //dest
payload[1] = SELF; //src
payload[2] = 0xB3;
payload[3] = 0x10;
ATOMIC_BLOCK(ATOMIC_FORCEON){
fillSend(payload, sizeToSend);
}
}
while(1){
//if(!readyToSend){}
ATOMIC_BLOCK(ATOMIC_FORCEON){
// Data Package: 0 Preamble, 1 - 4 CRC, 5 Length, 6 Destination, 7 Source, 8 - n Data
if(readyToReceive){
if(bufferIndex != 0) receivedFrame[receiveIndex] = frame[bufferIndex-1];
else receivedFrame[receiveIndex] = frame[MAXFRAMESIZE-1];
......@@ -110,8 +111,7 @@ int main(void){
}
else if(receiveIndex==5){
sizeToReceive = (uint16_t)receivedFrame[receiveIndex];
//printf("sizeToReceive = %d\n", sizeToReceive);
receivedFrame = (byte*) realloc (receivedFrame, (sizeToReceive+6)*sizeof(byte));
//receivedFrame = (byte*) realloc (receivedFrame, (sizeToReceive+6)*sizeof(byte));
receiveIndex++;
}
else if(receiveIndex==sizeToReceive+5){
......@@ -127,9 +127,12 @@ int main(void){
printf("\n");
//Hier evtl. noch Speicherung und/oder Ausgabe einbauen.
}
l3_exec(action)
receiveIndex = 0;
}
else if(receiveIndex==7){ //check destination
action = l3_action(receivedFrame[6], receivedFrame[7]);
}
else{
receiveIndex++;
}
......
......@@ -3,20 +3,79 @@
* What should happen? How do you realize the demanded priorization scheme?
*
*
* A node has one next and one previous node. If a received frame has a different destination, then the node needs to relay the frame to the next node.
* A node has one next and one previous node.
* If a received frame has a different destination, then the node needs to relay the frame to the next node.
* The unique node addresses should be a constant value (number of your Pi board as default value)
* There may be broadcast messages (destination 0x00) on layer 3 -> It must be checked who was the sender of the frame to decide about the forwarding.
*
* Receiving
* =========
* adress: const byte self = 205
* 1. Check destination adress
* if destination == self : Broadcast successful, hand package to lay4
* if source == self || source == 0x00 : discard package
*
* //if source == 0x00 : discard package
* if destination == 0x00:
if source == self : Broadcast successful, notify layer 4, discard package.
else relay message;
* else if destination == self: hand package to layer4;
* else relay message;
*
*
*
* A CRC-check is not performed at the intermediate-nodes between the sender and the receiver.
* The frame is received andread until the destination-address.
* If the destination differs from the own address, the ATMega can begin relaying the read Bytes to the next node, while still receiving the remaining ones.
* No CRC-check at the intermediate-nodes between the sender and the receiver.
* If the destination differs from self, begin relaying the read Bytes to the next node, while still receiving the remaining ones.
* -> An communication-error can be detected on the receivers end
*/
#include "lay3.h"
void broadcast_successful(){
puts("Broadcast successful.\n");
return;
}
byte l3_action(byte dest, byte src){
if(dest == 0x00){
if(src == SELF){
return 0;
}
}
else if(dest == SELF)
return 1; //receive, to layer 4
else
return 2; //relay
}
void l3_exec(byte action, byte* frame){
puts("l3_exec: ");
switch(action){
case 0:
broadcast_successful();
break;
case 1:
puts("Handing package to layer 4.\n");
break;
case 2:
fillSend(frame+6, frame[5]);
default:
break;
}
}
/* Ich muss noch die Funktion meines Sendebuffers erweitern. Ich möchte byteweise senden können, damit ich relayen kann, ohne viel zwischenzuspeichern.
*
*/
/*
* Priorities
* ==========
* Packages that need to be relayed should be handled with a higher priority than own sending-wishes of the node.
* Sending-wishes should be handled in order of arrival. This ensures, that own sending-wishes may not block the ring and congestions should not occur.
* If the node has no time to prepare its own sending-wishes, it cannot generate additional load onto the network.
* Also prioritizing packages from other nodes helps them holding their time-constraints.
*/
#include "crc.h"
void broadcast_successful();
byte l3_action(byte dest, byte src);
void l3_exec(byte action, byte* frame);
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment