@@ -465,6 +465,57 @@ static void tx_packet(struct pios_openlrs_dev *openlrs_dev, uint8_t *pkt, uint8_
465
465
}
466
466
}
467
467
468
+ #ifdef OPENLRS_SIMPLE_BEACON_TONE
469
+ // Basic tone
470
+ static void beacon_simpletone (struct pios_openlrs_dev * openlrs_dev , uint8_t tone , int16_t len __attribute__((unused )))
471
+ {
472
+ DEBUG_PRINTF (2 , "beacon_morse: %d\r\n" , len );
473
+
474
+ #if defined(PIOS_LED_LINK )
475
+ PIOS_LED_On (PIOS_LED_LINK );
476
+ #endif /* PIOS_LED_LINK */
477
+
478
+ rfm22_claimBus (openlrs_dev );
479
+
480
+ GPIO_TypeDef * gpio = openlrs_dev -> cfg .spi_cfg -> mosi .gpio ;
481
+ uint16_t pin_source = openlrs_dev -> cfg .spi_cfg -> mosi .init .GPIO_Pin ;
482
+ uint8_t remap = openlrs_dev -> cfg .spi_cfg -> remap ;
483
+
484
+ GPIO_InitTypeDef init = {
485
+ .GPIO_Speed = GPIO_Speed_50MHz ,
486
+ .GPIO_Mode = GPIO_Mode_OUT ,
487
+ .GPIO_OType = GPIO_OType_PP ,
488
+ .GPIO_PuPd = GPIO_PuPd_UP
489
+ };
490
+ init .GPIO_Pin = pin_source ;
491
+
492
+ // Set MOSI to digital out for bit banging
493
+ GPIO_PinAFConfig (gpio , pin_source , 0 );
494
+ GPIO_Init (gpio , & init );
495
+
496
+ int16_t cycles = (len * 50 ) / tone ;
497
+ for (int16_t i = 0 ; i < cycles ; i ++ ) {
498
+ GPIO_SetBits (gpio , pin_source );
499
+ PIOS_Thread_Sleep (tone );
500
+ GPIO_ResetBits (gpio , pin_source );
501
+ PIOS_Thread_Sleep (tone );
502
+ }
503
+ GPIO_Init (gpio , (GPIO_InitTypeDef * )& openlrs_dev -> cfg .spi_cfg -> mosi .init );
504
+ GPIO_PinAFConfig (gpio , pin_source , remap );
505
+ rfm22_releaseBus (openlrs_dev );
506
+
507
+ #if defined(PIOS_LED_LINK )
508
+ PIOS_LED_Off (PIOS_LED_LINK );
509
+ #endif /* PIOS_LED_LINK */
510
+
511
+ #if defined(PIOS_INCLUDE_WDG ) && defined(PIOS_WDG_RFM22B )
512
+ // Update the watchdog timer
513
+ PIOS_WDG_UpdateFlag (PIOS_WDG_RFM22B );
514
+ #endif /* PIOS_WDG_RFM22B */
515
+ }
516
+
517
+ #else /* OPENLRS_SIMPLE_BEACON_TONE */
518
+
468
519
static void beacon_tone (struct pios_openlrs_dev * openlrs_dev , int16_t hz , int16_t len __attribute__((unused ))) // duration is now in half seconds.
469
520
{
470
521
DEBUG_PRINTF (2 , "beacon_tone: %d %d\r\n" , hz , len * 2 );
@@ -481,7 +532,7 @@ static void beacon_tone(struct pios_openlrs_dev *openlrs_dev, int16_t hz, int16_
481
532
rfm22_claimBus (openlrs_dev );
482
533
483
534
// This need fixed for F1
484
- #ifdef GPIO_Mode_OUT
535
+ #ifdef GPIO_MODE_OUT
485
536
GPIO_TypeDef * gpio = openlrs_dev -> cfg .spi_cfg -> mosi .gpio ;
486
537
uint16_t pin_source = openlrs_dev -> cfg .spi_cfg -> mosi .init .GPIO_Pin ;
487
538
uint8_t remap = openlrs_dev -> cfg .spi_cfg -> remap ;
@@ -515,7 +566,7 @@ static void beacon_tone(struct pios_openlrs_dev *openlrs_dev, int16_t hz, int16_
515
566
516
567
GPIO_Init (gpio , (GPIO_InitTypeDef * )& openlrs_dev -> cfg .spi_cfg -> mosi .init );
517
568
GPIO_PinAFConfig (gpio , pin_source , remap );
518
- #endif /* ifdef GPIO_Mode_OUT */
569
+ #endif /* ifdef GPIO_MODE_OUT */
519
570
rfm22_releaseBus (openlrs_dev );
520
571
521
572
#if defined(PIOS_LED_LINK )
@@ -528,6 +579,7 @@ static void beacon_tone(struct pios_openlrs_dev *openlrs_dev, int16_t hz, int16_
528
579
#endif /* PIOS_WDG_RFM22B */
529
580
}
530
581
582
+ #endif /* OPENLRS_SIMPLE_BEACON_TONE */
531
583
532
584
static uint8_t beaconGetRSSI (struct pios_openlrs_dev * openlrs_dev )
533
585
{
@@ -588,9 +640,40 @@ static void beacon_send(struct pios_openlrs_dev *openlrs_dev, bool static_tone)
588
640
if (static_tone ) {
589
641
uint8_t i = 0 ;
590
642
while (i ++ < 20 ) {
643
+ #ifdef OPENLRS_SIMPLE_BEACON_TONE
644
+ beacon_simpletone (openlrs_dev , 2 , 3 );
645
+ #else
591
646
beacon_tone (openlrs_dev , 440 , 1 );
647
+ #endif
592
648
}
593
649
} else {
650
+ #ifdef OPENLRS_SIMPLE_BEACON_TONE
651
+ for (uint32_t tone = 1 ; tone < 4 ; tone ++ ) {
652
+ if (tone == 1 ) {
653
+ rfm22_write (openlrs_dev , 0x6d , 0x05 ); // 5 set min power 25mW
654
+ } else {
655
+ rfm22_write (openlrs_dev , 0x6d , 0x00 ); // 0 set min power 1.3mW
656
+ }
657
+ // L - --- - -
658
+ beacon_simpletone (openlrs_dev , tone , 1 );
659
+ PIOS_Thread_Sleep (100 );
660
+ beacon_simpletone (openlrs_dev , tone , 3 );
661
+ PIOS_Thread_Sleep (100 );
662
+ beacon_simpletone (openlrs_dev , tone , 1 );
663
+ PIOS_Thread_Sleep (100 );
664
+ beacon_simpletone (openlrs_dev , tone , 1 );
665
+ PIOS_Thread_Sleep (600 );
666
+ // P - --- --- -
667
+ beacon_simpletone (openlrs_dev , tone , 1 );
668
+ PIOS_Thread_Sleep (100 );
669
+ beacon_simpletone (openlrs_dev , tone , 3 );
670
+ PIOS_Thread_Sleep (100 );
671
+ beacon_simpletone (openlrs_dev , tone , 3 );
672
+ PIOS_Thread_Sleep (100 );
673
+ beacon_simpletone (openlrs_dev , tone , 1 );
674
+ PIOS_Thread_Sleep (2000 );
675
+ }
676
+ #else /* ifdef OPENLRS_SIMPLE_BEACON_TONE */
594
677
// close encounters tune
595
678
// G, A, F, F(lower octave), C
596
679
// octave 3: 392 440 349 175 261
@@ -612,6 +695,7 @@ static void beacon_send(struct pios_openlrs_dev *openlrs_dev, bool static_tone)
612
695
rfm22_write (openlrs_dev , 0x6d , 0x00 ); // 0 set min power 1.3mW
613
696
PIOS_Thread_Sleep (10 );
614
697
beacon_tone (openlrs_dev , 261 , 2 );
698
+ #endif /* #ifdef OPENLRS_SIMPLE_BEACON_TONE */
615
699
}
616
700
rfm22_write_claim (openlrs_dev , 0x07 , RF22B_PWRSTATE_READY );
617
701
}
@@ -829,9 +913,6 @@ static void pios_openlrs_rx_loop(struct pios_openlrs_dev *openlrs_dev)
829
913
OPLinkStatusData oplink_status ;
830
914
OPLinkStatusGet (& oplink_status );
831
915
832
- // Update the RSSI
833
- oplink_status .RSSI = openlrs_dev -> rssi ;
834
-
835
916
timeUs = PIOS_DELAY_GetuS ();
836
917
timeMs = PIOS_Thread_Systime ();
837
918
@@ -860,8 +941,8 @@ static void pios_openlrs_rx_loop(struct pios_openlrs_dev *openlrs_dev)
860
941
861
942
openlrs_dev -> lastPacketTimeUs = timeUs ;
862
943
openlrs_dev -> numberOfLostPackets = 0 ;
863
- oplink_status . LinkQuality <<= 1 ;
864
- oplink_status . LinkQuality |= 1 ;
944
+ openlrs_dev -> link_quality <<= 1 ;
945
+ openlrs_dev -> link_quality |= 1 ;
865
946
866
947
if ((openlrs_dev -> rx_buf [0 ] & 0x3e ) == 0x00 ) {
867
948
// This flag indicates receiving PPM data
@@ -928,7 +1009,7 @@ static void pios_openlrs_rx_loop(struct pios_openlrs_dev *openlrs_dev)
928
1009
}
929
1010
tx_buf [4 ] = (openlrs_dev -> lastAFCCvalue >> 8 );
930
1011
tx_buf [5 ] = openlrs_dev -> lastAFCCvalue & 0xff ;
931
- tx_buf [6 ] = countSetBits (oplink_status . LinkQuality & 0x7fff );
1012
+ tx_buf [6 ] = countSetBits (openlrs_dev -> link_quality & 0x7fff );
932
1013
}
933
1014
}
934
1015
@@ -949,7 +1030,7 @@ static void pios_openlrs_rx_loop(struct pios_openlrs_dev *openlrs_dev)
949
1030
if ((openlrs_dev -> numberOfLostPackets < openlrs_dev -> hopcount ) && (PIOS_DELAY_GetuSSince (openlrs_dev -> lastPacketTimeUs ) > (getInterval (& openlrs_dev -> bind_data ) + packet_timeout_us ))) {
950
1031
DEBUG_PRINTF (2 , "OLRS WARN: Lost packet: %d\r\n" , openlrs_dev -> numberOfLostPackets );
951
1032
// we lost packet, hop to next channel
952
- oplink_status . LinkQuality <<= 1 ;
1033
+ openlrs_dev -> link_quality <<= 1 ;
953
1034
openlrs_dev -> willhop = 1 ;
954
1035
if (openlrs_dev -> numberOfLostPackets == 0 ) {
955
1036
openlrs_dev -> linkLossTimeMs = timeMs ;
@@ -961,7 +1042,7 @@ static void pios_openlrs_rx_loop(struct pios_openlrs_dev *openlrs_dev)
961
1042
} else if ((openlrs_dev -> numberOfLostPackets >= openlrs_dev -> hopcount ) && (PIOS_DELAY_GetuSSince (openlrs_dev -> lastPacketTimeUs ) > (getInterval (& openlrs_dev -> bind_data ) * openlrs_dev -> hopcount ))) {
962
1043
DEBUG_PRINTF (2 , "ORLS WARN: Trying to resync\r\n" );
963
1044
// hop slowly to allow resync with TX
964
- oplink_status . LinkQuality = 0 ;
1045
+ openlrs_dev -> link_quality = 0 ;
965
1046
openlrs_dev -> willhop = 1 ;
966
1047
openlrs_dev -> lastPacketTimeUs = timeUs ;
967
1048
}
@@ -977,7 +1058,7 @@ static void pios_openlrs_rx_loop(struct pios_openlrs_dev *openlrs_dev)
977
1058
DEBUG_PRINTF (2 , "Failsafe activated: %d %d\r\n" , timeMs , openlrs_dev -> linkLossTimeMs );
978
1059
oplink_status .LinkState = OPLINKSTATUS_LINKSTATE_DISCONNECTED ;
979
1060
// failsafeApply();
980
- openlrs_dev -> nextBeaconTimeMs = (timeMs + 1000UL * openlrs_dev -> beacon_period ) | 1 ; // beacon activating...
1061
+ openlrs_dev -> nextBeaconTimeMs = (timeMs + ( 1000UL * openlrs_dev -> beacon_delay ) ) | 1 ; // beacon activating...
981
1062
}
982
1063
983
1064
if ((openlrs_dev -> beacon_frequency ) && (openlrs_dev -> nextBeaconTimeMs ) &&
@@ -993,7 +1074,7 @@ static void pios_openlrs_rx_loop(struct pios_openlrs_dev *openlrs_dev)
993
1074
beacon_send (openlrs_dev , false); // play cool tune
994
1075
init_rfm (openlrs_dev , 0 ); // go back to normal RX
995
1076
rx_reset (openlrs_dev );
996
- openlrs_dev -> nextBeaconTimeMs = (timeMs + 1000UL * openlrs_dev -> beacon_period ) | 1 ; // avoid 0 in time
1077
+ openlrs_dev -> nextBeaconTimeMs = (timeMs + ( 1000UL * openlrs_dev -> beacon_period ) ) | 1 ; // avoid 0 in time
997
1078
}
998
1079
}
999
1080
}
@@ -1029,6 +1110,19 @@ static void pios_openlrs_rx_loop(struct pios_openlrs_dev *openlrs_dev)
1029
1110
openlrs_dev -> willhop = 0 ;
1030
1111
}
1031
1112
1113
+ if (oplink_status .LinkState > OPLINKSTATUS_LINKSTATE_DISCONNECTED ) {
1114
+ // Convert raw Rssi to dBm
1115
+ oplink_status .RSSI = (int8_t )(openlrs_dev -> rssi >> 1 ) - 122 ;
1116
+
1117
+ // Count number of bits set in link_quality
1118
+ uint8_t linkquality_bits = countSetBits (openlrs_dev -> link_quality & 0x7fff );
1119
+ // Translate link quality to 0 - 128 range
1120
+ oplink_status .LinkQuality = (linkquality_bits + 1 ) * 8 ;
1121
+ } else {
1122
+ oplink_status .LinkQuality = 0 ;
1123
+ oplink_status .RSSI = -127 ;
1124
+ }
1125
+
1032
1126
// Update UAVO
1033
1127
OPLinkStatusSet (& oplink_status );
1034
1128
}
0 commit comments