MeterLogger
|
#include <esp8266.h>
#include "driver/uart.h"
#include "unix_time.h"
#include "mqtt.h"
#include "tinyprintf.h"
#include "en61107_request.h"
#include "en61107.h"
#include "config.h"
#include "crypto/crypto.h"
#include "crypto/aes.h"
#include "utils.h"
#include "led.h"
Go to the source code of this file.
Macros | |
#define | QUEUE_SIZE 256 |
Variables | |
uint32_t | en61107_serial = 0 |
bool | en61107_serial_set = false |
int8_t | en61107_request_num |
meter_is_ready_cb | en61107_meter_is_ready_cb = NULL |
bool | meter_is_ready_cb_called = false |
volatile unsigned int | fifo_head |
volatile unsigned int | fifo_tail |
volatile unsigned char | fifo_buffer [QUEUE_SIZE] |
char | frame [EN61107_FRAME_L] |
unsigned int | frame_length |
en61107_response_t | response |
static MQTT_Client * | mqtt_client = NULL |
static os_timer_t | en61107_receive_timeout_timer |
static os_timer_t | en61107_delayed_uart_change_setting_timer |
static os_timer_t | en61107_meter_wake_up_timer |
volatile en61107_uart_state_t | en61107_uart_state |
UartDevice | uart_settings |
volatile uint8_t | en61107_eod |
bool | en61107_etx_received |
#define QUEUE_SIZE 256 |
Definition at line 15 of file en61107_request.c.
Referenced by en61107_fifo_get(), en61107_fifo_put(), and en61107_fifo_snoop().
ICACHE_FLASH_ATTR void en61107_delayed_uart_change_setting_timer_func | ( | UartDevice * | uart_settings | ) |
Definition at line 83 of file en61107_request.c.
References UartDevice::baut_rate, ICACHE_FLASH_ATTR, UartDevice::stop_bits, UART0, uart_set_baudrate(), and uart_set_stop_bits().
Referenced by en61107_uart_send_en61107(), en61107_uart_send_en61107_ident(), en61107_uart_send_inst_values(), en61107_uart_send_standard_data_1(), and en61107_uart_send_standard_data_2().
ICACHE_FLASH_ATTR unsigned char en61107_fifo_get | ( | unsigned char * | c | ) |
Definition at line 583 of file en61107_request.c.
References en61107_fifo_in_use(), fifo_buffer, fifo_tail, ICACHE_FLASH_ATTR, and QUEUE_SIZE.
Referenced by en61107_received_task(), and en61107_request_send().
ICACHE_FLASH_ATTR unsigned int en61107_fifo_in_use | ( | ) |
Definition at line 563 of file en61107_request.c.
References fifo_head, and fifo_tail.
Referenced by en61107_fifo_get(), en61107_fifo_put(), and en61107_fifo_snoop().
|
inline |
Definition at line 568 of file en61107_request.c.
References en61107_fifo_in_use(), fifo_buffer, fifo_head, ICACHE_FLASH_ATTR, and QUEUE_SIZE.
Referenced by uart0_rx_intr_handler().
ICACHE_FLASH_ATTR unsigned char en61107_fifo_snoop | ( | unsigned char * | c, |
unsigned int | pos | ||
) |
Definition at line 598 of file en61107_request.c.
References en61107_fifo_in_use(), fifo_buffer, fifo_tail, and QUEUE_SIZE.
ICACHE_FLASH_ATTR unsigned int en61107_get_received_energy_kwh | ( | ) |
Definition at line 320 of file en61107_request.c.
References en61107_response_t::e1, EN61107_UNIT_L, EN61107_VALUE_L, mw_to_w_str(), strncmp, en61107_response_register_t::unit, and en61107_response_register_t::value.
ICACHE_FLASH_ATTR uint32_t en61107_get_received_serial | ( | ) |
|
inline |
Definition at line 330 of file en61107_request.c.
References en61107_eod, en61107_etx_received, and ICACHE_FLASH_ATTR.
Referenced by uart0_rx_intr_handler().
ICACHE_FLASH_ATTR void en61107_meter_wake_up_timer_func | ( | void * | arg | ) |
Definition at line 91 of file en61107_request.c.
References en61107_uart_send_en61107_ident(), and ICACHE_FLASH_ATTR.
Referenced by en61107_receive_timeout_timer_func(), and en61107_request_send().
ICACHE_FLASH_ATTR void en61107_receive_timeout_timer_func | ( | void * | arg | ) |
Definition at line 49 of file en61107_request.c.
References en61107_meter_wake_up_timer, en61107_meter_wake_up_timer_func(), en61107_request_num, en61107_uart_send_en61107_ident(), en61107_uart_send_inst_values(), en61107_uart_send_standard_data_1(), en61107_uart_send_standard_data_2(), en61107_uart_state, ICACHE_FLASH_ATTR, led_blink(), NULL, os_timer_arm, os_timer_disarm, os_timer_func_t, os_timer_setfn, UART_STATE_EN61107, UART_STATE_EN61107_IDENT, UART_STATE_INST_VALUES, UART_STATE_STANDARD_DATA_1, and UART_STATE_STANDARD_DATA_2.
Referenced by en61107_uart_send_en61107(), en61107_uart_send_en61107_ident(), en61107_uart_send_inst_values(), en61107_uart_send_standard_data_1(), and en61107_uart_send_standard_data_2().
|
static |
Definition at line 98 of file en61107_request.c.
References en61107_meter_program_t::a, en61107_meter_program_t::b, en61107_meter_program_t::ccc, current_unix_time, en61107_response_t::customer_no, en61107_meter_program_t::dd, en61107_meter_program_t::e, en61107_response_t::e1, en61107_response_t::effect1, en61107_fifo_get(), EN61107_FRAME_L, en61107_meter_is_ready_cb, en61107_receive_timeout_timer, en61107_request_num, en61107_serial, en61107_serial_set, en61107_uart_send_en61107(), en61107_uart_send_inst_values(), en61107_uart_send_standard_data_1(), en61107_uart_send_standard_data_2(), en61107_uart_state, encrypt_aes_hmac_combined(), en61107_meter_program_t::ff, en61107_response_t::flow1, get_unix_time(), en61107_meter_program_t::gg, en61107_response_t::hr, ICACHE_FLASH_ATTR, memset, meter_is_ready_cb_called, en61107_response_t::meter_program, MQTT_Publish(), MQTT_TOPIC_L, os_memset, os_printf, os_strncpy, os_timer_disarm, parse_en61107_frame(), parse_mc66cde_inst_values_frame(), parse_mc66cde_standard_data_1_frame(), parse_mc66cde_standard_data_2_frame(), strcat, strlen, system_get_free_heap_size(), en61107_response_t::t1, en61107_response_t::t2, en61107_response_t::t3, en61107_response_t::tdif, tfp_snprintf(), UART_STATE_EN61107, UART_STATE_EN61107_IDENT, UART_STATE_INST_VALUES, UART_STATE_NONE, UART_STATE_STANDARD_DATA_1, UART_STATE_STANDARD_DATA_2, en61107_response_register_t::unit, en61107_response_t::v1, and en61107_response_register_t::value.
Referenced by en61107_request_init().
ICACHE_FLASH_ATTR void en61107_register_meter_is_ready_cb | ( | meter_is_ready_cb | cb | ) |
Definition at line 308 of file en61107_request.c.
References en61107_meter_is_ready_cb, and ICACHE_FLASH_ATTR.
ICACHE_FLASH_ATTR void en61107_request_init | ( | ) |
Definition at line 286 of file en61107_request.c.
References en61107_etx_received, en61107_received_task(), en61107_received_task_prio, en61107_received_task_queue, en61107_received_task_queue_length, en61107_request_num, en61107_uart_state, fifo_head, fifo_tail, ICACHE_FLASH_ATTR, memset, system_os_task(), and UART_STATE_NONE.
ICACHE_FLASH_ATTR void en61107_request_send | ( | ) |
Definition at line 354 of file en61107_request.c.
References en61107_fifo_get(), EN61107_FRAME_L, en61107_meter_wake_up_timer, en61107_meter_wake_up_timer_func(), en61107_request_num, en61107_serial, en61107_uart_state, encrypt_aes_hmac_combined(), get_unix_time(), ICACHE_FLASH_ATTR, memset, MQTT_Publish(), NULL, os_memset, os_sprintf, os_strncpy, os_timer_arm, os_timer_disarm, os_timer_func_t, os_timer_setfn, strlen, and UART_STATE_NONE.
ICACHE_FLASH_ATTR void en61107_set_mqtt_client | ( | MQTT_Client * | client | ) |
ICACHE_FLASH_ATTR void en61107_uart_send_en61107 | ( | ) |
Definition at line 434 of file en61107_request.c.
References UartDevice::baut_rate, BIT_RATE_300, en61107_delayed_uart_change_setting_timer, en61107_delayed_uart_change_setting_timer_func(), en61107_eod, en61107_etx_received, en61107_receive_timeout_timer, en61107_receive_timeout_timer_func(), en61107_uart_state, EVEN_BITS, frame, frame_length, ICACHE_FLASH_ATTR, NULL, ONE_STOP_BIT, os_timer_arm, os_timer_disarm, os_timer_func_t, os_timer_setfn, SEVEN_BITS, UartDevice::stop_bits, strcpy, strlen, TWO_STOP_BIT, UART0, uart0_tx_buffer(), uart_set_baudrate(), uart_set_parity(), uart_set_stop_bits(), uart_set_word_length(), and UART_STATE_EN61107.
Referenced by en61107_received_task().
ICACHE_FLASH_ATTR void en61107_uart_send_en61107_ident | ( | ) |
Definition at line 402 of file en61107_request.c.
References UartDevice::baut_rate, BIT_RATE_300, en61107_delayed_uart_change_setting_timer, en61107_delayed_uart_change_setting_timer_func(), en61107_eod, en61107_etx_received, en61107_receive_timeout_timer, en61107_receive_timeout_timer_func(), en61107_uart_state, EVEN_BITS, frame, frame_length, ICACHE_FLASH_ATTR, NULL, ONE_STOP_BIT, os_timer_arm, os_timer_disarm, os_timer_func_t, os_timer_setfn, SEVEN_BITS, UartDevice::stop_bits, strcpy, strlen, TWO_STOP_BIT, UART0, uart0_tx_buffer(), uart_set_baudrate(), uart_set_parity(), uart_set_stop_bits(), uart_set_word_length(), and UART_STATE_EN61107_IDENT.
Referenced by en61107_meter_wake_up_timer_func(), and en61107_receive_timeout_timer_func().
ICACHE_FLASH_ATTR void en61107_uart_send_inst_values | ( | ) |
Definition at line 529 of file en61107_request.c.
References UartDevice::baut_rate, BIT_RATE_1200, BIT_RATE_300, en61107_delayed_uart_change_setting_timer, en61107_delayed_uart_change_setting_timer_func(), en61107_eod, en61107_receive_timeout_timer, en61107_receive_timeout_timer_func(), en61107_uart_state, EVEN_BITS, frame, frame_length, ICACHE_FLASH_ATTR, NULL, ONE_STOP_BIT, os_timer_arm, os_timer_disarm, os_timer_func_t, os_timer_setfn, SEVEN_BITS, UartDevice::stop_bits, strcpy, strlen, TWO_STOP_BIT, UART0, uart0_tx_buffer(), uart_set_baudrate(), uart_set_parity(), uart_set_stop_bits(), uart_set_word_length(), and UART_STATE_INST_VALUES.
Referenced by en61107_receive_timeout_timer_func(), and en61107_received_task().
ICACHE_FLASH_ATTR void en61107_uart_send_standard_data_1 | ( | ) |
Definition at line 466 of file en61107_request.c.
References UartDevice::baut_rate, BIT_RATE_1200, BIT_RATE_300, en61107_delayed_uart_change_setting_timer, en61107_delayed_uart_change_setting_timer_func(), en61107_eod, en61107_receive_timeout_timer, en61107_receive_timeout_timer_func(), en61107_uart_state, EVEN_BITS, frame, frame_length, ICACHE_FLASH_ATTR, NULL, ONE_STOP_BIT, os_timer_arm, os_timer_disarm, os_timer_func_t, os_timer_setfn, SEVEN_BITS, UartDevice::stop_bits, strcpy, strlen, TWO_STOP_BIT, UART0, uart0_tx_buffer(), uart_set_baudrate(), uart_set_parity(), uart_set_stop_bits(), uart_set_word_length(), and UART_STATE_STANDARD_DATA_1.
Referenced by en61107_receive_timeout_timer_func(), and en61107_received_task().
ICACHE_FLASH_ATTR void en61107_uart_send_standard_data_2 | ( | ) |
Definition at line 497 of file en61107_request.c.
References UartDevice::baut_rate, BIT_RATE_1200, BIT_RATE_300, en61107_delayed_uart_change_setting_timer, en61107_delayed_uart_change_setting_timer_func(), en61107_eod, en61107_receive_timeout_timer, en61107_receive_timeout_timer_func(), en61107_uart_state, EVEN_BITS, frame, frame_length, ICACHE_FLASH_ATTR, NULL, ONE_STOP_BIT, os_timer_arm, os_timer_disarm, os_timer_func_t, os_timer_setfn, SEVEN_BITS, UartDevice::stop_bits, strcpy, strlen, TWO_STOP_BIT, UART0, uart0_tx_buffer(), uart_set_baudrate(), uart_set_parity(), uart_set_stop_bits(), uart_set_word_length(), and UART_STATE_STANDARD_DATA_2.
Referenced by en61107_receive_timeout_timer_func(), and en61107_received_task().
|
static |
Definition at line 38 of file en61107_request.c.
Referenced by en61107_uart_send_en61107(), en61107_uart_send_en61107_ident(), en61107_uart_send_inst_values(), en61107_uart_send_standard_data_1(), and en61107_uart_send_standard_data_2().
volatile uint8_t en61107_eod |
Definition at line 45 of file en61107_request.c.
Referenced by en61107_is_eod_char(), en61107_uart_send_en61107(), en61107_uart_send_en61107_ident(), en61107_uart_send_inst_values(), en61107_uart_send_standard_data_1(), and en61107_uart_send_standard_data_2().
bool en61107_etx_received |
Definition at line 46 of file en61107_request.c.
Referenced by en61107_is_eod_char(), en61107_request_init(), en61107_uart_send_en61107(), and en61107_uart_send_en61107_ident().
meter_is_ready_cb en61107_meter_is_ready_cb = NULL |
Definition at line 20 of file en61107_request.c.
Referenced by en61107_received_task(), and en61107_register_meter_is_ready_cb().
|
static |
Definition at line 39 of file en61107_request.c.
Referenced by en61107_receive_timeout_timer_func(), and en61107_request_send().
|
static |
Definition at line 37 of file en61107_request.c.
Referenced by en61107_received_task(), en61107_uart_send_en61107(), en61107_uart_send_en61107_ident(), en61107_uart_send_inst_values(), en61107_uart_send_standard_data_1(), and en61107_uart_send_standard_data_2().
int8_t en61107_request_num |
Definition at line 19 of file en61107_request.c.
Referenced by en61107_receive_timeout_timer_func(), en61107_received_task(), en61107_request_init(), and en61107_request_send().
uint32_t en61107_serial = 0 |
Definition at line 17 of file en61107_request.c.
Referenced by en61107_get_received_serial(), en61107_received_task(), and en61107_request_send().
bool en61107_serial_set = false |
Definition at line 18 of file en61107_request.c.
Referenced by en61107_received_task().
volatile en61107_uart_state_t en61107_uart_state |
Definition at line 41 of file en61107_request.c.
Referenced by en61107_receive_timeout_timer_func(), en61107_received_task(), en61107_request_init(), en61107_request_send(), en61107_uart_send_en61107(), en61107_uart_send_en61107_ident(), en61107_uart_send_inst_values(), en61107_uart_send_standard_data_1(), and en61107_uart_send_standard_data_2().
volatile unsigned char fifo_buffer[QUEUE_SIZE] |
Definition at line 26 of file en61107_request.c.
Referenced by en61107_fifo_get(), en61107_fifo_put(), and en61107_fifo_snoop().
volatile unsigned int fifo_head |
Definition at line 25 of file en61107_request.c.
Referenced by en61107_fifo_in_use(), en61107_fifo_put(), and en61107_request_init().
volatile unsigned int fifo_tail |
Definition at line 25 of file en61107_request.c.
Referenced by en61107_fifo_get(), en61107_fifo_in_use(), en61107_fifo_snoop(), and en61107_request_init().
char frame[EN61107_FRAME_L] |
Definition at line 29 of file en61107_request.c.
Referenced by en61107_uart_send_en61107(), en61107_uart_send_en61107_ident(), en61107_uart_send_inst_values(), en61107_uart_send_standard_data_1(), en61107_uart_send_standard_data_2(), kmp_decode_frame(), kmp_get_register(), kmp_get_serial(), kmp_get_type(), and parse_en61107_frame().
unsigned int frame_length |
Definition at line 30 of file en61107_request.c.
Referenced by en61107_uart_send_en61107(), en61107_uart_send_en61107_ident(), en61107_uart_send_inst_values(), en61107_uart_send_standard_data_1(), en61107_uart_send_standard_data_2(), kmp_decode_frame(), and parse_en61107_frame().
bool meter_is_ready_cb_called = false |
Definition at line 21 of file en61107_request.c.
Referenced by en61107_received_task().
|
static |
Definition at line 35 of file en61107_request.c.
en61107_response_t response |
Definition at line 33 of file en61107_request.c.
Referenced by kmp_decode_frame().
UartDevice uart_settings |
Definition at line 43 of file en61107_request.c.