Jelajahi Sumber

update:去除mqtt 64KB接收限制,但是一般用不到这么大

alienwalker 1 tahun lalu
induk
melakukan
3213f1ef34

+ 7 - 7
components/network/libemqtt/libemqtt.c

@@ -62,9 +62,9 @@ uint8_t mqtt_num_rem_len_bytes(const uint8_t* buf) {
 	return num_bytes;
 }
 
-uint16_t mqtt_parse_rem_len(const uint8_t* buf) {
-	uint16_t multiplier = 1;
-	uint16_t value = 0;
+uint32_t mqtt_parse_rem_len(const uint8_t* buf) {
+	uint32_t multiplier = 1;
+	uint32_t value = 0;
 	uint8_t digit;
 	//printf("mqtt_parse_rem_len\n");
 	buf++;	// skip "flags" byte in fixed header
@@ -131,18 +131,18 @@ uint16_t mqtt_parse_pub_topic_ptr(const uint8_t* buf, const uint8_t **topic_ptr)
 	return len;
 }
 
-uint16_t mqtt_parse_publish_msg(const uint8_t* buf, uint8_t* msg) {
+uint32_t mqtt_parse_publish_msg(const uint8_t* buf, uint8_t* msg) {
 	const uint8_t* ptr;
 	//printf("mqtt_parse_publish_msg\n");
-	uint16_t msg_len = mqtt_parse_pub_msg_ptr(buf, &ptr);
+	uint32_t msg_len = mqtt_parse_pub_msg_ptr(buf, &ptr);
 	if(msg_len != 0 && ptr != NULL) {
 		memcpy(msg, ptr, msg_len);
 	}
 	return msg_len;
 }
 
-uint16_t mqtt_parse_pub_msg_ptr(const uint8_t* buf, const uint8_t **msg_ptr) {
-	uint16_t len = 0;
+uint32_t mqtt_parse_pub_msg_ptr(const uint8_t* buf, const uint8_t **msg_ptr) {
+	uint32_t len = 0;
 	//printf("mqtt_parse_pub_msg_ptr\n");
 	if(MQTTParseMessageType(buf) == MQTT_MSG_PUBLISH) {
 		// message starts at

+ 3 - 3
components/network/libemqtt/libemqtt.h

@@ -113,7 +113,7 @@ uint8_t mqtt_num_rem_len_bytes(const uint8_t* buf);
  *
  * @retval remaining length
  */
-uint16_t mqtt_parse_rem_len(const uint8_t* buf);
+uint32_t mqtt_parse_rem_len(const uint8_t* buf);
 
 /** Parse packet buffer for message id.
  *
@@ -151,13 +151,13 @@ uint16_t mqtt_parse_pub_topic_ptr(const uint8_t* buf, const uint8_t** topic_ptr)
  *
  * @retval size in bytes of topic (0 = no publish message in buffer)
  */
-uint16_t mqtt_parse_publish_msg(const uint8_t* buf, uint8_t* msg);
+uint32_t mqtt_parse_publish_msg(const uint8_t* buf, uint8_t* msg);
 
 /** Parse a packet buffer for a pointer to the publish message.
  *
  *  Not called directly - called by mqtt_parse_pub_msg
  */
-uint16_t mqtt_parse_pub_msg_ptr(const uint8_t* buf, const uint8_t** msg_ptr);
+uint32_t mqtt_parse_pub_msg_ptr(const uint8_t* buf, const uint8_t** msg_ptr);
 
 
 typedef struct {

+ 2 - 1
components/network/libemqtt/luat_mqtt.h

@@ -59,7 +59,8 @@ typedef struct{
 
 typedef struct{
 	uint16_t topic_len;
-    uint16_t payload_len;
+	uint16_t dummy;
+    uint32_t payload_len;
 	uint8_t data[];
 }luat_mqtt_msg_t;
 

+ 2 - 2
components/network/libemqtt/luat_mqtt_client.c

@@ -204,7 +204,7 @@ static int mqtt_parse(luat_mqtt_ctrl_t *mqtt_ctrl) {
 		}
 	}
 	// 判断数据总长, 这里rem_len只包含mqtt头部之外的数据
-	uint16_t rem_len = mqtt_parse_rem_len(mqtt_ctrl->mqtt_packet_buffer);
+	uint32_t rem_len = mqtt_parse_rem_len(mqtt_ctrl->mqtt_packet_buffer);
 	if (rem_len > mqtt_ctrl->buffer_offset - num_bytes - 1) {
 		LLOGD("wait more data for mqtt head");
 		return 0;
@@ -304,7 +304,7 @@ static int luat_mqtt_msg_cb(luat_mqtt_ctrl_t *mqtt_ctrl) {
 #ifdef __LUATOS__
 			const uint8_t* ptr;
 			uint16_t topic_len = mqtt_parse_pub_topic_ptr(mqtt_ctrl->mqtt_packet_buffer, &ptr);
-			uint16_t payload_len = mqtt_parse_pub_msg_ptr(mqtt_ctrl->mqtt_packet_buffer, &ptr);
+			uint32_t payload_len = mqtt_parse_pub_msg_ptr(mqtt_ctrl->mqtt_packet_buffer, &ptr);
 			luat_mqtt_msg_t *mqtt_msg = (luat_mqtt_msg_t *)luat_heap_malloc(sizeof(luat_mqtt_msg_t)+topic_len+payload_len);
 			mqtt_msg->topic_len = mqtt_parse_pub_topic(mqtt_ctrl->mqtt_packet_buffer, mqtt_msg->data);
             mqtt_msg->payload_len = mqtt_parse_publish_msg(mqtt_ctrl->mqtt_packet_buffer, mqtt_msg->data+topic_len);