There is a C struct like this:
、、、
struct dcmi_chip_info {
unsigned char chip_type[MAX_CHIP_NAME_LEN];
unsigned char chip_name[MAX_CHIP_NAME_LEN];
unsigned char chip_ver[MAX_CHIP_NAME_LEN];
unsigned int aicore_cnt;
};
、、、
and a C func like this:
DCMIDLLEXPORT int dcmi_get_device_chip_info(int card_id, int device_id, struct dcmi_chip_info *chip_info);
Then I want to use CGO to get the result:
、、、
ret = C.dcmi_get_device_id_in_card(card_id_list[card_id_index],
(*C.int)(unsafe.Pointer(&device_id_max)),
(*C.int)(unsafe.Pointer(&mcu_id)),
(*C.int)(unsafe.Pointer(&cpu_id)))
/chip_info := C.struct_dcmi_chip_info{
chip_type: [C.MAX_CHIP_NAME_LEN]C.uchar{},
chip_name: [C.MAX_CHIP_NAME_LEN]C.uchar{},
chip_ver: [C.MAX_CHIP_NAME_LEN]C.uchar{},
}/
chip_info := C.struct_dcmi_chip_info{}
ret = C.dcmi_get_device_chip_info(card_id_list[card_id_index], (C.int)(device_id_max), &chip_info)
fmt.Printf(“%T\n”, chip_info.chip_name)
fmt.Println(“chip_type”, chip_info.chip_name)
、、、
Sorry about that. The *C.uchar will need to be converted to *C.char, as that is what C.GoString needs. The Go compiler will not allow the conversion to be performed directly like this (*C.char)(&chip_info.chip_name[0]).
However any pointer type can be converted to unsafe.Pointer, and unsafe.Pointer can be converted to any pointer type.