[avr + fluksod] add per-port enable/disable commands
This commit is contained in:
parent
112661303d
commit
78b1ec3be3
|
@ -40,6 +40,9 @@ extern struct version_struct version;
|
|||
extern struct event_struct EEMEM EEPROM_event;
|
||||
extern struct event_struct event;
|
||||
|
||||
extern uint8_t EEMEM EEPROM_enabled;
|
||||
extern uint8_t enabled;
|
||||
|
||||
extern uint8_t EEMEM EEPROM_phy_to_log[MAX_SENSORS];
|
||||
extern uint8_t phy_to_log[MAX_SENSORS];
|
||||
|
||||
|
@ -284,6 +287,12 @@ void ctrlCmdGet(uint8_t cmd)
|
|||
ctrlWriteCharToTxBuffer(version.sw_minor);
|
||||
break;
|
||||
|
||||
case 'e': /* port enabled | disabled */
|
||||
ctrlReadCharFromRxBuffer(&i);
|
||||
ctrlWriteCharToTxBuffer(i);
|
||||
ctrlWriteCharToTxBuffer((enabled >> i) & 0x01);
|
||||
break;
|
||||
|
||||
case 'p': /* phy-to-logical mapping */
|
||||
for (i = 0 ; i < MAX_SENSORS; i++) {
|
||||
ctrlWriteCharToTxBuffer(phy_to_log[i]);
|
||||
|
@ -358,6 +367,21 @@ void ctrlCmdSet(uint8_t cmd)
|
|||
ctrlWriteCharToTxBuffer(version.sw_minor);
|
||||
break;
|
||||
|
||||
case 'e': /* port enabled | disabled */
|
||||
ctrlReadCharFromRxBuffer(&i);
|
||||
ctrlReadCharFromRxBuffer(&tmp8);
|
||||
|
||||
if (tmp8) {
|
||||
enabled |= (1 << i);
|
||||
}
|
||||
else {
|
||||
enabled &= ~(1 << i);
|
||||
}
|
||||
|
||||
ctrlWriteCharToTxBuffer(i);
|
||||
ctrlWriteCharToTxBuffer((enabled >> i) & 0x01);
|
||||
break;
|
||||
|
||||
case 'p': /* phy-to-logical mapping */
|
||||
for (i = 0 ; i < MAX_SENSORS; i++) {
|
||||
ctrlReadCharFromRxBuffer(&tmp8);
|
||||
|
@ -421,6 +445,7 @@ void ctrlCmdCommit(void)
|
|||
cli();
|
||||
eeprom_write_block((const void*)&version, (void*)&EEPROM_version, sizeof(version));
|
||||
eeprom_write_block((const void*)&event, (void*)&EEPROM_event, sizeof(event));
|
||||
eeprom_write_block((const void*)&enabled, (void*)&EEPROM_enabled, sizeof(enabled));
|
||||
eeprom_write_block((const void*)&phy_to_log, (void*)&EEPROM_phy_to_log, sizeof(phy_to_log));
|
||||
eeprom_write_block((const void*)&sensor, (void*)&EEPROM_sensor, sizeof(sensor));
|
||||
sei();
|
||||
|
|
|
@ -40,5 +40,7 @@
|
|||
#define CYCLES_PER_US ((F_CPU+500000)/1000000) // cpu cycles per microsecond
|
||||
|
||||
#define MAX_SENSORS 6
|
||||
#define ENABLE_ALL_SENSORS ((1 << MAX_SENSORS) - 1)
|
||||
#define DISABLE_ALL_SENSORS 0x00
|
||||
|
||||
#endif
|
||||
|
|
|
@ -47,6 +47,9 @@ struct version_struct version;
|
|||
struct event_struct EEMEM EEPROM_event = {0, 0};
|
||||
struct event_struct event;
|
||||
|
||||
uint8_t EEMEM EEPROM_enabled = DISABLE_ALL_SENSORS;
|
||||
uint8_t enabled;
|
||||
|
||||
uint8_t EEMEM EEPROM_phy_to_log[MAX_SENSORS] = {0, 1, 2, 3, 4, 5};
|
||||
uint8_t phy_to_log[MAX_SENSORS];
|
||||
|
||||
|
@ -160,9 +163,10 @@ ISR(INT0_vect)
|
|||
{
|
||||
DBG_ISR_BEGIN();
|
||||
|
||||
uint8_t muxn_l = phy_to_log[3];
|
||||
uint8_t muxn_l = phy_to_log[PORT_PULSE_1];
|
||||
|
||||
register_pulse(&sensor[muxn_l], &state[muxn_l]);
|
||||
if (enabled & (1 << PORT_PULSE_1))
|
||||
register_pulse(&sensor[muxn_l], &state[muxn_l]);
|
||||
|
||||
DBG_ISR_END();
|
||||
}
|
||||
|
@ -171,9 +175,10 @@ ISR(INT1_vect)
|
|||
{
|
||||
DBG_ISR_BEGIN();
|
||||
|
||||
uint8_t muxn_l = phy_to_log[4];
|
||||
uint8_t muxn_l = phy_to_log[PORT_PULSE_2];
|
||||
|
||||
register_pulse(&sensor[muxn_l], &state[muxn_l]);
|
||||
if (enabled & (1 << PORT_PULSE_2))
|
||||
register_pulse(&sensor[muxn_l], &state[muxn_l]);
|
||||
|
||||
DBG_ISR_END();
|
||||
}
|
||||
|
@ -189,24 +194,26 @@ ISR(TIMER1_COMPA_vect)
|
|||
{
|
||||
DBG_ISR_BEGIN();
|
||||
|
||||
uint8_t muxn_l = phy_to_log[muxn];
|
||||
if (enabled & (1 << muxn)) {
|
||||
uint8_t muxn_l = phy_to_log[muxn];
|
||||
|
||||
MacU16X16to32(state[muxn_l].nano, sensor[muxn_l].meterconst, ADC);
|
||||
MacU16X16to32(state[muxn_l].nano, sensor[muxn_l].meterconst, ADC);
|
||||
|
||||
if (state[muxn_l].nano > WATT) {
|
||||
sensor[muxn_l].counter++;
|
||||
if (state[muxn_l].nano > WATT) {
|
||||
sensor[muxn_l].counter++;
|
||||
|
||||
state[muxn_l].flags |= STATE_PULSE;
|
||||
state[muxn_l].nano -= WATT;
|
||||
state[muxn_l].pulse_count++;
|
||||
}
|
||||
state[muxn_l].flags |= STATE_PULSE;
|
||||
state[muxn_l].nano -= WATT;
|
||||
state[muxn_l].pulse_count++;
|
||||
}
|
||||
|
||||
if ((timer == SECOND) && (muxn == muxn_l)) {
|
||||
state[muxn].nano_start = state[muxn].nano_end;
|
||||
state[muxn].nano_end = state[muxn].nano;
|
||||
state[muxn].pulse_count_final = state[muxn].pulse_count;
|
||||
state[muxn].pulse_count = 0;
|
||||
state[muxn].flags |= STATE_POWER_CALC;
|
||||
if ((timer == SECOND) && !(state[muxn_l].flags & STATE_POWER_CALC)) {
|
||||
state[muxn_l].nano_start = state[muxn_l].nano_end;
|
||||
state[muxn_l].nano_end = state[muxn_l].nano;
|
||||
state[muxn_l].pulse_count_final = state[muxn_l].pulse_count;
|
||||
state[muxn_l].pulse_count = 0;
|
||||
state[muxn_l].flags |= STATE_POWER_CALC;
|
||||
}
|
||||
}
|
||||
|
||||
/* Cycle through the available ADC input channels (0/1/2). */
|
||||
|
@ -253,6 +260,7 @@ void setup_datastructs(void)
|
|||
{
|
||||
eeprom_read_block((void*)&version, (const void*)&EEPROM_version, sizeof(version));
|
||||
eeprom_read_block((void*)&event, (const void*)&EEPROM_event, sizeof(event));
|
||||
eeprom_read_block((void*)&enabled, (const void*)&EEPROM_enabled, sizeof(enabled));
|
||||
eeprom_read_block((void*)&phy_to_log, (const void*)&EEPROM_phy_to_log, sizeof(phy_to_log));
|
||||
eeprom_read_block((void*)&sensor, (const void*)&EEPROM_sensor, sizeof(sensor));
|
||||
}
|
||||
|
|
|
@ -5,6 +5,9 @@ struct version_struct {
|
|||
uint8_t sw_minor;
|
||||
};
|
||||
|
||||
#define PORT_PULSE_1 3
|
||||
#define PORT_PULSE_2 4
|
||||
|
||||
#define SPI_NO_OP_1 0x01
|
||||
#define SPI_NO_OP_2 0x02
|
||||
#define SPI_START_TX 0x04
|
||||
|
|
|
@ -87,6 +87,9 @@ function encode(msg)
|
|||
if noarg_cmd[msg.parsed.cmd] then
|
||||
msg.encoded = msg.parsed.cmd
|
||||
|
||||
elseif msg.parsed.cmd == 'ge' and argcheck(1) then
|
||||
msg.encoded = msg.parsed.cmd .. numtohex(msg.parsed[1], 1)
|
||||
|
||||
elseif msg.parsed.cmd == 'gc' and argcheck(1) then
|
||||
msg.encoded = msg.parsed.cmd .. numtohex(msg.parsed[1], 1)
|
||||
|
||||
|
@ -101,6 +104,10 @@ function encode(msg)
|
|||
msg.encoded = msg.parsed.cmd .. numtohex(msg.parsed[1], 1)
|
||||
.. numtohex(msg.parsed[2], 1)
|
||||
|
||||
elseif msg.parsed.cmd == 'se' and argcheck(2) then
|
||||
msg.encoded = msg.parsed.cmd .. numtohex(msg.parsed[1], 1)
|
||||
.. numtohex(msg.parsed[2], 1)
|
||||
|
||||
elseif msg.parsed.cmd == 'sp' and argcheck(6) then
|
||||
msg.encoded = msg.parsed.cmd
|
||||
|
||||
|
@ -177,7 +184,7 @@ function decode(msg)
|
|||
msg.decoded.cmd = msg.received.l:sub(1, 2)
|
||||
msg.decoded.args = msg.received.l:sub(3, -1)
|
||||
|
||||
if msg.decoded.cmd == 'gd' then
|
||||
if msg.decoded.cmd == 'gd' and msg.decoded.args ~= '' then
|
||||
for i = 1, msg.decoded.args:len() / 18 do
|
||||
msg.decoded[(i-1)*3 + 1] =
|
||||
hextonum(msg.decoded.args:sub((i-1)*18 + 1, (i-1)*18 + 2))
|
||||
|
@ -201,6 +208,12 @@ function decode(msg)
|
|||
|
||||
msg.decoded.ctrl = msg.decoded.cmd .. ' ' .. table.concat(msg.decoded, ' ')
|
||||
|
||||
elseif msg.decoded.cmd == 'ge' or msg.decoded.cmd == 'se' then
|
||||
msg.decoded[1] = hextonum(msg.decoded.args:sub(1, 2))
|
||||
msg.decoded[2] = hextonum(msg.decoded.args:sub(3, 4))
|
||||
|
||||
msg.decoded.ctrl = msg.decoded.cmd .. ' ' .. table.concat(msg.decoded, ' ')
|
||||
|
||||
elseif msg.decoded.cmd == 'gp' or msg.decoded.cmd == 'sp' then
|
||||
for i = 1, MAX_SENSORS do
|
||||
msg.decoded[i] = hextonum(msg.decoded.args:sub(i*2 - 1, i*2))
|
||||
|
|
Loading…
Reference in New Issue