acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

RTTY.h (5683B)

      1 #if !defined(_RADIOLIB_RTTY_H)
      2 #define _RADIOLIB_RTTY_H
      3 
      4 #include "../../TypeDef.h"
      5 
      6 #if !defined(RADIOLIB_EXCLUDE_RTTY)
      7 
      8 #include "../PhysicalLayer/PhysicalLayer.h"
      9 #include "../AFSK/AFSK.h"
     10 
     11 #define RADIOLIB_ITA2_FIGS                                      0x1B
     12 #define RADIOLIB_ITA2_LTRS                                      0x1F
     13 #define RADIOLIB_ITA2_LENGTH                                    32
     14 
     15 // ITA2 character table: - position in array corresponds to 5-bit ITA2 code
     16 //                       - characters to the left are in letters shift, characters to the right in figures shift
     17 //                       - characters marked 0x7F do not have ASCII equivalent
     18 static const char ITA2Table[RADIOLIB_ITA2_LENGTH][2] RADIOLIB_NONVOLATILE = {{'\0', '\0'}, {'E', '3'}, {'\n', '\n'}, {'A', '-'}, {' ', ' '}, {'S', '\''}, {'I', '8'}, {'U', '7'},
     19                                                                              {'\r', '\r'}, {'D', 0x05}, {'R', '4'}, {'J', '\a'}, {'N', ','}, {'F', '!'}, {'C', ':'}, {'K', '('},
     20                                                                              {'T', '5'}, {'Z', '+'}, {'L', ')'}, {'W', '2'}, {'H', 0x7F}, {'Y', '6'}, {'P', '0'}, {'Q', '1'},
     21                                                                              {'O', '9'}, {'B', '?'}, {'G', '&'}, {0x7F, 0x7F}, {'M', '.'}, {'X', '/'}, {'V', ';'}, {0x7F, 0x7F}};
     22 
     23 /*!
     24   \class ITA2String
     25 
     26   \brief ITA2-encoded string.
     27 */
     28 class ITA2String {
     29   public:
     30     /*!
     31       \brief Default single-character constructor.
     32 
     33       \param c ASCII-encoded character to encode as ITA2.
     34     */
     35     explicit ITA2String(char c);
     36 
     37     /*!
     38       \brief Default string constructor.
     39 
     40       \param str ASCII-encoded string to encode as ITA2.
     41     */
     42     explicit ITA2String(const char* str);
     43 
     44     /*!
     45       \brief Default destructor.
     46     */
     47     ~ITA2String();
     48 
     49     /*!
     50       \brief Gets the length of the ITA2 string. This number is not the same as the length of ASCII-encoded string!
     51 
     52       \returns Length of ITA2-encoded string.
     53     */
     54     size_t length();
     55 
     56     /*!
     57       \brief Gets the ITA2 representation of the ASCII string set in constructor.
     58 
     59       \returns Pointer to dynamically allocated array, which contains ITA2-encoded bytes.
     60       It is the caller's responsibility to deallocate this memory!
     61     */
     62     uint8_t* byteArr();
     63 
     64 #if !defined(RADIOLIB_GODMODE)
     65   private:
     66 #endif
     67     #if defined(RADIOLIB_STATIC_ONLY)
     68       char _str[RADIOLIB_STATIC_ARRAY_SIZE];
     69     #else
     70       char* _str;
     71     #endif
     72     size_t _len;
     73     size_t _ita2Len;
     74 
     75     static uint16_t getBits(char c);
     76 };
     77 
     78 // supported encoding schemes
     79 #define RADIOLIB_ASCII                                          0
     80 #define RADIOLIB_ASCII_EXTENDED                                 1
     81 #define RADIOLIB_ITA2                                           2
     82 
     83 /*!
     84   \class RTTYClient
     85 
     86   \brief Client for RTTY communication. The public interface is the same as Arduino Serial.
     87 */
     88 class RTTYClient {
     89   public:
     90     /*!
     91       \brief Constructor for 2-FSK mode.
     92 
     93       \param phy Pointer to the wireless module providing PhysicalLayer communication.
     94     */
     95     explicit RTTYClient(PhysicalLayer* phy);
     96 
     97     #if !defined(RADIOLIB_EXCLUDE_AFSK)
     98     /*!
     99       \brief Constructor for AFSK mode.
    100 
    101       \param audio Pointer to the AFSK instance providing audio.
    102     */
    103     explicit RTTYClient(AFSKClient* audio);
    104     #endif
    105 
    106     // basic methods
    107 
    108     /*!
    109       \brief Initialization method.
    110 
    111       \param base Base (space) frequency to be used in MHz (in 2-FSK mode), or the space tone frequency in Hz (in AFSK mode)
    112 
    113       \param shift Frequency shift between mark and space in Hz.
    114 
    115       \param rate Baud rate to be used during transmission.
    116 
    117       \param encoding Encoding to be used. Defaults to ASCII.
    118 
    119       \param stopBits Number of stop bits to be used.
    120 
    121       \returns \ref status_codes
    122     */
    123     int16_t begin(float base, uint32_t shift, uint16_t rate, uint8_t encoding = RADIOLIB_ASCII, uint8_t stopBits = 1);
    124 
    125     /*!
    126       \brief Send out idle condition (RF tone at mark frequency).
    127     */
    128     void idle();
    129 
    130     /*!
    131       \brief Stops transmitting.
    132 
    133       \returns \ref status_codes
    134     */
    135     int16_t standby();
    136 
    137     size_t write(const char* str);
    138     size_t write(uint8_t* buff, size_t len);
    139     size_t write(uint8_t b);
    140 
    141     size_t print(__FlashStringHelper*);
    142     size_t print(ITA2String &);
    143     size_t print(const String &);
    144     size_t print(const char[]);
    145     size_t print(char);
    146     size_t print(unsigned char, int = DEC);
    147     size_t print(int, int = DEC);
    148     size_t print(unsigned int, int = DEC);
    149     size_t print(long, int = DEC);
    150     size_t print(unsigned long, int = DEC);
    151     size_t print(double, int = 2);
    152 
    153     size_t println(void);
    154     size_t println(__FlashStringHelper*);
    155     size_t println(ITA2String &);
    156     size_t println(const String &);
    157     size_t println(const char[]);
    158     size_t println(char);
    159     size_t println(unsigned char, int = DEC);
    160     size_t println(int, int = DEC);
    161     size_t println(unsigned int, int = DEC);
    162     size_t println(long, int = DEC);
    163     size_t println(unsigned long, int = DEC);
    164     size_t println(double, int = 2);
    165 
    166 #if !defined(RADIOLIB_GODMODE)
    167   private:
    168 #endif
    169     PhysicalLayer* _phy;
    170     #if !defined(RADIOLIB_EXCLUDE_AFSK)
    171     AFSKClient* _audio;
    172     #endif
    173 
    174     uint8_t _encoding = RADIOLIB_ASCII;
    175     uint32_t _base = 0, _baseHz = 0;
    176     uint32_t _shift = 0, _shiftHz = 0;
    177     uint32_t _bitDuration = 0;
    178     uint8_t _dataBits = 0;
    179     uint8_t _stopBits = 0;
    180 
    181     void mark();
    182     void space();
    183 
    184     size_t printNumber(unsigned long, uint8_t);
    185     size_t printFloat(double, uint8_t);
    186 
    187     int16_t transmitDirect(uint32_t freq = 0, uint32_t freqHz = 0);
    188 };
    189 
    190 #endif
    191 
    192 #endif