4. Tool Application Reference

4.1. How to Import and Export Tool Parameters?

4.1.1. Import and Export Parameters Using Tool

CviPQ Tool supports the import and export of configuration files in JSON format on the PC side, and supports the solidification of tool parameters to the board side.

If the user wants to export or import the parameter file of CviPQ tool, please refer to the description in chapter 2.4.3.1 and 2.4.3.2 .

If the user wants to import parameters to the board or export parameters from the board to the PC for backup, use the “Bin Utility” tool. Specific operation instructions are as follows:

  • Import and export bin file of board end parameters

When connected to the board, click Bin Utility in the menu bar to open the binary utility window, as shown in Figure 4-1

_images/ToolAp002.png

Fig. 4.1 Binary Utilities

There are two buttons in the Bin Import Export group. Click the buttons respectively to complete the following operations:

  • Import the parameter bin file to the board end: Click “Import Bin File” and select the correct parameter bin file to be imported in the pop-up open file dialog box. When the tool completes sending the file to the board end, the parameters will take effect immediately.

  • Export the board end parameter bin file: Click on the bin type dropdown menu to select the export type, then click “Export Bin File” and select a save path in the pop-up save file dialog box. The tool will save the parameters of the selected type on the board end into the specified path.

  • Solidify parameter configuration to Flash

After filling in the author, description information and time information in the Bin Fix group, you can click “Fix Bin to Flash” to send instructions to the board end to write the current board end parameter information into Flash.

4.1.2. Import and export image quality parameters using libraries

The board end tool provides import and export of parameter library files. You can choose the following two methods according to your own needs. Note: The following interfaces must be called after calling the CVI_ISP_Init interface.

  1. Get and save all block bin data (ISP x, VPSS, VO, etc.):

  1. Get and save single block bin data (ISP x, VPSS, VO, etc.):

Please refer to the recommended usage process, as shown in the figure below.

_images/ToolAp003.png

Other related interface API:

4.1.3. API reference

4.1.3.1. CVI_BIN_GetBinTotalLen

【describe】

Get the total length of bin data.

【grammar】

CVI_U32 CVI_BIN_GetBinTotalLen(void);

【parameter】

parameter name

describe

input Output

none

none

none

【return value】

return value

describe

CVI_U32

The total length of the bin file

【need】

  • Header file: cvi_bin.h

  • Library files: libcvi_bin.so, libcvi_bin_isp.so

【Notice】

This function must be called before calling the :ref: CVI_BIN_ExportBinData <CVI_BIN_ExportBinData> interface. 【Example】

CVI_U32 u32BinLen = 0;

u32BinLen = CVI_BIN_GetBinTotalLen();

【related topic】

4.1.3.2. CVI_BIN_ExportBinData

【describe】

Export all block bin data.

【grammar】

CVI_S32 CVI_BIN_ExportBinData(CVI_U8*pu8Buffer, CVI_U32 u32DataLength);

【parameter】

parameter name

describe

input Output

pu8Buffer

Buffer to save pqbin data

input

u32DataLength

The total length of pqbin data

input

【return value】

return value

describe

0

success.

not 0

Failed, please see Error code 1 for its value.

【need】

  • Header file: cvi_bin.h

  • Library files: libcvi_bin.so, libcvi_bin_isp.so

【Notice】

When calling this function, you must first call the CVI_BIN_GetBinTotalLen function to obtain the size of the data, otherwise memory problems may occur.

【Example】

CVI_S32 ret = CVI_SUCCESS;

CVI_BIN_HEADER header;

CVI_U32 u32BinLen = 0, u32TempLen = 0;

CVI_U8 *pBuffer;

memset(&header, 0, sizeof(CVI_BIN_HEADER));
u32BinLen = CVI_BIN_GetBinTotalLen();

pBuffer = (CVI_U8 *)malloc(u32BinLen);

if (pBuffer == NULL) {

ISP_DAEMON_DEBUG(LOG_ALERT, "malloc err!\\n");

return CVI_FAILURE;

}

header.extraInfo = *binExtra;

memcpy(pBuffer, &header, sizeof(CVI_BIN_HEADER));

ret = CVI_BIN_ExportBinData(pBuffer, u32BinLen);

if (ret != CVI_SUCCESS) {

ISP_DAEMON_DEBUG_EX(LOG_ALERT, "CVI_BIN_ExportBinData err(%#x)!\\n", ret);

} else {
 u32TempLen = fwrite(pBuffer, 1, u32BinLen, fp);

if (u32TempLen != u32BinLen) {

ISP_DAEMON_DEBUG(LOG_ALERT, "writeIspRegToBin fail\\n");

ret = CVI_FAILURE;

}

}

if (pBuffer != NULL) {

free(pBuffer);

}

ISP_DAEMON_UNUSED(numDevice);

return ret;

【related topic】

none

4.1.3.3. CVI_BIN_ImportBinData

【describe】

Import all block bin data, which will match the data in the bin with the current modules and import all eligible data.

【grammar】

CVI_S32 CVI_BIN_ImportBinData(CVI_U8*pu8Buffer, CVI_U32 u32DataLength);

【parameter】

parameter name

describe

input Output

pu8Buffer

Bin memory space

input

u32DataLength

Bin size

input

【return value】

return value

describe

0

success.

not 0

Failed, please see Error code 2 for its value.

【need】

  • Header file: cvi_bin.h

  • Library files: libcvi_bin.so libcvi_bin_isp.so

【Notice】

none

【Example】

CVI_S32 ret = CVI_SUCCESS;

FILE *fp = NULL;

CVI_U8 *buf = NULL;
CVI_CHAR binName[BIN_FILE_LENGTH] = { 0 };

CVI_U32 u32TempLen = 0, u32FileSize = 0;

ret = CVI_BIN_GetBinName(binName);

if (ret != CVI_SUCCESS) {

CVI_TRACE_SYS(CVI_DBG_WARN, "GetBinName(%s) fail\\n", binName);

}

fp = fopen((const CVI_CHAR *)binName, "rb");

if (fp == NULL) {

CVI_TRACE_SYS(CVI_DBG_WARN, "Can't find bin(%s)\\n", binName);

ret = CVI_FAILURE;

goto ERROR_HANDLER;

} else {

CVI_TRACE_SYS(CVI_DBG_WARN, "Bin exist (%s)\\n", binName);

}
getFileSize(fp, &u32FileSize);

buf = (CVI_U8 *)malloc(u32FileSize);

if (buf == NULL) {

ret = CVI_FAILURE;

CVI_TRACE_SYS(CVI_DBG_WARN, "Allocate memory fail\\n");

goto ERROR_HANDLER;

}

u32TempLen = fread(buf, u32FileSize, 1, fp);

if (u32TempLen <= 0) {

CVI_TRACE_SYS(CVI_DBG_WARN, "read data to buff fail!\\n");

ret = CVI_FAILURE;

goto ERROR_HANDLER;

}

ret = CVI_BIN_ImportBinData(buf, (CVI_U32)u32FileSize);

if (ret != CVI_SUCCESS) {
CVI_TRACE_SYS(CVI_DBG_WARN, "CVI_BIN_ImportBinData error! value:(0x%x)\\n", ret);

goto ERROR_HANDLER;

}

ERROR_HANDLER:

if (fp != NULL) {

fclose(fp);

}

if (buf != NULL) {

free(buf);

}

return ret;

【Related topics】

Nothing

4.1.3.4. CVI_BIN_GetSingleISPBinLen

【describe】

Get the length of bin data of single module.

【grammar】

CVI_S32 CVI_BIN_GetSingleISPBinLen(enum CVI_BIN_SECTION_ID id);

【parameter】

parameter name

describe

input/Output

id

module ID

input

【return value】

return value

describe

CVI_U32

the length of bin data of single module.

【need】

  • Header file:cvi_bin.h

  • Library files:libcvi_bin.so,libcvi_bin_isp.so

【Notice】

This function must be called before calling the CVI_BIN_ExportSingleISPBinData interface.

【Example】

CVI_U32 u32BinLen = 0;

enum CVI_BIN_SECTION_ID id = CVI_BIN_ID_ISP0;

u32BinLen = CVI_BIN_GetBinTotalLen(id);

【related topic】

4.1.3.5. CVI_BIN_ExportSingleISPBinData

【describe】

Export a single module of bin data.

【grammar】

CVI_BIN_ExportSingleISPBinData(enum CVI_BIN_SECTION_ID id, CVI_U8*pu8Buffer, CVI_U32 u32DataLength);

【parameter】

parameter name

describe

input Output

id

module ID

input

pu8Buffer

Buffer to save pqbin data

input

u32DataLength

The total length of pqbin data

input

【return value】

return value

describe

0

success.

not 0

Failed, please see Error code 1 for its value.

【need】

  • Header file: cvi_bin.h

  • Library files: libcvi_bin.so,libcvi_bin_isp.so

【Notice】

When calling this function, you must first call the CVI_BIN_GetSingleISPBinLen function to obtain the size of the data, otherwise memory problems may occur.

【Example】

CVI_S32 ret = CVI_SUCCESS;

CVI_BIN_HEADER header;

CVI_U32 u32BinLen = 0, u32TempLen = 0;

CVI_U8 *pBuffer;

enum CVI_BIN_SECTION_ID id = CVI_BIN_ID_ISP0;

memset(&header, 0, sizeof(CVI_BIN_HEADER));

u32BinLen = CVI_BIN_GetSingleISPBinLen(id);

pBuffer = (CVI_U8 *)malloc(u32BinLen);

if (pBuffer == NULL) {

ISP_DAEMON_DEBUG(LOG_ALERT, "malloc err!\\n");

return CVI_FAILURE;

}

header.extraInfo = *binExtra;

memcpy(pBuffer, &header, sizeof(CVI_BIN_HEADER));

ret = CVI_BIN_ExportSingleISPBinData(id, pBuffer, u32BinLen);

if (ret != CVI_SUCCESS) {

ISP_DAEMON_DEBUG_EX(LOG_ALERT, "CVI_BIN_ExportBinData err(%#x)!\\n", ret);

} else {

u32TempLen = fwrite(pBuffer, 1, u32BinLen, fp);

if (u32TempLen != u32BinLen) {

ISP_DAEMON_DEBUG(LOG_ALERT, "writeIspRegToBin fail\\n");

ret = CVI_FAILURE;

}

}

if (pBuffer != NULL) {

free(pBuffer);

}

ISP_DAEMON_UNUSED(numDevice);

return ret;

【related topic】

none

4.1.3.6. CVI_BIN_SaveParamToBin

【describe】

Export single block bin data

【grammar】

CVI_S32 CVI_BIN_SaveParamToBin(FILE*fp, CVI_BIN_EXTRA_S*extraInfo);

【parameter】

parameter name

describe

input Output

fp

PQBin file pointer

input

extraInfo

PQBin information and description

input

【return value】

return value

describe

0

success.

not 0

Failed, please see Error code 1 for its value.

【need】

  • Header file: cvi_bin.h

  • Library files: libcvi_bin.so, libcvi_bin_isp.so

【Notice】

none 【Example】

CVI_BIN_EXTRA_S BinExtra = {

"User",

"test-default",

"2021-04-19",

};

FILE *fd = fopen(TEST_BIN, "wb");

if (fd == NULL) {

ISP_DEBUG(LOG_ERR, "Open file failed\\n");

}

CVI_BIN_SaveParamToBin(fd, &BinExtra);

fclose(fd);

【related topic】

none

4.1.3.7. CVI_BIN_LoadParamFromBin

【describe】

Import single block bin data.

【grammar】

CVI_S32 CVI_BIN_LoadParamFromBin(enum CVI_BIN_SECTION_ID id, CVI_U8*buf);

【parameter】

parameter name

describe

input Output

id

Module ID

input

buf

Data content of PQBin

input

【return value】

return value

describe

0

success.

not 0

Failure, please see Error code 2

【need】

  • Header file: cvi_bin.h

  • Library files: libcvi_bin.so, libcvi_bin_isp.so

【Notice】

The PQBin data must be read into the cache memory space first, and then this function is called. The function of this API will be replaced by CVI_BIN_LoadParamFromBinEx in the future. It is recommended to use it instead.

【Example】

CVI_S32 result = CVI_FAILURE;

CVI_U32 size = 0;

FILE *fp;

ISP_DEBUG(LOG_DEBUG, "try load default value from bin %s\\n", TEST_BIN);

fp = fopen(TEST_BIN, "rb");

if (fp == NULL) {

ISP_DEBUG(LOG_WARNING, "Cant find bin(%s)\\n", TEST_BIN);

} else {

ISP_DEBUG(LOG_INFO, "Bin exist (%s)\\n", TEST_BIN);

}

fseek(fp, 0L, SEEK_END);

size = ftell(fp);

rewind(fp);

if (size > 0) {

//allocate buffer
CVI_U8 *binBuffer = malloc(size);

fread(binBuffer, size, 1, fp);

for (CVI_U32 idx = CVI_BIN_ID_MIN ; idx < CVI_BIN_ID_MAX ; idx++) {

result = CVI_BIN_LoadParamFromBin((enum CVI_BIN_SECTION_ID)idx, binBuffer);

}

//free buffer

free(binBuffer);

if (result == CVI_SUCCESS) {

ISP_DEBUG(LOG_DEBUG, "load default value from bin %s\\n", TEST_BIN);

}

【Related topics】

CVI_BIN_LoadParamFromBinEx

4.1.3.8. CVI_BIN_LoadParamFromBinEx

【describe】

Same as CVI_BIN_LoadParamFromBin.

【grammar】

CVI_S32 CVI_BIN_LoadParamFromBin(enum CVI_BIN_SECTION_ID id, CVI_U8*buf, CVI_U32 u32DataLength);

【parameter】

parameter name

describe

input Output

id

Module ID

input

buf

Data content of PQBin

input

u32DataLength

size of buf

input

【return value】

return value

describe

0

success.

not 0

Failure, please see Error code 2

【need】

  • Header file: cvi_bin.h

  • Library files: libcvi_bin.so, libcvi_bin_isp.so

【Notice】

Same as CVI_BIN_LoadParamFromBin.

【Example】

Please refer to CVI_BIN_LoadParamFromBin. Note: the size of buf needs to be passed in.

4.1.3.9. CVI_BIN_SetBinName

【describe】

Set the path and file name where PQBin is stored.

【grammar】

CVI_S32 CVI_BIN_SetBinName(WDR_MODE_E wdrMode, const CVI_CHAR *binName);

【parameter】

parameter name

describe

input Output

wdrMode

Sensor wdr mode

input

binName

Set the path and file name of pqbin corresponding to wdr mode

For example “/mnt/data/cvi_sdr_bin”

input

【return value】

return value

describe

0

success.

not 0

Failure, please see error code.

【need】

  • Header file: cvi_bin.h

  • Library files: libcvi_bin.so, libcvi_bin_isp.so

【Notice】

none

【Example】

none

【related topic】

CVI_BIN_GetBinName

4.1.3.10. CVI_BIN_GetBinName

【describe】

Get the path and file name where PQBin is stored.

【grammar】

CVI_S32 CVI_BIN_GetBinName(CVI_CHAR*binName);

【parameter】

parameter name

describe

input Output

binName

pqbin path and file name

output

【return value】

return value

describe

0

success.

not 0

Failure, please see error code.

【need】

  • Header file: cvi_bin.h

  • Library files: libcvi_bin.so, libcvi_bin_isp.so

【Notice】

none

【Example】

none

【related topic】

4.1.3.11. CVI_BIN_GetBinExtraAttr

【describe】

Get bin header data information.

【grammar】

CVI_S32 CVI_BIN_GetBinExtraAttr(FILE*fp, CVI_BIN_EXTRA_S*extraInfo)

【parameter】

parameter name

describe

input Output

fp

PQBin file pointer

input

extraInfo

Memory space for bin header information

input

【return value】

return value

describe

0

success.

【need】 - Header file: cvi_bin.h

  • Library files: libcvi_bin.so, libcvi_bin_isp.so

【Notice】

none

【Example】

CVI_BIN_EXTRA_S BinExtraAttr = {};

FILE *fd = fopen("/mnt/data/bin/cvi_sdr_bin", "rb");

CVI_BIN_GetBinExtraAttr(fd, &BinExtraAttr);

【related topic】

none

4.1.3.12. CVI_BIN_EnSingleMode

【describe】

Enable pqbin single mode.

【grammar】

CVI_S32 CVI_BIN_EnSingleMode(void)

【parameter】

parameter name

describe

input Output

none

【return value】

return value

describe

0

success.

【need】 - Header file: cvi_bin.h

  • Library files: libcvi_bin.so, libcvi_bin_isp.so

【Notice】

none

【Example】

none

【related topic】

none

4.1.3.13. CVI_BIN_DisSingleMode

【describe】

Disable pqbin single mode.

【grammar】

CVI_S32 CVI_BIN_DisSingleMode(void)

【parameter】

parameter name

describe

input Output

none

【return value】

return value

describe

0

success.

【need】 - Header file: cvi_bin.h

  • Library files: libcvi_bin.so, libcvi_bin_isp.so

【Notice】

none

【Example】

none

【related topic】

none

4.1.3.14. CVI_ISP_BIN_SetBypassParams

【describe】

Set the params of ispBinBypass, indicatting which params to be bypassed.

【grammar】

CVI_S32 CVI_ISP_BIN_SetBypassParams(enum CVI_BIN_SECTION_ID id, ISP_BIN_BYPASS_U * ispBinBypass)

【parameter】

parameter name

describe

input Output

id

Sensor Id

input

ispBinBypass

The params indicatting which params to be bypassed in sensor of id.

input

【return value】

return value

describe

0

success.

-1

failure.

0xCB000013

invalid id error. The given id is not valid Sensor id.

【need】 - Header file: cvi_bin.h

  • Library files: libcvi_bin.so, libcvi_bin_isp.so

【Notice】

none

【Example】

CVI_S32 ret = CVI_SUCCESS;

ISP_BIN_BYPASS_U ispBinBypass = {0};

ispBinBypass.bitBypassFrameRate = CVI_TRUE;

ret = CVI_ISP_BIN_SetBypassParams(CVI_BIN_ID_ISP0, &ispBinBypass);

【related topic】

none

4.1.3.15. CVI_ISP_BIN_GetBypassParams

【describe】

Get the params of ispBinBypass, indicatting which params to be bypassed.

【grammar】

CVI_S32 CVI_ISP_BIN_GetBypassParams(enum CVI_BIN_SECTION_ID id, ISP_BIN_BYPASS_U * ispBinBypass)

【parameter】

parameter name

describe

input Output

id

Sensor Id

input

ispBinBypass

The params indicatting which params to be bypassed in sensor of id.

output

【return value】

return value

describe

0

success.

-1

failure.

0xCB000013

invalid id error. The given id is not valid Sensor id.

【need】 - Header file: cvi_bin.h

  • Library files: libcvi_bin.so, libcvi_bin_isp.so

【Notice】

none

【Example】

CVI_S32 ret = CVI_SUCCESS;

ISP_BIN_BYPASS_U ispBinBypass = {0};

ret = CVI_ISP_BIN_GetBypassParams(CVI_BIN_ID_ISP0, &ispBinBypass);

【related topic】

none

4.1.3.16. Error code 1

interface return value

meaning

0xCB000001

The input parameter pointer is empty

0xCB000003

Not allocated to memory space

0xCB00000B

json compression failed

0xCB00000D

Insufficient input buffer space

0xCB00000F

Failed to update parameters to PQbin file

0xCB000012

Failed to create json handle

0xCB000013

The block id entered is invalid

0xCB000014

Failed to read parameters from file

4.1.3.17. Error code 2

interface return value

meaning

0xCB000001

The input parameter pointer is empty

0xCB000003

Not allocated to memory space

0xCB000006

The size of the input buf is 0

0xCB000008

The data in PQbin is abnormal

0xCB00000C

json decompression failed

0xCB00000F

Failed to update parameters to PQbin file

0xCB000010

Unable to find bin file

0xCB000011

The json parameter in the current PQbin file is invalid

0xCB000012

Failed to create json handle

0xCB000013

The block id entered is invalid

0xCB000014

Failed to read parameters from file

0xCB000015

The PQbin file currently used is invalid

0xCB000016

The number of Sensors exceeds the number specified in the PQbin file