added lab 3

This commit is contained in:
aj 2020-10-19 11:24:51 +01:00
parent befa1f0507
commit 50db86ee9e
6 changed files with 2955 additions and 14 deletions

BIN
S3/contiki-sky.a Normal file

Binary file not shown.

2888
S3/contiki-sky.map Normal file

File diff suppressed because it is too large Load Diff

View File

@ -3,23 +3,61 @@
#include "dev/sht11-sensor.h" #include "dev/sht11-sensor.h"
#include <stdio.h> /* For printf() */ #include <stdio.h> /* For printf() */
typedef unsigned short USHORT;
//print a unsigned short (as returned from rand) picewise char by char
void
putShort(USHORT in)
{
// recursively shift each digit of the int to units from most to least significant
if (in >= 10)
{
putShort(in / 10);
}
// isolate unit digit from each number by modulo and add '0' char to turn integer into corresponding ascii char
putchar((in % 10) + '0');
}
void
putFloat(float in)
{
if(in < 0)
{
putchar('-'); // print negative sign if required
in = -in;
}
USHORT integerComponent = (USHORT) in; // truncate float to integer
float fractionComponent = (in - integerComponent) * 1000; // take fraction only and promote to integer
if (fractionComponent - (USHORT)fractionComponent >= 0.5) fractionComponent++; // round
putShort(integerComponent);
putchar('.');
putShort((USHORT) fractionComponent);
}
float getTemperature(void) float getTemperature(void)
{ {
int tempData; int tempData;
// NOTE: You only need to use one of the following // NOTE: You only need to use one of the following
// If you run the code in Cooja Simulator, please remove the second one // If you run the code in Cooja Simulator, please remove the second one
//tempData = sht11_sensor.value(SHT11_SENSOR_TEMP_SKYSIM); // For Cooja Sim tempData = sht11_sensor.value(SHT11_SENSOR_TEMP_SKYSIM); // For Cooja Sim
tempData = sht11_sensor.value(SHT11_SENSOR_TEMP); // For XM1000 mote //tempData = sht11_sensor.value(SHT11_SENSOR_TEMP); // For XM1000 mote
float temp = tempData; // you need to implement the transfer function here float d1 = -39.6f;
float d2 = 0.01f;
float temp = d1 + (d2 * tempData); // you need to implement the transfer function here
return temp; return temp;
} }
float getLight(void) float getLight(void)
{ {
int lightData = light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC); int lightData = light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC);
float light = lightData; // you need to implement the transfer function here
float V_sensor = 1.5 * lightData / 4096;
float I = V_sensor/1e5;
float light = 0.625 * 1e6 * I * 1000; // you need to implement the transfer function here
return light; return light;
} }
@ -32,8 +70,7 @@ PROCESS_THREAD(sensor_reading_process, ev, data)
{ {
static struct etimer timer; static struct etimer timer;
PROCESS_BEGIN(); PROCESS_BEGIN();
etimer_set(&timer, CLOCK_CONF_SECOND/4); // you need to put the correct etimer_set(&timer, CLOCK_SECOND); // you need to put the correct timer setting here
// timer setting here
SENSORS_ACTIVATE(light_sensor); SENSORS_ACTIVATE(light_sensor);
SENSORS_ACTIVATE(sht11_sensor); SENSORS_ACTIVATE(sht11_sensor);
@ -45,8 +82,17 @@ PROCESS_THREAD(sensor_reading_process, ev, data)
float temp = getTemperature(); float temp = getTemperature();
float light_lx = getLight(); float light_lx = getLight();
printf("%d\n", ++counter); // you should also print the temperature printf("%d\n", ++counter); // you should also print the temperature and light intensity here
// and light intensity here printf("Temperature: ");
putFloat(temp);
printf(" C");
putchar('\n');
printf("Light: ");
putFloat(light_lx);
putchar('\n');
putchar('\n');
etimer_reset(&timer); etimer_reset(&timer);
} }

BIN
S3/sensor.sky Normal file

Binary file not shown.

4
S3/symbols.c Normal file
View File

@ -0,0 +1,4 @@
#include "symbols.h"
const int symbols_nelts = 0;
const struct symbols symbols[] = {{0,0}};

3
S3/symbols.h Normal file
View File

@ -0,0 +1,3 @@
#include "loader/symbols.h"
extern const struct symbols symbols[1];