MQTT fix mqtt_timer_left_ms
mqtt_timer_left_ms: timer->end_time is in ticks, now is in ticks, so left is in ticks. left * portTICK_PERIOD_MS is the time left. With that change, the select in both mqtt_esp_read and mqtt_esp_write seems to work as expected(with time, not ticks)
This commit is contained in:
		
							parent
							
								
									49a0a74ae2
								
							
						
					
					
						commit
						67cd7bc031
					
				
					 1 changed files with 5 additions and 7 deletions
				
			
		|  | @ -53,7 +53,7 @@ int  mqtt_timer_left_ms(mqtt_timer_t* timer) | ||||||
| { | { | ||||||
|     TickType_t now = xTaskGetTickCount(); |     TickType_t now = xTaskGetTickCount(); | ||||||
|     int32_t left = timer->end_time - now; |     int32_t left = timer->end_time - now; | ||||||
|     return (left < 0) ? 0 : left / portTICK_PERIOD_MS; |     return (left < 0) ? 0 : left * portTICK_PERIOD_MS; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -72,9 +72,8 @@ int  mqtt_esp_read(mqtt_network_t* n, unsigned char* buffer, int len, int timeou | ||||||
|     int rcvd = 0; |     int rcvd = 0; | ||||||
|     FD_ZERO(&fdset); |     FD_ZERO(&fdset); | ||||||
|     FD_SET(n->my_socket, &fdset); |     FD_SET(n->my_socket, &fdset); | ||||||
|     // It seems tv_sec actually means FreeRTOS tick
 |     tv.tv_sec = timeout_ms / 1000; | ||||||
|     tv.tv_sec = timeout_ms / portTICK_PERIOD_MS; |     tv.tv_usec = (timeout_ms % 1000) * 1000; | ||||||
|     tv.tv_usec = 0; |  | ||||||
|     rc = select(n->my_socket + 1, &fdset, 0, 0, &tv); |     rc = select(n->my_socket + 1, &fdset, 0, 0, &tv); | ||||||
|     if ((rc > 0) && (FD_ISSET(n->my_socket, &fdset))) |     if ((rc > 0) && (FD_ISSET(n->my_socket, &fdset))) | ||||||
|     { |     { | ||||||
|  | @ -97,9 +96,8 @@ int  mqtt_esp_write(mqtt_network_t* n, unsigned char* buffer, int len, int timeo | ||||||
| 
 | 
 | ||||||
|     FD_ZERO(&fdset); |     FD_ZERO(&fdset); | ||||||
|     FD_SET(n->my_socket, &fdset); |     FD_SET(n->my_socket, &fdset); | ||||||
|     // It seems tv_sec actually means FreeRTOS tick
 |     tv.tv_sec = timeout_ms / 1000; | ||||||
|     tv.tv_sec = timeout_ms / portTICK_PERIOD_MS; |     tv.tv_usec = (timeout_ms % 1000) * 1000; | ||||||
|     tv.tv_usec = 0; |  | ||||||
|     rc = select(n->my_socket + 1, 0, &fdset, 0, &tv); |     rc = select(n->my_socket + 1, 0, &fdset, 0, &tv); | ||||||
|     if ((rc > 0) && (FD_ISSET(n->my_socket, &fdset))) |     if ((rc > 0) && (FD_ISSET(n->my_socket, &fdset))) | ||||||
|     { |     { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue