Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
LoRaWAN benchmark
RIOT - IM880B
Commits
6e7ad31f
Commit
6e7ad31f
authored
Apr 29, 2019
by
Guillaume Gonnet
Browse files
Add temperature to BM payload.
parent
047e8bb5
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
14 deletions
+67
-14
docs/payload.md
docs/payload.md
+1
-0
src/app/benchmark/benchmark.h
src/app/benchmark/benchmark.h
+3
-0
src/app/benchmark/payload.c
src/app/benchmark/payload.c
+48
-7
src/app/drivers/ds75lx.c
src/app/drivers/ds75lx.c
+10
-2
src/app/drivers/ds75lx.h
src/app/drivers/ds75lx.h
+5
-5
No files found.
docs/payload.md
View file @
6e7ad31f
...
...
@@ -11,6 +11,7 @@
| Altitude | 0 - 65535 | 2
*
8 = 16 |
This total length of the payload (without LoRaWAN header) is 10 bytes.
All integers are big endian.
## Spreading Factor (SF)
...
...
src/app/benchmark/benchmark.h
View file @
6e7ad31f
...
...
@@ -13,6 +13,9 @@ This project is under the MIT license
#include "lorariot.h"
// Update temperature value every .. ms
#define TEMPERATURE_UPDATE_MS 1500
// Static payload for benchmark.
extern
lorariot_mcps_t
bm_payload
;
...
...
src/app/benchmark/payload.c
View file @
6e7ad31f
...
...
@@ -8,35 +8,76 @@ This project is under the MIT license
*/
#include "benchmark.h"
#include "drivers/gps.h"
#include "drivers/ds75lx.h"
#include <xtimer.h>
// Buffer that contains encoded data.
uint8_t
bm_buffer
[
10
];
static
uint8_t
bm_buffer
[
10
];
// Temperature cache.
static
uint32_t
temp_last_usec
;
static
uint16_t
temp_cache
=
0
;
// Static payload for benchmark.
lorariot_mcps_t
bm_payload
=
LORARIOT_UNCONFIRMED_EX
(
DR_0
,
50
,
10
,
bm_buffer
);
// Get temperature with right payload format.
static
uint16_t
bm_get_temperature
(
void
)
{
uint32_t
now
=
xtimer_now_usec
();
if
(
now
-
temp_last_usec
<
(
TEMPERATURE_UPDATE_MS
*
1000
))
return
temp_cache
;
int16_t
temp
;
ds75_read_temperature
(
&
temp
);
temp_cache
=
temp
;
temp_last_usec
=
now
;
return
(
uint16_t
)(
temp
+
(
55
<<
8
))
&
0x1FF
;
}
// Encode message data to the payload.
void
bm_encode_payload
(
uint8_t
power_i
,
uint8_t
dr_i
,
uint8_t
cr_i
)
{
// Retreive GPS data.
int32_t
lat
,
lon
;
int16_t
alt
;
gps_get_binary
(
&
lat
,
&
lon
,
&
alt
);
// Retreive temperature.
uint16_t
temp
=
bm_get_temperature
();
// Encode LoRa settings (on 8 bits).
bm_buffer
[
0
]
=
((
dr_i
&
0
b111
)
<<
5
)
|
((
cr_i
&
0
b1
)
<<
4
)
|
((
power_i
&
0
b1111
)
<<
0
);
// Encode temperature (on 9 bits).
// TODO.
// Encode latitude (on 23 bits, we assume it's > 0).
// TODO.
bm_buffer
[
2
]
=
((
uint32_t
)
lat
>>
16
)
&
0x7F
;
bm_buffer
[
3
]
=
((
uint32_t
)
lat
>>
8
)
&
0xFF
;
bm_buffer
[
4
]
=
((
uint32_t
)
lat
>>
0
)
&
0xFF
;
// Encode longitude (on 24 bits).
// TODO.
bm_buffer
[
5
]
=
((
uint32_t
)
lon
>>
16
)
&
0xFF
;
bm_buffer
[
6
]
=
((
uint32_t
)
lon
>>
8
)
&
0xFF
;
bm_buffer
[
7
]
=
((
uint32_t
)
lon
>>
0
)
&
0xFF
;
// Encode temperature (on 9 bits).
bm_buffer
[
1
]
=
(
temp
>>
1
)
&
0xFF
;
bm_buffer
[
2
]
|=
temp
&
0
b1
;
// Encode altitude (on 16 bits);
// TODO.
bm_buffer
[
8
]
=
((
uint16_t
)
alt
>>
8
)
&
0xFF
;
bm_buffer
[
9
]
=
((
uint16_t
)
alt
>>
0
)
&
0xFF
;
// Change MCPS parameters for the next frame.
bm_payload
.
code_rate
=
bm_cr
[
cr_i
];
...
...
src/app/drivers/ds75lx.c
View file @
6e7ad31f
...
...
@@ -21,6 +21,14 @@ v1.0.
// Masks to extract the concerned bits.
#define MASK_RESOLUTION 0x60 // 0b01100000
// Resolution encoding.
static
const
uint8_t
resoltions
[]
=
{
0x00
,
// DS75_RES9
0x20
,
// DS75_RES10
0x40
,
// DS75_RES11
0x60
// DS75_RES12
};
// Debug an I2C result.
#define DS75_DEBUG(text, res) \
...
...
@@ -49,7 +57,7 @@ uint8_t ds75_set_resolution(uint8_t resol)
DS75_DEBUG
(
"read config error"
,
res
);
config
&=
~
MASK_RESOLUTION
;
config
|=
resol
;
config
|=
resol
tions
[
resol
]
;
res
=
i2c_write_reg
(
DS75_I2C_DEV
,
DS75_I2C_ADDRESS
,
CONFIG_REG
,
DS75_RES9
,
0
);
i2c_release
(
DS75_I2C_DEV
);
...
...
@@ -60,7 +68,7 @@ uint8_t ds75_set_resolution(uint8_t resol)
// Read temperature from DS75LX chip.
uint8_t
ds75_read_temperature
(
u
int16_t
*
temp
)
uint8_t
ds75_read_temperature
(
int16_t
*
temp
)
{
uint8_t
buffer
[
2
];
...
...
src/app/drivers/ds75lx.h
View file @
6e7ad31f
...
...
@@ -25,10 +25,10 @@ This project is under the MIT license
// DS75LX resolution.
#define DS75_RES9 0
x00
#define DS75_RES10
0x20
#define DS75_RES11
0x40
#define DS75_RES12
0x60
#define DS75_RES9 0
#define DS75_RES10
1
#define DS75_RES11
2
#define DS75_RES12
3
/**
...
...
@@ -49,4 +49,4 @@ uint8_t ds75_set_resolution(uint8_t resol);
* @param temp Where to store the result.
* @return `DS75_SUCCESS` or I2C error code.
*/
uint8_t
ds75_read_temperature
(
u
int16_t
*
temp
);
uint8_t
ds75_read_temperature
(
int16_t
*
temp
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment