Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • leger/avrcte
  • leger/avrcwa
2 results
Show changes
Commits on Source (18)
...@@ -5,3 +5,5 @@ __pycache__/ ...@@ -5,3 +5,5 @@ __pycache__/
*.hex *.hex
*.elf *.elf
commitid.h commitid.h
id.h
ID
...@@ -16,19 +16,22 @@ COMPILE = avr-gcc -Wall -Os -mmcu=$(DEVICE) ...@@ -16,19 +16,22 @@ COMPILE = avr-gcc -Wall -Os -mmcu=$(DEVICE)
.PHONY: clean all .PHONY: clean all
.INTERMEDIATE: commitid.h main.o .INTERMEDIATE: commitid.h id.h message.o main.o
# symbolic targets: # symbolic targets:
all: main.hex all: main.hex
clean: clean:
rm -f *.o *.elf *.hex commitid.h rm -f *.o *.elf *.hex commitid.h id.h
commitid.h: .git/refs/heads commitid.h: .git/refs/heads
cog -r *.c *.h cog -r *.c *.h
./define_commit_id.py > $@ ./define_commit_id.py > $@
%.o: %.c common.h commitid.h id.h: ID
./define_id.py > $@
%.o: %.c common.h commitid.h id.h
$(COMPILE) -c $< -o $@ $(COMPILE) -c $< -o $@
.S.o: .S.o:
......
Subproject commit f28703826cd780709e6e1d4ebf47c77827b86fe8 Subproject commit 1bbb9871f4a1f20de73f9e90b63757595e530c4a
...@@ -21,8 +21,8 @@ cog.out( ...@@ -21,8 +21,8 @@ cog.out(
#define BUS_port PORTC #define BUS_port PORTC
#define BUS_txpin PIN3_bm #define BUS_txpin PIN3_bm
#define BUS_rxlen 256 #define BUS_rxlen 384
#define BUS_txlen 256 #define BUS_txlen 384
#define BUS_baudrate 1200 #define BUS_baudrate 1200
#define BUS_chsize 8 #define BUS_chsize 8
#define BUS_rxtrigger '\n' #define BUS_rxtrigger '\n'
......
...@@ -36,8 +36,8 @@ BUS = { ...@@ -36,8 +36,8 @@ BUS = {
"rx": True, "rx": True,
"de_pindesc": PinDesc("C0"), "de_pindesc": PinDesc("C0"),
"rxhandler": "bus_msg_handler", "rxhandler": "bus_msg_handler",
"txlen": 256, "txlen": 384,
"rxlen": 256, "rxlen": 384,
"baudrate": 1200, "baudrate": 1200,
"rxtriggerbegin": ("S", "M"), "rxtriggerbegin": ("S", "M"),
} }
...@@ -45,6 +45,8 @@ BUS = { ...@@ -45,6 +45,8 @@ BUS = {
THERMO_PERIOD = 5 THERMO_PERIOD = 5
THERMO_MEDIAN_FILTER_LEN = 13 THERMO_MEDIAN_FILTER_LEN = 13
THERMO_FACTOR_FILTRE = 1 - math.exp(-5 / 60) THERMO_FACTOR_FILTRE = 1 - math.exp(-5 / 60)
THERMO_FAIL_NUMBER = 180
BID_WATER = 0xc0
ACTION_TIMER_MAIN = "TCC0" ACTION_TIMER_MAIN = "TCC0"
......
...@@ -5,7 +5,6 @@ cconfig_t cconfig; ...@@ -5,7 +5,6 @@ cconfig_t cconfig;
void config_write() void config_write()
{ {
return;
uint16_t k; uint16_t k;
for(k=0;k<sizeof(config_t);k++) for(k=0;k<sizeof(config_t);k++)
eeprom_write_byte(EEPROM_ADDR_CONFIG+k, *(((uint8_t*)&config)+k)); eeprom_write_byte(EEPROM_ADDR_CONFIG+k, *(((uint8_t*)&config)+k));
...@@ -13,7 +12,6 @@ void config_write() ...@@ -13,7 +12,6 @@ void config_write()
void config_read() void config_read()
{ {
return;
uint16_t k; uint16_t k;
for(k=0;k<sizeof(config_t);k++) for(k=0;k<sizeof(config_t);k++)
*(((uint8_t*)&config)+k) = eeprom_read_byte(EEPROM_ADDR_CONFIG+k); *(((uint8_t*)&config)+k) = eeprom_read_byte(EEPROM_ADDR_CONFIG+k);
...@@ -47,11 +45,18 @@ void cconfig_update(config_t * c, cconfig_t * cc) ...@@ -47,11 +45,18 @@ void cconfig_update(config_t * c, cconfig_t * cc)
cc->volume_manque_max = 0.01 * c->volume_manque_max; cc->volume_manque_max = 0.01 * c->volume_manque_max;
cc->m_rattrapage = c->m_rattrapage; cc->m_rattrapage = c->m_rattrapage;
cc->consigne_debit = 0.01 * c->consigne_debit; cc->consigne_debit = 0.01 * c->consigne_debit;
cc->post_refroi_T1 = 0.01 * c->post_refroi_T1;
cc->post_refroi_T2 = 0.01 * c->post_refroi_T2;
cc->post_refroi_cold_water_T1 = 0.01 * c->post_refroi_cold_water_T1;
cc->post_refroi_cold_water_T2 = 0.01 * c->post_refroi_cold_water_T2;
cc->post_refroi_hot_water_T1 = 0.01 * c->post_refroi_hot_water_T1;
cc->post_refroi_hot_water_T2 = 0.01 * c->post_refroi_hot_water_T2;
cc->post_refroi_dmax = (0.01 * c->post_refroi_dmax * c->vol_cuve)/300;
} }
uint8_t config_valid(cconfig_t * cc) uint8_t config_valid(cconfig_t * cc)
{ {
if(cc->mode<1 || cc->mode>5) if(cc->mode<1 || cc->mode>6)
return 0; return 0;
if(cc->Kp<1 || cc->Kp>100) if(cc->Kp<1 || cc->Kp>100)
return 0; return 0;
...@@ -79,6 +84,14 @@ uint8_t config_valid(cconfig_t * cc) ...@@ -79,6 +84,14 @@ uint8_t config_valid(cconfig_t * cc)
return 0; return 0;
if(cc->consigne_debit<0 || cc->consigne_debit>50) if(cc->consigne_debit<0 || cc->consigne_debit>50)
return 0; return 0;
if(cc->post_refroi_T1 < 7 || cc->post_refroi_T2 > 40 || cc->post_refroi_T2-cc->post_refroi_T1<1)
return 0;
if(cc->post_refroi_cold_water_T1 < 1 || cc->post_refroi_cold_water_T2 > 40 || cc->post_refroi_cold_water_T2-cc->post_refroi_cold_water_T1<1)
return 0;
if(cc->post_refroi_hot_water_T1 < 1 || cc->post_refroi_hot_water_T2 > 40 || cc->post_refroi_hot_water_T2-cc->post_refroi_hot_water_T1<1)
return 0;
if(cc->post_refroi_dmax < 0 || cc->post_refroi_dmax>40)
return 0;
return 1; return 1;
} }
...@@ -88,7 +101,7 @@ void config_default(config_t* c) ...@@ -88,7 +101,7 @@ void config_default(config_t* c)
c->vol_cuve = 300; c->vol_cuve = 300;
c->Kp = 32*100; c->Kp = 32*100;
c->ti = 3600; c->ti = 3600;
c->consigne_temperature = 2350; c->consigne_temperature = 2395;
c->debit_max = 1500; c->debit_max = 1500;
c->cst_ev = 10; c->cst_ev = 10;
c->debit_min1 = 200; c->debit_min1 = 200;
...@@ -97,6 +110,13 @@ void config_default(config_t* c) ...@@ -97,6 +110,13 @@ void config_default(config_t* c)
c->volume_manque_max = 7500; c->volume_manque_max = 7500;
c->m_rattrapage = 15; c->m_rattrapage = 15;
c->consigne_debit = 0; c->consigne_debit = 0;
c->post_refroi_T1 = 1200;
c->post_refroi_T2 = 1400;
c->post_refroi_cold_water_T1 = 750;
c->post_refroi_cold_water_T2 = 1050;
c->post_refroi_hot_water_T1 = 1050;
c->post_refroi_hot_water_T2 = 1350;
c->post_refroi_dmax = 1000;
} }
void config_apply_new_config(config_t * pnew_config) void config_apply_new_config(config_t * pnew_config)
...@@ -150,4 +170,10 @@ void config_mode_change() ...@@ -150,4 +170,10 @@ void config_mode_change()
status.volume_manque = 0; status.volume_manque = 0;
status.accu_integrateur = 0; status.accu_integrateur = 0;
} }
else if(config.mode == MODE_POST_REFROI)
{
orders.close_ev = 1;
status.volume_manque = 0;
status.consigne_debit = 0;
}
} }
...@@ -20,6 +20,7 @@ typedef enum mode_enum ...@@ -20,6 +20,7 @@ typedef enum mode_enum
MODE_FORCE_VIDANGE = 0x03, MODE_FORCE_VIDANGE = 0x03,
MODE_DEBIT = 0x04, MODE_DEBIT = 0x04,
MODE_AUTO = 0x05, MODE_AUTO = 0x05,
MODE_POST_REFROI = 0x06,
} mode_t; } mode_t;
typedef struct config_struct typedef struct config_struct
...@@ -37,6 +38,13 @@ typedef struct config_struct ...@@ -37,6 +38,13 @@ typedef struct config_struct
uint16_t volume_manque_max; uint16_t volume_manque_max;
uint8_t m_rattrapage; uint8_t m_rattrapage;
uint16_t consigne_debit; uint16_t consigne_debit;
int16_t post_refroi_T1;
int16_t post_refroi_T2;
int16_t post_refroi_cold_water_T1;
int16_t post_refroi_cold_water_T2;
int16_t post_refroi_hot_water_T1;
int16_t post_refroi_hot_water_T2;
uint16_t post_refroi_dmax;
} config_t; } config_t;
typedef struct cconfig_struct typedef struct cconfig_struct
...@@ -54,6 +62,13 @@ typedef struct cconfig_struct ...@@ -54,6 +62,13 @@ typedef struct cconfig_struct
float volume_manque_max; float volume_manque_max;
float m_rattrapage; float m_rattrapage;
float consigne_debit; float consigne_debit;
float post_refroi_T1;
float post_refroi_T2;
float post_refroi_cold_water_T1;
float post_refroi_cold_water_T2;
float post_refroi_hot_water_T1;
float post_refroi_hot_water_T2;
float post_refroi_dmax;
} cconfig_t; } cconfig_t;
void config_read(); void config_read();
......
...@@ -46,11 +46,31 @@ void debit_update() ...@@ -46,11 +46,31 @@ void debit_update()
status.consigne_adj = status.consigne_debit + status.volume_manque/cconfig.m_rattrapage; status.consigne_adj = status.consigne_debit + status.volume_manque/cconfig.m_rattrapage;
if(status.consigne_adj<0) if(status.consigne_adj<0)
status.consigne_adj = 0; status.consigne_adj = 0;
if(vanne_internal_status == EV_CLOSED)
{
if(count==0)
{
status.consecutive_closed_debit = 0;
}
else
{
if(status.consecutive_closed_debit == 5)
{
orders.force_close_ev = 1;
status.consecutive_closed_debit = 0;
}
else
status.consecutive_closed_debit++;
}
}
else
status.consecutive_closed_debit = 0;
} }
void debit_vanne_update() void debit_vanne_update()
{ {
if(cconfig.mode == MODE_AUTO || cconfig.mode == MODE_DEBIT) if(cconfig.mode == MODE_AUTO || cconfig.mode == MODE_DEBIT || cconfig.mode == MODE_POST_REFROI)
{ {
if( (status.consigne_adj>cconfig.debit_min2) || if( (status.consigne_adj>cconfig.debit_min2) ||
((status.consigne_adj>cconfig.debit_min1) && (vanne_internal_status != EV_CLOSED))) ((status.consigne_adj>cconfig.debit_min1) && (vanne_internal_status != EV_CLOSED)))
......
#!/usr/bin/python3
import re
with open("ID") as f:
content = f.read().strip()
a = re.match("^0x([0-9a-fA-F]{2})$", content)
if not a:
raise SyntaxError
(hbid,) = a.groups()
bid = int(hbid, 16)
hbid = f"{bid:02x}"
print(f"#define BID 0x{hbid}")
print(f"#define BID_C0 '{hbid[0]}'")
print(f"#define BID_C1 '{hbid[1]}'")
/*[[[cog
bid = 0x01
hbid = f"{bid:02x}"
cog.out(f"#define BID 0x{hbid}\n")
cog.out(f"#define BID_C0 '{hbid[0]}'\n")
cog.out(f"#define BID_C1 '{hbid[1]}'\n")
]]]*/
#define BID 0x01
#define BID_C0 '0'
#define BID_C1 '1'
///[[[end]]]
...@@ -49,6 +49,18 @@ uint8_t get_packet(char * z, uint8_t pid) ...@@ -49,6 +49,18 @@ uint8_t get_packet(char * z, uint8_t pid)
uint16_to_4char((uint16_t)(status.accu_integrateur * 1000 + .5), z+2); uint16_to_4char((uint16_t)(status.accu_integrateur * 1000 + .5), z+2);
return 6; return 6;
} }
if(pid == 0x0a)
{
int16_t icwtemp = (status.temperature_cold_water * 100 + .5);
uint16_to_4char((uint16_t)icwtemp, z+2);
return 6;
}
if(pid == 0x0b)
{
int16_t ichtemp = (status.temperature_hot_water * 100 + .5);
uint16_to_4char((uint16_t)ichtemp, z+2);
return 6;
}
if(pid == 0x80) if(pid == 0x80)
{ {
...@@ -115,6 +127,41 @@ uint8_t get_packet(char * z, uint8_t pid) ...@@ -115,6 +127,41 @@ uint8_t get_packet(char * z, uint8_t pid)
uint16_to_4char(config.debit_min2, z+2); uint16_to_4char(config.debit_min2, z+2);
return 6; return 6;
} }
if(pid == 0x8e)
{
uint16_to_4char(config.post_refroi_T1, z+2);
return 6;
}
if(pid == 0x8f)
{
uint16_to_4char(config.post_refroi_T2, z+2);
return 6;
}
if(pid == 0x90)
{
uint16_to_4char(config.post_refroi_cold_water_T1, z+2);
return 6;
}
if(pid == 0x91)
{
uint16_to_4char(config.post_refroi_cold_water_T2, z+2);
return 6;
}
if(pid == 0x92)
{
uint16_to_4char(config.post_refroi_hot_water_T1, z+2);
return 6;
}
if(pid == 0x93)
{
uint16_to_4char(config.post_refroi_hot_water_T2, z+2);
return 6;
}
if(pid == 0x94)
{
uint16_to_4char(config.post_refroi_dmax, z+2);
return 6;
}
if(pid == 0xb1) if(pid == 0xb1)
{ {
uint8_to_2char(COMMITID_MAJOR, z+2); uint8_to_2char(COMMITID_MAJOR, z+2);
...@@ -129,7 +176,7 @@ uint8_t get_packet(char * z, uint8_t pid) ...@@ -129,7 +176,7 @@ uint8_t get_packet(char * z, uint8_t pid)
void message_send() void message_send()
{ {
char msg[256]; char msg[384];
msg[0] = 'S'; msg[0] = 'S';
msg[1] = ','; msg[1] = ',';
uint8_to_2char(BID, msg+2); uint8_to_2char(BID, msg+2);
...@@ -153,9 +200,10 @@ void message_send() ...@@ -153,9 +200,10 @@ void message_send()
lines.format(packet_id=pid) lines.format(packet_id=pid)
for pid in ( for pid in (
"0x01", "0x02", "0x03", "0x04", "0x05", "0x06", "0x07", "0x08", "0x01", "0x02", "0x03", "0x04", "0x05", "0x06", "0x07", "0x08",
"0x09", "0x09", "0x0a", "0x0b",
"0x80", "0x81", "0x82", "0x83", "0x84", "0x85", "0x86", "0x80", "0x81", "0x82", "0x83", "0x84", "0x85", "0x86",
"0x88", "0x89", "0x8a", "0x8b", "0x8c", "0x8d", "0x88", "0x89", "0x8a", "0x8b", "0x8c", "0x8d", "0x8e",
"0x8f", "0x90", "0x91", "0x92", "0x93", "0x94",
"0xb1") "0xb1")
) )
cog.out(out) cog.out(out)
...@@ -203,6 +251,16 @@ void message_send() ...@@ -203,6 +251,16 @@ void message_send()
packet_len = get_packet(msg+msg_len, 0x09); packet_len = get_packet(msg+msg_len, 0x09);
msg_len += packet_len; msg_len += packet_len;
msg[msg_len] = ',';
msg_len++;
packet_len = get_packet(msg+msg_len, 0x0a);
msg_len += packet_len;
msg[msg_len] = ',';
msg_len++;
packet_len = get_packet(msg+msg_len, 0x0b);
msg_len += packet_len;
msg[msg_len] = ','; msg[msg_len] = ',';
msg_len++; msg_len++;
packet_len = get_packet(msg+msg_len, 0x80); packet_len = get_packet(msg+msg_len, 0x80);
...@@ -268,6 +326,41 @@ void message_send() ...@@ -268,6 +326,41 @@ void message_send()
packet_len = get_packet(msg+msg_len, 0x8d); packet_len = get_packet(msg+msg_len, 0x8d);
msg_len += packet_len; msg_len += packet_len;
msg[msg_len] = ',';
msg_len++;
packet_len = get_packet(msg+msg_len, 0x8e);
msg_len += packet_len;
msg[msg_len] = ',';
msg_len++;
packet_len = get_packet(msg+msg_len, 0x8f);
msg_len += packet_len;
msg[msg_len] = ',';
msg_len++;
packet_len = get_packet(msg+msg_len, 0x90);
msg_len += packet_len;
msg[msg_len] = ',';
msg_len++;
packet_len = get_packet(msg+msg_len, 0x91);
msg_len += packet_len;
msg[msg_len] = ',';
msg_len++;
packet_len = get_packet(msg+msg_len, 0x92);
msg_len += packet_len;
msg[msg_len] = ',';
msg_len++;
packet_len = get_packet(msg+msg_len, 0x93);
msg_len += packet_len;
msg[msg_len] = ',';
msg_len++;
packet_len = get_packet(msg+msg_len, 0x94);
msg_len += packet_len;
msg[msg_len] = ','; msg[msg_len] = ',';
msg_len++; msg_len++;
packet_len = get_packet(msg+msg_len, 0xb1); packet_len = get_packet(msg+msg_len, 0xb1);
...@@ -295,10 +388,22 @@ void message_send() ...@@ -295,10 +388,22 @@ void message_send()
void message_get(const char* msg) void message_get(const char* msg)
{ {
if(msg[0] != 'M' || msg[1] != ',') uint8_t message_from_master = 0;
return; // je n'écoute que le master if(msg[1] != ',')
if(msg[2] != BID_C0 || msg[3] != BID_C1) return;
return; // ce n'est pas à moi qu'on parle if(msg[0] != 'M')
{
//ce n'est pas master qui parle
if(msg[0] != 'S' || msg[2] != BID_WATER_C0 || msg[3] != BID_WATER_C1)
return; // ce n'est pas WATER qui parle, et à part lui, je n'écoute
// que le master
}
else
{
message_from_master = 1;
if(msg[2] != BID_C0 || msg[3] != BID_C1)
return; // ce n'est pas à moi que master parle
}
if(msg[4] != ',' && msg[4] != ':') if(msg[4] != ',' && msg[4] != ':')
return; //message mal formaté return; //message mal formaté
uint16_t crc = 0xFFFF; uint16_t crc = 0xFFFF;
...@@ -319,34 +424,73 @@ void message_get(const char* msg) ...@@ -319,34 +424,73 @@ void message_get(const char* msg)
uint16_to_4char(crc, zcrc); uint16_to_4char(crc, zcrc);
if(zcrc[0] != msg[msg_len] || zcrc[1] != msg[msg_len+1] || zcrc[2] != msg[msg_len+2] || zcrc[3] != msg[msg_len+3]) if(zcrc[0] != msg[msg_len] || zcrc[1] != msg[msg_len+1] || zcrc[2] != msg[msg_len+2] || zcrc[3] != msg[msg_len+3])
return; // invalid message return; // invalid message
if(msg_len>5)
if(message_from_master)
{ {
config_t new_config; if(msg_len>5)
memcpy(&new_config, &config, sizeof(config_t));
uint8_t pos = 5;
while(pos<msg_len)
{ {
for(k=0; pos+k<msg_len; k++) config_t new_config;
if(msg[pos+k] == ',' || msg[pos+k] == ':') memcpy(&new_config, &config, sizeof(config_t));
uint8_t pos = 5;
while(pos<msg_len)
{
for(k=0; pos+k<msg_len; k++)
if(msg[pos+k] == ',' || msg[pos+k] == ':')
break;
readed_packet(msg+pos, k, &new_config);
pos += k+1;
if(msg[pos-1] == ':')
break; break;
readed_packet(msg+pos, k, &new_config); }
pos += k+1; if(memcmp(&new_config, &config, sizeof(config_t)))
if(msg[pos-1] == ':') {
break; cconfig_t new_cconfig;
cconfig_update(&new_config, &new_cconfig);
if(config_valid(&new_cconfig))
config_apply_new_config(&new_config);
}
} }
if(memcmp(&new_config, &config, sizeof(config_t)))
// we can reply
message_send();
}
else
{
if(msg_len>5)
{ {
cconfig_t new_cconfig; uint8_t pos = 5;
cconfig_update(&new_config, &new_cconfig); while(pos<msg_len)
if(config_valid(&new_cconfig)) {
config_apply_new_config(&new_config); for(k=0; pos+k<msg_len; k++)
if(msg[pos+k] == ',' || msg[pos+k] == ':')
break;
update_temp_readed_status_packet(msg+pos, k);
pos += k+1;
}
} }
} }
}
// we can reply void update_temp_readed_status_packet(const char *z, uint8_t len)
message_send(); {
if(len<2)
return;
uint8_t pid = uint8_from_2char(z);
if(pid == 0x0a)
{
if(len!=6)
return;
status.temperature_cold_water = 0.01*uint16_from_4char(z+2);
}
if(pid == 0x0b)
{
if(len!=6)
return;
status.temperature_hot_water = 0.01*uint16_from_4char(z+2);
}
} }
void readed_packet(const char * z, uint8_t len, config_t * nc) void readed_packet(const char * z, uint8_t len, config_t * nc)
{ {
if(len<2) if(len<2)
...@@ -443,4 +587,53 @@ void readed_packet(const char * z, uint8_t len, config_t * nc) ...@@ -443,4 +587,53 @@ void readed_packet(const char * z, uint8_t len, config_t * nc)
nc->debit_min2 = uint16_from_4char(z+2); nc->debit_min2 = uint16_from_4char(z+2);
return; return;
} }
if(pid == 0x8e)
{
if(len!=6)
return;
nc->post_refroi_T1 = uint16_from_4char(z+2);
return;
}
if(pid == 0x8f)
{
if(len!=6)
return;
nc->post_refroi_T2 = uint16_from_4char(z+2);
return;
}
if(pid == 0x90)
{
if(len!=6)
return;
nc->post_refroi_cold_water_T1 = uint16_from_4char(z+2);
return;
}
if(pid == 0x91)
{
if(len!=6)
return;
nc->post_refroi_cold_water_T2 = uint16_from_4char(z+2);
return;
}
if(pid == 0x92)
{
if(len!=6)
return;
nc->post_refroi_hot_water_T1 = uint16_from_4char(z+2);
return;
}
if(pid == 0x93)
{
if(len!=6)
return;
nc->post_refroi_hot_water_T2 = uint16_from_4char(z+2);
return;
}
if(pid == 0x94)
{
if(len!=6)
return;
nc->post_refroi_dmax = uint16_from_4char(z+2);
return;
}
} }
...@@ -9,6 +9,16 @@ uint8_t get_packet(char * z, uint8_t pid); ...@@ -9,6 +9,16 @@ uint8_t get_packet(char * z, uint8_t pid);
void message_send(); void message_send();
void message_get(const char* msg); void message_get(const char* msg);
void readed_packet(const char * z, uint8_t len, config_t * nc); void readed_packet(const char * z, uint8_t len, config_t * nc);
void update_temp_readed_status_packet(const char *z, uint8_t len);
/*[[[cog
import conf
hbid_water = f"{conf.BID_WATER:02x}"
cog.out(f"#define BID_WATER_C0 '{hbid_water[0]}'\n")
cog.out(f"#define BID_WATER_C1 '{hbid_water[1]}'\n")
]]] */
#define BID_WATER_C0 'c'
#define BID_WATER_C1 '0'
//[[[end]]]
#endif #endif
...@@ -6,28 +6,40 @@ void do_orders() ...@@ -6,28 +6,40 @@ void do_orders()
{ {
if(orders.open_ev_step) if(orders.open_ev_step)
{ {
vanne_step_open(orders.open_ev_step_value); vanne_step_open(orders.open_ev_step_value,1);
orders.open_ev_step = 0; orders.open_ev_step = 0;
status.force_closed = 0;
} }
if(orders.close_ev_step) if(orders.close_ev_step)
{ {
vanne_step_close(orders.close_ev_step_value); vanne_step_close(orders.close_ev_step_value,1);
orders.close_ev_step = 0; orders.close_ev_step = 0;
} }
if(orders.open_ev) if(orders.open_ev)
{ {
vanne_open(); vanne_open();
orders.open_ev=0; orders.open_ev=0;
status.force_closed = 0;
} }
if(orders.close_ev) if(orders.close_ev)
{ {
vanne_close(); vanne_close();
orders.close_ev=0; orders.close_ev=0;
} }
if(orders.force_close_ev)
{
if(!status.force_closed)
{
vanne_force_close();
status.force_closed = 1;
}
orders.force_close_ev = 0;
}
if(orders.vidange_ev) if(orders.vidange_ev)
{ {
vanne_vidange(); vanne_vidange();
orders.vidange_ev=0; orders.vidange_ev=0;
status.force_closed = 0;
} }
if(orders.write_config) if(orders.write_config)
{ {
...@@ -53,22 +65,30 @@ void do_orders() ...@@ -53,22 +65,30 @@ void do_orders()
} }
if(status_thermo > 0) if(status_thermo > 0)
{ {
status.fail |= STATUS_FAIL_T; if(status.fail_get_T >= THERMO_FAIL_NUMBER)
status.fail |= STATUS_FAIL_T;
else
status.fail_get_T++;
} }
else else
{ {
status.fail_get_T = 0;
status.fail &= ~STATUS_FAIL_T; status.fail &= ~STATUS_FAIL_T;
status.temperature_insta = temp; status.temperature_insta = temp;
if(median_filter_thermometer_filled) if(!median_filter_thermometer_filled)
median_filter_thermometer_update(temp);
else
{ {
median_filter_thermometer_fill(temp); median_filter_thermometer_fill(temp);
status.temperature.v1 = status.temperature.v2 = .0625*temp; status.temperature.v1 = status.temperature.v2 = .0625*temp;
} }
}
if(median_filter_thermometer_filled)
{
median_filter_thermometer_update(status.temperature_insta);
float Tinstamf = .0625*median_filter_thermometer_read(); float Tinstamf = .0625*median_filter_thermometer_read();
update_filtre2(&(status.temperature), THERMO_FACTOR_FILTRE, Tinstamf); update_filtre2(&(status.temperature), THERMO_FACTOR_FILTRE, Tinstamf);
float consigne_debit;
if(cconfig.mode == MODE_AUTO) if(cconfig.mode == MODE_AUTO)
{ {
float temperature_diff = status.temperature.v2 - cconfig.consigne_temperature; float temperature_diff = status.temperature.v2 - cconfig.consigne_temperature;
...@@ -80,7 +100,7 @@ void do_orders() ...@@ -80,7 +100,7 @@ void do_orders()
status.accu_integrateur = max_integrateur; status.accu_integrateur = max_integrateur;
if(status.accu_integrateur<0) if(status.accu_integrateur<0)
status.accu_integrateur = 0; status.accu_integrateur = 0;
float consigne_debit = cconfig.Kp * (temperature_diff + status.accu_integrateur); consigne_debit = cconfig.Kp * (temperature_diff + status.accu_integrateur);
if(consigne_debit>cconfig.debit_max) if(consigne_debit>cconfig.debit_max)
consigne_debit = cconfig.debit_max; consigne_debit = cconfig.debit_max;
if(consigne_debit < 0) if(consigne_debit < 0)
...@@ -91,6 +111,27 @@ void do_orders() ...@@ -91,6 +111,27 @@ void do_orders()
else else
status.consigne_debit = consigne_debit; status.consigne_debit = consigne_debit;
} }
else if(cconfig.mode == MODE_POST_REFROI)
{
if(status.temperature.v2>cconfig.post_refroi_T2)
consigne_debit = cconfig.post_refroi_dmax;
else if(status.temperature.v2<cconfig.post_refroi_T1)
consigne_debit = 0;
else
consigne_debit = (status.temperature.v2-cconfig.post_refroi_T1)/(cconfig.post_refroi_T2-cconfig.post_refroi_T1)*cconfig.post_refroi_dmax;
if (status.temperature_cold_water > cconfig.post_refroi_cold_water_T2)
consigne_debit = 0;
else if(status.temperature_cold_water > cconfig.post_refroi_cold_water_T1)
consigne_debit *= (cconfig.post_refroi_cold_water_T2-status.temperature_cold_water)/(cconfig.post_refroi_cold_water_T2-cconfig.post_refroi_cold_water_T1);
if (status.temperature_hot_water > cconfig.post_refroi_hot_water_T2)
consigne_debit = 0;
else if(status.temperature_hot_water > cconfig.post_refroi_hot_water_T1)
consigne_debit *= (cconfig.post_refroi_hot_water_T2-status.temperature_hot_water)/(cconfig.post_refroi_hot_water_T2-cconfig.post_refroi_hot_water_T1);
if(consigne_debit < 0)
status.consigne_debit = 0;
else
status.consigne_debit = consigne_debit;
}
} }
} }
} }
...@@ -11,6 +11,7 @@ typedef struct orders_struct ...@@ -11,6 +11,7 @@ typedef struct orders_struct
uint16_t close_ev_step_value; uint16_t close_ev_step_value;
uint8_t open_ev; uint8_t open_ev;
uint8_t close_ev; uint8_t close_ev;
uint8_t force_close_ev;
uint8_t vidange_ev; uint8_t vidange_ev;
uint8_t get_T; uint8_t get_T;
uint8_t write_config; uint8_t write_config;
...@@ -22,9 +23,11 @@ void do_orders(); ...@@ -22,9 +23,11 @@ void do_orders();
/*[[[cog /*[[[cog
import conf import conf
cog.out(f"#define THERMO_FACTOR_FILTRE {conf.THERMO_FACTOR_FILTRE:e}") cog.out(f"#define THERMO_FACTOR_FILTRE {conf.THERMO_FACTOR_FILTRE:e}\n")
cog.out(f"#define THERMO_FAIL_NUMBER {conf.THERMO_FAIL_NUMBER:d}\n")
]]] */ ]]] */
#define THERMO_FACTOR_FILTRE 7.995559e-02 #define THERMO_FACTOR_FILTRE 7.995559e-02
#define THERMO_FAIL_NUMBER 180
//[[[end]]] //[[[end]]]
#endif #endif
...@@ -13,4 +13,8 @@ void status_init() ...@@ -13,4 +13,8 @@ void status_init()
status.volume_manque = 0; status.volume_manque = 0;
status.accu_integrateur = 0; status.accu_integrateur = 0;
status.fail = 0; status.fail = 0;
status.temperature_cold_water = 20;
status.temperature_hot_water = 20;
status.consecutive_closed_debit = 0;
status.force_closed = 0;
} }
...@@ -18,6 +18,11 @@ typedef struct status_struct ...@@ -18,6 +18,11 @@ typedef struct status_struct
float consigne_adj; float consigne_adj;
float accu_integrateur; float accu_integrateur;
uint8_t fail; uint8_t fail;
uint16_t fail_get_T;
float temperature_cold_water;
float temperature_hot_water;
uint16_t consecutive_closed_debit;
uint8_t force_closed;
} status_t; } status_t;
extern status_t status; extern status_t status;
......
...@@ -28,10 +28,11 @@ void vanne_init() ...@@ -28,10 +28,11 @@ void vanne_init()
vanne_internal_status = EV_MID; vanne_internal_status = EV_MID;
} }
uint8_t vanne_internal_step_close(uint16_t d) uint8_t vanne_internal_step_close(uint16_t d, uint8_t force)
{ {
if(vanne_internal_status == EV_CLOSED) if(!force)
return 1; if(vanne_internal_status == EV_CLOSED)
return 1;
if(d<VANNE_ACTION_LIMIT) if(d<VANNE_ACTION_LIMIT)
return 0; return 0;
...@@ -45,8 +46,9 @@ uint8_t vanne_internal_step_close(uint16_t d) ...@@ -45,8 +46,9 @@ uint8_t vanne_internal_step_close(uint16_t d)
VANNE_CMD_PORT.OUTSET = VANNE_CMD_CLOSE_bm; VANNE_CMD_PORT.OUTSET = VANNE_CMD_CLOSE_bm;
for(k=0;k<d;k++) for(k=0;k<d;k++)
_delay_ms(1); _delay_ms(1);
if(!(VANNE_SENSOR_PORT.IN & VANNE_SENSOR_CLOSE_bm)) if(!force)
vanne_internal_status = EV_CLOSED; if(!(VANNE_SENSOR_PORT.IN & VANNE_SENSOR_CLOSE_bm))
vanne_internal_status = EV_CLOSED;
VANNE_CMD_PORT.OUTCLR = VANNE_CMD_CLOSE_bm; VANNE_CMD_PORT.OUTCLR = VANNE_CMD_CLOSE_bm;
if(vanne_internal_status == EV_CLOSED) if(vanne_internal_status == EV_CLOSED)
...@@ -54,10 +56,11 @@ uint8_t vanne_internal_step_close(uint16_t d) ...@@ -54,10 +56,11 @@ uint8_t vanne_internal_step_close(uint16_t d)
return 0; return 0;
} }
uint8_t vanne_internal_step_open(uint16_t d) uint8_t vanne_internal_step_open(uint16_t d, uint8_t force)
{ {
if(vanne_internal_status == EV_OPENED) if(!force)
return 1; if(vanne_internal_status == EV_OPENED)
return 1;
if(d<VANNE_ACTION_LIMIT) if(d<VANNE_ACTION_LIMIT)
return 0; return 0;
...@@ -71,8 +74,9 @@ uint8_t vanne_internal_step_open(uint16_t d) ...@@ -71,8 +74,9 @@ uint8_t vanne_internal_step_open(uint16_t d)
VANNE_CMD_PORT.OUTSET = VANNE_CMD_OPEN_bm; VANNE_CMD_PORT.OUTSET = VANNE_CMD_OPEN_bm;
for(k=0;k<d;k++) for(k=0;k<d;k++)
_delay_ms(1); _delay_ms(1);
if(!(VANNE_SENSOR_PORT.IN & VANNE_SENSOR_OPEN_bm)) if(!force)
vanne_internal_status = EV_OPENED; if(!(VANNE_SENSOR_PORT.IN & VANNE_SENSOR_OPEN_bm))
vanne_internal_status = EV_OPENED;
VANNE_CMD_PORT.OUTCLR = VANNE_CMD_OPEN_bm; VANNE_CMD_PORT.OUTCLR = VANNE_CMD_OPEN_bm;
if(vanne_internal_status == EV_OPENED) if(vanne_internal_status == EV_OPENED)
...@@ -80,7 +84,7 @@ uint8_t vanne_internal_step_open(uint16_t d) ...@@ -80,7 +84,7 @@ uint8_t vanne_internal_step_open(uint16_t d)
return 0; return 0;
} }
uint8_t vanne_step_close(uint16_t d) uint8_t vanne_step_close(uint16_t d, uint8_t force)
{ {
uint16_t steps = d/(d/101+1); uint16_t steps = d/(d/101+1);
uint16_t k; uint16_t k;
...@@ -88,16 +92,16 @@ uint8_t vanne_step_close(uint16_t d) ...@@ -88,16 +92,16 @@ uint8_t vanne_step_close(uint16_t d)
for(k=0;k<d;k+=steps) for(k=0;k<d;k+=steps)
{ {
if(k+steps<=d) if(k+steps<=d)
ret = vanne_internal_step_close(steps); ret = vanne_internal_step_close(steps, force);
else else
ret = vanne_internal_step_close(d-k); ret = vanne_internal_step_close(d-k, force);
if(ret) if(ret)
return ret; return ret;
} }
return ret; return ret;
} }
uint8_t vanne_step_open(uint16_t d) uint8_t vanne_step_open(uint16_t d, uint8_t force)
{ {
uint16_t steps = d/(d/101+1); uint16_t steps = d/(d/101+1);
uint16_t k; uint16_t k;
...@@ -105,9 +109,9 @@ uint8_t vanne_step_open(uint16_t d) ...@@ -105,9 +109,9 @@ uint8_t vanne_step_open(uint16_t d)
for(k=0;k<d;k+=steps) for(k=0;k<d;k+=steps)
{ {
if(k+steps<=d) if(k+steps<=d)
ret = vanne_internal_step_open(steps); ret = vanne_internal_step_open(steps, force);
else else
ret = vanne_internal_step_open(d-k); ret = vanne_internal_step_open(d-k, force);
if(ret) if(ret)
return ret; return ret;
} }
...@@ -118,29 +122,54 @@ void vanne_close() ...@@ -118,29 +122,54 @@ void vanne_close()
{ {
uint16_t k; uint16_t k;
for(k=0;k<1000;k++) for(k=0;k<1000;k++)
if(vanne_internal_step_close(10)) if(vanne_internal_step_close(10,0))
break; break;
vanne_internal_status = EV_CLOSED;
} }
void vanne_open() void vanne_force_close()
{ {
uint16_t k; uint16_t k;
for(k=0;k<1000;k++) for(k=0;k<1000;k++)
if(vanne_internal_step_open(10)) if(vanne_internal_step_close(10,1))
break; break;
vanne_internal_status = EV_CLOSED;
} }
void vanne_vidange() void vanne_open()
{ {
uint16_t k; uint16_t k;
vanne_close();
for(k=0;k<1000;k++) for(k=0;k<1000;k++)
if(vanne_internal_step_open(10)) if(vanne_internal_step_open(10,0))
break; break;
vanne_internal_status = EV_OPENED;
}
void vanne_vidange()
{
uint16_t kclose;
uint16_t kopen;
vanne_close(); vanne_close();
for(kopen=0;kopen<1000;kopen++)
if(vanne_internal_step_open(10,0))
break;
for(kclose=0;kclose<1000;kclose++)
if(vanne_internal_step_close(10,0))
break;
uint8_t kmin;
if(kopen<900)
kmin = kopen/2;
else
{
if(kclose<900)
kmin = kclose/2;
else
kmin = 50;
}
uint16_t k2=0; uint16_t k2=0;
for(k2=0;k2<k/2;k2++) for(k2=0;k2<kmin;k2++)
if(vanne_internal_step_open(10)) if(vanne_internal_step_open(10,1))
break; break;
} }
///[[[end]]] ///[[[end]]]
......
...@@ -44,11 +44,12 @@ typedef enum state_ev ...@@ -44,11 +44,12 @@ typedef enum state_ev
extern volatile ev_state_t vanne_internal_status; extern volatile ev_state_t vanne_internal_status;
void vanne_init(); void vanne_init();
uint8_t vanne_internal_step_close(uint16_t d); uint8_t vanne_internal_step_close(uint16_t d, uint8_t force);
uint8_t vanne_internal_step_open(uint16_t d); uint8_t vanne_internal_step_open(uint16_t d, uint8_t force);
uint8_t vanne_step_close(uint16_t d); uint8_t vanne_step_close(uint16_t d, uint8_t force);
uint8_t vanne_step_open(uint16_t d); uint8_t vanne_step_open(uint16_t d, uint8_t force);
void vanne_close(); void vanne_close();
void vanne_force_close();
void vanne_open(); void vanne_open();
void vanne_vidange(); void vanne_vidange();
#endif #endif
......