53 lines
1.6 KiB
C
Raw Normal View History

2022-04-16 00:02:41 +08:00
#include "ctypes_Test.h"
2022-04-18 18:44:14 +08:00
#include "ctypes_c_float.h"
2022-04-16 11:38:47 +08:00
#include "ctypes_c_uint.h"
#include "ctypes_c_wchar_p.h"
#include "ctypes_utils.h"
2022-04-16 11:38:47 +08:00
void ctypes_c_uint___init__(PikaObj* self, int value) {
2022-04-17 22:56:21 +08:00
ctypesUtils_setInt(self, value);
2022-04-16 00:02:41 +08:00
}
2022-04-16 11:38:47 +08:00
void ctypes_c_wchar_p___init__(PikaObj* self, char* value) {
2022-04-17 22:56:21 +08:00
ctypesUtils_setStr(self, value);
2022-04-16 00:02:41 +08:00
}
2022-04-18 18:44:14 +08:00
void ctypes_c_float___init__(PikaObj* self, float value) {
2022-04-18 14:16:55 +08:00
ctypesUtils_setFloat(self, value);
}
int ctypes_Test_add(PikaObj* self, PikaObj* c_uint1, PikaObj* c_uint2) {
2022-04-17 22:56:21 +08:00
return ctypesUtils_getInt(c_uint1) + ctypesUtils_getInt(c_uint2);
}
int ctypes_Test_dc_cpuapdu_hex(PikaObj* self,
PikaObj* rcvbuf,
PikaObj* rlen,
2022-04-19 18:30:24 +08:00
uint8_t* sendbuf,
int slen) {
2022-04-20 14:52:20 +08:00
/* print input */
__platform_printf("input: slen = %d\n", slen);
__platform_printf("sendbuf :\n");
for (int i = 0; i < slen; i++) {
__platform_printf("0x%02x ", sendbuf[i]);
}
__platform_printf("\n");
/* set output */
ctypesUtils_setInt(rlen, 5);
2022-04-18 18:44:14 +08:00
char rcv[] = {0x01, 0x02, 0x03, 0x00, 0x05, 0x08};
2022-04-19 18:12:07 +08:00
ctypesUtils_setBytes(rcvbuf, rcv, sizeof(rcv));
return 0;
2022-04-16 00:02:41 +08:00
}
2022-04-18 18:44:14 +08:00
void ctypes_Test_print_rcv(PikaObj* self, PikaObj* rcvbuf) {
2022-04-19 18:12:07 +08:00
char* rcv = ctypesUtils_getBytes(rcvbuf);
size_t rcv_size = ctypesUtils_getBytesSize(rcvbuf);
2022-04-18 18:44:14 +08:00
__platform_printf("{");
for (size_t i = 0; i < rcv_size - 1; i++) {
2022-04-20 14:52:20 +08:00
__platform_printf("0x%02x, ", rcv[i]);
2022-04-18 18:44:14 +08:00
}
2022-04-20 14:52:20 +08:00
__platform_printf("0x%02x", rcv[rcv_size - 1]);
2022-04-18 18:44:14 +08:00
__platform_printf("}\r\n");
}