@@ -765,11 +765,29 @@ class LoRaModem : public Stream
765765 return true ;
766766 }
767767
768+ /* *
769+ * @brief transmit uplink
770+ *
771+ * @param buff data to transmit`
772+ * @param len length of the buffer`
773+ * @param confirmed true = transmit confirmed uplink
774+ * @return int a positive number indicate success and is the number of bytes transmitted
775+ * -1 indicates a timeout error
776+ * -2 indicates LORA_ERROR
777+ * -3 indicates LORA_ERROR_PARAM
778+ * -4 indicates LORA_ERROR_BUSY
779+ * -5 indicates LORA_ERROR_OVERFLOW
780+ * -6 indicates LORA_ERROR_NO_NETWORK
781+ * -7 indicates LORA_ERROR_RX
782+ * -8 indicates LORA_ERROR_UNKNOWN
783+ * -20 packet exceeds max length
784+ *
785+ */
768786 int modemSend (const void * buff, size_t len, bool confirmed) {
769787
770788 size_t max_len = modemGetMaxSize ();
771789 if (len > max_len) {
772- return -1 ;
790+ return -20 ;
773791 }
774792
775793 if (confirmed) {
@@ -780,16 +798,14 @@ class LoRaModem : public Stream
780798
781799 stream.write ((uint8_t *)buff, len);
782800
783- uint8_t rc = waitResponse ( GFP (LORA_OK), GFP (LORA_ERROR), GFP (LORA_ERROR_PARAM), GFP (LORA_ERROR_BUSY), GFP (LORA_ERROR_OVERFLOW), GFP (LORA_ERROR_NO_NETWORK), GFP (LORA_ERROR_RX), GFP (LORA_ERROR_UNKNOWN) );
784- if (rc != 1 ) {
785- return rc;
801+ int8_t rc = waitResponse ( GFP (LORA_OK), GFP (LORA_ERROR), GFP (LORA_ERROR_PARAM), GFP (LORA_ERROR_BUSY), GFP (LORA_ERROR_OVERFLOW), GFP (LORA_ERROR_NO_NETWORK), GFP (LORA_ERROR_RX), GFP (LORA_ERROR_UNKNOWN) );
802+ if (rc == 1 ) { // /< OK
803+ return len;
804+ } else if ( rc > 1 ) { // /< LORA ERROR
805+ return -rc;
806+ } else { // /< timeout
807+ return -1 ;
786808 }
787- if (confirmed) {
788- if (waitResponse (10000L , " +ACK" ) != 1 ) {
789- return -1 ;
790- }
791- }
792- return len;
793809 }
794810
795811 size_t modemGetMaxSize () {
@@ -845,13 +861,30 @@ class LoRaModem : public Stream
845861 }
846862
847863 // TODO: Optimize this!
848- uint8_t waitResponse (uint32_t timeout, String& data,
864+ /* *
865+ * @brief wait for a response from the modem.
866+ *
867+ * @param timeout the time in milliseconds to wait for a response
868+ * @param data a string containing the response to wait for
869+ * @param r1 response string
870+ * @param r2 response string
871+ * @param r3 response string
872+ * @param r4 response string
873+ * @param r5 response string
874+ * @param r6 response string
875+ * @param r7 response string
876+ * @param r8 response string
877+ * @return int8_t n if the response = r<n>
878+ * 99 if the response ends with "+RECV="
879+ * -1 if timeout
880+ */
881+ int8_t waitResponse (uint32_t timeout, String& data,
849882 ConstStr r1=GFP(LORA_OK), ConstStr r2=GFP(LORA_ERROR),
850883 ConstStr r3=NULL, ConstStr r4=NULL, ConstStr r5=NULL,
851884 ConstStr r6=NULL, ConstStr r7=NULL, ConstStr r8=NULL)
852885 {
853886 data.reserve (64 );
854- int index = -1 ;
887+ int8_t index = -1 ;
855888 int length = 0 ;
856889 unsigned long startMillis = millis ();
857890 do {
@@ -910,7 +943,7 @@ class LoRaModem : public Stream
910943 return index;
911944 }
912945
913- uint8_t waitResponse (uint32_t timeout,
946+ int8_t waitResponse (uint32_t timeout,
914947 ConstStr r1=GFP(LORA_OK), ConstStr r2=GFP(LORA_ERROR),
915948 ConstStr r3=NULL, ConstStr r4=NULL, ConstStr r5=NULL,
916949 ConstStr r6=NULL, ConstStr r7=NULL, ConstStr r8=NULL)
@@ -919,7 +952,7 @@ class LoRaModem : public Stream
919952 return waitResponse (timeout, data, r1, r2, r3, r4, r5, r6, r7, r8);
920953 }
921954
922- uint8_t waitResponse (ConstStr r1=GFP(LORA_OK), ConstStr r2=GFP(LORA_ERROR),
955+ int8_t waitResponse (ConstStr r1=GFP(LORA_OK), ConstStr r2=GFP(LORA_ERROR),
923956 ConstStr r3=NULL, ConstStr r4=NULL, ConstStr r5=NULL,
924957 ConstStr r6=NULL, ConstStr r7=NULL, ConstStr r8=NULL)
925958 {
0 commit comments