فهرست منبع

Version 6.2.7; Improve downlink

platenspeler 4 سال پیش
والد
کامیت
050b87de8f
4فایلهای تغییر یافته به همراه18 افزوده شده و 28 حذف شده
  1. 3 14
      src/_sensor.ino
  2. 1 2
      src/_txRx.ino
  3. 12 10
      src/_udpSemtech.ino
  4. 2 2
      src/_utils.ino

+ 3 - 14
src/_sensor.ino

@@ -568,7 +568,8 @@ int sensorPacket() {
 	// we have to include the AES functions at this stage in order to generate LoRa Payload.
 	uint8_t CodeLength = encodePacket(
 		(uint8_t *)(LUP.payLoad + LUP.size), 
-		PayLength, (uint16_t)frameCount, 
+		PayLength,
+		(uint16_t)frameCount, 
 		DevAddr, 
 		AppSKey, 
 		0
@@ -727,19 +728,6 @@ int sensorPacket() {
 // ----------------------------------------------------------------------------
 uint8_t encodePacket(uint8_t *Data, uint8_t DataLength, uint16_t FrameCount, uint8_t *DevAddr, uint8_t *AppSKey, uint8_t Direction)
 {
-
-#if _MONITOR>=1
-	if ((debug>=2) && (pdebug & P_MAIN)) {
-		String response="encodePacket:: DevAddr=";
-		for (int i=0; i<4; i++ ) { response += (String(DevAddr[i],HEX)+(' ')); }
-		response += ", fcnt=" + String(FrameCount);
-		response += ", encodePacket:: AppSKey=";
-		for (int i=0; i<16; i++ ) { response += (String(AppSKey[i],HEX)+(' ')); }
-		response += ", direction=" + String(Direction);
-		mPrint(response);
-	}
-#endif //_MONITOR
-
 	//unsigned char AppSKey[16] = _APPSKEY ;	// see configGway.h
 	uint8_t i, j;
 	uint8_t Block_A[16];
@@ -784,6 +772,7 @@ uint8_t encodePacket(uint8_t *Data, uint8_t DataLength, uint16_t FrameCount, uin
 			Data++;
 		}
 	}
+
 	//return(numBlocks*16);			// Do we really want to return all 16 bytes in lastblock
 	return(DataLength);				// or only 16*(numBlocks-1)+bLen;
 }

+ 1 - 2
src/_txRx.ino

@@ -58,7 +58,7 @@ int sendPacket(uint8_t *buf, uint8_t len)
 	// datr	: "SF7BW125"
 	// imme : false										// Immediately transfer
 	// fdev	: FSK frequency deviation (unsigned integer, in Hz) // NOT USED
-	// prea	: 8
+	// prea	: 0x08 or 0x0A
 	// ncrc	: 
 	
 	// time Y: Mandatory time
@@ -139,7 +139,6 @@ int sendPacket(uint8_t *buf, uint8_t len)
 
 	//	preamble definition
 	if (LoraDown.prea == 0) LoraDown.prea = 0x0A;		// Change one time, maybe better use 0x0A or so
-//MMM	mPrint("v sendPacket:: time="+String(time)+", ipol="+String(LoraDown.ipol)+", codr="+String(codr)+", prea="+String(LoraDown.prea) );
 	
 	// Compute wait time in microseconds
 	//int32_t w = (int32_t) (LoraDown.tmst - micros());	// Wait Time compute

+ 12 - 10
src/_udpSemtech.ino

@@ -88,7 +88,7 @@ bool connectUdp()
 //	Byte 0: 	Contains Protocol Version
 //	Byte 1+2:	Contain Token
 //	Byte 3:		Contains PULL_RESP or other identifier
-//	Byte 4 >	Contains payload (or Gateway EUI 8 bytes first)
+//	Byte 4-n: 	Contains payload (or Gateway EUI 8 bytes first)
 //
 // Returns:
 //	-1 or false if not read
@@ -309,7 +309,7 @@ int readUdp(int packetSize)
 			//_state=S_TX;
 			sendTime = micros();						// record when we started sending the message
 
-			// Prepare to send the package DOWN to the sensor
+			// Prepare to send the buffre package DOWN to the sensor
 			// We just read the packet from the Network Server and it is formatted
 			// as described in the specs. This function fills LoraDown struct.
 			if (sendPacket(buff_down, packetSize) < 0) {
@@ -336,7 +336,7 @@ int readUdp(int packetSize)
 			// (We normally react on ALL interrupts if we are in TX state)
 			txLoraModem(&LoraDown);									// Calling sendPkt() in turn
 
-			// Copy the lastSeen data down
+			// Copy the lastSeen data down, making room on first entry
 			for (int m=( gwayConfig.maxStat -1); m>0; m--) statr[m]= statr[m-1];
 			
 			// If transmission is finished, print statistics
@@ -364,22 +364,24 @@ int readUdp(int packetSize)
 				uint8_t DevAddr[4];
 				uint16_t frameCount;
 				int index;
-				
-				if ((index = inDecodes((char *)(LoraDown.payLoad+1))) >=0 ) {
+
+				if ((index = inDecodes((char *)(LoraDown.payLoad+1))) >= 0 ) {
 #	ifdef _FCNT
 					frameCount= LoraDown.fcnt;
 #	else
 					frameCount= LoraDown.payLoad[7]*256 + LoraDown.payLoad[6];
 #	endif
+
 					// Only if _LOCALSERVER >= 2 for downstream
-					strncpy ((char *)statr[0].data, (char *)LoraDown.payLoad,  LoraDown.size);
+					strncpy ((char *)statr[0].data, (char *)LoraDown.payLoad+9,  LoraDown.size-9-4);
 
 					DevAddr[0]= LoraDown.payLoad[4];
 					DevAddr[1]= LoraDown.payLoad[3];
 					DevAddr[2]= LoraDown.payLoad[2];
 					DevAddr[3]= LoraDown.payLoad[1];
 
-					statr[0].datal = encodePacket((uint8_t *)(statr[0].data + 9), 
+					statr[0].datal = encodePacket(
+						(uint8_t *)(statr[0].data), 
 						LoraDown.size -9 -4, 
 						(uint16_t)frameCount, 
 						DevAddr, 
@@ -396,7 +398,7 @@ int readUdp(int packetSize)
 				// If we should not print data for downlink
 				statr[0].datal = 0;
 #			  endif //_LOCALSERVER
-			
+
 			// If _MONITOR set print the statistics
 			if ((debug>=1) && (pdebug & P_TX)) {
 
@@ -418,7 +420,7 @@ int readUdp(int packetSize)
 						statr[0].datal=24;
 					}
 					
-					response+= "coded=<";
+					response+= "new=<";
 					
 					if (statr[0].datal < 0) {
 						mPrint("ERROR datal=0");
@@ -436,7 +438,7 @@ int readUdp(int packetSize)
 #				endif //_LOCALSERVER
 
 				response += ", size=" + String(LoraDown.size);
-				response += ", load=<";
+				response += ", old=<";
 				for(int i=0; i<LoraDown.size; i++) {
 					response += String(LoraDown.payLoad[i],HEX) + " ";
 				}

+ 2 - 2
src/_utils.ino

@@ -53,8 +53,8 @@ void printRegs(struct LoraDown *LoraDown, String & response)
 		Serial.print("v FIFO                 (0x00)\t=0x"); printReg(REG_FIFO);
 		Serial.print("v OPMODE               (0x01)\t=0x"); printReg(REG_OPMODE);
 		Serial.print("v FRF                  (0x06)\t=0x"); printReg(REG_FRF_MSB); 
-			Serial.print(' '); printReg(REG_FRF_MID); 
-			Serial.print(' '); printReg(REG_FRF_LSB);
+			Serial.print("  "); printReg(REG_FRF_MID); 
+			Serial.print("  "); printReg(REG_FRF_LSB);
 		Serial.print("v PAC                  (0x09)\t=0x"); printReg(REG_PAC);
 		Serial.print("v PARAMP               (0x0A)\t=0x"); printReg(REG_PARAMP);
 		Serial.print("v REG_OCP              (0x0B)\t=0x"); printReg(REG_OCP);