DRA818 VHF or UHF radio module library. http://www.dorji.com/docs/data/DRA818V.pdf
dra818.cpp@0:cb7724063ba3, 2016-05-25 (annotated)
- Committer:
- ebarranco
- Date:
- Wed May 25 19:07:49 2016 +0000
- Revision:
- 0:cb7724063ba3
- Child:
- 2:2561b105f0b0
DRA818 Lib - Initial commit.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ebarranco | 0:cb7724063ba3 | 1 | #include "mbed.h" |
ebarranco | 0:cb7724063ba3 | 2 | #include "dra818.h" |
ebarranco | 0:cb7724063ba3 | 3 | |
ebarranco | 0:cb7724063ba3 | 4 | DRA818::DRA818(Serial *s, PinName PTT): PTT_PIN(PTT){ |
ebarranco | 0:cb7724063ba3 | 5 | this->serial = s; |
ebarranco | 0:cb7724063ba3 | 6 | this->PTT_PIN=1; |
ebarranco | 0:cb7724063ba3 | 7 | |
ebarranco | 0:cb7724063ba3 | 8 | this->tx_ctcss = 0; |
ebarranco | 0:cb7724063ba3 | 9 | this->rx_ctcss = 0; |
ebarranco | 0:cb7724063ba3 | 10 | this->tx_freq = 146.500; |
ebarranco | 0:cb7724063ba3 | 11 | |
ebarranco | 0:cb7724063ba3 | 12 | this->volume = 4; |
ebarranco | 0:cb7724063ba3 | 13 | this->squelch = 0; |
ebarranco | 0:cb7724063ba3 | 14 | this->preemph = 0; |
ebarranco | 0:cb7724063ba3 | 15 | this->highpass = 0; |
ebarranco | 0:cb7724063ba3 | 16 | this->lowpass = 0; |
ebarranco | 0:cb7724063ba3 | 17 | } |
ebarranco | 0:cb7724063ba3 | 18 | |
ebarranco | 0:cb7724063ba3 | 19 | |
ebarranco | 0:cb7724063ba3 | 20 | void DRA818::setTXFreq(double tx_freq){ |
ebarranco | 0:cb7724063ba3 | 21 | if( (tx_freq>136.000 && tx_freq<174.000 ) || (tx_freq>410.000 && tx_freq<480.000) ){ |
ebarranco | 0:cb7724063ba3 | 22 | this->tx_freq = tx_freq; |
ebarranco | 0:cb7724063ba3 | 23 | } |
ebarranco | 0:cb7724063ba3 | 24 | } |
ebarranco | 0:cb7724063ba3 | 25 | |
ebarranco | 0:cb7724063ba3 | 26 | void DRA818::setRXFreq(double rx_freq){ |
ebarranco | 0:cb7724063ba3 | 27 | if( (rx_freq>136.000 && rx_freq<174.000 ) || (rx_freq>410.000 && rx_freq<480.000) ){ |
ebarranco | 0:cb7724063ba3 | 28 | this->rx_freq = rx_freq; |
ebarranco | 0:cb7724063ba3 | 29 | } |
ebarranco | 0:cb7724063ba3 | 30 | } |
ebarranco | 0:cb7724063ba3 | 31 | |
ebarranco | 0:cb7724063ba3 | 32 | // Refer to https://en.wikipedia.org/wiki/CTCSS for CTCSS values. |
ebarranco | 0:cb7724063ba3 | 33 | void DRA818::setTXCTCSS(uint8_t ctcss){ |
ebarranco | 0:cb7724063ba3 | 34 | if(ctcss<=38){ |
ebarranco | 0:cb7724063ba3 | 35 | this->tx_ctcss = ctcss; |
ebarranco | 0:cb7724063ba3 | 36 | } |
ebarranco | 0:cb7724063ba3 | 37 | } |
ebarranco | 0:cb7724063ba3 | 38 | void DRA818::setRXCTCSS(uint8_t ctcss){ |
ebarranco | 0:cb7724063ba3 | 39 | if(ctcss<=38){ |
ebarranco | 0:cb7724063ba3 | 40 | this->rx_ctcss = ctcss; |
ebarranco | 0:cb7724063ba3 | 41 | } |
ebarranco | 0:cb7724063ba3 | 42 | } |
ebarranco | 0:cb7724063ba3 | 43 | |
ebarranco | 0:cb7724063ba3 | 44 | void DRA818::setGWB(bool gwb){ |
ebarranco | 0:cb7724063ba3 | 45 | this->gwb=gwb?1:0; |
ebarranco | 0:cb7724063ba3 | 46 | } |
ebarranco | 0:cb7724063ba3 | 47 | |
ebarranco | 0:cb7724063ba3 | 48 | void DRA818::setSquelch(uint8_t sql){ |
ebarranco | 0:cb7724063ba3 | 49 | if(sql<=8){ |
ebarranco | 0:cb7724063ba3 | 50 | this->squelch = sql; |
ebarranco | 0:cb7724063ba3 | 51 | } |
ebarranco | 0:cb7724063ba3 | 52 | } |
ebarranco | 0:cb7724063ba3 | 53 | |
ebarranco | 0:cb7724063ba3 | 54 | void DRA818::writeFreq(){ |
ebarranco | 0:cb7724063ba3 | 55 | this->PTT_PIN=1; |
ebarranco | 0:cb7724063ba3 | 56 | wait_ms(500); // Delay for a bit, to let the uC boot up (?) |
ebarranco | 0:cb7724063ba3 | 57 | |
ebarranco | 0:cb7724063ba3 | 58 | char tx_freq_buffer[10]; |
ebarranco | 0:cb7724063ba3 | 59 | char rx_freq_buffer[10]; |
ebarranco | 0:cb7724063ba3 | 60 | |
ebarranco | 0:cb7724063ba3 | 61 | sprintf(tx_freq_buffer,"%.3f",this->tx_freq); |
ebarranco | 0:cb7724063ba3 | 62 | sprintf(rx_freq_buffer,"%.3f",this->rx_freq); |
ebarranco | 0:cb7724063ba3 | 63 | sprintf(this->buffer,"AT+DMOSETGROUP=%d,%s,%s,%04d,%1d,%04d\r\n",this->gwb,tx_freq_buffer,rx_freq_buffer,this->tx_ctcss,this->squelch,this->rx_ctcss); |
ebarranco | 0:cb7724063ba3 | 64 | this->serial->printf("%s",this->buffer); |
ebarranco | 0:cb7724063ba3 | 65 | } |
ebarranco | 0:cb7724063ba3 | 66 | |
ebarranco | 0:cb7724063ba3 | 67 | void DRA818::setVolume(uint8_t vol){ |
ebarranco | 0:cb7724063ba3 | 68 | if(vol>=1 || vol<=8){ |
ebarranco | 0:cb7724063ba3 | 69 | this->volume = vol; |
ebarranco | 0:cb7724063ba3 | 70 | } |
ebarranco | 0:cb7724063ba3 | 71 | |
ebarranco | 0:cb7724063ba3 | 72 | this->PTT_PIN=1; |
ebarranco | 0:cb7724063ba3 | 73 | wait_ms(500); // Delay for a bit, to let the uC boot up (?) |
ebarranco | 0:cb7724063ba3 | 74 | |
ebarranco | 0:cb7724063ba3 | 75 | sprintf(this->buffer,"AT+DMOSETVOLUME=%1d\r\n",this->volume); |
ebarranco | 0:cb7724063ba3 | 76 | this->serial->printf("%s",this->buffer); |
ebarranco | 0:cb7724063ba3 | 77 | } |
ebarranco | 0:cb7724063ba3 | 78 | |
ebarranco | 0:cb7724063ba3 | 79 | void DRA818::setFilters(bool preemph, bool highpass, bool lowpass){ |
ebarranco | 0:cb7724063ba3 | 80 | this->preemph=preemph?1:0; |
ebarranco | 0:cb7724063ba3 | 81 | this->highpass=highpass?1:0; |
ebarranco | 0:cb7724063ba3 | 82 | this->lowpass=lowpass?1:0; |
ebarranco | 0:cb7724063ba3 | 83 | |
ebarranco | 0:cb7724063ba3 | 84 | this->PTT_PIN=1; |
ebarranco | 0:cb7724063ba3 | 85 | wait_ms(500); // Delay for a bit, to let the uC boot up (?) |
ebarranco | 0:cb7724063ba3 | 86 | |
ebarranco | 0:cb7724063ba3 | 87 | sprintf(this->buffer,"AT+SETFILTER=%1d,%1d,%1d\r\n",this->preemph,this->highpass,this->lowpass); |
ebarranco | 0:cb7724063ba3 | 88 | this->serial->printf("%s",this->buffer); |
ebarranco | 0:cb7724063ba3 | 89 | } |