add c_buffer class for ctypes

This commit is contained in:
lyon 2022-05-25 14:44:59 +08:00
parent 54ad82d5a8
commit 4ac3eaf76f
4 changed files with 136 additions and 2 deletions

View File

@ -1,4 +1,5 @@
#include "ctypes_Test.h" #include "ctypes_Test.h"
#include "ctypes_c_buffer.h"
#include "ctypes_c_float.h" #include "ctypes_c_float.h"
#include "ctypes_c_uint.h" #include "ctypes_c_uint.h"
#include "ctypes_c_wchar_p.h" #include "ctypes_c_wchar_p.h"
@ -50,3 +51,54 @@ void ctypes_Test_print_rcv(PikaObj* self, PikaObj* rcvbuf) {
__platform_printf("0x%02x", rcv[rcv_size - 1]); __platform_printf("0x%02x", rcv[rcv_size - 1]);
__platform_printf("}\r\n"); __platform_printf("}\r\n");
} }
void ctypes_create_string_buffer___init__(PikaObj* self, int size) {
uint8_t* buffer;
obj_setBytes(self, "raw", NULL, size);
buffer = obj_getBytes(self, "raw");
__platform_printf("0x%x", &buffer);
}
int ctypes_create_string_buffer___get__(PikaObj* self, int __key) {
uint8_t* buffer;
int i;
i = __key;
buffer = obj_getBytes(self, "raw");
return buffer[i];
}
int ctypes_c_buffer___get__(PikaObj* self, int __key) {
int i;
uint8_t* buffer;
i = __key;
buffer = obj_getBytes(self, "raw");
return buffer[i];
}
void ctypes_c_buffer___init__(PikaObj* self, int size, Arg* value) {
uint8_t* buffer;
uint8_t* value_buffer;
size_t value_size;
ArgType arg_type;
arg_type = arg_getType(value);
if (arg_type == ARG_TYPE_BYTES) {
obj_setBytes(self, "raw", NULL, size);
buffer = obj_getBytes(self, "raw");
value_size = arg_getBytesSize(value);
value_buffer = arg_getBytes(value);
__platform_memcpy(buffer, value_buffer, value_size);
} else if (ARG_TYPE_STRING == arg_type) {
obj_setBytes(self, "raw", NULL, size);
buffer = obj_getBytes(self, "raw");
value_buffer = (uint8_t*)arg_getStr(value);
__platform_memcpy(buffer, value_buffer,
strGetSize((char*)value_buffer) + 1);
} else {
__platform_printf("value type is not support!");
while (1)
;
}
}

View File

@ -1,6 +1,6 @@
#api
from PikaObj import * from PikaObj import *
class c_uint(TinyObj): class c_uint(TinyObj):
def __init__(self, value:int):... def __init__(self, value:int):...
@ -34,3 +34,18 @@ class Test(TinyObj):
def add(self, c_uint1:c_uint, c_uint2:c_uint)->int:... def add(self, c_uint1:c_uint, c_uint2:c_uint)->int:...
def dc_cpuapdu_hex(self, slen:int, sendbuf:bytes, rlen:c_uint, rcvbuf:c_char_p) -> int:... def dc_cpuapdu_hex(self, slen:int, sendbuf:bytes, rlen:c_uint, rcvbuf:c_char_p) -> int:...
def print_rcv(self, rcvbuf: c_char_p):... def print_rcv(self, rcvbuf: c_char_p):...
class create_string_buffer(TinyObj):
def __init__(self, size:int):...
# support val = string[]
def __get__(self, __key: int) -> int:
pass
class c_buffer(TinyObj):
def __init__(self, value:any, size:int):
pass
# support val = string[]
def __get__(self, __key: int) -> int:
pass

View File

@ -1,6 +1,6 @@
#api
from PikaObj import * from PikaObj import *
class c_uint(TinyObj): class c_uint(TinyObj):
def __init__(self, value:int):... def __init__(self, value:int):...
@ -34,3 +34,18 @@ class Test(TinyObj):
def add(self, c_uint1:c_uint, c_uint2:c_uint)->int:... def add(self, c_uint1:c_uint, c_uint2:c_uint)->int:...
def dc_cpuapdu_hex(self, slen:int, sendbuf:bytes, rlen:c_uint, rcvbuf:c_char_p) -> int:... def dc_cpuapdu_hex(self, slen:int, sendbuf:bytes, rlen:c_uint, rcvbuf:c_char_p) -> int:...
def print_rcv(self, rcvbuf: c_char_p):... def print_rcv(self, rcvbuf: c_char_p):...
class create_string_buffer(TinyObj):
def __init__(self, size:int):...
# support val = string[]
def __get__(self, __key: int) -> int:
pass
class c_buffer(TinyObj):
def __init__(self, value:any, size:int):
pass
# support val = string[]
def __get__(self, __key: int) -> int:
pass

View File

@ -1,4 +1,5 @@
#include "ctypes_Test.h" #include "ctypes_Test.h"
#include "ctypes_c_buffer.h"
#include "ctypes_c_float.h" #include "ctypes_c_float.h"
#include "ctypes_c_uint.h" #include "ctypes_c_uint.h"
#include "ctypes_c_wchar_p.h" #include "ctypes_c_wchar_p.h"
@ -50,3 +51,54 @@ void ctypes_Test_print_rcv(PikaObj* self, PikaObj* rcvbuf) {
__platform_printf("0x%02x", rcv[rcv_size - 1]); __platform_printf("0x%02x", rcv[rcv_size - 1]);
__platform_printf("}\r\n"); __platform_printf("}\r\n");
} }
void ctypes_create_string_buffer___init__(PikaObj* self, int size) {
uint8_t* buffer;
obj_setBytes(self, "raw", NULL, size);
buffer = obj_getBytes(self, "raw");
__platform_printf("0x%x", &buffer);
}
int ctypes_create_string_buffer___get__(PikaObj* self, int __key) {
uint8_t* buffer;
int i;
i = __key;
buffer = obj_getBytes(self, "raw");
return buffer[i];
}
int ctypes_c_buffer___get__(PikaObj* self, int __key) {
int i;
uint8_t* buffer;
i = __key;
buffer = obj_getBytes(self, "raw");
return buffer[i];
}
void ctypes_c_buffer___init__(PikaObj* self, int size, Arg* value) {
uint8_t* buffer;
uint8_t* value_buffer;
size_t value_size;
ArgType arg_type;
arg_type = arg_getType(value);
if (arg_type == ARG_TYPE_BYTES) {
obj_setBytes(self, "raw", NULL, size);
buffer = obj_getBytes(self, "raw");
value_size = arg_getBytesSize(value);
value_buffer = arg_getBytes(value);
__platform_memcpy(buffer, value_buffer, value_size);
} else if (ARG_TYPE_STRING == arg_type) {
obj_setBytes(self, "raw", NULL, size);
buffer = obj_getBytes(self, "raw");
value_buffer = (uint8_t*)arg_getStr(value);
__platform_memcpy(buffer, value_buffer,
strGetSize((char*)value_buffer) + 1);
} else {
__platform_printf("value type is not support!");
while (1)
;
}
}