Skip to content

Commit c821b6c

Browse files
committed
Periodic Reading Feature Added
1 parent a0c356b commit c821b6c

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

components/iec1107/iec1107.c

+22-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#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>
67
#include "iec1107.h"
78
#include "config.h"
89

@@ -23,6 +24,9 @@ ESP_EVENT_DEFINE_BASE(IEC1107_EVENT);
2324

2425
static const char *IEC1107_TAG = "iec1107_parser";
2526

27+
/* @brief Software Timer to reading meter */
28+
static TimerHandle_t iec1107_cycle_timer = NULL;
29+
2630
/* @brief FreeRTOS event group to signal when we need to make a start & readout request */
2731
static EventGroupHandle_t s_iec1107_event_group;
2832

@@ -102,6 +106,16 @@ static void export_val_deinit()
102106
free(export_hdl);
103107
}
104108

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+
}
105119

106120
static void iec1107_management_task(void* pvParameters)
107121
{
@@ -196,6 +210,7 @@ static void export_line(esp_event_loop_handle_t hdl, const uint8_t* buffer)
196210
esp_event_post_to(hdl, IEC1107_EVENT, IEC1107_FIELDS_UPDATED, NULL, 0, 100 / portTICK_PERIOD_MS);
197211
xEventGroupClearBits(s_iec1107_event_group, READOUT_MESSAGE_SENDED);
198212
xEventGroupSetBits(s_iec1107_event_group, READOUT_MESSAGE_ENDED);
213+
xTimerStart( iec1107_cycle_timer, (TickType_t)0 );
199214
return; // Don't remove return exp for this statement.
200215
}
201216

@@ -344,6 +359,9 @@ iec1107_parser_handle_t iec1107_parser_init(reading_mode_t mode, uint16_t timeou
344359
iec1107 -> read_mode = mode;
345360
iec1107 -> timeout = timeout;
346361

362+
iec1107_cycle_timer = xTimerCreate( NULL, pdMS_TO_TICKS(iec1107 -> timeout), pdFALSE, ( void * ) 0, iec1107_timer_cb);
363+
364+
347365
iec1107 -> buffer = calloc(1, IEC1107_PARSER_RUNTIME_BUFFER_SIZE);
348366
if (!iec1107 -> buffer)
349367
{

main/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static void iec1107_event_handler(void* event_handler_arg, esp_event_base_t even
5252

5353
void app_main()
5454
{
55-
iec1107_parser_handle_t iec1107 = iec1107_parser_init(LOOP, 1000);
55+
iec1107_parser_handle_t iec1107 = iec1107_parser_init(LOOP, 10000);
5656

5757
iec1107_parser_add_handler(iec1107, iec1107_event_handler, NULL);
5858

0 commit comments

Comments
 (0)