Skip to content

Commit

Permalink
Battery status printed correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
nezabelej committed Jun 3, 2016
1 parent a2b4fb2 commit 9821997
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion gateway/gateway.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ static void bsort(int arr[][2]) {
}
}

float floor(float x)
{
if(x >= 0.0f) {
return (float)((int)x);
} else {
return (float)((int)x - 1);
}
}

static int findPower(int arr[][2], int a) {
int i;
for (i = 0; i < NUMBER_OF_COWS; i++) {
Expand Down Expand Up @@ -194,8 +203,10 @@ static void init_data_received(struct unicast_conn *c, const linkaddr_t *from)
for (i = 0; i < NUMBER_OF_COWS; i++) {
int *row = *(data + i);
battery_status_list[i] = *row;
float mv = (battery_status_list[i] * 2.500 * 2) / 4096;
temperature_list[i] = *(row + 1);
printf("[%d] Bat: %d, Temp: %d, RSSI: ", i, battery_status_list[i], temperature_list[i]);
printf("[%d] Bat:%i(%ld.%03dmV), Temp:%d, RSSI: ", i, battery_status_list[i], (long)mv,
(unsigned)((mv - floor(mv)) * 1000), temperature_list[i]);
int j;
for (j = 0; j < NUMBER_OF_COWS; j++) {
RSSIs[i][j] = *(row + j + 2);
Expand Down

0 comments on commit 9821997

Please sign in to comment.