Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing enums to nodejs wrapper and python script for check enums #7632

Merged
merged 4 commits into from
Oct 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ matrix:
node_js: "10"
env: LRS_BUILD_NODEJS=true
script:
- python ../wrappers/nodejs/tools/enums.py -i ../include/librealsense2 -a ../wrappers/nodejs/src -v
- cmake .. -DBUILD_PYTHON_BINDINGS=true -DBUILD_NODEJS_BINDINGS=true -DPYBIND11_PYTHON_VERSION=2.7 -DCHECK_FOR_UPDATES=true
- cmake --build . --config $LRS_BUILD_CONFIG -- -j4
- cd ../wrappers/nodejs/
Expand Down
108 changes: 107 additions & 1 deletion wrappers/nodejs/src/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4539,6 +4539,7 @@ void InitModule(v8::Local<v8::Object> exports) {
_FORCE_SET_ENUM(RS2_EXCEPTION_TYPE_WRONG_API_CALL_SEQUENCE);
_FORCE_SET_ENUM(RS2_EXCEPTION_TYPE_NOT_IMPLEMENTED);
_FORCE_SET_ENUM(RS2_EXCEPTION_TYPE_DEVICE_IN_RECOVERY_MODE);
_FORCE_SET_ENUM(RS2_EXCEPTION_TYPE_IO);
_FORCE_SET_ENUM(RS2_EXCEPTION_TYPE_COUNT);

// rs2_stream
Expand Down Expand Up @@ -4583,9 +4584,10 @@ void InitModule(v8::Local<v8::Object> exports) {
_FORCE_SET_ENUM(RS2_FORMAT_INZI);
_FORCE_SET_ENUM(RS2_FORMAT_INVI);
_FORCE_SET_ENUM(RS2_FORMAT_W10);
_FORCE_SET_ENUM(RS2_FORMAT_Z16H);
_FORCE_SET_ENUM(RS2_FORMAT_COUNT);

// rs2_frame_type_value
// rs2_frame_metadata_value
_FORCE_SET_ENUM(RS2_FRAME_METADATA_FRAME_COUNTER);
_FORCE_SET_ENUM(RS2_FRAME_METADATA_FRAME_TIMESTAMP);
_FORCE_SET_ENUM(RS2_FRAME_METADATA_SENSOR_TIMESTAMP);
Expand Down Expand Up @@ -4615,6 +4617,13 @@ void InitModule(v8::Local<v8::Object> exports) {
_FORCE_SET_ENUM(RS2_FRAME_METADATA_MANUAL_WHITE_BALANCE);
_FORCE_SET_ENUM(RS2_FRAME_METADATA_POWER_LINE_FREQUENCY);
_FORCE_SET_ENUM(RS2_FRAME_METADATA_LOW_LIGHT_COMPENSATION);
_FORCE_SET_ENUM(RS2_FRAME_METADATA_FRAME_EMITTER_MODE);
_FORCE_SET_ENUM(RS2_FRAME_METADATA_FRAME_LED_POWER);
_FORCE_SET_ENUM(RS2_FRAME_METADATA_RAW_FRAME_SIZE);
_FORCE_SET_ENUM(RS2_FRAME_METADATA_GPIO_INPUT_DATA);
_FORCE_SET_ENUM(RS2_FRAME_METADATA_SEQUENCE_NAME);
_FORCE_SET_ENUM(RS2_FRAME_METADATA_SEQUENCE_ID);
_FORCE_SET_ENUM(RS2_FRAME_METADATA_SEQUENCE_SIZE);
_FORCE_SET_ENUM(RS2_FRAME_METADATA_COUNT);

// rs2_distortion
Expand All @@ -4623,6 +4632,7 @@ void InitModule(v8::Local<v8::Object> exports) {
_FORCE_SET_ENUM(RS2_DISTORTION_INVERSE_BROWN_CONRADY);
_FORCE_SET_ENUM(RS2_DISTORTION_FTHETA);
_FORCE_SET_ENUM(RS2_DISTORTION_BROWN_CONRADY);
_FORCE_SET_ENUM(RS2_DISTORTION_KANNALA_BRANDT4);
_FORCE_SET_ENUM(RS2_DISTORTION_COUNT);

// rs2_option
Expand Down Expand Up @@ -4721,8 +4731,13 @@ void InitModule(v8::Local<v8::Object> exports) {
_FORCE_SET_ENUM(RS2_CAMERA_INFO_PRODUCT_ID);
_FORCE_SET_ENUM(RS2_CAMERA_INFO_CAMERA_LOCKED);
_FORCE_SET_ENUM(RS2_CAMERA_INFO_USB_TYPE_DESCRIPTOR);
_FORCE_SET_ENUM(RS2_CAMERA_INFO_PRODUCT_LINE);
_FORCE_SET_ENUM(RS2_CAMERA_INFO_ASIC_SERIAL_NUMBER);
_FORCE_SET_ENUM(RS2_CAMERA_INFO_FIRMWARE_UPDATE_ID);
_FORCE_SET_ENUM(RS2_CAMERA_INFO_IP_ADDRESS);
_FORCE_SET_ENUM(RS2_CAMERA_INFO_COUNT);


// rs2_log_severity
_FORCE_SET_ENUM(RS2_LOG_SEVERITY_DEBUG);
_FORCE_SET_ENUM(RS2_LOG_SEVERITY_INFO);
Expand All @@ -4731,6 +4746,7 @@ void InitModule(v8::Local<v8::Object> exports) {
_FORCE_SET_ENUM(RS2_LOG_SEVERITY_FATAL);
_FORCE_SET_ENUM(RS2_LOG_SEVERITY_NONE);
_FORCE_SET_ENUM(RS2_LOG_SEVERITY_COUNT);
_FORCE_SET_ENUM(RS2_LOG_SEVERITY_ALL);

// rs2_notification_category
_FORCE_SET_ENUM(RS2_NOTIFICATION_CATEGORY_FRAMES_TIMEOUT);
Expand All @@ -4739,11 +4755,13 @@ void InitModule(v8::Local<v8::Object> exports) {
_FORCE_SET_ENUM(RS2_NOTIFICATION_CATEGORY_HARDWARE_EVENT);
_FORCE_SET_ENUM(RS2_NOTIFICATION_CATEGORY_UNKNOWN_ERROR);
_FORCE_SET_ENUM(RS2_NOTIFICATION_CATEGORY_FIRMWARE_UPDATE_RECOMMENDED);
_FORCE_SET_ENUM(RS2_NOTIFICATION_CATEGORY_POSE_RELOCALIZATION);
_FORCE_SET_ENUM(RS2_NOTIFICATION_CATEGORY_COUNT);

// rs2_timestamp_domain
_FORCE_SET_ENUM(RS2_TIMESTAMP_DOMAIN_HARDWARE_CLOCK);
_FORCE_SET_ENUM(RS2_TIMESTAMP_DOMAIN_SYSTEM_TIME);
_FORCE_SET_ENUM(RS2_TIMESTAMP_DOMAIN_GLOBAL_TIME);
_FORCE_SET_ENUM(RS2_TIMESTAMP_DOMAIN_COUNT);

// rs2_recording_mode
Expand Down Expand Up @@ -4830,8 +4848,96 @@ void InitModule(v8::Local<v8::Object> exports) {
_FORCE_SET_ENUM(RS2_EXTENSION_COLOR_SENSOR);
_FORCE_SET_ENUM(RS2_EXTENSION_MOTION_SENSOR);
_FORCE_SET_ENUM(RS2_EXTENSION_FISHEYE_SENSOR);
_FORCE_SET_ENUM(RS2_EXTENSION_DEPTH_HUFFMAN_DECODER);
_FORCE_SET_ENUM(RS2_EXTENSION_SERIALIZABLE);
_FORCE_SET_ENUM(RS2_EXTENSION_FW_LOGGER);
_FORCE_SET_ENUM(RS2_EXTENSION_AUTO_CALIBRATION_FILTER);
_FORCE_SET_ENUM(RS2_EXTENSION_DEVICE_CALIBRATION);
_FORCE_SET_ENUM(RS2_EXTENSION_CALIBRATED_SENSOR);
_FORCE_SET_ENUM(RS2_EXTENSION_HDR_MERGE);
_FORCE_SET_ENUM(RS2_EXTENSION_SEQUENCE_ID_FILTER);
_FORCE_SET_ENUM(RS2_EXTENSION_COUNT);


// rs2_ambient_light
_FORCE_SET_ENUM(RS2_AMBIENT_LIGHT_NO_AMBIENT)
_FORCE_SET_ENUM(RS2_AMBIENT_LIGHT_LOW_AMBIENT)


// rs2_cah_trigger
_FORCE_SET_ENUM(RS2_CAH_TRIGGER_MANUAL)
_FORCE_SET_ENUM(RS2_CAH_TRIGGER_NOW)
_FORCE_SET_ENUM(RS2_CAH_TRIGGER_AUTO)
_FORCE_SET_ENUM(RS2_CAH_TRIGGER_COUNT)


// rs2_calibration_type
_FORCE_SET_ENUM(RS2_CALIBRATION_AUTO_DEPTH_TO_RGB)
_FORCE_SET_ENUM(RS2_CALIBRATION_MANUAL_DEPTH_TO_RGB)
_FORCE_SET_ENUM(RS2_CALIBRATION_TYPE_COUNT)


// rs2_calibration_status
_FORCE_SET_ENUM(RS2_CALIBRATION_TRIGGERED)
_FORCE_SET_ENUM(RS2_CALIBRATION_SPECIAL_FRAME)
_FORCE_SET_ENUM(RS2_CALIBRATION_STARTED)
_FORCE_SET_ENUM(RS2_CALIBRATION_NOT_NEEDED)
_FORCE_SET_ENUM(RS2_CALIBRATION_SUCCESSFUL)
_FORCE_SET_ENUM(RS2_CALIBRATION_RETRY)
_FORCE_SET_ENUM(RS2_CALIBRATION_FAILED)
_FORCE_SET_ENUM(RS2_CALIBRATION_SCENE_INVALID)
_FORCE_SET_ENUM(RS2_CALIBRATION_BAD_RESULT)
_FORCE_SET_ENUM(RS2_CALIBRATION_BAD_CONDITIONS)
_FORCE_SET_ENUM(RS2_CALIBRATION_STATUS_FIRST)
_FORCE_SET_ENUM(RS2_CALIBRATION_STATUS_LAST)
_FORCE_SET_ENUM(RS2_CALIBRATION_STATUS_COUNT)


// rs2_dsm_correction_model
_FORCE_SET_ENUM(RS2_DSM_CORRECTION_NONE)
_FORCE_SET_ENUM(RS2_DSM_CORRECTION_AOT)
_FORCE_SET_ENUM(RS2_DSM_CORRECTION_TOA)
_FORCE_SET_ENUM(RS2_DSM_CORRECTION_COUNT)


// rs2_host_perf_mode
_FORCE_SET_ENUM(RS2_HOST_PERF_DEFAULT)
_FORCE_SET_ENUM(RS2_HOST_PERF_LOW)
_FORCE_SET_ENUM(RS2_HOST_PERF_HIGH)
_FORCE_SET_ENUM(RS2_HOST_PERF_COUNT)


// rs2_l500_visual_preset
_FORCE_SET_ENUM(RS2_L500_VISUAL_PRESET_CUSTOM)
_FORCE_SET_ENUM(RS2_L500_VISUAL_PRESET_DEFAULT)
_FORCE_SET_ENUM(RS2_L500_VISUAL_PRESET_NO_AMBIENT)
_FORCE_SET_ENUM(RS2_L500_VISUAL_PRESET_LOW_AMBIENT)
_FORCE_SET_ENUM(RS2_L500_VISUAL_PRESET_MAX_RANGE)
_FORCE_SET_ENUM(RS2_L500_VISUAL_PRESET_SHORT_RANGE)
_FORCE_SET_ENUM(RS2_L500_VISUAL_PRESET_COUNT)


// rs2_matchers
_FORCE_SET_ENUM(RS2_MATCHER_DI)
_FORCE_SET_ENUM(RS2_MATCHER_DI_C)
_FORCE_SET_ENUM(RS2_MATCHER_DLR_C)
_FORCE_SET_ENUM(RS2_MATCHER_DLR)
_FORCE_SET_ENUM(RS2_MATCHER_DIC)
_FORCE_SET_ENUM(RS2_MATCHER_DIC_C)
_FORCE_SET_ENUM(RS2_MATCHER_DEFAULT)
_FORCE_SET_ENUM(RS2_MATCHER_COUNT)


// rs2_sensor_mode
_FORCE_SET_ENUM(RS2_SENSOR_MODE_VGA)
_FORCE_SET_ENUM(RS2_SENSOR_MODE_XGA)
_FORCE_SET_ENUM(RS2_SENSOR_MODE_QVGA)
_FORCE_SET_ENUM(RS2_SENSOR_MODE_COUNT)


// rs2_digital_gain
_FORCE_SET_ENUM(RS2_DIGITAL_GAIN_HIGH)
_FORCE_SET_ENUM(RS2_DIGITAL_GAIN_LOW)
}

NODE_MODULE(node_librealsense, InitModule);
75 changes: 75 additions & 0 deletions wrappers/nodejs/tools/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# -*- coding: utf-8 -*-
import re
import os
import sys
import argparse


ENUM_H_REGEXP = r'^[ ]*(RS2_\w+)'
ENUM_CPP_REGEXP = r'^[ ]*_FORCE_SET_ENUM\((\w+)\)'
ENUM_JS_REGEXP = r'RS2\.(RS2_\w+)'


def files_gen(path, ends):
for root, dirs, files in os.walk(path):
for file in files:
if file.endswith(ends):
yield os.path.join(root, file)


def get_first_by_regexp(line, regexp):
res = re.findall(regexp, line)
if res:
return res[0]
return ''


def get_enums_from_folder(folder_path, ends, regexp):
file_paths = files_gen(folder_path, ends)
enums = []
for file_path in file_paths:
enums += get_enums_from_file(file_path, regexp)
return enums


def get_enums_from_file(file_path, regexp):
enums = []
with open(file_path) as f:
for line in f:
enum = get_first_by_regexp(line, regexp)
if enum:
enums.append(enum)

return enums


def run(include_folder_path, addon_folder_path):

include_enums = get_enums_from_folder(include_folder_path, '.h', ENUM_H_REGEXP)
cpp_enums = get_enums_from_folder(addon_folder_path, '.cpp', ENUM_CPP_REGEXP)
# js_enums = get_enums_from_file(js_file_path, ENUM_JS_REGEXP)

include_enums.sort()
cpp_enums.sort()
# js_enums.sort()

# print(len(include_enums), len(cpp_enums), len(js_enums))
return list(set(include_enums) - set(cpp_enums))


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Ping script')
parser.add_argument('-i', action='store', dest='include_folder_path', required=True)
parser.add_argument('-a', action='store', dest='addon_folder_path', required=True)
parser.add_argument('-v', '--verbose', action='store_true', help='print not user enums')

args = parser.parse_args()

missed = run(args.include_folder_path, args.addon_folder_path)

if missed:
missed.sort()
message = "[ERROR] Node.js wrapper has missing enum values: %s" % (', '.join(missed))
sys.exit(message if args.verbose else 1)

sys.exit()