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 (25)
......@@ -5,3 +5,5 @@ __pycache__/
*.hex
*.elf
commitid.h
id.h
ID
DEVICE = atxmega64a3u
DEVICE = atxmega256a3u
PROGRAMMER = -c avrispmkII
OBJECTS = main.o clock.o debug.o bus.o config.o status.o utils.o messages.o vanne.o debit.o orders.o thermometer.o median_filter.o leds.o main_timer.o
PORT = usb
......@@ -16,19 +16,22 @@ COMPILE = avr-gcc -Wall -Os -mmcu=$(DEVICE)
.PHONY: clean all
.INTERMEDIATE: commitid.h main.o
.INTERMEDIATE: commitid.h id.h message.o main.o
# symbolic targets:
all: main.hex
clean:
rm -f *.o *.elf *.hex commitid.h
rm -f *.o *.elf *.hex commitid.h id.h
commitid.h: .git/refs/heads
cog -r *.c *.h
./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 $@
.S.o:
......
Subproject commit f28703826cd780709e6e1d4ebf47c77827b86fe8
Subproject commit 1bbb9871f4a1f20de73f9e90b63757595e530c4a
......@@ -186,4 +186,6 @@ void bus_printf(const char *fmt, ...)
///[[[end]]]
void bus_msg_handler(const char * msg)
{}
{
message_get(msg);
}
......@@ -21,8 +21,8 @@ cog.out(
#define BUS_port PORTC
#define BUS_txpin PIN3_bm
#define BUS_rxlen 256
#define BUS_txlen 256
#define BUS_rxlen 384
#define BUS_txlen 384
#define BUS_baudrate 1200
#define BUS_chsize 8
#define BUS_rxtrigger '\n'
......
......@@ -36,8 +36,8 @@ BUS = {
"rx": True,
"de_pindesc": PinDesc("C0"),
"rxhandler": "bus_msg_handler",
"txlen": 256,
"rxlen": 256,
"txlen": 384,
"rxlen": 384,
"baudrate": 1200,
"rxtriggerbegin": ("S", "M"),
}
......@@ -45,6 +45,8 @@ BUS = {
THERMO_PERIOD = 5
THERMO_MEDIAN_FILTER_LEN = 13
THERMO_FACTOR_FILTRE = 1 - math.exp(-5 / 60)
THERMO_FAIL_NUMBER = 180
BID_WATER = 0xc0
ACTION_TIMER_MAIN = "TCC0"
......
......@@ -19,6 +19,7 @@ void config_read()
void config_init()
{
config_read();
cconfig_update(&config, &cconfig);
if(!config_valid(&cconfig))
......@@ -32,11 +33,10 @@ void config_init()
void cconfig_update(config_t * c, cconfig_t * cc)
{
cc->mode = c->mode;
cc->vol_cuve = c->vol_cuve;
cc->Kp = 0.01 * c->Kp;
cc->Kp = (0.01 * c->Kp * c->vol_cuve) / 300;
cc->ti = c->ti;
cc->consigne_temperature = 0.01 * c->consigne_temperature;
cc->debit_max = 0.01 * c->debit_max;
cc->debit_max = (0.01 * c->debit_max * c->vol_cuve) / 300;
cc->cst_ev = c->cst_ev;
cc->debit_min1 = 0.01 * c->debit_min1;
cc->debit_min2 = 0.01 * c->debit_min2;
......@@ -45,13 +45,18 @@ void cconfig_update(config_t * c, cconfig_t * cc)
cc->volume_manque_max = 0.01 * c->volume_manque_max;
cc->m_rattrapage = c->m_rattrapage;
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)
{
if(cc->mode<1 || cc->mode>5)
return 0;
if(cc->vol_cuve<25 || cc->vol_cuve>1000)
if(cc->mode<1 || cc->mode>6)
return 0;
if(cc->Kp<1 || cc->Kp>100)
return 0;
......@@ -73,12 +78,20 @@ uint8_t config_valid(cconfig_t * cc)
return 0;
if(cc->minimum_step < 1 || cc->minimum_step > 150)
return 0;
if(cc->volume_manque_max < 1 || cc->volume_manque_max)
if(cc->volume_manque_max < 1 || cc->volume_manque_max>250)
return 0;
if(cc->m_rattrapage < 1 || cc->m_rattrapage > 60)
return 0;
if(cc->consigne_debit<0 || cc->consigne_debit>50)
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;
}
......@@ -88,8 +101,8 @@ void config_default(config_t* c)
c->vol_cuve = 300;
c->Kp = 32*100;
c->ti = 3600;
c->consigne_temperature = 2350;
c->debit_max = 2000;
c->consigne_temperature = 2395;
c->debit_max = 1500;
c->cst_ev = 10;
c->debit_min1 = 200;
c->debit_min2 = 400;
......@@ -97,6 +110,13 @@ void config_default(config_t* c)
c->volume_manque_max = 7500;
c->m_rattrapage = 15;
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)
......@@ -108,10 +128,8 @@ void config_apply_new_config(config_t * pnew_config)
uint8_t mode_change = 0;
if(pnew_config->mode != config.mode)
mode_change = 1;
// TODO: si mode change, action
// TODO: si mode==MODE_DEBIT, update consigne
memcpy(&config, pnew_config, sizeof(config_t));
config_write();
orders.write_config = 1;
cconfig_update(&config, &cconfig);
if(mode_change)
config_mode_change();
......@@ -123,15 +141,28 @@ void config_apply_new_config(config_t * pnew_config)
void config_mode_change()
{
if(config.mode == MODE_FORCE_CLOSE)
{
orders.close_ev = 1;
status.consigne_debit = 0;
status.volume_manque = 0;
}
else if(config.mode == MODE_FORCE_OPEN)
{
orders.open_ev = 1;
status.consigne_debit = 0;
status.volume_manque = 0;
}
else if(config.mode == MODE_FORCE_VIDANGE)
{
orders.vidange_ev = 1;
status.consigne_debit = 0;
status.volume_manque = 0;
}
else if(config.mode == MODE_DEBIT)
{
orders.close_ev = 1;
status.volume_manque = 0;
status.consigne_debit = cconfig.consigne_debit;
}
else if(config.mode == MODE_AUTO)
{
......@@ -139,6 +170,10 @@ void config_mode_change()
status.volume_manque = 0;
status.accu_integrateur = 0;
}
if(config.mode == MODE_DEBIT)
status.consigne_debit = cconfig.consigne_debit;
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
MODE_FORCE_VIDANGE = 0x03,
MODE_DEBIT = 0x04,
MODE_AUTO = 0x05,
MODE_POST_REFROI = 0x06,
} mode_t;
typedef struct config_struct
......@@ -37,12 +38,18 @@ typedef struct config_struct
uint16_t volume_manque_max;
uint8_t m_rattrapage;
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;
typedef struct cconfig_struct
{
mode_t mode;
float vol_cuve;
float Kp;
float ti;
float consigne_temperature;
......@@ -55,6 +62,13 @@ typedef struct cconfig_struct
float volume_manque_max;
float m_rattrapage;
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;
void config_read();
......
......@@ -28,10 +28,17 @@ void debit_update()
float vol_sur_seconde = 1.8500e-04*count+(2.9027e-06*count)*count;
float debit_insta = vol_sur_seconde*60;
status.volume_manque += status.consigne_debit/60-vol_sur_seconde;
status.fail &= ~(STATUS_FAIL_UNDERFLOW|STATUS_FAIL_OVERFLOW);
if(status.volume_manque > cconfig.volume_manque_max)
{
status.volume_manque = cconfig.volume_manque_max;
if(status.volume_manque < - cconfig.volume_manque_max)
status.fail |= STATUS_FAIL_UNDERFLOW;
}
else if(status.volume_manque < - cconfig.volume_manque_max)
{
status.volume_manque = - cconfig.volume_manque_max;
status.fail |= STATUS_FAIL_OVERFLOW;
}
update_filtre2(&(status.debit5), FLOW_FACTOR_FILTRE_5, debit_insta);
update_filtre2(&(status.debit60), FLOW_FACTOR_FILTRE_60, debit_insta);
......@@ -39,11 +46,31 @@ void debit_update()
status.consigne_adj = status.consigne_debit + status.volume_manque/cconfig.m_rattrapage;
if(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()
{
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) ||
((status.consigne_adj>cconfig.debit_min1) && (vanne_internal_status != EV_CLOSED)))
......
......@@ -3,22 +3,23 @@
import os
import time
import subprocess
import re
import sys
CMDCOMMIT = ('git', 'describe', '--abbr=5', '--dirty=+')
CMDCOMMIT = ('git', 'describe', '--abbr=7', '--dirty', '--long')
def retain_out(x):
return subprocess.check_output(x).strip().decode('utf8')
if False:
commit = retain_out(CMDCOMMIT)
mts = max(os.path.getmtime(x) for x in os.listdir() if x.endswith('.c') or x.endswith('.h') or x.endswith('.py'))
mtime = time.strftime('%Y-%m-%d %H:%M',time.localtime(mts))
print(f'#define COMMITID_LINE0 "{commit}"')
print(f'#define COMMITID_LINE1 "{mtime}"')
if __name__ == '__main__':
print(f'#define COMMITID_MAJOR 0')
print(f'#define COMMITID_MINOR 0')
print(f'#define COMMITID_NBCOMMITS 0x78')
print(f'#define COMMITID_HASH 0xB00B')
print(f'#define COMMITID_DIRTY 7')
commit = retain_out(CMDCOMMIT)
a = re.match("v([0-9]+)\.([0-9]+)-([0-9]+)-g([0-9a-f]{7})((?:-dirty)?)$",commit)
if a:
major, minor, nbc, commithash, dirty = a.groups()
dirtyhash = (int(commithash,16)<<4) + (1 if dirty else 0)
print(f'#define COMMITID_MAJOR {major}')
print(f'#define COMMITID_MINOR {minor}')
print(f'#define COMMITID_NBCOMMITS 0x{int(nbc):02x}')
print(f'#define COMMITID_DIRTYHASH 0x{dirtyhash:08x}')
else:
sys.exit(1)
#!/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]]]
......@@ -9,12 +9,17 @@ int main(void)
debug_init();
status_init();
config_init();
bus_init();
vanne_init();
debit_init();
led_init();
main_timer_init();
uint8_t k;
for(k=0; k<BID; k++)
_delay_ms(2500);
bus_init();
while(1)
{
do_orders();
......
......@@ -5,7 +5,7 @@ uint8_t get_packet(char * z, uint8_t pid)
uint8_to_2char(pid,z);
if(pid == 0x01)
{
uint8_to_2char(status.failT, z+2);
uint8_to_2char(status.fail, z+2);
return 4;
}
if(pid == 0x02)
......@@ -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);
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)
{
......@@ -85,12 +97,6 @@ uint8_t get_packet(char * z, uint8_t pid)
uint8_to_2char(config.cst_ev, z+2);
return 4;
}
if(pid == 0x87)
{
uint16_to_4char(config.debit_min1, z+2);
uint16_to_4char(config.debit_min2, z+6);
return 10;
}
if(pid == 0x88)
{
uint8_to_2char(config.minimum_step, z+2);
......@@ -111,14 +117,58 @@ uint8_t get_packet(char * z, uint8_t pid)
uint16_to_4char(config.consigne_debit, z+2);
return 6;
}
if(pid == 0x8c)
{
uint16_to_4char(config.debit_min1, z+2);
return 6;
}
if(pid == 0x8d)
{
uint16_to_4char(config.debit_min2, z+2);
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)
{
uint8_to_2char(COMMITID_MAJOR, z+2);
uint8_to_2char(COMMITID_MINOR, z+4);
uint8_to_2char(COMMITID_NBCOMMITS, z+6);
uint32_to_8char(COMMITID_HASH, z+8);
uint8_to_2char(COMMITID_DIRTY, z+16);
return 18;
uint32_to_8char(COMMITID_DIRTYHASH, z+8);
return 16;
}
return 0;
}
......@@ -126,7 +176,7 @@ uint8_t get_packet(char * z, uint8_t pid)
void message_send()
{
char msg[256];
char msg[384];
msg[0] = 'S';
msg[1] = ',';
uint8_to_2char(BID, msg+2);
......@@ -150,9 +200,10 @@ void message_send()
lines.format(packet_id=pid)
for pid in (
"0x01", "0x02", "0x03", "0x04", "0x05", "0x06", "0x07", "0x08",
"0x09",
"0x80", "0x81", "0x82", "0x83", "0x84", "0x85", "0x86", "0x87",
"0x88", "0x89", "0x8a", "0x8b",
"0x09", "0x0a", "0x0b",
"0x80", "0x81", "0x82", "0x83", "0x84", "0x85", "0x86",
"0x88", "0x89", "0x8a", "0x8b", "0x8c", "0x8d", "0x8e",
"0x8f", "0x90", "0x91", "0x92", "0x93", "0x94",
"0xb1")
)
cog.out(out)
......@@ -200,6 +251,16 @@ void message_send()
packet_len = get_packet(msg+msg_len, 0x09);
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_len++;
packet_len = get_packet(msg+msg_len, 0x80);
......@@ -235,11 +296,6 @@ void message_send()
packet_len = get_packet(msg+msg_len, 0x86);
msg_len += packet_len;
msg[msg_len] = ',';
msg_len++;
packet_len = get_packet(msg+msg_len, 0x87);
msg_len += packet_len;
msg[msg_len] = ',';
msg_len++;
packet_len = get_packet(msg+msg_len, 0x88);
......@@ -260,6 +316,51 @@ void message_send()
packet_len = get_packet(msg+msg_len, 0x8b);
msg_len += packet_len;
msg[msg_len] = ',';
msg_len++;
packet_len = get_packet(msg+msg_len, 0x8c);
msg_len += packet_len;
msg[msg_len] = ',';
msg_len++;
packet_len = get_packet(msg+msg_len, 0x8d);
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_len++;
packet_len = get_packet(msg+msg_len, 0xb1);
......@@ -287,10 +388,22 @@ void message_send()
void message_get(const char* msg)
{
if(msg[0] != 'M' || msg[1] != ',')
return; // je n'écoute que le master
if(msg[2] != BID_C0 || msg[3] != BID_C1)
return; // ce n'est pas à moi qu'on parle
uint8_t message_from_master = 0;
if(msg[1] != ',')
return;
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] != ':')
return; //message mal formaté
uint16_t crc = 0xFFFF;
......@@ -312,32 +425,72 @@ void message_get(const char* msg)
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
if(msg_len>5)
if(message_from_master)
{
config_t new_config;
memcpy(&new_config, &config, sizeof(config_t));
uint8_t pos = 5;
while(pos<msg_len)
if(msg_len>5)
{
for(k=0; pos+k<msg_len; k++)
if(msg[pos+k] == ',')
config_t new_config;
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;
readed_packet(msg+pos, k, &new_config);
pos += k;
}
if(memcmp(&new_config, &config, sizeof(config_t)))
{
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;
cconfig_update(&new_config, &new_cconfig);
if(config_valid(&new_cconfig))
config_apply_new_config(&new_config);
uint8_t pos = 5;
while(pos<msg_len)
{
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
message_send();
void update_temp_readed_status_packet(const char *z, uint8_t len)
{
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)
{
if(len<2)
......@@ -392,14 +545,6 @@ void readed_packet(const char * z, uint8_t len, config_t * nc)
nc->cst_ev = uint8_from_2char(z+2);
return;
}
if(pid == 0x87)
{
if(len!=10)
return;
nc->debit_min1 = uint16_from_4char(z+2);
nc->debit_min2 = uint16_from_4char(z+6);
return;
}
if(pid == 0x88)
{
if(len!=4)
......@@ -428,4 +573,67 @@ void readed_packet(const char * z, uint8_t len, config_t * nc)
nc->consigne_debit = uint16_from_4char(z+2);
return;
}
if(pid == 0x8c)
{
if(len!=6)
return;
nc->debit_min1 = uint16_from_4char(z+2);
return;
}
if(pid == 0x8d)
{
if(len!=6)
return;
nc->debit_min2 = uint16_from_4char(z+2);
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);
void message_send();
void message_get(const char* msg);
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
......@@ -6,28 +6,45 @@ void do_orders()
{
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;
status.force_closed = 0;
}
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;
}
if(orders.open_ev)
{
vanne_open();
orders.open_ev=0;
status.force_closed = 0;
}
if(orders.close_ev)
{
vanne_close();
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)
{
vanne_vidange();
orders.vidange_ev=0;
status.force_closed = 0;
}
if(orders.write_config)
{
orders.write_config=0;
config_write();
}
if(orders.get_T)
{
......@@ -48,22 +65,30 @@ void do_orders()
}
if(status_thermo > 0)
{
status.failT = 1;
if(status.fail_get_T >= THERMO_FAIL_NUMBER)
status.fail |= STATUS_FAIL_T;
else
status.fail_get_T++;
}
else
{
status.failT = 0;
status.fail_get_T = 0;
status.fail &= ~STATUS_FAIL_T;
status.temperature_insta = temp;
if(median_filter_thermometer_filled)
median_filter_thermometer_update(temp);
else
if(!median_filter_thermometer_filled)
{
median_filter_thermometer_fill(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();
update_filtre2(&(status.temperature), THERMO_FACTOR_FILTRE, Tinstamf);
float consigne_debit;
if(cconfig.mode == MODE_AUTO)
{
float temperature_diff = status.temperature.v2 - cconfig.consigne_temperature;
......@@ -75,7 +100,37 @@ void do_orders()
status.accu_integrateur = max_integrateur;
if(status.accu_integrateur<0)
status.accu_integrateur = 0;
status.consigne_debit = cconfig.Kp * (temperature_diff + status.accu_integrateur);
consigne_debit = cconfig.Kp * (temperature_diff + status.accu_integrateur);
if(consigne_debit>cconfig.debit_max)
consigne_debit = cconfig.debit_max;
if(consigne_debit < 0)
{
status.consigne_debit = 0;
status.volume_manque = 0;
}
else
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,8 +11,10 @@ typedef struct orders_struct
uint16_t close_ev_step_value;
uint8_t open_ev;
uint8_t close_ev;
uint8_t force_close_ev;
uint8_t vidange_ev;
uint8_t get_T;
uint8_t write_config;
} orders_t;
extern orders_t orders;
......@@ -21,9 +23,11 @@ void do_orders();
/*[[[cog
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_FAIL_NUMBER 180
//[[[end]]]
#endif
......@@ -12,5 +12,9 @@ void status_init()
status.debit5.v2 = 0;
status.volume_manque = 0;
status.accu_integrateur = 0;
status.failT = 0;
status.fail = 0;
status.temperature_cold_water = 20;
status.temperature_hot_water = 20;
status.consecutive_closed_debit = 0;
status.force_closed = 0;
}
......@@ -3,6 +3,10 @@
#ifndef STATUS_H
#define STATUS_H 1
#define STATUS_FAIL_T (0x01)
#define STATUS_FAIL_UNDERFLOW (0x01<<1)
#define STATUS_FAIL_OVERFLOW (0x01<<2)
typedef struct status_struct
{
int16_t temperature_insta;
......@@ -13,7 +17,12 @@ typedef struct status_struct
float consigne_debit;
float consigne_adj;
float accu_integrateur;
uint8_t failT;
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;
extern status_t status;
......
......@@ -53,42 +53,42 @@ void uint32_to_8char(uint32_t nb, char* c)
uint8_t uint8_from_2char(const char* c)
{
uint8_t nb = 0x00;
nb += snip_from_char(c[1]);
nb<<=4;
nb += snip_from_char(c[0]);
nb<<=4;
nb += snip_from_char(c[1]);
return nb;
}
uint16_t uint16_from_4char(const char* c)
{
uint16_t nb = 0x00;
nb += snip_from_char(c[3]);
nb<<=4;
nb += snip_from_char(c[2]);
nb += snip_from_char(c[0]);
nb<<=4;
nb += snip_from_char(c[1]);
nb<<=4;
nb += snip_from_char(c[0]);
nb += snip_from_char(c[2]);
nb<<=4;
nb += snip_from_char(c[3]);
return nb;
}
uint32_t uint32_from_8char(const char* c)
{
uint32_t nb = 0x00;
nb += snip_from_char(c[7]);
nb<<=4;
nb += snip_from_char(c[6]);
nb += snip_from_char(c[0]);
nb<<=4;
nb += snip_from_char(c[5]);
nb += snip_from_char(c[1]);
nb<<=4;
nb += snip_from_char(c[4]);
nb += snip_from_char(c[2]);
nb<<=4;
nb += snip_from_char(c[3]);
nb<<=4;
nb += snip_from_char(c[2]);
nb += snip_from_char(c[4]);
nb<<=4;
nb += snip_from_char(c[1]);
nb += snip_from_char(c[5]);
nb<<=4;
nb += snip_from_char(c[0]);
nb += snip_from_char(c[6]);
nb<<=4;
nb += snip_from_char(c[7]);
return nb;
}