@@ -572,6 +572,182 @@ struct peer_address_type_t :SafeEnum<peer_address_type_t, uint8_t> {
572
572
SafeEnum<peer_address_type_t , uint8_t >(PUBLIC) { }
573
573
};
574
574
575
+ /* *
576
+ * Type that describes a bluetooth PHY(sical) transport.
577
+ */
578
+ struct phy_t : SafeEnum<phy_t , uint8_t > {
579
+ /* * struct scoped enum wrapped by the class */
580
+ enum type {
581
+ /* *
582
+ * 1Mbit/s LE.
583
+ *
584
+ * @note This physical transport was available since Bluetooth 4.0
585
+ */
586
+ LE_1M = 1 ,
587
+
588
+ /* *
589
+ * 2Mbit/s LE.
590
+ *
591
+ * Modulation is similar to LE_1M but differs in rate. Therefore range
592
+ * performances are in the same ballpark as LE_1M while the increased rate
593
+ * minimize time spent to transfer or receive a packet which leads to a
594
+ * better power consumption and/or faster transfer.
595
+ *
596
+ * @note This transport has been introduced with the Bluetooth 5.
597
+ * @note When operating at 2Mbit/s range is not exactly identical to the
598
+ * range at 1Mbit/s due to a loss in sensitivity.
599
+ */
600
+ LE_2M = 2 ,
601
+
602
+ /* *
603
+ * LE Coded PHY.
604
+ *
605
+ * This transport reuse the 1Mbit/s channel with different coding schemes.
606
+ * Either two (S=2) or eight (S=8) symbols can be used to represent a
607
+ * bit while the 1Mbit/s transport use 1 symbol to code 1 bit of data.
608
+ *
609
+ * Here is the data rate of the two coding schemes:
610
+ * - S=2: 500kbit/s
611
+ * - S=8: 125kbit/s
612
+ *
613
+ * The goal of the coded PHY is to increase the range of BLE devices.
614
+ * Of course given it takes more time to transfer data, transmission
615
+ * and reception last longer which leads to an increase in power
616
+ * consumption.
617
+ *
618
+ * @note This transport has been introduced with the Bluetooth 5.
619
+ */
620
+ LE_CODED
621
+ };
622
+
623
+ /* *
624
+ * Construct a new instance of phy_t.
625
+ */
626
+ phy_t (type value) :
627
+ SafeEnum<phy_t , uint8_t >(value) { }
628
+ };
629
+
630
+ /* *
631
+ * Type that describe a set of PHY(sical) transports. This is used to
632
+ * indicate preference for the PHY transports set within it.
633
+ */
634
+ class phy_set_t {
635
+ public:
636
+ enum PhysFlags_t {
637
+ PHY_SET_1M = 0x01 ,
638
+ PHY_SET_2M = 0x02 ,
639
+ PHY_SET_CODED = 0x04
640
+ };
641
+
642
+ /* *
643
+ * Create set that indicates no preference.
644
+ */
645
+ phy_set_t () : _value(0 ) { }
646
+
647
+ /* *
648
+ * Create a set based on the mask specified in the Bluetooth spec.
649
+ *
650
+ * @param value Octet containing the set of preferred PHYs
651
+ */
652
+ phy_set_t (uint8_t value) : _value(value) { }
653
+
654
+ /* *
655
+ * Create a set based on individual settings.
656
+ *
657
+ * @param phy_1m Prefer LE 1M
658
+ * @param phy_2m Prefer LE 2M if avaiable
659
+ * @param phy_coded Prefer coded modulation if avaiable
660
+ */
661
+ phy_set_t (
662
+ bool phy_1m,
663
+ bool phy_2m,
664
+ bool phy_coded
665
+ ) {
666
+ set_1m (phy_1m);
667
+ set_2m (phy_2m);
668
+ set_coded (phy_coded);
669
+ }
670
+
671
+ /* * Prefer 1M PHY. */
672
+ void set_1m (bool enabled = true ) {
673
+ if (enabled) {
674
+ _value |= PHY_SET_1M;
675
+ } else {
676
+ _value &= ~PHY_SET_1M;
677
+ }
678
+ }
679
+
680
+ /* * Prefer 2M PHY. */
681
+ void set_2m (bool enabled = true ) {
682
+ if (enabled) {
683
+ _value |= PHY_SET_2M;
684
+ } else {
685
+ _value &= ~PHY_SET_2M;
686
+ }
687
+ }
688
+
689
+ /* * Prefer coded PHY. */
690
+ void set_coded (bool enabled = true ) {
691
+ if (enabled) {
692
+ _value |= PHY_SET_CODED;
693
+ } else {
694
+ _value &= ~PHY_SET_CODED;
695
+ }
696
+ }
697
+
698
+ bool get_1m () const {
699
+ return (_value & PHY_SET_1M);
700
+ }
701
+
702
+ bool get_2m () const {
703
+ return (_value & PHY_SET_2M);
704
+ }
705
+
706
+ bool get_coded () const {
707
+ return (_value & PHY_SET_CODED);
708
+ }
709
+
710
+ operator uint8_t () const {
711
+ return _value;
712
+ }
713
+
714
+ uint8_t value () const {
715
+ return _value;
716
+ }
717
+
718
+ private:
719
+ uint8_t _value;
720
+ };
721
+
722
+ /* *
723
+ * Type describing the number of symbols per bit in le coded PHY.
724
+ */
725
+ struct coded_symbol_per_bit_t :SafeEnum<coded_symbol_per_bit_t , uint8_t > {
726
+ /* * struct scoped enum wrapped by the class */
727
+ enum type {
728
+ /* *
729
+ * The Number of symbol used to code a bit is undefined.
730
+ */
731
+ UNDEFINED,
732
+
733
+ /* *
734
+ * Two symbols to code a bit.
735
+ */
736
+ S2,
737
+
738
+ /* *
739
+ * Eight symbols to code a bit.
740
+ */
741
+ S8
742
+ };
743
+
744
+ /* *
745
+ * Construct a new instance of coded_symbol_per_bit_t.
746
+ */
747
+ coded_symbol_per_bit_t (type value) :
748
+ SafeEnum<coded_symbol_per_bit_t , uint8_t >(value) { }
749
+ };
750
+
575
751
} // namespace ble
576
752
577
753
/* *
0 commit comments