@@ -465,6 +465,57 @@ static void tx_packet(struct pios_openlrs_dev *openlrs_dev, uint8_t *pkt, uint8_
465465 }
466466}
467467
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+
468519static void beacon_tone (struct pios_openlrs_dev * openlrs_dev , int16_t hz , int16_t len __attribute__((unused ))) // duration is now in half seconds.
469520{
470521 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_
481532 rfm22_claimBus (openlrs_dev );
482533
483534 // This need fixed for F1
484- #ifdef GPIO_Mode_OUT
535+ #ifdef GPIO_MODE_OUT
485536 GPIO_TypeDef * gpio = openlrs_dev -> cfg .spi_cfg -> mosi .gpio ;
486537 uint16_t pin_source = openlrs_dev -> cfg .spi_cfg -> mosi .init .GPIO_Pin ;
487538 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_
515566
516567 GPIO_Init (gpio , (GPIO_InitTypeDef * )& openlrs_dev -> cfg .spi_cfg -> mosi .init );
517568 GPIO_PinAFConfig (gpio , pin_source , remap );
518- #endif /* ifdef GPIO_Mode_OUT */
569+ #endif /* ifdef GPIO_MODE_OUT */
519570 rfm22_releaseBus (openlrs_dev );
520571
521572#if defined(PIOS_LED_LINK )
@@ -528,6 +579,7 @@ static void beacon_tone(struct pios_openlrs_dev *openlrs_dev, int16_t hz, int16_
528579#endif /* PIOS_WDG_RFM22B */
529580}
530581
582+ #endif /* OPENLRS_SIMPLE_BEACON_TONE */
531583
532584static uint8_t beaconGetRSSI (struct pios_openlrs_dev * openlrs_dev )
533585{
@@ -588,9 +640,40 @@ static void beacon_send(struct pios_openlrs_dev *openlrs_dev, bool static_tone)
588640 if (static_tone ) {
589641 uint8_t i = 0 ;
590642 while (i ++ < 20 ) {
643+ #ifdef OPENLRS_SIMPLE_BEACON_TONE
644+ beacon_simpletone (openlrs_dev , 2 , 3 );
645+ #else
591646 beacon_tone (openlrs_dev , 440 , 1 );
647+ #endif
592648 }
593649 } 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 */
594677 // close encounters tune
595678 // G, A, F, F(lower octave), C
596679 // octave 3: 392 440 349 175 261
@@ -612,6 +695,7 @@ static void beacon_send(struct pios_openlrs_dev *openlrs_dev, bool static_tone)
612695 rfm22_write (openlrs_dev , 0x6d , 0x00 ); // 0 set min power 1.3mW
613696 PIOS_Thread_Sleep (10 );
614697 beacon_tone (openlrs_dev , 261 , 2 );
698+ #endif /* #ifdef OPENLRS_SIMPLE_BEACON_TONE */
615699 }
616700 rfm22_write_claim (openlrs_dev , 0x07 , RF22B_PWRSTATE_READY );
617701}
@@ -829,9 +913,6 @@ static void pios_openlrs_rx_loop(struct pios_openlrs_dev *openlrs_dev)
829913 OPLinkStatusData oplink_status ;
830914 OPLinkStatusGet (& oplink_status );
831915
832- // Update the RSSI
833- oplink_status .RSSI = openlrs_dev -> rssi ;
834-
835916 timeUs = PIOS_DELAY_GetuS ();
836917 timeMs = PIOS_Thread_Systime ();
837918
@@ -860,8 +941,8 @@ static void pios_openlrs_rx_loop(struct pios_openlrs_dev *openlrs_dev)
860941
861942 openlrs_dev -> lastPacketTimeUs = timeUs ;
862943 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 ;
865946
866947 if ((openlrs_dev -> rx_buf [0 ] & 0x3e ) == 0x00 ) {
867948 // This flag indicates receiving PPM data
@@ -928,7 +1009,7 @@ static void pios_openlrs_rx_loop(struct pios_openlrs_dev *openlrs_dev)
9281009 }
9291010 tx_buf [4 ] = (openlrs_dev -> lastAFCCvalue >> 8 );
9301011 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 );
9321013 }
9331014 }
9341015
@@ -949,7 +1030,7 @@ static void pios_openlrs_rx_loop(struct pios_openlrs_dev *openlrs_dev)
9491030 if ((openlrs_dev -> numberOfLostPackets < openlrs_dev -> hopcount ) && (PIOS_DELAY_GetuSSince (openlrs_dev -> lastPacketTimeUs ) > (getInterval (& openlrs_dev -> bind_data ) + packet_timeout_us ))) {
9501031 DEBUG_PRINTF (2 , "OLRS WARN: Lost packet: %d\r\n" , openlrs_dev -> numberOfLostPackets );
9511032 // we lost packet, hop to next channel
952- oplink_status . LinkQuality <<= 1 ;
1033+ openlrs_dev -> link_quality <<= 1 ;
9531034 openlrs_dev -> willhop = 1 ;
9541035 if (openlrs_dev -> numberOfLostPackets == 0 ) {
9551036 openlrs_dev -> linkLossTimeMs = timeMs ;
@@ -961,7 +1042,7 @@ static void pios_openlrs_rx_loop(struct pios_openlrs_dev *openlrs_dev)
9611042 } else if ((openlrs_dev -> numberOfLostPackets >= openlrs_dev -> hopcount ) && (PIOS_DELAY_GetuSSince (openlrs_dev -> lastPacketTimeUs ) > (getInterval (& openlrs_dev -> bind_data ) * openlrs_dev -> hopcount ))) {
9621043 DEBUG_PRINTF (2 , "ORLS WARN: Trying to resync\r\n" );
9631044 // hop slowly to allow resync with TX
964- oplink_status . LinkQuality = 0 ;
1045+ openlrs_dev -> link_quality = 0 ;
9651046 openlrs_dev -> willhop = 1 ;
9661047 openlrs_dev -> lastPacketTimeUs = timeUs ;
9671048 }
@@ -977,7 +1058,7 @@ static void pios_openlrs_rx_loop(struct pios_openlrs_dev *openlrs_dev)
9771058 DEBUG_PRINTF (2 , "Failsafe activated: %d %d\r\n" , timeMs , openlrs_dev -> linkLossTimeMs );
9781059 oplink_status .LinkState = OPLINKSTATUS_LINKSTATE_DISCONNECTED ;
9791060 // 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...
9811062 }
9821063
9831064 if ((openlrs_dev -> beacon_frequency ) && (openlrs_dev -> nextBeaconTimeMs ) &&
@@ -993,7 +1074,7 @@ static void pios_openlrs_rx_loop(struct pios_openlrs_dev *openlrs_dev)
9931074 beacon_send (openlrs_dev , false); // play cool tune
9941075 init_rfm (openlrs_dev , 0 ); // go back to normal RX
9951076 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
9971078 }
9981079 }
9991080 }
@@ -1029,6 +1110,19 @@ static void pios_openlrs_rx_loop(struct pios_openlrs_dev *openlrs_dev)
10291110 openlrs_dev -> willhop = 0 ;
10301111 }
10311112
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+
10321126 // Update UAVO
10331127 OPLinkStatusSet (& oplink_status );
10341128}
0 commit comments