Program to transmit strings as Morse code using the CC1200. Useful for amateur radio projects!
Dependencies: CC1200 SerialStream
CC1200Morse.h
00001 // 00002 // Class allowing you to transmit Morse code using the CC1200 radio 00003 // 00004 00005 #ifndef LIGHTSPEEDRANGEFINDER_CC1200MORSE_H 00006 #define LIGHTSPEEDRANGEFINDER_CC1200MORSE_H 00007 00008 #include <CC1200.h> 00009 00010 class CC1200Morse 00011 { 00012 CC1200 & radio; 00013 00014 // time units at the start and end of the morse message. 00015 const size_t spaceBefore = 3; 00016 const size_t spaceAfter = 3; 00017 00018 public: 00019 00020 CC1200Morse(CC1200 & _radio): 00021 radio(_radio){} 00022 00023 /** 00024 * Configure the CC1200 to transmit morse code. 00025 * 00026 * @param band Radio band containing the frequency. 00027 * @param radioFrequency Frequency to transmit on. 00028 * @param morseTimePeriod Time unit in seconds to use when transmitting. 00029 * @param transmitPower Power in dBm to transmit at. Must be in the CC1200 allowed range. 00030 * Dots are one time unit, dashes are three. 00031 * 50ms is about the fastest a human can understand, while 125ms is a more reasonable speed. 00032 * Specifics are here: http://www.codebug.org.uk/learn/step/541/morse-code-timing-rules/#:~:text=The%20space%20between%20symbols%20(dots,words%20is%207%20time%20units. 00033 */ 00034 void configure(CC1200::Band band, float radioFrequency, float morseTimePeriod, float transmitPower); 00035 00036 struct EncodedMorse 00037 { 00038 /// Whether this morse data is valid.. If false, it couldn't be encoded due to an error. 00039 bool valid; 00040 00041 /// Buffer storing morse data. Uses memory passed to configure() 00042 uint8_t const * buffer; 00043 00044 /// Number of complete bytes and bits used in the data 00045 size_t byteLen; 00046 uint8_t bitLen; 00047 00048 // Number of bytes in the buffer that are at least partially filled. 00049 size_t totalLength; 00050 }; 00051 00052 /** 00053 * Convert ASCII text into characters suitable to be sent over the radio. 00054 * Some ASCII characters do not have a morse equivalent, these will be removed. 00055 * 00056 * @param string ASCII string to convert. 00057 * @param outputBuffer Buffer to write morse into. Will be zeroed. 00058 * @return Encoded morse data, if there was insufficient space valid will be false. 00059 */ 00060 EncodedMorse convertToMorse(const char* string, uint8_t * outputBuffer, size_t bufferLen); 00061 00062 /** 00063 * Queue this morse code to be transmitted over the radio. 00064 * Packets with a total length larger than 128 bytes cannot be transmitted (though this limit 00065 * could be worked around). 00066 * 00067 * The packet will be transmitted as soon as the radio is switched to TX state. 00068 * If it's already in TX then it will be transmitted immediately. 00069 * @param morse 00070 */ 00071 void transmit(EncodedMorse const & morse); 00072 }; 00073 00074 00075 #endif //LIGHTSPEEDRANGEFINDER_CC1200MORSE_H
Generated on Sun Jul 24 2022 06:31:11 by 1.7.2