DataObjects moved into own .cpp file
Some restructuring was done by moving the static const array DataObjects[] out of the header file. This makes sure to have only a single instance of it in the resulting binary leading to less memory usage. Before that we had a individual DataObject[] in each compilation unit data_objects.h was included in. For const data this is in most cases not much of a deal beyond wasting memory, but for non-const static objects potentially a source of confusion during programming since changing the value in one cpp file would not change it in other places.
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
/* LibreSolar Battery Management System firmware
|
||||
* Copyright (c) 2016-2018 Martin Jäger (www.libre.solar)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "mbed.h"
|
||||
#include "config.h"
|
||||
|
||||
#include "data_objects.h"
|
||||
|
||||
|
||||
static uint16_t oid;
|
||||
|
||||
const DataObject_t dataObjects[] {
|
||||
// output data
|
||||
{oid=0x4001, ACCESS_READ, TS_C_OUTPUT, T_FLOAT32, 0, (void*) &(device.bus_voltage), "vBat"},
|
||||
{++oid, ACCESS_READ, TS_C_OUTPUT, T_FLOAT32, 0, (void*) &(device.input_voltage), "vSolar"},
|
||||
{++oid, ACCESS_READ, TS_C_OUTPUT, T_FLOAT32, 0, (void*) &(device.bus_current), "iBat"},
|
||||
{++oid, ACCESS_READ, TS_C_OUTPUT, T_FLOAT32, 0, (void*) &(device.load_current), "iLoad"},
|
||||
{++oid, ACCESS_READ, TS_C_OUTPUT, T_FLOAT32, 0, (void*) &(device.external_temperature), "tempExt"},
|
||||
{++oid, ACCESS_READ, TS_C_OUTPUT, T_FLOAT32, 0, (void*) &(device.internal_temperature), "tempInt"},
|
||||
{++oid, ACCESS_READ, TS_C_OUTPUT, T_BOOL, 0, (void*) &(device.load_enabled), "loaEn"},
|
||||
{++oid, ACCESS_READ, TS_C_OUTPUT, T_FLOAT32, 0, (void*) &(device.input_Wh_day), "eInputDay_Wh"},
|
||||
{++oid, ACCESS_READ, TS_C_OUTPUT, T_FLOAT32, 0, (void*) &(device.output_Wh_day), "eOutputDay_Wh"},
|
||||
{++oid, ACCESS_READ, TS_C_OUTPUT, T_FLOAT32, 0, (void*) &(device.input_Wh_total), "eInputTotal_Wh"},
|
||||
{++oid, ACCESS_READ, TS_C_OUTPUT, T_FLOAT32, 0, (void*) &(device.output_Wh_total), "eOutputTotal_Wh"},
|
||||
|
||||
// calibration data
|
||||
{oid=0x6001, ACCESS_READ | ACCESS_WRITE, TS_C_CAL, T_FLOAT32, 0, (void*) &(cal.dcdc_current_min), "iDcdcMin"},
|
||||
{++oid, ACCESS_READ | ACCESS_WRITE, TS_C_CAL, T_FLOAT32, 0, (void*) &(cal.solar_voltage_max), "vSolarMax"},
|
||||
{++oid, ACCESS_READ | ACCESS_WRITE, TS_C_CAL, T_INT32, 0, (void*) &(cal.dcdc_restart_interval), "tDcdcRestart"},
|
||||
{++oid, ACCESS_READ | ACCESS_WRITE, TS_C_CAL, T_FLOAT32, 0, (void*) &(cal.solar_voltage_offset_start), "vSolarOffsetStart"},
|
||||
{++oid, ACCESS_READ | ACCESS_WRITE, TS_C_CAL, T_FLOAT32, 0, (void*) &(cal.solar_voltage_offset_stop), "vSolarOffsetStop"},
|
||||
{++oid, ACCESS_READ | ACCESS_WRITE, TS_C_CAL, T_INT32, 0, (void*) &(cal.thermistor_beta_value), "thermistorBetaValue"}
|
||||
};
|
||||
|
||||
const size_t dataObjectsCount = sizeof(dataObjects)/sizeof(DataObject_t);
|
||||
|
||||
Reference in New Issue
Block a user