add SDM120 electricity meter library (only transmit works)

This commit is contained in:
King Kévin 2016-09-13 22:43:38 +02:00
parent 1e1cfb8c62
commit 9b047ccf41
1 changed files with 54 additions and 0 deletions

54
lib/sensor_sdm120.h Normal file
View File

@ -0,0 +1,54 @@
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/** library to query measurements from eastron SDM120-ModBus electricity meter (API)
* @file sensor_sdm120.h
* @author King Kévin <kingkevin@cuvoodoo.info>
* @date 2016
* @note peripherals used: USART @ref sensor_sdm120_usart , GPIO @ref sensor_sdm120_gpio
*/
#pragma once
/** a measurement response has been received */
extern volatile bool sensor_sdm120_measurement_received;
/** measurements offered by electricity meter */
enum sensor_sdm120_measurement_type_t {
SENSOR_SDM120_VOLTAGE = 0,
SENSOR_SDM120_CURRENT,
SENSOR_SDM120_POWER_ACTIVE,
SENSOR_SDM120_POWER_APPARENT,
SENSOR_SDM120_POWER_REACTIVE,
SENSOR_SDM120_POWER_FACTOR,
SENSOR_SDM120_FREQUENCY,
SENSOR_SDM120_ENERGY_ACTIVE_IMPORT,
SENSOR_SDM120_ENERGY_ACTIVE_EXPORT,
SENSOR_SDM120_ENERGY_REACTIVE_IMPORT,
SENSOR_SDM120_ENERGY_REACTIVE_EXPORT,
SENSOR_SDM120_ENERGY_ACTIVE_TOTAL,
SENSOR_SDM120_ENERGY_REACTIVE_TOTAL,
SENSOR_SDM120_MAX
};
/** setup peripherals to communicate with electricity meter */
void sensor_sdm120_setup(void);
/** request measurement from electricity meter
* @param[in] address electricity meter device address
* @param[in] type measurement type to request
*/
void sensor_sdm120_measurement_request(uint8_t address, enum sensor_sdm120_measurement_type_t type);
/** decode received measurement
* @return decoded measurement (NaN if invalid or no new measurement has been received)
*/
float sensor_sdm120_measurement_decode(void);