1
1
#include <string.h>
2
- #include "freertos/FreeRTOS.h"
3
- #include "freertos/task.h"
4
- #include "freertos/event_groups.h"
5
- #include "esp_log.h"
2
+ #include <freertos/FreeRTOS.h>
3
+ #include <freertos/task.h>
4
+ #include <freertos/event_groups.h>
5
+ #include <esp_log.h>
6
+ #include <freertos/timers.h>
6
7
#include "iec1107.h"
7
8
#include "config.h"
8
9
@@ -23,6 +24,9 @@ ESP_EVENT_DEFINE_BASE(IEC1107_EVENT);
23
24
24
25
static const char * IEC1107_TAG = "iec1107_parser" ;
25
26
27
+ /* @brief Software Timer to reading meter */
28
+ static TimerHandle_t iec1107_cycle_timer = NULL ;
29
+
26
30
/* @brief FreeRTOS event group to signal when we need to make a start & readout request */
27
31
static EventGroupHandle_t s_iec1107_event_group ;
28
32
@@ -102,6 +106,16 @@ static void export_val_deinit()
102
106
free (export_hdl );
103
107
}
104
108
109
+ static void iec1107_timer_cb (TimerHandle_t xTimer )
110
+ {
111
+ ESP_LOGI (IEC1107_TAG , "Reading EM Starting Again.." );
112
+
113
+ /* Stop the timer */
114
+ xTimerStop (xTimer , (TickType_t ) 0 );
115
+
116
+ /*Attempt to send start message */
117
+ xEventGroupSetBits (s_iec1107_event_group , START_MESSAGE_SEND );
118
+ }
105
119
106
120
static void iec1107_management_task (void * pvParameters )
107
121
{
@@ -196,6 +210,7 @@ static void export_line(esp_event_loop_handle_t hdl, const uint8_t* buffer)
196
210
esp_event_post_to (hdl , IEC1107_EVENT , IEC1107_FIELDS_UPDATED , NULL , 0 , 100 / portTICK_PERIOD_MS );
197
211
xEventGroupClearBits (s_iec1107_event_group , READOUT_MESSAGE_SENDED );
198
212
xEventGroupSetBits (s_iec1107_event_group , READOUT_MESSAGE_ENDED );
213
+ xTimerStart ( iec1107_cycle_timer , (TickType_t )0 );
199
214
return ; // Don't remove return exp for this statement.
200
215
}
201
216
@@ -344,6 +359,9 @@ iec1107_parser_handle_t iec1107_parser_init(reading_mode_t mode, uint16_t timeou
344
359
iec1107 -> read_mode = mode ;
345
360
iec1107 -> timeout = timeout ;
346
361
362
+ iec1107_cycle_timer = xTimerCreate ( NULL , pdMS_TO_TICKS (iec1107 -> timeout ), pdFALSE , ( void * ) 0 , iec1107_timer_cb );
363
+
364
+
347
365
iec1107 -> buffer = calloc (1 , IEC1107_PARSER_RUNTIME_BUFFER_SIZE );
348
366
if (!iec1107 -> buffer )
349
367
{
0 commit comments