diff --git a/CHANGELOG.md b/CHANGELOG.md index 872c93e08..e33eac30e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file. - Berry add `solidify.nocompact()` and reduce size of Matter UI ### Breaking Changed +- Berry `energy` module support for 8 phases and move to pseudo-arrays ### Changed - Berry consolidated constants for solidified classes reduces Flash size (#2185) diff --git a/lib/libesp32/berry_tasmota/src/be_energylib.c b/lib/libesp32/berry_tasmota/src/be_energylib.c index b21259058..854f41d60 100644 --- a/lib/libesp32/berry_tasmota/src/be_energylib.c +++ b/lib/libesp32/berry_tasmota/src/be_energylib.c @@ -9,6 +9,9 @@ #ifdef USE_ENERGY_SENSOR +// unless we get it from an include +#define ENERGY_MAX_PHASES 8 // Support max eight phases/channels + extern struct ENERGY Energy; extern int module_energy_update_total(bvm *vm); @@ -21,10 +24,17 @@ module energy (scope: global) { init, closure(module_energy_init_closure) _ptr, comptr(&Energy) _deref, closure(module_energy__deref_closure) + _phases, int(ENERGY_MAX_PHASES) + + _phases_float, class(be_class_energy_phases_float) + _phases_int32, class(be_class_energy_phases_int32) + _phases_uint8, class(be_class_energy_phases_uint8) + _phases_uint16, class(be_class_energy_phases_uint16) read, closure(module_energy_read_closure) member, closure(module_energy_member_closure) setmember, closure(module_energy_setmember_closure) + tomap, closure(module_energy_tomap_closure) update_total, func(module_energy_update_total) } diff --git a/lib/libesp32/berry_tasmota/src/embedded/energy.be b/lib/libesp32/berry_tasmota/src/embedded/energy.be index 2f5bb2e1d..9a21db917 100644 --- a/lib/libesp32/berry_tasmota/src/embedded/energy.be +++ b/lib/libesp32/berry_tasmota/src/embedded/energy.be @@ -2,8 +2,117 @@ _energy = nil # avoid compilation error energy_struct = nil +#@ solidify:bytes_array +# implement an array of simple types +class bytes_array : bytes + var item_type # item_type number for each element + var sz # size (number of items in the array) + var item_size # size in bytes of each element (inferred from item_type) + + def init(ptr, item_type, sz) + self.item_type = item_type + self.sz = sz + var item_size # size in bytes of each element + if (item_type >= -4) && (item_type <= 4) && (item_type != 0) + item_size = (item_type > 0) ? item_type : - item_type + elif (item_type == 5) + item_size = 4 + else + raise "value error", "unsupported item_type number" + end + self.item_size = item_size + super(self).init(ptr, self.item_size * self.sz) + end + + def item(idx) + if (idx < 0) idx += self.sz end + if (idx < 0) || (idx >= self.sz) + raise "index_error", "list index out of range" + end + if (self.item_type == 5) + return self.getfloat(idx * self.item_size) + else + return self.get(idx * self.item_size, self.item_type) + end + end + + def setitem(idx, v) + if (idx < 0) idx += self.sz end + if (idx < 0) || (idx >= self.sz) + raise "index_error", "list assignment index out of range" + end + if (self.item_type == 5) + return self.setfloat(idx * self.item_size, v) + else + return self.set(idx * self.item_size, self.item_type, v) + end + end + + def size() + return self.sz + end + + def tostring() + var ret = '[' + var idx = 0 + while (idx < self.sz) + if idx > 0 + ret += ',' + end + # + if (self.item_type == 5) + ret += str(self.getfloat(idx * self.item_size)) + else + ret += str(self.get(idx * self.item_size, self.item_type)) + end + + idx += 1 + end + ret += ']' + return ret + end +end + +#@ solidify:energy_phases_float +class energy_phases_float : bytes_array + def init(ptr) + import energy + super(self).init(ptr, 5 #-type float-#, energy._phases) + end +end + + +#@ solidify:energy_phases_int32 +class energy_phases_int32 : bytes_array + def init(ptr) + import energy + super(self).init(ptr, 4 #-type int32-#, energy._phases) + end +end + +#@ solidify:energy_phases_uint8 +class energy_phases_uint8 : bytes_array + def init(ptr) + import energy + super(self).init(ptr, 1 #-type int32-#, energy._phases) + end +end + +#@ solidify:energy_phases_uint16 +class energy_phases_uint16 : bytes_array + def init(ptr) + import energy + super(self).init(ptr, 2 #-type uint16-#, energy._phases) + end +end + energy = module("energy") -energy._ptr = nil +energy._ptr = nil # will be replaced by C code +energy._phases = 8 # will be replaced by C code +energy._phases_float = energy_phases_float +energy._phases_int32 = energy_phases_int32 +energy._phases_uint8 = energy_phases_uint8 +energy._phases_uint16 = energy_phases_uint16 def init(m) global._energy = nil @@ -46,8 +155,17 @@ def setmember(k, v) end energy.setmember = setmember +def tomap() + energy._deref() + if global._energy + return _energy.tomap() + end +end +energy.tomap = tomap + #@ solidify:energy.init #@ solidify:energy._deref #@ solidify:energy.read #@ solidify:energy.member #@ solidify:energy.setmember +#@ solidify:energy.tomap diff --git a/lib/libesp32/berry_tasmota/src/solidify/solidified_energy.h b/lib/libesp32/berry_tasmota/src/solidify/solidified_energy.h index 5682971af..d1765fd6c 100644 --- a/lib/libesp32/berry_tasmota/src/solidify/solidified_energy.h +++ b/lib/libesp32/berry_tasmota/src/solidify/solidified_energy.h @@ -3,6 +3,505 @@ * Generated code, don't edit * \********************************************************************/ #include "be_constobj.h" +// compact class 'bytes_array' ktab size: 18, total: 34 (saved 128 bytes) +static const bvalue be_ktab_class_bytes_array[18] = { + /* K0 */ be_nested_str(item_type), + /* K1 */ be_nested_str(sz), + /* K2 */ be_const_int(0), + /* K3 */ be_nested_str(value_X20error), + /* K4 */ be_nested_str(unsupported_X20item_type_X20number), + /* K5 */ be_nested_str(item_size), + /* K6 */ be_nested_str(init), + /* K7 */ be_nested_str(_X5B), + /* K8 */ be_nested_str(_X2C), + /* K9 */ be_nested_str(getfloat), + /* K10 */ be_nested_str(get), + /* K11 */ be_const_int(1), + /* K12 */ be_nested_str(_X5D), + /* K13 */ be_nested_str(index_error), + /* K14 */ be_nested_str(list_X20index_X20out_X20of_X20range), + /* K15 */ be_nested_str(list_X20assignment_X20index_X20out_X20of_X20range), + /* K16 */ be_nested_str(setfloat), + /* K17 */ be_nested_str(set), +}; + + +extern const bclass be_class_bytes_array; + +/******************************************************************** +** Solidified function: init +********************************************************************/ +be_local_closure(class_bytes_array_init, /* name */ + be_nested_proto( + 10, /* nstack */ + 4, /* argc */ + 10, /* varg */ + 0, /* has upvals */ + NULL, /* no upvals */ + 0, /* has sup protos */ + NULL, /* no sub protos */ + 1, /* has constants */ + &be_ktab_class_bytes_array, /* shared constants */ + &be_const_str_init, + &be_const_str_solidified, + ( &(const binstruction[35]) { /* code */ + 0x90020002, // 0000 SETMBR R0 K0 R2 + 0x90020203, // 0001 SETMBR R0 K1 R3 + 0x4C100000, // 0002 LDNIL R4 + 0x5415FFFB, // 0003 LDINT R5 -4 + 0x28140405, // 0004 GE R5 R2 R5 + 0x7816000B, // 0005 JMPF R5 #0012 + 0x54160003, // 0006 LDINT R5 4 + 0x18140405, // 0007 LE R5 R2 R5 + 0x78160008, // 0008 JMPF R5 #0012 + 0x20140502, // 0009 NE R5 R2 K2 + 0x78160006, // 000A JMPF R5 #0012 + 0x24140502, // 000B GT R5 R2 K2 + 0x78160001, // 000C JMPF R5 #000F + 0x5C140400, // 000D MOVE R5 R2 + 0x70020000, // 000E JMP #0010 + 0x44140400, // 000F NEG R5 R2 + 0x5C100A00, // 0010 MOVE R4 R5 + 0x70020005, // 0011 JMP #0018 + 0x54160004, // 0012 LDINT R5 5 + 0x1C140405, // 0013 EQ R5 R2 R5 + 0x78160001, // 0014 JMPF R5 #0017 + 0x54120003, // 0015 LDINT R4 4 + 0x70020000, // 0016 JMP #0018 + 0xB0060704, // 0017 RAISE 1 K3 K4 + 0x90020A04, // 0018 SETMBR R0 K5 R4 + 0x60140003, // 0019 GETGBL R5 G3 + 0x5C180000, // 001A MOVE R6 R0 + 0x7C140200, // 001B CALL R5 1 + 0x8C140B06, // 001C GETMET R5 R5 K6 + 0x5C1C0200, // 001D MOVE R7 R1 + 0x88200105, // 001E GETMBR R8 R0 K5 + 0x88240101, // 001F GETMBR R9 R0 K1 + 0x08201009, // 0020 MUL R8 R8 R9 + 0x7C140600, // 0021 CALL R5 3 + 0x80000000, // 0022 RET 0 + }) + ) +); +/*******************************************************************/ + + +/******************************************************************** +** Solidified function: size +********************************************************************/ +be_local_closure(class_bytes_array_size, /* name */ + be_nested_proto( + 2, /* nstack */ + 1, /* argc */ + 10, /* varg */ + 0, /* has upvals */ + NULL, /* no upvals */ + 0, /* has sup protos */ + NULL, /* no sub protos */ + 1, /* has constants */ + &be_ktab_class_bytes_array, /* shared constants */ + &be_const_str_size, + &be_const_str_solidified, + ( &(const binstruction[ 2]) { /* code */ + 0x88040101, // 0000 GETMBR R1 R0 K1 + 0x80040200, // 0001 RET 1 R1 + }) + ) +); +/*******************************************************************/ + + +/******************************************************************** +** Solidified function: tostring +********************************************************************/ +be_local_closure(class_bytes_array_tostring, /* name */ + be_nested_proto( + 8, /* nstack */ + 1, /* argc */ + 10, /* varg */ + 0, /* has upvals */ + NULL, /* no upvals */ + 0, /* has sup protos */ + NULL, /* no sub protos */ + 1, /* has constants */ + &be_ktab_class_bytes_array, /* shared constants */ + &be_const_str_tostring, + &be_const_str_solidified, + ( &(const binstruction[32]) { /* code */ + 0x58040007, // 0000 LDCONST R1 K7 + 0x58080002, // 0001 LDCONST R2 K2 + 0x880C0101, // 0002 GETMBR R3 R0 K1 + 0x140C0403, // 0003 LT R3 R2 R3 + 0x780E0018, // 0004 JMPF R3 #001E + 0x240C0502, // 0005 GT R3 R2 K2 + 0x780E0000, // 0006 JMPF R3 #0008 + 0x00040308, // 0007 ADD R1 R1 K8 + 0x880C0100, // 0008 GETMBR R3 R0 K0 + 0x54120004, // 0009 LDINT R4 5 + 0x1C0C0604, // 000A EQ R3 R3 R4 + 0x780E0007, // 000B JMPF R3 #0014 + 0x600C0008, // 000C GETGBL R3 G8 + 0x8C100109, // 000D GETMET R4 R0 K9 + 0x88180105, // 000E GETMBR R6 R0 K5 + 0x08180406, // 000F MUL R6 R2 R6 + 0x7C100400, // 0010 CALL R4 2 + 0x7C0C0200, // 0011 CALL R3 1 + 0x00040203, // 0012 ADD R1 R1 R3 + 0x70020007, // 0013 JMP #001C + 0x600C0008, // 0014 GETGBL R3 G8 + 0x8C10010A, // 0015 GETMET R4 R0 K10 + 0x88180105, // 0016 GETMBR R6 R0 K5 + 0x08180406, // 0017 MUL R6 R2 R6 + 0x881C0100, // 0018 GETMBR R7 R0 K0 + 0x7C100600, // 0019 CALL R4 3 + 0x7C0C0200, // 001A CALL R3 1 + 0x00040203, // 001B ADD R1 R1 R3 + 0x0008050B, // 001C ADD R2 R2 K11 + 0x7001FFE3, // 001D JMP #0002 + 0x0004030C, // 001E ADD R1 R1 K12 + 0x80040200, // 001F RET 1 R1 + }) + ) +); +/*******************************************************************/ + + +/******************************************************************** +** Solidified function: item +********************************************************************/ +be_local_closure(class_bytes_array_item, /* name */ + be_nested_proto( + 6, /* nstack */ + 2, /* argc */ + 10, /* varg */ + 0, /* has upvals */ + NULL, /* no upvals */ + 0, /* has sup protos */ + NULL, /* no sub protos */ + 1, /* has constants */ + &be_ktab_class_bytes_array, /* shared constants */ + &be_const_str_item, + &be_const_str_solidified, + ( &(const binstruction[27]) { /* code */ + 0x14080302, // 0000 LT R2 R1 K2 + 0x780A0001, // 0001 JMPF R2 #0004 + 0x88080101, // 0002 GETMBR R2 R0 K1 + 0x00040202, // 0003 ADD R1 R1 R2 + 0x14080302, // 0004 LT R2 R1 K2 + 0x740A0002, // 0005 JMPT R2 #0009 + 0x88080101, // 0006 GETMBR R2 R0 K1 + 0x28080202, // 0007 GE R2 R1 R2 + 0x780A0000, // 0008 JMPF R2 #000A + 0xB0061B0E, // 0009 RAISE 1 K13 K14 + 0x88080100, // 000A GETMBR R2 R0 K0 + 0x540E0004, // 000B LDINT R3 5 + 0x1C080403, // 000C EQ R2 R2 R3 + 0x780A0005, // 000D JMPF R2 #0014 + 0x8C080109, // 000E GETMET R2 R0 K9 + 0x88100105, // 000F GETMBR R4 R0 K5 + 0x08100204, // 0010 MUL R4 R1 R4 + 0x7C080400, // 0011 CALL R2 2 + 0x80040400, // 0012 RET 1 R2 + 0x70020005, // 0013 JMP #001A + 0x8C08010A, // 0014 GETMET R2 R0 K10 + 0x88100105, // 0015 GETMBR R4 R0 K5 + 0x08100204, // 0016 MUL R4 R1 R4 + 0x88140100, // 0017 GETMBR R5 R0 K0 + 0x7C080600, // 0018 CALL R2 3 + 0x80040400, // 0019 RET 1 R2 + 0x80000000, // 001A RET 0 + }) + ) +); +/*******************************************************************/ + + +/******************************************************************** +** Solidified function: setitem +********************************************************************/ +be_local_closure(class_bytes_array_setitem, /* name */ + be_nested_proto( + 8, /* nstack */ + 3, /* argc */ + 10, /* varg */ + 0, /* has upvals */ + NULL, /* no upvals */ + 0, /* has sup protos */ + NULL, /* no sub protos */ + 1, /* has constants */ + &be_ktab_class_bytes_array, /* shared constants */ + &be_const_str_setitem, + &be_const_str_solidified, + ( &(const binstruction[29]) { /* code */ + 0x140C0302, // 0000 LT R3 R1 K2 + 0x780E0001, // 0001 JMPF R3 #0004 + 0x880C0101, // 0002 GETMBR R3 R0 K1 + 0x00040203, // 0003 ADD R1 R1 R3 + 0x140C0302, // 0004 LT R3 R1 K2 + 0x740E0002, // 0005 JMPT R3 #0009 + 0x880C0101, // 0006 GETMBR R3 R0 K1 + 0x280C0203, // 0007 GE R3 R1 R3 + 0x780E0000, // 0008 JMPF R3 #000A + 0xB0061B0F, // 0009 RAISE 1 K13 K15 + 0x880C0100, // 000A GETMBR R3 R0 K0 + 0x54120004, // 000B LDINT R4 5 + 0x1C0C0604, // 000C EQ R3 R3 R4 + 0x780E0006, // 000D JMPF R3 #0015 + 0x8C0C0110, // 000E GETMET R3 R0 K16 + 0x88140105, // 000F GETMBR R5 R0 K5 + 0x08140205, // 0010 MUL R5 R1 R5 + 0x5C180400, // 0011 MOVE R6 R2 + 0x7C0C0600, // 0012 CALL R3 3 + 0x80040600, // 0013 RET 1 R3 + 0x70020006, // 0014 JMP #001C + 0x8C0C0111, // 0015 GETMET R3 R0 K17 + 0x88140105, // 0016 GETMBR R5 R0 K5 + 0x08140205, // 0017 MUL R5 R1 R5 + 0x88180100, // 0018 GETMBR R6 R0 K0 + 0x5C1C0400, // 0019 MOVE R7 R2 + 0x7C0C0800, // 001A CALL R3 4 + 0x80040600, // 001B RET 1 R3 + 0x80000000, // 001C RET 0 + }) + ) +); +/*******************************************************************/ + + +/******************************************************************** +** Solidified class: bytes_array +********************************************************************/ +extern const bclass be_class_bytes; +be_local_class(bytes_array, + 3, + &be_class_bytes, + be_nested_map(8, + ( (struct bmapnode*) &(const bmapnode[]) { + { be_const_key(sz, -1), be_const_var(1) }, + { be_const_key(setitem, -1), be_const_closure(class_bytes_array_setitem_closure) }, + { be_const_key(item_size, -1), be_const_var(2) }, + { be_const_key(init, 7), be_const_closure(class_bytes_array_init_closure) }, + { be_const_key(size, 1), be_const_closure(class_bytes_array_size_closure) }, + { be_const_key(tostring, -1), be_const_closure(class_bytes_array_tostring_closure) }, + { be_const_key(item, -1), be_const_closure(class_bytes_array_item_closure) }, + { be_const_key(item_type, -1), be_const_var(0) }, + })), + (bstring*) &be_const_str_bytes_array +); + +extern const bclass be_class_energy_phases_float; + +/******************************************************************** +** Solidified function: init +********************************************************************/ +be_local_closure(class_energy_phases_float_init, /* name */ + be_nested_proto( + 8, /* nstack */ + 2, /* argc */ + 2, /* varg */ + 0, /* has upvals */ + NULL, /* no upvals */ + 0, /* has sup protos */ + NULL, /* no sub protos */ + 1, /* has constants */ + ( &(const bvalue[ 3]) { /* constants */ + /* K0 */ be_nested_str(energy), + /* K1 */ be_nested_str(init), + /* K2 */ be_nested_str(_phases), + }), + &be_const_str_init, + &be_const_str_solidified, + ( &(const binstruction[10]) { /* code */ + 0xA40A0000, // 0000 IMPORT R2 K0 + 0x600C0003, // 0001 GETGBL R3 G3 + 0x5C100000, // 0002 MOVE R4 R0 + 0x7C0C0200, // 0003 CALL R3 1 + 0x8C0C0701, // 0004 GETMET R3 R3 K1 + 0x5C140200, // 0005 MOVE R5 R1 + 0x541A0004, // 0006 LDINT R6 5 + 0x881C0502, // 0007 GETMBR R7 R2 K2 + 0x7C0C0800, // 0008 CALL R3 4 + 0x80000000, // 0009 RET 0 + }) + ) +); +/*******************************************************************/ + + +/******************************************************************** +** Solidified class: energy_phases_float +********************************************************************/ +extern const bclass be_class_bytes_array; +be_local_class(energy_phases_float, + 0, + &be_class_bytes_array, + be_nested_map(1, + ( (struct bmapnode*) &(const bmapnode[]) { + { be_const_key(init, -1), be_const_closure(class_energy_phases_float_init_closure) }, + })), + (bstring*) &be_const_str_energy_phases_float +); + +extern const bclass be_class_energy_phases_int32; + +/******************************************************************** +** Solidified function: init +********************************************************************/ +be_local_closure(class_energy_phases_int32_init, /* name */ + be_nested_proto( + 8, /* nstack */ + 2, /* argc */ + 2, /* varg */ + 0, /* has upvals */ + NULL, /* no upvals */ + 0, /* has sup protos */ + NULL, /* no sub protos */ + 1, /* has constants */ + ( &(const bvalue[ 3]) { /* constants */ + /* K0 */ be_nested_str(energy), + /* K1 */ be_nested_str(init), + /* K2 */ be_nested_str(_phases), + }), + &be_const_str_init, + &be_const_str_solidified, + ( &(const binstruction[10]) { /* code */ + 0xA40A0000, // 0000 IMPORT R2 K0 + 0x600C0003, // 0001 GETGBL R3 G3 + 0x5C100000, // 0002 MOVE R4 R0 + 0x7C0C0200, // 0003 CALL R3 1 + 0x8C0C0701, // 0004 GETMET R3 R3 K1 + 0x5C140200, // 0005 MOVE R5 R1 + 0x541A0003, // 0006 LDINT R6 4 + 0x881C0502, // 0007 GETMBR R7 R2 K2 + 0x7C0C0800, // 0008 CALL R3 4 + 0x80000000, // 0009 RET 0 + }) + ) +); +/*******************************************************************/ + + +/******************************************************************** +** Solidified class: energy_phases_int32 +********************************************************************/ +extern const bclass be_class_bytes_array; +be_local_class(energy_phases_int32, + 0, + &be_class_bytes_array, + be_nested_map(1, + ( (struct bmapnode*) &(const bmapnode[]) { + { be_const_key(init, -1), be_const_closure(class_energy_phases_int32_init_closure) }, + })), + (bstring*) &be_const_str_energy_phases_int32 +); + +extern const bclass be_class_energy_phases_uint8; + +/******************************************************************** +** Solidified function: init +********************************************************************/ +be_local_closure(class_energy_phases_uint8_init, /* name */ + be_nested_proto( + 8, /* nstack */ + 2, /* argc */ + 2, /* varg */ + 0, /* has upvals */ + NULL, /* no upvals */ + 0, /* has sup protos */ + NULL, /* no sub protos */ + 1, /* has constants */ + ( &(const bvalue[ 4]) { /* constants */ + /* K0 */ be_nested_str(energy), + /* K1 */ be_nested_str(init), + /* K2 */ be_const_int(1), + /* K3 */ be_nested_str(_phases), + }), + &be_const_str_init, + &be_const_str_solidified, + ( &(const binstruction[10]) { /* code */ + 0xA40A0000, // 0000 IMPORT R2 K0 + 0x600C0003, // 0001 GETGBL R3 G3 + 0x5C100000, // 0002 MOVE R4 R0 + 0x7C0C0200, // 0003 CALL R3 1 + 0x8C0C0701, // 0004 GETMET R3 R3 K1 + 0x5C140200, // 0005 MOVE R5 R1 + 0x58180002, // 0006 LDCONST R6 K2 + 0x881C0503, // 0007 GETMBR R7 R2 K3 + 0x7C0C0800, // 0008 CALL R3 4 + 0x80000000, // 0009 RET 0 + }) + ) +); +/*******************************************************************/ + + +/******************************************************************** +** Solidified class: energy_phases_uint8 +********************************************************************/ +extern const bclass be_class_bytes_array; +be_local_class(energy_phases_uint8, + 0, + &be_class_bytes_array, + be_nested_map(1, + ( (struct bmapnode*) &(const bmapnode[]) { + { be_const_key(init, -1), be_const_closure(class_energy_phases_uint8_init_closure) }, + })), + (bstring*) &be_const_str_energy_phases_uint8 +); + +extern const bclass be_class_energy_phases_uint16; + +/******************************************************************** +** Solidified function: init +********************************************************************/ +be_local_closure(class_energy_phases_uint16_init, /* name */ + be_nested_proto( + 8, /* nstack */ + 2, /* argc */ + 2, /* varg */ + 0, /* has upvals */ + NULL, /* no upvals */ + 0, /* has sup protos */ + NULL, /* no sub protos */ + 1, /* has constants */ + ( &(const bvalue[ 4]) { /* constants */ + /* K0 */ be_nested_str(energy), + /* K1 */ be_nested_str(init), + /* K2 */ be_const_int(2), + /* K3 */ be_nested_str(_phases), + }), + &be_const_str_init, + &be_const_str_solidified, + ( &(const binstruction[10]) { /* code */ + 0xA40A0000, // 0000 IMPORT R2 K0 + 0x600C0003, // 0001 GETGBL R3 G3 + 0x5C100000, // 0002 MOVE R4 R0 + 0x7C0C0200, // 0003 CALL R3 1 + 0x8C0C0701, // 0004 GETMET R3 R3 K1 + 0x5C140200, // 0005 MOVE R5 R1 + 0x58180002, // 0006 LDCONST R6 K2 + 0x881C0503, // 0007 GETMBR R7 R2 K3 + 0x7C0C0800, // 0008 CALL R3 4 + 0x80000000, // 0009 RET 0 + }) + ) +); +/*******************************************************************/ + + +/******************************************************************** +** Solidified class: energy_phases_uint16 +********************************************************************/ +extern const bclass be_class_bytes_array; +be_local_class(energy_phases_uint16, + 0, + &be_class_bytes_array, + be_nested_map(1, + ( (struct bmapnode*) &(const bmapnode[]) { + { be_const_key(init, -1), be_const_closure(class_energy_phases_uint16_init_closure) }, + })), + (bstring*) &be_const_str_energy_phases_uint16 +); /******************************************************************** ** Solidified function: init @@ -206,5 +705,45 @@ be_local_closure(module_energy_setmember, /* name */ ); /*******************************************************************/ + +/******************************************************************** +** Solidified function: tomap +********************************************************************/ +be_local_closure(module_energy_tomap, /* name */ + be_nested_proto( + 2, /* nstack */ + 0, /* argc */ + 0, /* varg */ + 0, /* has upvals */ + NULL, /* no upvals */ + 0, /* has sup protos */ + NULL, /* no sub protos */ + 1, /* has constants */ + ( &(const bvalue[ 5]) { /* constants */ + /* K0 */ be_nested_str(energy), + /* K1 */ be_nested_str(_deref), + /* K2 */ be_nested_str(global), + /* K3 */ be_nested_str(_energy), + /* K4 */ be_nested_str(tomap), + }), + &be_const_str_tomap, + &be_const_str_solidified, + ( &(const binstruction[11]) { /* code */ + 0xB8020000, // 0000 GETNGBL R0 K0 + 0x8C000101, // 0001 GETMET R0 R0 K1 + 0x7C000200, // 0002 CALL R0 1 + 0xB8020400, // 0003 GETNGBL R0 K2 + 0x88000103, // 0004 GETMBR R0 R0 K3 + 0x78020003, // 0005 JMPF R0 #000A + 0xB8020600, // 0006 GETNGBL R0 K3 + 0x8C000104, // 0007 GETMET R0 R0 K4 + 0x7C000200, // 0008 CALL R0 1 + 0x80040000, // 0009 RET 1 R0 + 0x80000000, // 000A RET 0 + }) + ) +); +/*******************************************************************/ + /********************************************************************/ /* End of solidification */ diff --git a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_energy.ino b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_energy.ino index 874de687d..fcc55f795 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_energy.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_energy.ino @@ -38,51 +38,68 @@ extern "C" { be_return_nil(vm); } - - #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Winvalid-offsetof" // avoid warnings since we're using offsetof() in a risky way + enum { + PHASES_ARRAY_FLOAT = 1, + PHASES_ARRAY_INT32, + PHASES_ARRAY_UINT8, + PHASES_ARRAY_UINT16, + }; + static const char * be_ctypes_instance_mappings[] = { + "energy._phases_float", + "energy._phases_int32", + "energy._phases_uint8", + "energy._phases_uint16", NULL }; extern "C" const be_ctypes_structure_t be_energy_struct = { sizeof(tEnergy), /* size in bytes */ - 88, /* number of elements */ + 68, /* number of elements */ be_ctypes_instance_mappings, - (const be_ctypes_structure_item_t[88]) { + (const be_ctypes_structure_item_t[68]) { { "active_power", offsetof(tEnergy, active_power[0]), 0, 0, ctypes_float, 0 }, - { "active_power_2", offsetof(tEnergy, active_power[1]), 0, 0, ctypes_float, 0 }, - { "active_power_3", offsetof(tEnergy, active_power[2]), 0, 0, ctypes_float, 0 }, + // { "active_power_2", offsetof(tEnergy, active_power[1]), 0, 0, ctypes_float, 0 }, + // { "active_power_3", offsetof(tEnergy, active_power[2]), 0, 0, ctypes_float, 0 }, + { "active_power_phases", offsetof(tEnergy, active_power[0]), 0, 0, ctypes_addr, PHASES_ARRAY_FLOAT }, { "apparent_power", offsetof(tEnergy, apparent_power[0]), 0, 0, ctypes_float, 0 }, - { "apparent_power_2", offsetof(tEnergy, apparent_power[1]), 0, 0, ctypes_float, 0 }, - { "apparent_power_3", offsetof(tEnergy, apparent_power[2]), 0, 0, ctypes_float, 0 }, + // { "apparent_power_2", offsetof(tEnergy, apparent_power[1]), 0, 0, ctypes_float, 0 }, + // { "apparent_power_3", offsetof(tEnergy, apparent_power[2]), 0, 0, ctypes_float, 0 }, + { "apparent_power_phases", offsetof(tEnergy, apparent_power[0]), 0, 0, ctypes_addr, PHASES_ARRAY_FLOAT }, { "command_code", offsetof(tEnergy, command_code), 0, 0, ctypes_u8, 0 }, { "current", offsetof(tEnergy, current[0]), 0, 0, ctypes_float, 0 }, - { "current_2", offsetof(tEnergy, current[1]), 0, 0, ctypes_float, 0 }, - { "current_3", offsetof(tEnergy, current[2]), 0, 0, ctypes_float, 0 }, + // { "current_2", offsetof(tEnergy, current[1]), 0, 0, ctypes_float, 0 }, + // { "current_3", offsetof(tEnergy, current[2]), 0, 0, ctypes_float, 0 }, { "current_available", offsetof(tEnergy, current_available), 0, 0, ctypes_u8, 0 }, + { "current_phases", offsetof(tEnergy, current[0]), 0, 0, ctypes_addr, PHASES_ARRAY_FLOAT }, { "daily", offsetof(tEnergy, daily_kWh[0]), 0, 0, ctypes_float, 0 }, - { "daily_2", offsetof(tEnergy, daily_kWh[1]), 0, 0, ctypes_float, 0 }, - { "daily_3", offsetof(tEnergy, daily_kWh[2]), 0, 0, ctypes_float, 0 }, + // { "daily_2", offsetof(tEnergy, daily_kWh[1]), 0, 0, ctypes_float, 0 }, + // { "daily_3", offsetof(tEnergy, daily_kWh[2]), 0, 0, ctypes_float, 0 }, + { "daily_phases", offsetof(tEnergy, daily_kWh[0]), 0, 0, ctypes_addr, PHASES_ARRAY_FLOAT }, { "daily_sum", offsetof(tEnergy, daily_sum), 0, 0, ctypes_float, 0 }, { "daily_sum_export_balanced", offsetof(tEnergy, daily_sum_export_balanced), 0, 0, ctypes_float, 0 }, { "daily_sum_import_balanced", offsetof(tEnergy, daily_sum_import_balanced), 0, 0, ctypes_float, 0 }, { "data_valid", offsetof(tEnergy, data_valid[0]), 0, 0, ctypes_u8, 0 }, - { "data_valid_2", offsetof(tEnergy, data_valid[1]), 0, 0, ctypes_u8, 0 }, - { "data_valid_3", offsetof(tEnergy, data_valid[2]), 0, 0, ctypes_u8, 0 }, + // { "data_valid_2", offsetof(tEnergy, data_valid[1]), 0, 0, ctypes_u8, 0 }, + // { "data_valid_3", offsetof(tEnergy, data_valid[2]), 0, 0, ctypes_u8, 0 }, + { "data_valid_phases", offsetof(tEnergy, data_valid[0]), 0, 0, ctypes_addr, PHASES_ARRAY_UINT8 }, { "energy_active_export", offsetof(tEnergy, local_energy_active_export), 0, 0, ctypes_u8, 0 }, { "export_active", offsetof(tEnergy, export_active[0]), 0, 0, ctypes_float, 0 }, - { "export_active_2", offsetof(tEnergy, export_active[1]), 0, 0, ctypes_float, 0 }, - { "export_active_3", offsetof(tEnergy, export_active[2]), 0, 0, ctypes_float, 0 }, + // { "export_active_2", offsetof(tEnergy, export_active[1]), 0, 0, ctypes_float, 0 }, + // { "export_active_3", offsetof(tEnergy, export_active[2]), 0, 0, ctypes_float, 0 }, + { "export_active_phases", offsetof(tEnergy, export_active[0]), 0, 0, ctypes_addr, PHASES_ARRAY_FLOAT }, { "fifth_second", offsetof(tEnergy, fifth_second), 0, 0, ctypes_u8, 0 }, { "frequency", offsetof(tEnergy, frequency[0]), 0, 0, ctypes_float, 0 }, - { "frequency_2", offsetof(tEnergy, frequency[1]), 0, 0, ctypes_float, 0 }, - { "frequency_3", offsetof(tEnergy, frequency[2]), 0, 0, ctypes_float, 0 }, + // { "frequency_2", offsetof(tEnergy, frequency[1]), 0, 0, ctypes_float, 0 }, + // { "frequency_3", offsetof(tEnergy, frequency[2]), 0, 0, ctypes_float, 0 }, { "frequency_common", offsetof(tEnergy, frequency_common), 0, 0, ctypes_u8, 0 }, + { "frequency_phases", offsetof(tEnergy, frequency[0]), 0, 0, ctypes_addr, PHASES_ARRAY_FLOAT }, { "import_active", offsetof(tEnergy, import_active[0]), 0, 0, ctypes_float, 0 }, - { "import_active_2", offsetof(tEnergy, import_active[1]), 0, 0, ctypes_float, 0 }, - { "import_active_3", offsetof(tEnergy, import_active[2]), 0, 0, ctypes_float, 0 }, + // { "import_active_2", offsetof(tEnergy, import_active[1]), 0, 0, ctypes_float, 0 }, + // { "import_active_3", offsetof(tEnergy, import_active[2]), 0, 0, ctypes_float, 0 }, + { "import_active_phases", offsetof(tEnergy, import_active[0]), 0, 0, ctypes_addr, PHASES_ARRAY_FLOAT }, { "max_current_flag", offsetof(tEnergy, max_current_flag[0]), 0, 0, ctypes_u8, 0 }, { "max_energy_state", offsetof(tEnergy, max_energy_state[0]), 0, 0, ctypes_u8, 0 }, { "max_power_flag", offsetof(tEnergy, max_power_flag[0]), 0, 0, ctypes_u8, 0 }, @@ -94,50 +111,62 @@ extern "C" { { "mpl_retry_counter", offsetof(tEnergy, mpl_retry_counter[0]), 0, 0, ctypes_u8, 0 }, { "mpl_window_counter", offsetof(tEnergy, mpl_window_counter[0]), 0, 0, ctypes_u16, 0 }, { "period", offsetof(tEnergy, period_kWh[0]), 0, 0, ctypes_float, 0 }, - { "period_2", offsetof(tEnergy, period_kWh[1]), 0, 0, ctypes_float, 0 }, - { "period_3", offsetof(tEnergy, period_kWh[2]), 0, 0, ctypes_float, 0 }, + // { "period_2", offsetof(tEnergy, period_kWh[1]), 0, 0, ctypes_float, 0 }, + // { "period_3", offsetof(tEnergy, period_kWh[2]), 0, 0, ctypes_float, 0 }, + { "period_phases", offsetof(tEnergy, period_kWh[0]), 0, 0, ctypes_addr, PHASES_ARRAY_FLOAT }, { "phase_count", offsetof(tEnergy, phase_count), 0, 0, ctypes_u8, 0 }, { "power_factor", offsetof(tEnergy, power_factor[0]), 0, 0, ctypes_float, 0 }, - { "power_factor_2", offsetof(tEnergy, power_factor[1]), 0, 0, ctypes_float, 0 }, - { "power_factor_3", offsetof(tEnergy, power_factor[2]), 0, 0, ctypes_float, 0 }, + // { "power_factor_2", offsetof(tEnergy, power_factor[1]), 0, 0, ctypes_float, 0 }, + // { "power_factor_3", offsetof(tEnergy, power_factor[2]), 0, 0, ctypes_float, 0 }, + { "power_factor_phases", offsetof(tEnergy, power_factor[0]), 0, 0, ctypes_addr, PHASES_ARRAY_FLOAT }, { "power_history_0", offsetof(tEnergy, power_history[0][0]), 0, 0, ctypes_u16, 0 }, - { "power_history_0_2", offsetof(tEnergy, power_history[0][1]), 0, 0, ctypes_u16, 0 }, - { "power_history_0_3", offsetof(tEnergy, power_history[0][2]), 0, 0, ctypes_u16, 0 }, + // { "power_history_0_2", offsetof(tEnergy, power_history[0][1]), 0, 0, ctypes_u16, 0 }, + // { "power_history_0_3", offsetof(tEnergy, power_history[0][2]), 0, 0, ctypes_u16, 0 }, + { "power_history_0_phases", offsetof(tEnergy, power_history[0][0]), 0, 0, ctypes_addr, PHASES_ARRAY_UINT16 }, { "power_history_1", offsetof(tEnergy, power_history[1][0]), 0, 0, ctypes_u16, 0 }, - { "power_history_1_2", offsetof(tEnergy, power_history[1][1]), 0, 0, ctypes_u16, 0 }, - { "power_history_1_3", offsetof(tEnergy, power_history[1][2]), 0, 0, ctypes_u16, 0 }, + // { "power_history_1_2", offsetof(tEnergy, power_history[1][1]), 0, 0, ctypes_u16, 0 }, + // { "power_history_1_3", offsetof(tEnergy, power_history[1][2]), 0, 0, ctypes_u16, 0 }, + { "power_history_1_phases", offsetof(tEnergy, power_history[1][0]), 0, 0, ctypes_addr, PHASES_ARRAY_UINT16 }, { "power_history_2", offsetof(tEnergy, power_history[2][0]), 0, 0, ctypes_u16, 0 }, - { "power_history_2_2", offsetof(tEnergy, power_history[2][1]), 0, 0, ctypes_u16, 0 }, - { "power_history_2_3", offsetof(tEnergy, power_history[2][2]), 0, 0, ctypes_u16, 0 }, + // { "power_history_2_2", offsetof(tEnergy, power_history[2][1]), 0, 0, ctypes_u16, 0 }, + // { "power_history_2_3", offsetof(tEnergy, power_history[2][2]), 0, 0, ctypes_u16, 0 }, + { "power_history_2_phases", offsetof(tEnergy, power_history[2][0]), 0, 0, ctypes_addr, PHASES_ARRAY_UINT16 }, { "power_on", offsetof(tEnergy, power_on), 0, 0, ctypes_u8, 0 }, { "power_steady_counter", offsetof(tEnergy, power_steady_counter), 0, 0, ctypes_u8, 0 }, { "reactive_power", offsetof(tEnergy, reactive_power[0]), 0, 0, ctypes_float, 0 }, - { "reactive_power_2", offsetof(tEnergy, reactive_power[1]), 0, 0, ctypes_float, 0 }, - { "reactive_power_3", offsetof(tEnergy, reactive_power[2]), 0, 0, ctypes_float, 0 }, + // { "reactive_power_2", offsetof(tEnergy, reactive_power[1]), 0, 0, ctypes_float, 0 }, + // { "reactive_power_3", offsetof(tEnergy, reactive_power[2]), 0, 0, ctypes_float, 0 }, + { "reactive_power_phases", offsetof(tEnergy, reactive_power[0]), 0, 0, ctypes_addr, PHASES_ARRAY_FLOAT }, { "start_energy", offsetof(tEnergy, start_energy[0]), 0, 0, ctypes_float, 0 }, - { "start_energy_2", offsetof(tEnergy, start_energy[1]), 0, 0, ctypes_float, 0 }, - { "start_energy_3", offsetof(tEnergy, start_energy[2]), 0, 0, ctypes_float, 0 }, - { "today_delta_kwh", offsetof(tEnergy, kWhtoday_delta[0]), 0, 0, ctypes_u32, 0 }, - { "today_delta_kwh_2", offsetof(tEnergy, kWhtoday_delta[1]), 0, 0, ctypes_u32, 0 }, - { "today_delta_kwh_3", offsetof(tEnergy, kWhtoday_delta[2]), 0, 0, ctypes_u32, 0 }, - { "today_kwh", offsetof(tEnergy, kWhtoday[0]), 0, 0, ctypes_u32, 0 }, - { "today_kwh_2", offsetof(tEnergy, kWhtoday[1]), 0, 0, ctypes_u32, 0 }, - { "today_kwh_3", offsetof(tEnergy, kWhtoday[2]), 0, 0, ctypes_u32, 0 }, + // { "start_energy_2", offsetof(tEnergy, start_energy[1]), 0, 0, ctypes_float, 0 }, + // { "start_energy_3", offsetof(tEnergy, start_energy[2]), 0, 0, ctypes_float, 0 }, + { "start_energy_phases", offsetof(tEnergy, start_energy[0]), 0, 0, ctypes_addr, PHASES_ARRAY_FLOAT }, + { "today_delta_kwh", offsetof(tEnergy, kWhtoday_delta[0]), 0, 0, ctypes_i32, 0 }, + // { "today_delta_kwh_2", offsetof(tEnergy, kWhtoday_delta[1]), 0, 0, ctypes_i32, 0 }, + // { "today_delta_kwh_3", offsetof(tEnergy, kWhtoday_delta[2]), 0, 0, ctypes_i32, 0 }, + { "today_delta_kwh_phases", offsetof(tEnergy, kWhtoday_delta[0]), 0, 0, ctypes_addr, PHASES_ARRAY_UINT8 }, + { "today_kwh", offsetof(tEnergy, kWhtoday[0]), 0, 0, ctypes_i32, 0 }, + // { "today_kwh_2", offsetof(tEnergy, kWhtoday[1]), 0, 0, ctypes_i32, 0 }, + // { "today_kwh_3", offsetof(tEnergy, kWhtoday[2]), 0, 0, ctypes_i32, 0 }, + { "today_kwh_phases", offsetof(tEnergy, kWhtoday[0]), 0, 0, ctypes_addr, PHASES_ARRAY_INT32 }, { "today_offset_init_kwh", offsetof(tEnergy, kWhtoday_offset_init), 0, 0, ctypes_u8, 0 }, { "today_offset_kwh", offsetof(tEnergy, energy_today_offset_kWh[0]), 0, 0, ctypes_float, 0 }, - { "today_offset_kwh_2", offsetof(tEnergy, energy_today_offset_kWh[1]), 0, 0, ctypes_float, 0 }, - { "today_offset_kwh_3", offsetof(tEnergy, energy_today_offset_kWh[2]), 0, 0, ctypes_float, 0 }, + // { "today_offset_kwh_2", offsetof(tEnergy, energy_today_offset_kWh[1]), 0, 0, ctypes_float, 0 }, + // { "today_offset_kwh_3", offsetof(tEnergy, energy_today_offset_kWh[2]), 0, 0, ctypes_float, 0 }, + { "today_offset_kwh_phases", offsetof(tEnergy, energy_today_offset_kWh[0]), 0, 0, ctypes_addr, PHASES_ARRAY_FLOAT }, { "total", offsetof(tEnergy, total[0]), 0, 0, ctypes_float, 0 }, - { "total_2", offsetof(tEnergy, total[1]), 0, 0, ctypes_float, 0 }, - { "total_3", offsetof(tEnergy, total[2]), 0, 0, ctypes_float, 0 }, + // { "total_2", offsetof(tEnergy, total[1]), 0, 0, ctypes_float, 0 }, + // { "total_3", offsetof(tEnergy, total[2]), 0, 0, ctypes_float, 0 }, + { "total_phases", offsetof(tEnergy, total[0]), 0, 0, ctypes_addr, PHASES_ARRAY_FLOAT }, { "total_sum", offsetof(tEnergy, total_sum), 0, 0, ctypes_float, 0 }, { "type_dc", offsetof(tEnergy, type_dc), 0, 0, ctypes_u8, 0 }, { "use_overtemp", offsetof(tEnergy, use_overtemp), 0, 0, ctypes_u8, 0 }, { "voltage", offsetof(tEnergy, voltage[0]), 0, 0, ctypes_float, 0 }, - { "voltage_2", offsetof(tEnergy, voltage[1]), 0, 0, ctypes_float, 0 }, - { "voltage_3", offsetof(tEnergy, voltage[2]), 0, 0, ctypes_float, 0 }, + // { "voltage_2", offsetof(tEnergy, voltage[1]), 0, 0, ctypes_float, 0 }, + // { "voltage_3", offsetof(tEnergy, voltage[2]), 0, 0, ctypes_float, 0 }, { "voltage_available", offsetof(tEnergy, voltage_available), 0, 0, ctypes_u8, 0 }, { "voltage_common", offsetof(tEnergy, voltage_common), 0, 0, ctypes_u8, 0 }, + { "voltage_phases", offsetof(tEnergy, voltage[0]), 0, 0, ctypes_addr, PHASES_ARRAY_FLOAT }, { "yesterday_sum", offsetof(tEnergy, yesterday_sum), 0, 0, ctypes_float, 0 }, }}; // be_define_ctypes_class(energy_struct, &be_energy_struct, &be_class_ctypes_bytes, "energy_struct");