Merge pull request #15730 from s-hadinger/zigbee_zcl_frame_payload

Berry Zigbee support payload of zcl_frame as bytes()
This commit is contained in:
s-hadinger 2022-06-01 22:22:09 +02:00 committed by GitHub
commit 6d58e801f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 1423 additions and 1402 deletions

View File

@ -246,6 +246,7 @@ extern const bcstring be_const_str__energy;
extern const bcstring be_const_str__error;
extern const bcstring be_const_str__filename;
extern const bcstring be_const_str__fl;
extern const bcstring be_const_str__get_bytes;
extern const bcstring be_const_str__global_addr;
extern const bcstring be_const_str__global_def;
extern const bcstring be_const_str__lvgl;
@ -256,6 +257,7 @@ extern const bcstring be_const_str__read;
extern const bcstring be_const_str__request_from;
extern const bcstring be_const_str__rmt;
extern const bcstring be_const_str__rules;
extern const bcstring be_const_str__set_bytes;
extern const bcstring be_const_str__settings_def;
extern const bcstring be_const_str__settings_ptr;
extern const bcstring be_const_str__splash;

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,14 @@
#include "be_constobj.h"
static be_define_const_map_slots(be_class_zcl_frame_ntv_map) {
{ be_const_key(_def, -1), be_const_comptr(&be_zigbee_zcl_frame_struct) },
{ be_const_key(_set_bytes, -1), be_const_ctype_func(zfn_set_bytes) },
{ be_const_key(_def, 2), be_const_comptr(&be_zigbee_zcl_frame_struct) },
{ be_const_key(_get_bytes, -1), be_const_ctype_func(zfn_get_bytes) },
};
static be_define_const_map(
be_class_zcl_frame_ntv_map,
1
3
);
BE_EXPORT_VARIABLE be_define_const_class(

View File

@ -127,6 +127,16 @@ static int zigbee_init(bvm *vm) {
be_return(vm);
}
/*******************************************************************/
extern void* zfn_get_bytes(void* sbuf_ptr, size_t *len_bytes);
BE_FUNC_CTYPE_DECLARE(zfn_get_bytes, "&", "-c");
extern void zfn_set_bytes(void* sbuf_ptr, const uint8_t* bytes, size_t len_bytes);
BE_FUNC_CTYPE_DECLARE(zfn_set_bytes, "", "-c(bytes)~");
/*******************************************************************/
#include "be_fixed_be_class_zb_device.h"
#include "be_fixed_be_class_zb_coord_ntv.h"
#include "be_fixed_be_class_zcl_frame_ntv.h"
@ -161,6 +171,9 @@ class be_class_zb_coord_ntv (scope: global, name: zb_coord_ntv) {
/* @const_object_info_begin
class be_class_zcl_frame_ntv (scope: global, name: zcl_frame_ntv, super: be_class_ctypes_bytes) {
_def, comptr(&be_zigbee_zcl_frame_struct)
_get_bytes, ctype_func(zfn_get_bytes)
_set_bytes, ctype_func(zfn_set_bytes)
}
@const_object_info_end */

View File

@ -22,28 +22,111 @@ be_local_closure(zcl_frame_member, /* name */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 3]) { /* constants */
( &(const bvalue[ 4]) { /* constants */
/* K0 */ be_nested_str_literal("payload"),
/* K1 */ be_nested_str_literal("_get_bytes"),
/* K2 */ be_nested_str_literal("member"),
/* K2 */ be_nested_str_literal("payload_ptr"),
/* K3 */ be_nested_str_literal("member"),
}),
be_str_literal("member"),
&be_const_str_solidified,
( &(const binstruction[14]) { /* code */
( &(const binstruction[15]) { /* code */
0x1C080300, // 0000 EQ R2 R1 K0
0x780A0003, // 0001 JMPF R2 #0006
0x780A0004, // 0001 JMPF R2 #0007
0x8C080101, // 0002 GETMET R2 R0 K1
0x7C080200, // 0003 CALL R2 1
0x80040400, // 0004 RET 1 R2
0x70020006, // 0005 JMP #000D
0x60080003, // 0006 GETGBL R2 G3
0x5C0C0000, // 0007 MOVE R3 R0
0x7C080200, // 0008 CALL R2 1
0x8C080502, // 0009 GETMET R2 R2 K2
0x5C100200, // 000A MOVE R4 R1
0x7C080400, // 000B CALL R2 2
0x80040400, // 000C RET 1 R2
0x80000000, // 000D RET 0
0x88100102, // 0003 GETMBR R4 R0 K2
0x7C080400, // 0004 CALL R2 2
0x80040400, // 0005 RET 1 R2
0x70020006, // 0006 JMP #000E
0x60080003, // 0007 GETGBL R2 G3
0x5C0C0000, // 0008 MOVE R3 R0
0x7C080200, // 0009 CALL R2 1
0x8C080503, // 000A GETMET R2 R2 K3
0x5C100200, // 000B MOVE R4 R1
0x7C080400, // 000C CALL R2 2
0x80040400, // 000D RET 1 R2
0x80000000, // 000E RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: setmember
********************************************************************/
be_local_closure(zcl_frame_setmember, /* name */
be_nested_proto(
7, /* nstack */
3, /* 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_literal("payload"),
/* K1 */ be_nested_str_literal("_set_bytes"),
/* K2 */ be_nested_str_literal("payload_ptr"),
/* K3 */ be_nested_str_literal("setmember"),
}),
be_str_literal("setmember"),
&be_const_str_solidified,
( &(const binstruction[17]) { /* code */
0x1C0C0300, // 0000 EQ R3 R1 K0
0x780E0005, // 0001 JMPF R3 #0008
0x8C0C0101, // 0002 GETMET R3 R0 K1
0x88140102, // 0003 GETMBR R5 R0 K2
0x5C180400, // 0004 MOVE R6 R2
0x7C0C0600, // 0005 CALL R3 3
0x80040600, // 0006 RET 1 R3
0x70020007, // 0007 JMP #0010
0x600C0003, // 0008 GETGBL R3 G3
0x5C100000, // 0009 MOVE R4 R0
0x7C0C0200, // 000A CALL R3 1
0x8C0C0703, // 000B GETMET R3 R3 K3
0x5C140200, // 000C MOVE R5 R1
0x5C180400, // 000D MOVE R6 R2
0x7C0C0600, // 000E CALL R3 3
0x80040600, // 000F RET 1 R3
0x80000000, // 0010 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: init
********************************************************************/
be_local_closure(zcl_frame_init, /* name */
be_nested_proto(
5, /* nstack */
2, /* argc */
2, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 2]) { /* constants */
/* K0 */ be_nested_str_literal("init"),
/* K1 */ be_nested_str_literal("no_bytes"),
}),
be_str_literal("init"),
&be_const_str_solidified,
( &(const binstruction[10]) { /* code */
0x60080003, // 0000 GETGBL R2 G3
0x5C0C0000, // 0001 MOVE R3 R0
0x7C080200, // 0002 CALL R2 1
0x8C080500, // 0003 GETMET R2 R2 K0
0x5C100200, // 0004 MOVE R4 R1
0x7C080400, // 0005 CALL R2 2
0x60080015, // 0006 GETGBL R2 G21
0x7C080000, // 0007 CALL R2 0
0x90020202, // 0008 SETMBR R0 K1 R2
0x80000000, // 0009 RET 0
})
)
);
@ -95,105 +178,6 @@ be_local_closure(zcl_frame_tomap, /* name */
/*******************************************************************/
/********************************************************************
** Solidified function: init
********************************************************************/
be_local_closure(zcl_frame_init, /* name */
be_nested_proto(
5, /* nstack */
2, /* argc */
2, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 2]) { /* constants */
/* K0 */ be_nested_str_literal("init"),
/* K1 */ be_nested_str_literal("no_bytes"),
}),
be_str_literal("init"),
&be_const_str_solidified,
( &(const binstruction[10]) { /* code */
0x60080003, // 0000 GETGBL R2 G3
0x5C0C0000, // 0001 MOVE R3 R0
0x7C080200, // 0002 CALL R2 1
0x8C080500, // 0003 GETMET R2 R2 K0
0x5C100200, // 0004 MOVE R4 R1
0x7C080400, // 0005 CALL R2 2
0x60080015, // 0006 GETGBL R2 G21
0x7C080000, // 0007 CALL R2 0
0x90020202, // 0008 SETMBR R0 K1 R2
0x80000000, // 0009 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: _get_bytes
********************************************************************/
be_local_closure(zcl_frame__get_bytes, /* name */
be_nested_proto(
10, /* nstack */
1, /* argc */
2, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 7]) { /* constants */
/* K0 */ be_nested_str_literal("introspect"),
/* K1 */ be_nested_str_literal("toptr"),
/* K2 */ be_nested_str_literal("payload_ptr"),
/* K3 */ be_const_int(0),
/* K4 */ be_nested_str_literal("get"),
/* K5 */ be_const_int(2),
/* K6 */ be_nested_str_literal("no_bytes"),
}),
be_str_literal("_get_bytes"),
&be_const_str_solidified,
( &(const binstruction[32]) { /* code */
0xA4060000, // 0000 IMPORT R1 K0
0x8C080301, // 0001 GETMET R2 R1 K1
0x88100102, // 0002 GETMBR R4 R0 K2
0x7C080400, // 0003 CALL R2 2
0x600C0009, // 0004 GETGBL R3 G9
0x5C100400, // 0005 MOVE R4 R2
0x7C0C0200, // 0006 CALL R3 1
0x200C0703, // 0007 NE R3 R3 K3
0x780E0013, // 0008 JMPF R3 #001D
0x600C0015, // 0009 GETGBL R3 G21
0x5C100400, // 000A MOVE R4 R2
0x5415FFFB, // 000B LDINT R5 -4
0x7C0C0400, // 000C CALL R3 2
0x8C100704, // 000D GETMET R4 R3 K4
0x58180005, // 000E LDCONST R6 K5
0x581C0005, // 000F LDCONST R7 K5
0x7C100600, // 0010 CALL R4 3
0x60140015, // 0011 GETGBL R5 G21
0x8C180301, // 0012 GETMET R6 R1 K1
0x60200009, // 0013 GETGBL R8 G9
0x5C240400, // 0014 MOVE R9 R2
0x7C200200, // 0015 CALL R8 1
0x54260003, // 0016 LDINT R9 4
0x00201009, // 0017 ADD R8 R8 R9
0x7C180400, // 0018 CALL R6 2
0x5C1C0800, // 0019 MOVE R7 R4
0x7C140400, // 001A CALL R5 2
0x80040A00, // 001B RET 1 R5
0x70020001, // 001C JMP #001F
0x880C0106, // 001D GETMBR R3 R0 K6
0x80040600, // 001E RET 1 R3
0x80000000, // 001F RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: tostring
********************************************************************/
@ -236,10 +220,10 @@ be_local_class(zcl_frame,
( (struct bmapnode*) &(const bmapnode[]) {
{ be_const_key_literal("no_bytes", -1), be_const_var(0) },
{ be_const_key_literal("member", 2), be_const_closure(zcl_frame_member_closure) },
{ be_const_key_literal("tostring", -1), be_const_closure(zcl_frame_tostring_closure) },
{ be_const_key_literal("tostring", 5), be_const_closure(zcl_frame_tostring_closure) },
{ be_const_key_literal("init", -1), be_const_closure(zcl_frame_init_closure) },
{ be_const_key_literal("tomap", 5), be_const_closure(zcl_frame_tomap_closure) },
{ be_const_key_literal("_get_bytes", -1), be_const_closure(zcl_frame__get_bytes_closure) },
{ be_const_key_literal("tomap", -1), be_const_closure(zcl_frame_tomap_closure) },
{ be_const_key_literal("setmember", -1), be_const_closure(zcl_frame_setmember_closure) },
})),
be_str_literal("zcl_frame")
);

View File

@ -2,7 +2,7 @@
#
# solidify.dump(zcl_frame,true)
var zcl_frame_ntv = super(zcl_frame)
class zcl_frame_ntv end
class zcl_frame : zcl_frame_ntv
var no_bytes
@ -14,23 +14,17 @@ class zcl_frame : zcl_frame_ntv
def member(name)
if name == "payload"
return self._get_bytes()
return self._get_bytes(self.payload_ptr)
else
return super(self).member(name)
end
end
# return a bytes() object from a pre-populated zcl_frame payload
def _get_bytes()
import introspect
var payload_ptr = introspect.toptr(self.payload_ptr)
if int(payload_ptr) != 0
var sbuffer = bytes(payload_ptr, -4)
var sbuffer_len = sbuffer.get(2,2)
return bytes(introspect.toptr(int(payload_ptr) + 4), sbuffer_len)
def setmember(name, val)
if name == "payload"
return self._set_bytes(self.payload_ptr, val)
else
return self.no_bytes
return super(self).setmember(name, val)
end
end

View File

@ -234,6 +234,29 @@ extern "C" {
#pragma GCC diagnostic pop
}
/*********************************************************************************************\
* Functions for zcl_frame
*
\*********************************************************************************************/
extern "C" {
void* zfn_get_bytes(void* sbuf_ptr, size_t *len_bytes) {
if (sbuf_ptr == NULL || len_bytes == NULL) { return NULL; }
const SBuffer &sbuf = (const SBuffer&) sbuf_ptr;
*len_bytes = sbuf.getLen();
return sbuf.getBuffer();
}
void zfn_set_bytes(void* sbuf_ptr, const uint8_t* bytes, size_t len_bytes) {
if (sbuf_ptr == NULL || bytes == NULL) { return; }
SBuffer &sbuf = (SBuffer&) sbuf_ptr;
sbuf.reserve(len_bytes); // make sure it's large enough
sbuf.setLen(0); // clear content
sbuf.addBuffer(bytes, len_bytes); // add content of bytes() buffer
}
}
#endif // USE_ZIGBEE
#endif // USE_BERRY