This commit is contained in:
King Kévin 2016-10-10 10:24:55 +02:00
parent fce8008a68
commit 071cda7035
3 changed files with 9 additions and 8 deletions

View File

@ -13,7 +13,7 @@
* *
*/ */
/** library to query measurements from eastron SDM120-ModBus electricity meter (code) /** library to query measurements from eastron SDM120-ModBus electricity meter (code)
* @file sensor_sdm120.h * @file sensor_sdm120.c
* @author King Kévin <kingkevin@cuvoodoo.info> * @author King Kévin <kingkevin@cuvoodoo.info>
* @date 2016 * @date 2016
* @note peripherals used: USART @ref sensor_sdm120_usart , GPIO @ref sensor_sdm120_gpio * @note peripherals used: USART @ref sensor_sdm120_usart , GPIO @ref sensor_sdm120_gpio
@ -33,13 +33,13 @@
#include "sensor_sdm120.h" // SDM120 electricity meter header and definitions #include "sensor_sdm120.h" // SDM120 electricity meter header and definitions
#include "global.h" // common methods #include "global.h" // common methods
/** @defgroup sensor_psdm120_usart USART peripheral used for communication with electricity meter /** @defgroup sensor_sdm120_usart USART peripheral used for communication with electricity meter
* @{ * @{
*/ */
#define SENSOR_SDM120_USART 3 /**< USART peripheral */ #define SENSOR_SDM120_USART 3 /**< USART peripheral */
/** @} */ /** @} */
/** @defgroup sensor_psdm120_gpio GPIO peripheral used for controlling RS-485 adapter /** @defgroup sensor_sdm120_gpio GPIO peripheral used for controlling RS-485 adapter
* @note driver output is enabled on high while receiver output is enabled on low, thus one pin can be used to control both * @note driver output is enabled on high while receiver output is enabled on low, thus one pin can be used to control both
* @{ * @{
*/ */
@ -87,7 +87,7 @@ static const uint16_t register_holding[] = {
/** compute CRC for ModBus /** compute CRC for ModBus
* @note ModBus uses ANSi/IBM 16-bits CRC (with normal polynomial 0x8005, reverse polynomial 0xA001, start value 0xfff) * @note ModBus uses ANSi/IBM 16-bits CRC (with normal polynomial 0x8005, reverse polynomial 0xA001, start value 0xfff)
* @param[in] buffer data on which to compute the CRC for * @param[in] buffer data on which to compute the CRC for
* @param[in] number of byte to compute the CRC for * @param[in] size number of byte to compute the CRC for
* @return computed CRC checksum * @return computed CRC checksum
*/ */
static uint16_t crc_modbus(uint8_t* buffer, uint8_t size) static uint16_t crc_modbus(uint8_t* buffer, uint8_t size)

View File

@ -57,19 +57,19 @@ enum sensor_sdm120_configuration_type_t {
/** setup peripherals to communicate with electricity meter */ /** setup peripherals to communicate with electricity meter */
void sensor_sdm120_setup(void); void sensor_sdm120_setup(void);
/** request measurement from electricity meter /** request measurement from electricity meter
* @param[in] mater_id electricity meter device ID * @param[in] meter_id electricity meter device ID
* @param[in] type measurement type to request * @param[in] type measurement type to request
* @return if transmission started * @return if transmission started
*/ */
bool sensor_sdm120_measurement_request(uint8_t meter_id, enum sensor_sdm120_measurement_type_t type); bool sensor_sdm120_measurement_request(uint8_t meter_id, enum sensor_sdm120_measurement_type_t type);
/** request configuration from electricity meter /** request configuration from electricity meter
* @param[in] mater_id electricity meter device ID * @param[in] meter_id electricity meter device ID
* @param[in] type configuration type to request * @param[in] type configuration type to request
* @return if transmission started * @return if transmission started
*/ */
bool sensor_sdm120_configuration_request(uint8_t meter_id, enum sensor_sdm120_configuration_type_t type); bool sensor_sdm120_configuration_request(uint8_t meter_id, enum sensor_sdm120_configuration_type_t type);
/** set configuration in electricity meter /** set configuration in electricity meter
* @param[in] mater_id electricity meter device ID * @param[in] meter_id electricity meter device ID
* @param[in] type configuration type to set * @param[in] type configuration type to set
* @param[in] value configuration value to set * @param[in] value configuration value to set
* @return if transmission started * @return if transmission started

3
main.c
View File

@ -46,6 +46,8 @@
#include "sensor_sdm120.h" // SDM120 electricity meter utilities #include "sensor_sdm120.h" // SDM120 electricity meter utilities
#include "radio_esp8266.h" // ESP8266 WiFi SoC utilities #include "radio_esp8266.h" // ESP8266 WiFi SoC utilities
#define WATCHDOG_PERIOD 10000 /**< watchdog period in ms */
/** @defgroup main_flags flag set in interrupts to be processed in main task /** @defgroup main_flags flag set in interrupts to be processed in main task
* @{ * @{
*/ */
@ -271,7 +273,6 @@ void main(void)
#if !(DEBUG) #if !(DEBUG)
//setup watchdog to reset in case we get stuck (i.e. when an error occurred) //setup watchdog to reset in case we get stuck (i.e. when an error occurred)
#define WATCHDOG_PERIOD 10000 /**< watchdog period in ms */
printf("setup watchdog (%.2fs): ",WATCHDOG_PERIOD/1000.0); printf("setup watchdog (%.2fs): ",WATCHDOG_PERIOD/1000.0);
iwdg_set_period_ms(WATCHDOG_PERIOD); // set independent watchdog period iwdg_set_period_ms(WATCHDOG_PERIOD); // set independent watchdog period
iwdg_start(); // start independent watchdog iwdg_start(); // start independent watchdog