2016-09-13 22:43:38 +02:00
|
|
|
/* 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
|
2016-09-14 16:39:31 +02:00
|
|
|
* @param[in] slave electricity meter slave device address
|
2016-09-13 22:43:38 +02:00
|
|
|
* @param[in] type measurement type to request
|
2016-09-14 16:39:31 +02:00
|
|
|
* @return if transmission started
|
2016-09-13 22:43:38 +02:00
|
|
|
*/
|
2016-09-14 16:39:31 +02:00
|
|
|
bool sensor_sdm120_measurement_request(uint8_t slave, enum sensor_sdm120_measurement_type_t type);
|
2016-09-13 22:43:38 +02:00
|
|
|
/** decode received measurement
|
|
|
|
* @return decoded measurement (NaN if invalid or no new measurement has been received)
|
|
|
|
*/
|
|
|
|
float sensor_sdm120_measurement_decode(void);
|