@@ -468,15 +468,7 @@ class LoRaModem : public Stream
468468
469469
470470 int getrxfreq () {
471- String rxFreq;
472-
473- sendAT (GF (" +RX2FQ=?" ));
474-
475- if (waitResponse (rxFreq) == 1 ) {
476- rxFreq=rxFreq.substring (0 ,rxFreq.lastIndexOf (' \r ' , rxFreq.indexOf (" OK" )));
477- }
478-
479- return rxFreq.toInt ();
471+ return getValue (" RX2FQ" ).toInt ();
480472 }
481473
482474
@@ -523,21 +515,11 @@ class LoRaModem : public Stream
523515 }
524516
525517 String deviceEUI () {
526- String eui;
527- sendAT (GF (" +DEUI=?" ));
528- if (waitResponse (eui) == 1 ) {
529- eui=eui.substring (0 ,eui.lastIndexOf (' \r ' , eui.indexOf (" OK" )));
530- }
531- return eui;
518+ return getValue (" DEUI" );
532519 }
533520
534521 String applicationKey () {
535- String appKeyRead;
536- sendAT (GF (" +APPKEY=?" ));
537- if (waitResponse (appKeyRead) == 1 ) {
538- appKeyRead=appKeyRead.substring (0 ,appKeyRead.lastIndexOf (' \r ' , appKeyRead.indexOf (" OK" )));
539- }
540- return appKeyRead;
522+ return getValue (" APPKEY" );
541523 }
542524
543525 void maintain () {
@@ -669,12 +651,7 @@ class LoRaModem : public Stream
669651 }
670652
671653 int getDataRate () {
672- int dr = -1 ;
673- sendAT (GF (" +DR=?" ));
674- if (waitResponse () == 1 ) {
675- dr = stream.readStringUntil (' \r ' ).toInt ();
676- }
677- return dr;
654+ return getValue (" DR" ).toInt ();
678655 }
679656
680657 bool setADR (bool adr) {
@@ -686,12 +663,7 @@ class LoRaModem : public Stream
686663 }
687664
688665 int getADR () {
689- int adr = -1 ;
690- sendAT (GF (" +ADR=?" ));
691- if (waitResponse () == 1 ) {
692- adr = stream.readStringUntil (' \r ' ).toInt ();
693- }
694- return adr;
666+ return getValue (" ADR" ).toInt ();
695667 }
696668
697669 bool setCFM (bool cfm) {
@@ -703,48 +675,23 @@ class LoRaModem : public Stream
703675 }
704676
705677 int getCFM () {
706- int cfm = -1 ;
707- sendAT (GF (" +CFM=?" ));
708- if (waitResponse () == 1 ) {
709- cfm = stream.readStringUntil (' \r ' ).toInt ();
710- }
711- return cfm;
678+ return getValue (" CFM" ).toInt ();
712679 }
713680
714681 int getCFS () {
715- int cfs = -1 ;
716- sendAT (GF (" +CFS=?" ));
717- if (waitResponse () == 1 ) {
718- cfs = stream.readStringUntil (' \r ' ).toInt ();
719- }
720- return cfs;
682+ return getValue (" CFS" ).toInt ();
721683 }
722684
723685 String getDevAddr () {
724- String devaddr = " " ;
725- sendAT (GF (" +DADDR=?" ));
726- if (waitResponse () == 1 ) {
727- devaddr = stream.readStringUntil (' \r ' );
728- }
729- return devaddr;
686+ return getValue (" DADDR" );
730687 }
731688
732689 String getNwkSKey () {
733- String nwkskey = " " ;
734- sendAT (GF (" +NWKSKEY?" ));
735- if (waitResponse (" +OK=" ) == 1 ) {
736- nwkskey = stream.readStringUntil (' \r ' );
737- }
738- return nwkskey;
690+ return getValue (" NWKSKEY" );
739691 }
740692
741693 String getAppSKey () {
742- String appskey = " " ;
743- sendAT (GF (" +APPKEY=?" ));
744- if (waitResponse () == 1 ) {
745- appskey = stream.readStringUntil (' \r ' );
746- }
747- return appskey;
694+ return getValue (" APPKEY" );
748695 }
749696
750697 bool setFCU (uint16_t fcu) {
@@ -756,12 +703,7 @@ class LoRaModem : public Stream
756703 }
757704
758705 int32_t getFCU () {
759- int32_t fcu = -1 ;
760- sendAT (GF (" +FCU?" ));
761- if (waitResponse (" +OK=" ) == 1 ) {
762- fcu = stream.readStringUntil (' \r ' ).toInt ();
763- }
764- return fcu;
706+ return getValue (" FCU" ).toInt ();
765707 }
766708
767709 bool setFCD (uint16_t fcd) {
@@ -773,12 +715,7 @@ class LoRaModem : public Stream
773715 }
774716
775717 int32_t getFCD () {
776- int32_t fcd = -1 ;
777- sendAT (GF (" +FCD?" ));
778- if (waitResponse (" +OK=" ) == 1 ) {
779- fcd = stream.readStringUntil (' \r ' ).toInt ();
780- }
781- return fcd;
718+ return getValue (" FCD" ).toInt ();
782719 }
783720
784721
@@ -931,6 +868,16 @@ class LoRaModem : public Stream
931868 return false ;
932869 }
933870
871+ String getValue (String val) {
872+ String temp;
873+ sendAT (GF (" +" + val + " =?" ));
874+ if (waitResponse (temp) == 1 ) {
875+ temp=temp.substring (0 ,temp.lastIndexOf (' \r ' , temp.indexOf (" OK" )));
876+ return temp;
877+ }
878+ return " " ;
879+ }
880+
934881 /* Utilities */
935882 template <typename T>
936883 void streamWrite (T last) {
0 commit comments