mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
add ctypes_utils to supply method for ctypes
This commit is contained in:
parent
6c0e7e78c9
commit
a2bbe2ef5e
@ -1,8 +1,9 @@
|
||||
#include "ctypes_Test.h"
|
||||
#include "ctypes_c_uint.h"
|
||||
#include "ctypes_c_wchar_p.h"
|
||||
#include "ctypes_utils.h"
|
||||
|
||||
void ctypes_c_uint___init__(PikaObj *self, int value){
|
||||
void ctypes_c_uint___init__(PikaObj* self, int value) {
|
||||
obj_setInt(self, "value", value);
|
||||
}
|
||||
|
||||
@ -10,8 +11,17 @@ void ctypes_c_wchar_p___init__(PikaObj* self, char* value) {
|
||||
obj_setStr(self, "value", value);
|
||||
}
|
||||
|
||||
int ctypes_Test_add(PikaObj* self, void* c_uint1, void* c_uint2) {
|
||||
PikaObj* c_uint1_obj = c_uint1;
|
||||
PikaObj* c_uint2_obj = c_uint2;
|
||||
return obj_getInt(c_uint1_obj, "value") + obj_getInt(c_uint2_obj, "value");
|
||||
int ctypes_Test_add(PikaObj* self, PikaObj* c_uint1, PikaObj* c_uint2) {
|
||||
return obj_getInt(c_uint1, "value") + obj_getInt(c_uint2, "value");
|
||||
}
|
||||
|
||||
int ctypes_Test_dc_cpuapdu_hex(PikaObj* self,
|
||||
PikaObj* rcvbuf,
|
||||
PikaObj* rlen,
|
||||
char* sendbuf,
|
||||
int slen) {
|
||||
printf("input: slen = %d, sendbuf = %s\n", slen, sendbuf);
|
||||
ctypesUtils_setInt(rlen, 5);
|
||||
ctypesUtils_setStr(rcvbuf, "testout");
|
||||
return 0;
|
||||
}
|
||||
|
@ -9,5 +9,8 @@ class c_wchar_p(TinyObj):
|
||||
pass
|
||||
|
||||
class Test(TinyObj):
|
||||
def add(self, c_uint1:pointer, c_uint2:pointer)->int:
|
||||
def add(self, c_uint1:c_uint, c_uint2:c_uint)->int:
|
||||
pass
|
||||
|
||||
def dc_cpuapdu_hex(self, slen:int, sendbuf:str, rlen:c_uint, rcvbuf:c_wchar_p) -> int:
|
||||
pass
|
||||
|
33
package/ctypes/ctypes_utils.c
Normal file
33
package/ctypes/ctypes_utils.c
Normal file
@ -0,0 +1,33 @@
|
||||
#include "PikaObj.h"
|
||||
|
||||
void ctypesUtils_setInt(PikaObj* self, int val) {
|
||||
obj_setInt(self, "value", val);
|
||||
}
|
||||
|
||||
void ctypesUtils_setStr(PikaObj* self, char* val) {
|
||||
obj_setStr(self, "value", val);
|
||||
}
|
||||
|
||||
void ctypesUtils_setFloat(PikaObj* self, float val) {
|
||||
obj_setFloat(self, "value", val);
|
||||
}
|
||||
|
||||
void ctypesUtils_setPtr(PikaObj* self, void* ptr) {
|
||||
obj_setPtr(self, "value", ptr);
|
||||
}
|
||||
|
||||
int ctypesUtils_getInt(PikaObj* self) {
|
||||
return obj_getInt(self, "value");
|
||||
}
|
||||
|
||||
char* ctypesUtils_getStr(PikaObj* self) {
|
||||
return obj_getStr(self, "value");
|
||||
}
|
||||
|
||||
float ctypesUtils_getFloat(PikaObj* self) {
|
||||
return obj_getFloat(self, "value");
|
||||
}
|
||||
|
||||
void* ctypesUtils_getPtr(PikaObj* self) {
|
||||
return obj_getPtr(self, "value");
|
||||
}
|
15
package/ctypes/ctypes_utils.h
Normal file
15
package/ctypes/ctypes_utils.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef __CTYPES_UTILS__H
|
||||
#define __CTYPES_UTILS__H
|
||||
|
||||
void ctypesUtils_setInt(PikaObj* self, int val);
|
||||
void ctypesUtils_setStr(PikaObj* self, char* val);
|
||||
void ctypesUtils_setFloat(PikaObj* self, float val);
|
||||
void ctypesUtils_setPtr(PikaObj* self, void* ptr);
|
||||
|
||||
int ctypesUtils_getInt(PikaObj* self);
|
||||
char* ctypesUtils_getStr(PikaObj* self);
|
||||
float ctypesUtils_getFloat(PikaObj* self);
|
||||
void *ctypesUtils_getPtr(PikaObj* self);
|
||||
|
||||
|
||||
#endif
|
3
port/linux/.vscode/settings.json
vendored
3
port/linux/.vscode/settings.json
vendored
@ -53,7 +53,8 @@
|
||||
"pikastddevice_can.h": "c",
|
||||
"ctypes.h": "c",
|
||||
"ctypes_test.h": "c",
|
||||
"ctypes_c_uint.h": "c"
|
||||
"ctypes_c_uint.h": "c",
|
||||
"ctypes_utils.h": "c"
|
||||
},
|
||||
"python.formatting.provider": "autopep8"
|
||||
}
|
@ -11,3 +11,6 @@ class c_wchar_p(TinyObj):
|
||||
class Test(TinyObj):
|
||||
def add(self, c_uint1:c_uint, c_uint2:c_uint)->int:
|
||||
pass
|
||||
|
||||
def dc_cpuapdu_hex(self, slen:int, sendbuf:str, rlen:c_uint, rcvbuf:c_wchar_p) -> int:
|
||||
pass
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "ctypes_Test.h"
|
||||
#include "ctypes_c_uint.h"
|
||||
#include "ctypes_c_wchar_p.h"
|
||||
#include "ctypes_utils.h"
|
||||
|
||||
void ctypes_c_uint___init__(PikaObj* self, int value) {
|
||||
obj_setInt(self, "value", value);
|
||||
@ -13,3 +14,14 @@ void ctypes_c_wchar_p___init__(PikaObj* self, char* value) {
|
||||
int ctypes_Test_add(PikaObj* self, PikaObj* c_uint1, PikaObj* c_uint2) {
|
||||
return obj_getInt(c_uint1, "value") + obj_getInt(c_uint2, "value");
|
||||
}
|
||||
|
||||
int ctypes_Test_dc_cpuapdu_hex(PikaObj* self,
|
||||
PikaObj* rcvbuf,
|
||||
PikaObj* rlen,
|
||||
char* sendbuf,
|
||||
int slen) {
|
||||
printf("input: slen = %d, sendbuf = %s\n", slen, sendbuf);
|
||||
ctypesUtils_setInt(rlen, 5);
|
||||
ctypesUtils_setStr(rcvbuf, "testout");
|
||||
return 0;
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
#include "PikaObj.h"
|
||||
|
||||
void ctypesUtils_setInt(PikaObj* self, int val) {
|
||||
obj_setInt(self, "value", val);
|
||||
}
|
||||
|
||||
void ctypesUtils_setStr(PikaObj* self, char* val) {
|
||||
obj_setStr(self, "value", val);
|
||||
}
|
||||
|
||||
void ctypesUtils_setFloat(PikaObj* self, float val) {
|
||||
obj_setFloat(self, "value", val);
|
||||
}
|
||||
|
||||
void ctypesUtils_setPtr(PikaObj* self, void* ptr) {
|
||||
obj_setPtr(self, "value", ptr);
|
||||
}
|
||||
|
||||
int ctypesUtils_getInt(PikaObj* self) {
|
||||
return obj_getInt(self, "value");
|
||||
}
|
||||
|
||||
char* ctypesUtils_getStr(PikaObj* self) {
|
||||
return obj_getStr(self, "value");
|
||||
}
|
||||
|
||||
float ctypesUtils_getFloat(PikaObj* self) {
|
||||
return obj_getFloat(self, "value");
|
||||
}
|
||||
|
||||
void* ctypesUtils_getPtr(PikaObj* self) {
|
||||
return obj_getPtr(self, "value");
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
#ifndef __CTYPES_UTILS__H
|
||||
#define __CTYPES_UTILS__H
|
||||
|
||||
void ctypesUtils_setInt(PikaObj* self, int val);
|
||||
void ctypesUtils_setStr(PikaObj* self, char* val);
|
||||
void ctypesUtils_setFloat(PikaObj* self, float val);
|
||||
void ctypesUtils_setPtr(PikaObj* self, void* ptr);
|
||||
|
||||
int ctypesUtils_getInt(PikaObj* self);
|
||||
char* ctypesUtils_getStr(PikaObj* self);
|
||||
float ctypesUtils_getFloat(PikaObj* self);
|
||||
void *ctypesUtils_getPtr(PikaObj* self);
|
||||
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user