Skip to content

Commit 175ff1a

Browse files
committed
backported lwl mqtt code
1 parent 3143541 commit 175ff1a

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

code/CM7/Core/Src/freertos.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,6 @@ void StartDefaultTask(void *argument)
203203
lwl_init();
204204
lwl_enter_record( TEST_LWL_ID , TEST_TEST_LWL_ID , "h" , t );
205205
}
206-
if( input == 'd' )
207-
dump_log();
208-
209206
if( input == 's')
210207
{
211208
float lux;

code/CM7/Core/lwl/lwl.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,32 @@ void dump_log()
142142
HAL_UART_Transmit(&hcom_uart [COM_ActiveLogPort], (uint8_t *) &index , sizeof(index) , COM_POLL_TIMEOUT );
143143
HAL_UART_Transmit(&hcom_uart [COM_ActiveLogPort], lwl_data.buffer , LWL_BUFFER_SIZE , COM_POLL_TIMEOUT );
144144
}
145+
146+
147+
#if __has_include("mqtt_client.h")
148+
#include "mqtt_client.h"
149+
void dump_log_mqtt()
150+
{
151+
// make sure it does not change while dumping. We may loose a few entries while dumping but it is better than corrupting the data.
152+
lwl_driver.is_initialized = false;
153+
154+
uint8_t metadata[ sizeof(lwl_data.next_entry_index) + sizeof(uint32_t) ];
155+
memcpy( &(metadata[0]) , &(lwl_data.next_entry_index) , sizeof(lwl_data.next_entry_index) );
156+
memcpy( &(metadata[sizeof(lwl_data.next_entry_index)]) , &(uint32_t){LWL_BUFFER_SIZE} , sizeof(uint32_t) );
157+
158+
mqtt_publish( mqtt_data.client , MQTT_PUB_LWL_INDEX_ID , metadata , sizeof(metadata) , 0 , 0 , NULL , NULL );
159+
160+
int32_t current_sent_size = 0;
161+
for( int32_t remaining_data = LWL_BUFFER_SIZE ; remaining_data > 0 ; remaining_data -= current_sent_size )
162+
{
163+
const int32_t payload_max_size = MQTT_OUTPUT_RINGBUF_SIZE - sizeof(MQTT_PUB_LWL_DATA_ID) - 5; // dont know why -5. According to mqtt, largest outgoing publish message = topic+payloads
164+
current_sent_size = ( remaining_data > payload_max_size ) ? payload_max_size : remaining_data ;
165+
166+
err_t rv;
167+
do{
168+
rv = mqtt_publish( mqtt_data.client , MQTT_PUB_LWL_DATA_ID , &(lwl_data.buffer[LWL_BUFFER_SIZE - remaining_data]) , current_sent_size , 0 , 0 , NULL , NULL );
169+
} while( rv == ERR_MEM );
170+
}
171+
lwl_driver.is_initialized = true;
172+
}
173+
#endif

code/CM7/Core/lwl/lwl.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
/* Exported functions prototypes ---------------------------------------------*/
3737
void lwl_init();
3838
void lwl_enter_record( uint8_t module_id , char functionality_id[] , const char* fmt , ... );
39-
void dump_log();
39+
40+
#if __has_include("mqtt_client.h")
41+
void dump_log_mqtt();
42+
#endif
4043

4144
#endif /* LWL_LWL_H_ */

0 commit comments

Comments
 (0)