Skip to content

Commit 9416e90

Browse files
New data structures added. Documentation updated.
1 parent d1e6177 commit 9416e90

File tree

7 files changed

+1339
-147
lines changed

7 files changed

+1339
-147
lines changed

README.md

Lines changed: 112 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11

22

3-
4-
53
![logo](_static/lens_logo.png)
64

75
# **Lens interface C++ library**
86

9-
**v4.0.3**
7+
**v4.1.0**
108

119
------
1210

@@ -17,7 +15,7 @@
1715
- [Overview](#Overview)
1816
- [Versions](#Versions)
1917
- [Lens interface class description](#Lens-interface-class-description)
20-
- [Class declaration](#Class-declaration)
18+
- [Class declaration](#Lens-class-declaration)
2119
- [getVersion method](#getVersion-method)
2220
- [openLens method](#openLens-method)
2321
- [initLens method](#initLens-method)
@@ -36,7 +34,7 @@
3634
- [LensCommand enum](#LensCommand-enum)
3735
- [LensParam enum](#LensParam-enum)
3836
- [LensParams class description](#LensParams-class-description)
39-
- [Class declaration](#Class-declaration)
37+
- [LensParams class declaration](#LensParams-class-declaration)
4038
- [Serialize lens params](#Serialize-lens-params)
4139
- [Deserialize lens params](#Deserialize-lens-params)
4240
- [Read params from JSON file and write to JSON file](#Read-params-from-JSON-file-and-write-to-JSON-file)
@@ -46,7 +44,7 @@
4644

4745
# Overview
4846

49-
**Lens** C++ library provides standard interface as well defines data structures and rules for different lens controllers. **Lens** interface class doesn't do anything, just provides interface, data structures and service functions to encode/decode parameter. Different lens controller classes inherit interface form **Lens** C++ class. **Lens.h** file contains list of data structures (**LensCommand** enum, **LensParam** enum and **LensParams** class) and **Lens** class declaration. **LensCommand** enum contains IDs of commands supported by **Lens** class. **LensParam** enum contains IDs of params supported by **Lens** class. **LensParams** class contains fields for lens parameters values and provides methods to encode/decode and read/write lens parameters from JSON file. All lens controllers should include params and commands listed in **Lens.h** file. Lens interface class depends on **Frame** class (describes video frame and video frame data structures, necessary for autofocus functions) and **ConfigReader** library (provides methods to read/write JSON config files).
47+
**Lens** C++ library provides standard interface as well defines data structures and rules for different lens controllers. **Lens** interface class doesn't do anything, just provides interface, data structures and service functions to encode/decode parameter and commands. Different lens controller classes inherit interface form **Lens** C++ class. **Lens.h** file contains list of data structures (**LensCommand** enum, **LensParam** enum and **LensParams** class) and **Lens** class declaration. **LensCommand** enum contains IDs of commands supported by **Lens** class. **LensParam** enum contains IDs of params supported by **Lens** class. **LensParams** class contains fields for lens parameters values and provides methods to encode/decode and read/write lens parameters from JSON file. All lens controllers should include params and commands listed in **Lens.h** file. Lens interface class depends on [**Frame**](https://github.com/ConstantRobotics-Ltd/Frame) class (describes video frame and video frame data structures, necessary for autofocus functions) and [**ConfigReader**](https://github.com/ConstantRobotics-Ltd/ConfigReader) library (provides methods to read/write JSON config files).
5048

5149

5250

@@ -65,14 +63,15 @@
6563
| 4.0.1 | 28.06.2023 | - ConfigReader submodule updated.<br />- Frame submodule updated. |
6664
| 4.0.2 | 29.06.2023 | - Documentation updated. |
6765
| 4.0.3 | 01.07.2023 | - Documentation updated.<br />- Lens class comments in source code updated. |
66+
| 4.1.0 | 11.07.2023 | - Added LensParamsMask for lens params masking.<br />- encode(...) method of LensParams class updated.<br />- Documentation updated. |
6867

6968

7069

7170
# Lens interface class description
7271

7372

7473

75-
## Class declaration
74+
## Lens class declaration
7675

7776
**Lens** interface class declared in **Lens.h** file. Class declaration:
7877

@@ -208,7 +207,7 @@ std::cout << "Lens class version: " << Lens::getVersion() << std::endl;
208207
Console output:
209208

210209
```bash
211-
Lens class version: 4.0.2
210+
Lens class version: 4.1.0
212211
```
213212

214213

@@ -378,7 +377,7 @@ static void encodeSetParamCommand(uint8_t* data, int& size, LensParam id, float
378377
| ---- | ----- | -------------------------------------------------- |
379378
| 0 | 0x01 | SET_PARAM command header value. |
380379
| 1 | 0x04 | Major version of Lens class. |
381-
| 2 | 0x00 | Minor version of Lens class. |
380+
| 2 | 0x01 | Minor version of Lens class. |
382381
| 3 | id | Parameter ID **int32_t** in Little-endian format. |
383382
| 4 | id | Parameter ID **int32_t** in Little-endian format. |
384383
| 5 | id | Parameter ID **int32_t** in Little-endian format. |
@@ -424,7 +423,7 @@ static void encodeCommand(uint8_t* data, int& size, LensCommand id, float arg =
424423
| ---- | ----- | --------------------------------------------------------- |
425424
| 0 | 0x00 | SET_PARAM command header value. |
426425
| 1 | 0x04 | Major version of Lens class. |
427-
| 2 | 0x00 | Minor version of Lens class. |
426+
| 2 | 0x01 | Minor version of Lens class. |
428427
| 3 | id | Command ID **int32_t** in Little-endian format. |
429428
| 4 | id | Command ID **int32_t** in Little-endian format. |
430429
| 5 | id | Command ID **int32_t** in Little-endian format. |
@@ -463,7 +462,7 @@ static int decodeCommand(uint8_t* data, int size, LensParam& paramId, LensComman
463462
| size | Size of command. Should be 11 bytes. |
464463
| paramId | Lens parameter ID according to **LensParam** enum. After decoding SET_PARAM command the method will return parameter ID. |
465464
| commandId | Lens command ID according to **LensCommand** enum. After decoding COMMAND the method will return command ID. |
466-
| value | Len parameter value (after decoding SET_PARAM command) or lens command argument (after decoding COMMAND). |
465+
| value | Lens parameter value (after decoding SET_PARAM command) or lens command argument (after decoding COMMAND). |
467466
468467
**Returns:** **0** - in case decoding COMMAND, **1** - in case decoding SET_PARAM command or **-1** in case errors.
469468
@@ -864,11 +863,11 @@ enum class LensParam
864863

865864
# LensParams class description
866865

867-
**LensParams** class used for lens controller initialization (**initLens(...)** method) or to get all actual params (**getParams()** method). Also **LensParams** provide structure to write/read params from JSON files (**JSON_READABLE** macro) and provide methos to encode and decode params.
866+
**LensParams** class used for lens controller initialization (**initLens(...)** method) or to get all actual params (**getParams()** method). Also **LensParams** provides structure to write/read params from JSON files (**JSON_READABLE** macro) and provides methos to encode and decode params.
868867

869868

870869

871-
## Class declaration
870+
## LensParams class declaration
872871

873872
**LensParams** interface class declared in **Lens.h** file. Class declaration:
874873

@@ -885,7 +884,6 @@ public:
885884
float yFovDeg{0.0f};
886885

887886
JSON_READABLE(FovPoint, hwZoomPos, xFovDeg, yFovDeg);
888-
889887
/**
890888
* @brief operator =
891889
* @param src Source object.
@@ -1121,27 +1119,29 @@ public:
11211119
/// Lens custom parameter. Value depends on particular lens controller.
11221120
/// Custom parameters used when particular lens equipment has specific
11231121
/// unusual parameter.
1124-
float custom1;
1122+
float custom1{0.0f};
11251123
/// Lens custom parameter. Value depends on particular lens controller.
11261124
/// Custom parameters used when particular lens equipment has specific
11271125
/// unusual parameter.
1128-
float custom2;
1126+
float custom2{0.0f};
11291127
/// Lens custom parameter. Value depends on particular lens controller.
11301128
/// Custom parameters used when particular lens equipment has specific
11311129
/// unusual parameter.
1132-
float custom3;
1130+
float custom3{0.0f};
11331131
/// List of points to calculate fiend of view. Lens controller should
11341132
/// calculate FOV table according to given list f points using
11351133
/// approximation.
11361134
std::vector<FovPoint> fovPoints{std::vector<FovPoint>()};
11371135

1138-
JSON_READABLE(LensParams, initString, focusMode, filterMode, afRoiX0, afRoiY0, afRoiX1,
1139-
afRoiY1, zoomHwMaxSpeed, focusHwMaxSpeed, irisHwMaxSpeed, zoomHwTeleLimit,
1140-
zoomHwWideLimit, focusHwFarLimit, focusHwNearLimit, irisHwOpenLimit,
1141-
irisHwCloseLimit, afHwSpeed, focusFactorThreshold, refocusTimeoutSec,
1142-
irisMode, autoAfRoiWidth, autoAfRoiHeight, autoAfRoiBorder, afRoiMode,
1143-
extenderMode, stabiliserMode, afRange, logMode, type, custom1, custom2,
1144-
custom3,fovPoints);
1136+
JSON_READABLE(LensParams, initString, focusMode, filterMode, afRoiX0,
1137+
afRoiY0, afRoiX1, afRoiY1, zoomHwMaxSpeed, focusHwMaxSpeed,
1138+
irisHwMaxSpeed, zoomHwTeleLimit, zoomHwWideLimit,
1139+
focusHwFarLimit, focusHwNearLimit, irisHwOpenLimit,
1140+
irisHwCloseLimit, afHwSpeed, focusFactorThreshold,
1141+
refocusTimeoutSec, irisMode, autoAfRoiWidth, autoAfRoiHeight,
1142+
autoAfRoiBorder, afRoiMode, extenderMode, stabiliserMode,
1143+
afRange, logMode, type, custom1, custom2, custom3, fovPoints);
1144+
11451145
/**
11461146
* @brief operator =
11471147
* @param src Source object.
@@ -1152,8 +1152,9 @@ public:
11521152
* @brief Encode params. The method doesn't encode initString and fovPoints.
11531153
* @param data Pointer to data buffer.
11541154
* @param size Size of data.
1155+
* @param mask Pointer to params mask.
11551156
*/
1156-
void encode(uint8_t* data, int& size);
1157+
void encode(uint8_t* data, int& size, LensParamsMask* mask = nullptr);
11571158
/**
11581159
* @brief Decode params. The method doesn't decode initString and fovPoints.
11591160
* @param data Pointer to data.
@@ -1226,33 +1227,111 @@ public:
12261227
12271228
## Serialize lens params
12281229
1229-
**LensParams** class provides method **encode(...)** to serialize lens params (fields of LensParams class, see Table 4). Serialization of lens params necessary in case when you need to send lens params via communication channels. Method doesn't encode **initString** string field and **fovPoints**. Method declaration:
1230+
**LensParams** class provides method **encode(...)** to serialize lens params (fields of LensParams class, see Table 4). Serialization of lens params necessary in case when you need to send lens params via communication channels. Method doesn't encode **initString** string field and **fovPoints**. Method provides options to exclude particular parameters from serialization. To do this method inserts binary mask (7 bytes) where each bit represents particular parameter and **decode(...)** method recognizes it. Method declaration:
12301231
12311232
```cpp
1232-
void encode(uint8_t* data, int& size);
1233+
void encode(uint8_t* data, int& size, LensParamsMask* mask = nullptr);
12331234
```
12341235

1235-
| Parameter | Value |
1236-
| --------- | ----------------------- |
1237-
| data | Pointer to data buffer. |
1238-
| size | Size of encoded data. |
1236+
| Parameter | Value |
1237+
| --------- | ------------------------------------------------------------ |
1238+
| data | Pointer to data buffer. |
1239+
| size | Size of encoded data. |
1240+
| mask | Parameters mask - pointer to **LensParamsMask** structure. **LensParamsMask** (declared in Lens.h file) determines flags for each field (parameter) declared in **LensParams** class. If the user wants to exclude any parameters from serialization, he can put a pointer to the mask. If the user wants to exclude a particular parameter from serialization, he should set the corresponding flag in the LensParamsMask structure. |
12391241

1240-
Example:
1242+
**LensParamsMask** structure declaration:
1243+
1244+
```cpp
1245+
typedef struct LensParamsMask
1246+
{
1247+
bool zoomPos{true};
1248+
bool zoomHwPos{true};
1249+
bool focusPos{true};
1250+
bool focusHwPos{true};
1251+
bool irisPos{true};
1252+
bool irisHwPos{true};
1253+
bool focusMode{true};
1254+
bool filterMode{true};
1255+
bool afRoiX0{true};
1256+
bool afRoiY0{true};
1257+
bool afRoiX1{true};
1258+
bool afRoiY1{true};
1259+
bool zoomSpeed{true};
1260+
bool zoomHwSpeed{true};
1261+
bool zoomHwMaxSpeed{true};
1262+
bool focusSpeed{true};
1263+
bool focusHwSpeed{true};
1264+
bool focusHwMaxSpeed{true};
1265+
bool irisSpeed{true};
1266+
bool irisHwSpeed{true};
1267+
bool irisHwMaxSpeed{true};
1268+
bool zoomHwTeleLimit{true};
1269+
bool zoomHwWideLimit{true};
1270+
bool focusHwFarLimit{true};
1271+
bool focusHwNearLimit{true};
1272+
bool irisHwOpenLimit{true};
1273+
bool irisHwCloseLimit{true};
1274+
bool focusFactor{true};
1275+
bool isConnected{true};
1276+
bool afHwSpeed{true};
1277+
bool focusFactorThreshold{true};
1278+
bool refocusTimeoutSec{true};
1279+
bool afIsActive{true};
1280+
bool irisMode{true};
1281+
bool autoAfRoiWidth{true};
1282+
bool autoAfRoiHeight{true};
1283+
bool autoAfRoiBorder{true};
1284+
bool afRoiMode{true};
1285+
bool extenderMode{true};
1286+
bool stabiliserMode{true};
1287+
bool afRange{true};
1288+
bool xFovDeg{true};
1289+
bool yFovDeg{true};
1290+
bool logMode{true};
1291+
bool temperature{true};
1292+
bool isOpen{false};
1293+
bool type{true};
1294+
bool custom1{true};
1295+
bool custom2{true};
1296+
bool custom3{true};
1297+
} LensParamsMask;
1298+
```
1299+
1300+
Example without parameters mask:
12411301

12421302
```cpp
12431303
// Encode data.
12441304
LensParams in;
1305+
in.logMode = 3;
12451306
uint8_t data[1024];
12461307
int size = 0;
12471308
in.encode(data, size);
12481309
cout << "Encoded data size: " << size << " bytes" << endl;
12491310
```
12501311

1312+
Example with parameters mask:
1313+
1314+
```cpp
1315+
// Prepare params.
1316+
LensParams in;
1317+
in.logMode = 3;
1318+
1319+
// Prepare mask.
1320+
LensParamsMask mask;
1321+
mask.logMode = false; // Exclude logMode. Others by default.
1322+
1323+
// Encode.
1324+
uint8_t data[1024];
1325+
int size = 0;
1326+
in.encode(data, size, &mask);
1327+
cout << "Encoded data size: " << size << " bytes" << endl;
1328+
```
1329+
12511330

12521331

12531332
## Deserialize lens params
12541333

1255-
**LensParams** class provides method **decode(...)** to deserialize lens params (fields of LensParams class, see Table 4). Deserialization of lens params necessary in case when you need to receive lens params via communication channels. Method doesn't decode fields: **initString** and **fovPoints**. Method declaration:
1334+
**LensParams** class provides method **decode(...)** to deserialize lens params (fields of LensParams class, see Table 4). Deserialization of lens params necessary in case when you need to receive lens params via communication channels. Method automatically recognizes which parameters were serialized by **encode(...)** method. Method doesn't decode fields: **initString** and **fovPoints**. Method declaration:
12561335

12571336
```cpp
12581337
bool decode(uint8_t* data);

README.pdf

54.7 KB
Binary file not shown.

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.13)
66
## INTERFACE-PROJECT
77
## name and version
88
###############################################################################
9-
project(Lens VERSION 4.0.1 LANGUAGES CXX)
9+
project(Lens VERSION 4.1.0 LANGUAGES CXX)
1010

1111

1212

0 commit comments

Comments
 (0)