[avr + fsync] check against MAX_ANALOG_SENSOR
This commit is contained in:
parent
13fad26051
commit
23b47bd955
|
@ -339,7 +339,7 @@ void ctrlCmdGet(uint8_t cmd)
|
||||||
|
|
||||||
cli();
|
cli();
|
||||||
tmp32 = sensor[i].counter;
|
tmp32 = sensor[i].counter;
|
||||||
tmp32_bis = (i < 3) ? state[i].power : state[i].timestamp;
|
tmp32_bis = (i < MAX_ANALOG_SENSORS) ? state[i].power : state[i].timestamp;
|
||||||
state[i].flags &= ~(STATE_PULSE | STATE_POWER);
|
state[i].flags &= ~(STATE_PULSE | STATE_POWER);
|
||||||
sei();
|
sei();
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,8 @@
|
||||||
#define DISABLE_PORT 0xff
|
#define DISABLE_PORT 0xff
|
||||||
|
|
||||||
#define MAX_SENSORS 6
|
#define MAX_SENSORS 6
|
||||||
|
#define MAX_ANALOG_SENSORS 3
|
||||||
|
|
||||||
#define ENABLE_ALL_SENSORS ((1 << MAX_SENSORS) - 1)
|
#define ENABLE_ALL_SENSORS ((1 << MAX_SENSORS) - 1)
|
||||||
#define DISABLE_ALL_SENSORS 0x00
|
#define DISABLE_ALL_SENSORS 0x00
|
||||||
|
|
||||||
|
|
|
@ -394,7 +394,7 @@ int main(void)
|
||||||
spi_status &= ~SPI_NEW_CTRL_MSG;
|
spi_status &= ~SPI_NEW_CTRL_MSG;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < MAX_SENSORS; i++) {
|
for (i = 0; i < MAX_ANALOG_SENSORS; i++) {
|
||||||
if (state[i].flags & STATE_POWER_CALC) {
|
if (state[i].flags & STATE_POWER_CALC) {
|
||||||
calculate_power(&state[i]);
|
calculate_power(&state[i]);
|
||||||
state[i].flags &= ~STATE_POWER_CALC;
|
state[i].flags &= ~STATE_POWER_CALC;
|
||||||
|
|
|
@ -4,6 +4,7 @@ config settings main
|
||||||
option sw_major 1
|
option sw_major 1
|
||||||
option sw_minor 0
|
option sw_minor 0
|
||||||
option max_sensors 6
|
option max_sensors 6
|
||||||
|
option max_analog_sensors 3
|
||||||
option reset_counters 0
|
option reset_counters 0
|
||||||
|
|
||||||
### sensor config options
|
### sensor config options
|
||||||
|
|
|
@ -101,15 +101,16 @@ local flukso = uci:get_all('flukso')
|
||||||
|
|
||||||
local HW_CHECK_OVERRIDE = (arg[1] == '-f')
|
local HW_CHECK_OVERRIDE = (arg[1] == '-f')
|
||||||
|
|
||||||
local MAX_SENSORS = tonumber(flukso.main.max_sensors)
|
local MAX_SENSORS = tonumber(flukso.main.max_sensors)
|
||||||
local METERCONST_FACTOR = 0.449
|
local MAX_ANALOG_SENSORS = tonumber(flukso.main.max_analog_sensors)
|
||||||
|
local METERCONST_FACTOR = 0.449
|
||||||
|
|
||||||
local GET_HW_VERSION = 'gh'
|
local GET_HW_VERSION = 'gh'
|
||||||
local GET_HW_VERSION_R = '^gh%s+(%d+)%s+(%d+)$'
|
local GET_HW_VERSION_R = '^gh%s+(%d+)%s+(%d+)$'
|
||||||
local SET_ENABLE = 'se %d %d'
|
local SET_ENABLE = 'se %d %d'
|
||||||
local SET_PHY_TO_LOG = 'sp' -- with [1..MAX_SENSORS] arguments
|
local SET_PHY_TO_LOG = 'sp' -- with [1..MAX_SENSORS] arguments
|
||||||
local SET_METERCONST = 'sm %d %d'
|
local SET_METERCONST = 'sm %d %d'
|
||||||
local SET_COUNTER = 'sc %d %d'
|
local SET_COUNTER = 'sc %d %d'
|
||||||
|
|
||||||
-- check hardware version
|
-- check hardware version
|
||||||
local hw_major, hw_minor = send(ctrl, GET_HW_VERSION):match(GET_HW_VERSION_R)
|
local hw_major, hw_minor = send(ctrl, GET_HW_VERSION):match(GET_HW_VERSION_R)
|
||||||
|
@ -145,14 +146,20 @@ local phy_to_log = {}
|
||||||
|
|
||||||
for i = 1, MAX_SENSORS do
|
for i = 1, MAX_SENSORS do
|
||||||
if flukso[tostring(i)] ~= nil then
|
if flukso[tostring(i)] ~= nil then
|
||||||
|
if flukso[tostring(i)]['type'] == 'analog' and i > MAX_ANALOG_SENSORS then
|
||||||
|
print(string.format('Error. Analog sensor %s should be less than or equal to max_analog_sensors (%s)', i, MAX_ANALOG_SENSORS))
|
||||||
|
os.exit(4)
|
||||||
|
end
|
||||||
|
|
||||||
local ports = flukso[tostring(i)].port or {}
|
local ports = flukso[tostring(i)].port or {}
|
||||||
|
|
||||||
for j = 1, #ports do
|
for j = 1, #ports do
|
||||||
if tonumber(ports[j]) <= MAX_SENSORS then
|
if tonumber(ports[j]) > MAX_SENSORS then
|
||||||
phy_to_log[toc(tonumber(ports[j]))] = toc(i)
|
|
||||||
else
|
|
||||||
print(string.format('Error. Port numbering in sensor %s should be less than or equal to max_sensors (%s)', i, MAX_SENSORS))
|
print(string.format('Error. Port numbering in sensor %s should be less than or equal to max_sensors (%s)', i, MAX_SENSORS))
|
||||||
os.exit(4)
|
os.exit(5)
|
||||||
|
|
||||||
|
else
|
||||||
|
phy_to_log[toc(tonumber(ports[j]))] = toc(i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue