@@ -786,7 +786,7 @@ static int parse_gateway_configuration(const char * conf_file) {
786
786
val = json_object_get_value (conf_obj , "beacon_period" );
787
787
if (val != NULL ) {
788
788
beacon_period = (uint32_t )json_value_get_number (val );
789
- if (beacon_period < 6 ) {
789
+ if (( beacon_period > 0 ) && ( beacon_period < 6 ) ) {
790
790
MSG ("ERROR: invalid configuration for Beacon period, must be >= 6s\n" );
791
791
return -1 ;
792
792
} else {
@@ -819,24 +819,14 @@ static int parse_gateway_configuration(const char * conf_file) {
819
819
val = json_object_get_value (conf_obj , "beacon_datarate" );
820
820
if (val != NULL ) {
821
821
beacon_datarate = (uint8_t )json_value_get_number (val );
822
- if ((beacon_datarate != 9 ) && (beacon_datarate != 10 )) {
823
- MSG ("ERROR: invalid configuration for Beacon datarate\n" );
824
- return -1 ;
825
- } else {
826
- MSG ("INFO: Beaconing datarate is set to SF%d\n" , beacon_datarate );
827
- }
822
+ MSG ("INFO: Beaconing datarate is set to SF%d\n" , beacon_datarate );
828
823
}
829
824
830
825
/* Beacon modulation bandwidth (optional) */
831
826
val = json_object_get_value (conf_obj , "beacon_bw_hz" );
832
827
if (val != NULL ) {
833
828
beacon_bw_hz = (uint32_t )json_value_get_number (val );
834
- if ((beacon_bw_hz != 125000 ) && (beacon_bw_hz != 500000 )) {
835
- MSG ("ERROR: invalid configuration for Beacon modulation bandwidth\n" );
836
- return -1 ;
837
- } else {
838
- MSG ("INFO: Beaconing modulation bandwidth is set to %dHz\n" , beacon_bw_hz );
839
- }
829
+ MSG ("INFO: Beaconing modulation bandwidth is set to %dHz\n" , beacon_bw_hz );
840
830
}
841
831
842
832
/* Beacon TX power (optional) */
@@ -1931,7 +1921,8 @@ void thread_down(void) {
1931
1921
struct lgw_pkt_tx_s beacon_pkt ;
1932
1922
uint8_t beacon_chan ;
1933
1923
uint8_t beacon_loop ;
1934
- uint8_t beacon_padding = 0 ;
1924
+ size_t beacon_RFU1_size = 0 ;
1925
+ size_t beacon_RFU2_size = 0 ;
1935
1926
uint8_t beacon_pyld_idx = 0 ;
1936
1927
time_t diff_beacon_time ;
1937
1928
struct timespec next_beacon_gps_time ; /* gps time of next beacon packet */
@@ -1987,39 +1978,46 @@ void thread_down(void) {
1987
1978
exit (EXIT_FAILURE );
1988
1979
}
1989
1980
switch (beacon_datarate ) {
1981
+ case 8 :
1982
+ beacon_pkt .datarate = DR_LORA_SF8 ;
1983
+ beacon_RFU1_size = 1 ;
1984
+ beacon_RFU2_size = 3 ;
1985
+ break ;
1990
1986
case 9 :
1991
1987
beacon_pkt .datarate = DR_LORA_SF9 ;
1992
- beacon_pkt . size = 17 ;
1993
- beacon_padding = 0 ;
1988
+ beacon_RFU1_size = 2 ;
1989
+ beacon_RFU2_size = 0 ;
1994
1990
break ;
1995
1991
case 10 :
1996
1992
beacon_pkt .datarate = DR_LORA_SF10 ;
1997
- beacon_pkt .size = 19 ;
1998
- beacon_padding = 1 ;
1993
+ beacon_RFU1_size = 3 ;
1994
+ beacon_RFU2_size = 1 ;
1995
+ break ;
1996
+ case 12 :
1997
+ beacon_pkt .datarate = DR_LORA_SF12 ;
1998
+ beacon_RFU1_size = 5 ;
1999
+ beacon_RFU2_size = 3 ;
1999
2000
break ;
2000
2001
default :
2001
2002
/* should not happen */
2002
2003
MSG ("ERROR: unsupported datarate for beacon\n" );
2003
2004
exit (EXIT_FAILURE );
2004
2005
}
2006
+ beacon_pkt .size = beacon_RFU1_size + 4 + 2 + 7 + beacon_RFU2_size + 2 ;
2005
2007
beacon_pkt .coderate = CR_LORA_4_5 ;
2006
2008
beacon_pkt .invert_pol = false;
2007
2009
beacon_pkt .preamble = 10 ;
2008
2010
beacon_pkt .no_crc = true;
2009
2011
beacon_pkt .no_header = true;
2010
2012
2011
2013
/* network common part beacon fields (little endian) */
2012
- beacon_pyld_idx = 0 ;
2013
- beacon_pkt .payload [beacon_pyld_idx ++ ] = 0x0 ; /* RFU */
2014
- beacon_pkt .payload [beacon_pyld_idx ++ ] = 0x0 ; /* RFU */
2015
- if (beacon_padding == 1 ) {
2016
- beacon_pkt .payload [beacon_pyld_idx ++ ] = 0x0 ; /* RFU */
2014
+ for (i = 0 ; i < (int )beacon_RFU1_size ; i ++ ) {
2015
+ beacon_pkt .payload [beacon_pyld_idx ++ ] = 0x0 ;
2017
2016
}
2018
2017
2019
- /* time (variable), filled later */
2020
- beacon_pyld_idx += 4 ;
2021
- /* crc1 (variable), filled later */
2022
- beacon_pyld_idx += 2 ;
2018
+ /* network common part beacon fields (little endian) */
2019
+ beacon_pyld_idx += 4 ; /* time (variable), filled later */
2020
+ beacon_pyld_idx += 2 ; /* crc1 (variable), filled later */
2023
2021
2024
2022
/* calculate the latitude and longitude that must be publicly reported */
2025
2023
field_latitude = (int32_t )((reference_coord .lat / 90.0 ) * (double )(1 <<23 ));
@@ -2043,12 +2041,14 @@ void thread_down(void) {
2043
2041
beacon_pkt .payload [beacon_pyld_idx ++ ] = 0xFF & field_longitude ;
2044
2042
beacon_pkt .payload [beacon_pyld_idx ++ ] = 0xFF & (field_longitude >> 8 );
2045
2043
beacon_pkt .payload [beacon_pyld_idx ++ ] = 0xFF & (field_longitude >> 16 );
2046
- if (beacon_padding == 1 ) {
2047
- beacon_pkt .payload [beacon_pyld_idx ++ ] = 0x0 ; /* RFU */
2044
+
2045
+ /* RFU */
2046
+ for (i = 0 ; i < (int )beacon_RFU2_size ; i ++ ) {
2047
+ beacon_pkt .payload [beacon_pyld_idx ++ ] = 0x0 ;
2048
2048
}
2049
2049
2050
2050
/* CRC of the beacon gateway specific part fields */
2051
- field_crc2 = crc16 ((beacon_pkt .payload + 8 + beacon_padding ), 7 + beacon_padding );
2051
+ field_crc2 = crc16 ((beacon_pkt .payload + 6 + beacon_RFU1_size ), 7 + beacon_RFU2_size );
2052
2052
beacon_pkt .payload [beacon_pyld_idx ++ ] = 0xFF & field_crc2 ;
2053
2053
beacon_pkt .payload [beacon_pyld_idx ++ ] = 0xFF & (field_crc2 >> 8 );
2054
2054
@@ -2136,23 +2136,16 @@ void thread_down(void) {
2136
2136
}
2137
2137
/* Compute beacon frequency */
2138
2138
beacon_pkt .freq_hz = beacon_freq_hz + (beacon_chan * beacon_freq_step );
2139
- #if 0
2140
- /* Compensate breacon frequency with xtal error */
2141
- pthread_mutex_lock (& mx_xcorr );
2142
- beacon_pkt .freq_hz = (uint32_t )(xtal_correct * (double )beacon_pkt .freq_hz );
2143
- printf ("beacon_pkt.freq_hz=%u (xtal_correct=%.15lf)\n" , beacon_pkt .freq_hz , xtal_correct );
2144
- pthread_mutex_unlock (& mx_xcorr );
2145
- #endif
2146
2139
2147
2140
/* load time in beacon payload */
2148
- beacon_pyld_idx = 2 + beacon_padding ;
2141
+ beacon_pyld_idx = beacon_RFU1_size ;
2149
2142
beacon_pkt .payload [beacon_pyld_idx ++ ] = 0xFF & next_beacon_gps_time .tv_sec ;
2150
2143
beacon_pkt .payload [beacon_pyld_idx ++ ] = 0xFF & (next_beacon_gps_time .tv_sec >> 8 );
2151
2144
beacon_pkt .payload [beacon_pyld_idx ++ ] = 0xFF & (next_beacon_gps_time .tv_sec >> 16 );
2152
2145
beacon_pkt .payload [beacon_pyld_idx ++ ] = 0xFF & (next_beacon_gps_time .tv_sec >> 24 );
2153
2146
2154
2147
/* calculate CRC */
2155
- field_crc1 = crc16 (beacon_pkt .payload , 6 + beacon_padding ); /* CRC for the network common part */
2148
+ field_crc1 = crc16 (beacon_pkt .payload , 4 + beacon_RFU1_size ); /* CRC for the network common part */
2156
2149
beacon_pkt .payload [beacon_pyld_idx ++ ] = 0xFF & field_crc1 ;
2157
2150
beacon_pkt .payload [beacon_pyld_idx ++ ] = 0xFF & (field_crc1 >> 8 );
2158
2151
@@ -2172,19 +2165,12 @@ void thread_down(void) {
2172
2165
last_beacon_gps_time .tv_sec = next_beacon_gps_time .tv_sec ; /* keep this beacon time as reference for next one to be programmed */
2173
2166
2174
2167
/* display beacon payload */
2175
- MSG ("--- Beacon queued (count_us=%u, freq_hz=%u) - payload: ---\n" , beacon_pkt .count_us , beacon_pkt .freq_hz );
2176
- for (i = 0 ; i < beacon_pkt .size ; ++ i ) {
2177
- MSG ("0x%02X" , beacon_pkt .payload [i ]);
2178
- if (i %8 == 7 ) {
2179
- MSG ("\n" );
2180
- } else {
2181
- MSG (" - " );
2182
- }
2183
- }
2184
- if (i %8 != 0 ) {
2185
- MSG ("\n" );
2168
+ MSG ("INFO: Beacon queued (count_us=%u, freq_hz=%u, size=%u):\n" , beacon_pkt .count_us , beacon_pkt .freq_hz , beacon_pkt .size );
2169
+ printf ( " => " );
2170
+ for (i = 0 ; i < beacon_pkt .size ; ++ i ) {
2171
+ MSG ("%02X " , beacon_pkt .payload [i ]);
2186
2172
}
2187
- MSG ("--- end of payload --- \n" );
2173
+ MSG ("\n" );
2188
2174
} else {
2189
2175
MSG_DEBUG (DEBUG_BEACON , "--> beacon queuing failed with %d\n" , jit_result );
2190
2176
/* update stats */
@@ -2608,9 +2594,17 @@ void thread_jit(void) {
2608
2594
if (jit_result == JIT_ERROR_OK ) {
2609
2595
/* update beacon stats */
2610
2596
if (pkt_type == JIT_PKT_TYPE_BEACON ) {
2597
+ /* Compensate breacon frequency with xtal error */
2598
+ pthread_mutex_lock (& mx_xcorr );
2599
+ pkt .freq_hz = (uint32_t )(xtal_correct * (double )pkt .freq_hz );
2600
+ MSG_DEBUG (DEBUG_BEACON , "beacon_pkt.freq_hz=%u (xtal_correct=%.15lf)\n" , pkt .freq_hz , xtal_correct );
2601
+ pthread_mutex_unlock (& mx_xcorr );
2602
+
2603
+ /* Update statistics */
2611
2604
pthread_mutex_lock (& mx_meas_dw );
2612
2605
meas_nb_beacon_sent += 1 ;
2613
2606
pthread_mutex_unlock (& mx_meas_dw );
2607
+ MSG ("INFO: Beacon dequeued (count_us=%u)\n" , pkt .count_us );
2614
2608
}
2615
2609
2616
2610
/* check if concentrator is free for sending new packet */
0 commit comments