mirror of
https://github.com/qmk/qmk_firmware.git
synced 2024-11-26 21:26:46 +00:00
partial gen for return_execute
This commit is contained in:
parent
5a099e1ad7
commit
6269c6b51c
@ -234,7 +234,7 @@
|
||||
request_type: u16
|
||||
request_purpose: offset
|
||||
return_type: u8[32]
|
||||
return_execute: info_json_gz
|
||||
return_execute: get_info_json_chunk
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -51,7 +51,7 @@ def print_dotted_output(kb_info_json, prefix=''):
|
||||
def _xap_transaction(device, sub, route, ret_len, *args):
|
||||
# gen token
|
||||
tok = random.getrandbits(16)
|
||||
token = tok.to_bytes(2, byteorder='big')
|
||||
token = tok.to_bytes(2, byteorder='little')
|
||||
|
||||
# send with padding
|
||||
# TODO: this code is total garbage
|
||||
@ -59,13 +59,13 @@ def _xap_transaction(device, sub, route, ret_len, *args):
|
||||
args_len = 2
|
||||
if len(args) == 1:
|
||||
args_len += 2
|
||||
args_data = args[0].to_bytes(2, byteorder='big')
|
||||
args_data = args[0].to_bytes(2, byteorder='little')
|
||||
|
||||
padding_len = 64 - 3 - args_len
|
||||
padding = b"\x00" * padding_len
|
||||
if args_data:
|
||||
padding = args_data + padding
|
||||
buffer = token + args_len.to_bytes(1, byteorder='big') + sub.to_bytes(1, byteorder='big') + route.to_bytes(1, byteorder='big') + padding
|
||||
buffer = token + args_len.to_bytes(1, byteorder='little') + sub.to_bytes(1, byteorder='little') + route.to_bytes(1, byteorder='little') + padding
|
||||
|
||||
# prepend 0 on windows because reasons...
|
||||
if 'windows' in platform().lower():
|
||||
|
@ -24,6 +24,20 @@ def _get_c_type(xap_type):
|
||||
return 'unknown'
|
||||
|
||||
|
||||
def _get_c_size(xap_type):
|
||||
if xap_type == 'u8':
|
||||
return 1
|
||||
elif xap_type == 'u16':
|
||||
return 2
|
||||
elif xap_type == 'u32':
|
||||
return 4
|
||||
elif xap_type == 'u64':
|
||||
return 8
|
||||
elif xap_type == 'u8[32]':
|
||||
return 32
|
||||
return -1
|
||||
|
||||
|
||||
def _get_route_type(container):
|
||||
if 'routes' in container:
|
||||
return 'XAP_ROUTE'
|
||||
@ -52,8 +66,26 @@ def _append_routing_table_declaration(lines, container, container_id, route_stac
|
||||
|
||||
elif 'return_execute' in container:
|
||||
execute = container['return_execute']
|
||||
lines.append('')
|
||||
lines.append(f'bool xap_respond_{execute}(xap_token_t token, const uint8_t *data, size_t data_len);')
|
||||
request_type = container['request_type']
|
||||
return_type = container['return_type']
|
||||
lines.append(f'''
|
||||
bool xap_respond_{execute}(xap_token_t token, const uint8_t *data, size_t data_len) {{
|
||||
if (data_len != sizeof({_get_c_type(request_type)})) {{
|
||||
xap_respond_failure(token, 0);
|
||||
return false;
|
||||
}}
|
||||
|
||||
uint8_t ret[{_get_c_size(return_type)}] = {{0}};
|
||||
{_get_c_type(request_type)} *argp = ({_get_c_type(request_type)} *)&data[0];
|
||||
|
||||
bool {execute}({_get_c_type(request_type)} arg, uint8_t *ret, uint8_t ret_len);
|
||||
if(!{execute}(*argp, ret, sizeof(ret))) {{
|
||||
xap_respond_failure(token, 0);
|
||||
return false;
|
||||
}}
|
||||
|
||||
return xap_respond_data(token, ret, sizeof(ret));
|
||||
}}''')
|
||||
|
||||
elif 'return_constant' in container:
|
||||
|
||||
|
@ -18,13 +18,13 @@
|
||||
#include <xap.h>
|
||||
|
||||
#include "info_json_gz.h"
|
||||
void get_info_json_chunk(uint8_t *data, size_t offset) {
|
||||
uint8_t len = 32;
|
||||
if (offset + len > info_json_gz_len) {
|
||||
len = info_json_gz_len - offset;
|
||||
bool get_info_json_chunk(uint16_t offset, uint8_t *data, uint8_t data_len) {
|
||||
if (offset + data_len > info_json_gz_len) {
|
||||
data_len = info_json_gz_len - offset;
|
||||
}
|
||||
|
||||
memcpy_P(data, &info_json_gz[offset], len);
|
||||
memcpy_P(data, &info_json_gz[offset], data_len);
|
||||
return true;
|
||||
}
|
||||
|
||||
#define QSTR2(z) #z
|
||||
|
@ -40,18 +40,3 @@ bool xap_respond_u32(xap_token_t token, uint32_t value) {
|
||||
uint32_t xap_route_qmk_ffffffffffffffff_getter(void) {
|
||||
return 0x12345678;
|
||||
}
|
||||
|
||||
bool xap_respond_info_json_gz(xap_token_t token, const uint8_t *data, size_t data_len) {
|
||||
if (data_len != 2) {
|
||||
xap_respond_failure(token, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t blob[32] = {0};
|
||||
uint16_t offset = ((uint16_t)data[0]) << 8 | data[1];
|
||||
|
||||
void get_info_json_chunk(uint8_t * data, size_t offset);
|
||||
get_info_json_chunk(blob, offset);
|
||||
|
||||
return xap_respond_data(token, blob, 32);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user