completed s1 and s2

This commit is contained in:
aj 2020-10-05 18:54:44 +01:00
parent d575bd32cf
commit befa1f0507
10 changed files with 3285 additions and 465 deletions

File diff suppressed because it is too large Load Diff

View File

@ -49,7 +49,7 @@ PROCESS_THREAD(hello_world_process, ev, data)
{
PROCESS_BEGIN();
printf("Hello, world 321\n");
printf("Hello, world - Modified\n");
PROCESS_END();
}

Binary file not shown.

BIN
S2/contiki-sky.a Normal file

Binary file not shown.

2747
S2/contiki-sky.map Normal file

File diff suppressed because it is too large Load Diff

View File

@ -62,7 +62,7 @@
<plugin>
se.sics.cooja.plugins.SimControl
<width>417</width>
<z>0</z>
<z>1</z>
<height>160</height>
<location_x>400</location_x>
<location_y>0</location_y>
@ -115,7 +115,7 @@
<scrollpos>0,0</scrollpos>
</plugin_config>
<width>422</width>
<z>1</z>
<z>0</z>
<height>265</height>
<location_x>397</location_x>
<location_y>162</location_y>

View File

@ -38,9 +38,47 @@
* Adam Dunkels <adam@sics.se>
*/
#define RANDOM_NUMBER_COUNT 3
#define RANDOM_NUMBER_MAX_VALUE 2.5
#include "contiki.h"
#include "lib/random.h"
#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);
}
/*---------------------------------------------------------------------------*/
PROCESS(hello_world_process, "Hello world process");
AUTOSTART_PROCESSES(&hello_world_process);
@ -49,7 +87,35 @@ PROCESS_THREAD(hello_world_process, ev, data)
{
PROCESS_BEGIN();
printf("Hello, world\n");
printf("Printing rands\n");
USHORT randomNumbers[RANDOM_NUMBER_COUNT]; //array for retreived random numbers
float normalisedRandomNumbers[RANDOM_NUMBER_COUNT]; //array for those rands normalised between 0 and 2.5
float total = 0;
int i;
for(i = 0; i < RANDOM_NUMBER_COUNT; i++)
{
USHORT nextRand = random_rand();
float normalisedRand = ((float) nextRand / RANDOM_RAND_MAX ) * RANDOM_NUMBER_MAX_VALUE;
randomNumbers[i] = nextRand;
normalisedRandomNumbers[i] = normalisedRand;
total = total + normalisedRand;
putShort(nextRand);
putchar('\n');
putFloat(normalisedRand);
putchar('\n');putchar('\n');
}
printf("Printed rands\n");
printf("Total of random numbers: ");
putFloat(total);
putchar('\n');
PROCESS_END();
}

BIN
S2/hello-world.sky Normal file

Binary file not shown.

4
S2/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
S2/symbols.h Normal file
View File

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