-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloratest.c
78 lines (61 loc) · 1.6 KB
/
loratest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* loratest.c
*
* Created on: Feb 17, 2019
* Author: TritonCubed
*/
#include "spi.h"
#include "lora.h"
#include "helper.h"
#include <stdlib.h>
#include <stdio.h>
//payload
char payload[25];
/**
* Helper function to construct payload.
*/
void buildPayload( ) {
//stub
//memset( payload, 0, sizeof( payload ) );
strcpy( payload, "Hello, world!" );
}
int main( int argc, char **argv ){
// BCM Lib initialization
if( !bcm2835_init() ) {
fprintf( stderr, "bcm2835_init failed. Must run as root.\n" );
exit( EXIT_FAILURE );
}
spi_init(); //setup spi
lora_init( sizeof( payload ) ); //boot sequence to LoRa standby
//begin beaconing cycle
while( 1 ) {
//make the payload
buildPayload( payload, sizeof( payload ) );
//set SPI access to fifo to the Tx base reg
write_reg( REG_FIFO_ADDR_PTR, FIFO_TX_BASE_ADDR );
//load payload into FIFO
for( int k = 0; k < ( sizeof( payload ) - 1 ); k++ ){
write_reg( REG_FIFO, payload[k] );
}
//commence Tx
write_reg( REG_OP_MODE, LORA_TX );
//half second delay before confirm
time_delay( 0.5 );
//confirm Tx
if( read_reg( REG_IRQ_FLAGS ) == FLAG_TX_DONE
&& read_reg(REG_OP_MODE) == LORA_STANDBY ) {
write_reg( REG_IRQ_FLAGS, CLEAR_IRQ_FLAGS );
fprintf( stdout, "Transmitted payload.");
}
else if( read_reg( REG_OP_MODE ) != LORA_STANDBY ){
//reinit lora module
lora_init( sizeof( payload ) );
}
//4.5 second delay for a full 5 second delay
time_delay( 4.5 );
}
lora_close();
spi_close();
bcm2835_close();
return EXIT_SUCCESS;
}