Edgar Barranco / DRA818lib

DRA818 VHF or UHF radio module library. http://www.dorji.com/docs/data/DRA818V.pdf

Committer:
ebarranco
Date:
Thu May 26 18:50:36 2016 +0000
Revision:
3:b822fbac58f4
Parent:
0:cb7724063ba3
Rename example to avoid main conflicts. Maybe there is a better way to do this?

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ebarranco0:cb7724063ba3 1#include "mbed.h"
ebarranco0:cb7724063ba3 2#include "dra818.h"
ebarranco0:cb7724063ba3 3
ebarranco0:cb7724063ba3 4DRA818::DRA818(Serial *s, PinName PTT): PTT_PIN(PTT){
ebarranco0:cb7724063ba3 5 this->serial = s;
ebarranco0:cb7724063ba3 6 this->PTT_PIN=1;
ebarranco0:cb7724063ba3 7
ebarranco0:cb7724063ba3 8 this->tx_ctcss = 0;
ebarranco0:cb7724063ba3 9 this->rx_ctcss = 0;
ebarranco0:cb7724063ba3 10 this->tx_freq = 146.500;
ebarranco0:cb7724063ba3 11
ebarranco0:cb7724063ba3 12 this->volume = 4;
ebarranco0:cb7724063ba3 13 this->squelch = 0;
ebarranco0:cb7724063ba3 14 this->preemph = 0;
ebarranco0:cb7724063ba3 15 this->highpass = 0;
ebarranco0:cb7724063ba3 16 this->lowpass = 0;
ebarranco0:cb7724063ba3 17}
ebarranco0:cb7724063ba3 18
ebarranco0:cb7724063ba3 19
ebarranco0:cb7724063ba3 20void DRA818::setTXFreq(double tx_freq){
ebarranco0:cb7724063ba3 21 if( (tx_freq>136.000 && tx_freq<174.000 ) || (tx_freq>410.000 && tx_freq<480.000) ){
ebarranco0:cb7724063ba3 22 this->tx_freq = tx_freq;
ebarranco0:cb7724063ba3 23 }
ebarranco0:cb7724063ba3 24}
ebarranco0:cb7724063ba3 25
ebarranco0:cb7724063ba3 26void DRA818::setRXFreq(double rx_freq){
ebarranco0:cb7724063ba3 27 if( (rx_freq>136.000 && rx_freq<174.000 ) || (rx_freq>410.000 && rx_freq<480.000) ){
ebarranco0:cb7724063ba3 28 this->rx_freq = rx_freq;
ebarranco0:cb7724063ba3 29 }
ebarranco0:cb7724063ba3 30}
ebarranco0:cb7724063ba3 31
ebarranco0:cb7724063ba3 32// Refer to https://en.wikipedia.org/wiki/CTCSS for CTCSS values.
ebarranco0:cb7724063ba3 33void DRA818::setTXCTCSS(uint8_t ctcss){
ebarranco0:cb7724063ba3 34 if(ctcss<=38){
ebarranco0:cb7724063ba3 35 this->tx_ctcss = ctcss;
ebarranco0:cb7724063ba3 36 }
ebarranco0:cb7724063ba3 37}
ebarranco0:cb7724063ba3 38void DRA818::setRXCTCSS(uint8_t ctcss){
ebarranco0:cb7724063ba3 39 if(ctcss<=38){
ebarranco0:cb7724063ba3 40 this->rx_ctcss = ctcss;
ebarranco0:cb7724063ba3 41 }
ebarranco0:cb7724063ba3 42}
ebarranco0:cb7724063ba3 43
ebarranco0:cb7724063ba3 44void DRA818::setGWB(bool gwb){
ebarranco0:cb7724063ba3 45 this->gwb=gwb?1:0;
ebarranco0:cb7724063ba3 46}
ebarranco0:cb7724063ba3 47
ebarranco0:cb7724063ba3 48void DRA818::setSquelch(uint8_t sql){
ebarranco0:cb7724063ba3 49 if(sql<=8){
ebarranco0:cb7724063ba3 50 this->squelch = sql;
ebarranco0:cb7724063ba3 51 }
ebarranco0:cb7724063ba3 52}
ebarranco0:cb7724063ba3 53
ebarranco0:cb7724063ba3 54void DRA818::writeFreq(){
ebarranco0:cb7724063ba3 55 this->PTT_PIN=1;
ebarranco0:cb7724063ba3 56 wait_ms(500); // Delay for a bit, to let the uC boot up (?)
ebarranco0:cb7724063ba3 57
ebarranco0:cb7724063ba3 58 char tx_freq_buffer[10];
ebarranco0:cb7724063ba3 59 char rx_freq_buffer[10];
ebarranco0:cb7724063ba3 60
ebarranco2:2561b105f0b0 61 sprintf(tx_freq_buffer,"%.4f",this->tx_freq);
ebarranco2:2561b105f0b0 62 sprintf(rx_freq_buffer,"%.4f",this->rx_freq);
ebarranco0: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);
ebarranco0:cb7724063ba3 64 this->serial->printf("%s",this->buffer);
ebarranco0:cb7724063ba3 65}
ebarranco0:cb7724063ba3 66
ebarranco0:cb7724063ba3 67void DRA818::setVolume(uint8_t vol){
ebarranco0:cb7724063ba3 68 if(vol>=1 || vol<=8){
ebarranco0:cb7724063ba3 69 this->volume = vol;
ebarranco0:cb7724063ba3 70 }
ebarranco0:cb7724063ba3 71
ebarranco0:cb7724063ba3 72 this->PTT_PIN=1;
ebarranco0:cb7724063ba3 73 wait_ms(500); // Delay for a bit, to let the uC boot up (?)
ebarranco0:cb7724063ba3 74
ebarranco0:cb7724063ba3 75 sprintf(this->buffer,"AT+DMOSETVOLUME=%1d\r\n",this->volume);
ebarranco0:cb7724063ba3 76 this->serial->printf("%s",this->buffer);
ebarranco0:cb7724063ba3 77}
ebarranco0:cb7724063ba3 78
ebarranco0:cb7724063ba3 79void DRA818::setFilters(bool preemph, bool highpass, bool lowpass){
ebarranco0:cb7724063ba3 80 this->preemph=preemph?1:0;
ebarranco0:cb7724063ba3 81 this->highpass=highpass?1:0;
ebarranco0:cb7724063ba3 82 this->lowpass=lowpass?1:0;
ebarranco0:cb7724063ba3 83
ebarranco0:cb7724063ba3 84 this->PTT_PIN=1;
ebarranco0:cb7724063ba3 85 wait_ms(500); // Delay for a bit, to let the uC boot up (?)
ebarranco0:cb7724063ba3 86
ebarranco0:cb7724063ba3 87 sprintf(this->buffer,"AT+SETFILTER=%1d,%1d,%1d\r\n",this->preemph,this->highpass,this->lowpass);
ebarranco0:cb7724063ba3 88 this->serial->printf("%s",this->buffer);
ebarranco0:cb7724063ba3 89}