Skip to content

Commit

Permalink
working clustering. Node recognizes it's role (cluster head /regular …
Browse files Browse the repository at this point in the history
…node).
  • Loading branch information
Nejc Bizjak committed May 8, 2016
1 parent 6494691 commit 74a1ef3
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 7 deletions.
19 changes: 12 additions & 7 deletions gateway/gateway.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ static void compute_clusters(int RSSI[NUMBER_OF_COWS][NUMBER_OF_COWS], struct br
roles[c] = -2;
}

int clusters[NUMBER_OF_COWS][power[0][1]+1];
//int clusters[NUMBER_OF_COWS][power[0][1]+1];
int clusters[NUMBER_OF_COWS][NUMBER_OF_COWS];
for (i = 0; i < NUMBER_OF_COWS; i++) {
for (j = 0; j < NUMBER_OF_COWS; j++) {
clusters[i][j] = -1; //Not a RSSI value (-100 - 0)
}
}
int counter = 0;
int counter2;

Expand All @@ -110,19 +116,18 @@ static void compute_clusters(int RSSI[NUMBER_OF_COWS][NUMBER_OF_COWS], struct br
}
}

packetbuf_copyfrom(clusters, sizeof(clusters));
broadcast_send(conn);

printf("GATEWAY broadcasted clusters....\n");

/*for (i = 0; i < counter; i++) {
for (i = 0; i < counter; i++) {
printf("HEAD: %d -- NODES: ",clusters[i][0]+1);
int p = findPower(power, clusters[i][0]);
for (j = 1; j <= p; j++) {
printf("%d ", clusters[i][j]+1);
}
printf("\n");
}*/
}

packetbuf_copyfrom(clusters, sizeof(clusters));
broadcast_send(conn);
}

static void init_power_received(struct unicast_conn *c, const linkaddr_t *from)
Expand Down
46 changes: 46 additions & 0 deletions node/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "net/rime/mesh.h"
#include "dev/button-sensor.h"
#include "dev/leds.h"
#include "node-id.h"
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
Expand All @@ -22,6 +23,11 @@ AUTOSTART_PROCESSES (&herd_monitor_node);

static int neighbour_list[NUMBER_OF_COWS];

//0 -> node; 1 -> cluster head;
static int role = 0;
static int my_clusters[NUMBER_OF_COWS - 1];
static int num_of_my_clusters = 0;

static void reset_neighbour_list()
{
printf("Reseting list... \n");
Expand All @@ -47,6 +53,46 @@ static void init_broadcast_recv(struct broadcast_conn *c, const linkaddr_t *from
static void clustering_broadcast_recv(struct broadcast_conn *c, const linkaddr_t *from)
{
printf("Clustering results received!\n");

int (*clusters)[NUMBER_OF_COWS] = (int (*)[NUMBER_OF_COWS])packetbuf_dataptr();

int i,j;
int k = 0;
//Checking if am cluster head.
for (i = 0; i < NUMBER_OF_COWS; i++) {
int *cluster = *(clusters + i);
int cluster_head = *(cluster) + 1;
if (cluster_head == node_id) {
role = 1;
printf("I, node %d, am Cluster head and these are my nodes: ", node_id);
for (j = 1; j < NUMBER_OF_COWS; j++) {
int node = *(cluster + j) + 1;
if (node == 0) {
break;
}
printf("%d,",node);
my_clusters[j] = node;
}
printf("\n");
break;
}

for (j = 1; j < NUMBER_OF_COWS; j++) {
int node = *(cluster + j) + 1;
if (node == 0 ) {
break;
}
if (node == node_id) { //We save cluster heads of my clusters.
my_clusters[k] = cluster_head;
printf("cluster %d,",cluster_head);
k++;
break;
}
}
printf("\n");
}


}

static void init_send_to_gateway(struct unicast_conn *c)
Expand Down

0 comments on commit 74a1ef3

Please sign in to comment.