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

Fix code generation for 16-bit block moves #1007

Merged
merged 4 commits into from
Oct 5, 2023
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
52 changes: 8 additions & 44 deletions generated/visa/visa_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -955,48 +955,6 @@ namespace visa_grpc {
}
}

//---------------------------------------------------------------------
//---------------------------------------------------------------------
::grpc::Status VisaService::MoveIn16(::grpc::ServerContext* context, const MoveIn16Request* request, MoveIn16Response* response)
{
if (context->IsCancelled()) {
return ::grpc::Status::CANCELLED;
}
try {
auto vi_grpc_session = request->vi();
ViSession vi = session_repository_->access_session(vi_grpc_session.name());
ViUInt16 address_space;
switch (request->address_space_enum_case()) {
case visa_grpc::MoveIn16Request::AddressSpaceEnumCase::kAddressSpace: {
address_space = static_cast<ViUInt16>(request->address_space());
break;
}
case visa_grpc::MoveIn16Request::AddressSpaceEnumCase::kAddressSpaceRaw: {
address_space = static_cast<ViUInt16>(request->address_space_raw());
break;
}
case visa_grpc::MoveIn16Request::AddressSpaceEnumCase::ADDRESS_SPACE_ENUM_NOT_SET: {
return ::grpc::Status(::grpc::INVALID_ARGUMENT, "The value for address_space was not specified or out of range");
break;
}
}

ViBusAddress64 offset = request->offset();
ViBusSize count = request->count();
response->mutable_buffer()->Resize(count, 0);
ViUInt16* buffer = reinterpret_cast<ViUInt16*>(response->mutable_buffer()->mutable_data());
auto status = library_->MoveIn16(vi, address_space, offset, count, buffer);
if (!status_ok(status)) {
return ConvertApiErrorStatusForViSession(context, status, vi);
}
response->set_status(status);
return ::grpc::Status::OK;
}
catch (nidevice_grpc::NonDriverException& ex) {
return ex.GetStatus();
}
}

//---------------------------------------------------------------------
//---------------------------------------------------------------------
::grpc::Status VisaService::MoveIn32(::grpc::ServerContext* context, const MoveIn32Request* request, MoveIn32Response* response)
Expand Down Expand Up @@ -1151,8 +1109,14 @@ namespace visa_grpc {

ViBusAddress64 offset = request->offset();
ViBusSize count = static_cast<ViBusSize>(request->buffer().size());
auto buffer = const_cast<ViUInt16*>(reinterpret_cast<const ViUInt16*>(request->buffer().data()));
auto status = library_->MoveOut16(vi, address_space, offset, count, buffer);
auto buffer_request = request->buffer();
std::vector<ViUInt16> buffer;
std::transform(
buffer_request.begin(),
buffer_request.end(),
std::back_inserter(buffer),
[](auto x) { return (ViUInt16)x; });
auto status = library_->MoveOut16(vi, address_space, offset, count, buffer.data());
if (!status_ok(status)) {
return ConvertApiErrorStatusForViSession(context, status, vi);
}
Expand Down
1 change: 1 addition & 0 deletions source/codegen/metadata/visa/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@
},
'MoveIn16': {
'cname': 'viMoveIn16Ex',
'codegen_method': 'CustomCode',
'parameters': [
{
'direction': 'in',
Expand Down
3 changes: 2 additions & 1 deletion source/codegen/service_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ def _is_array_that_requires_conversion(parameter):
or get_c_element_type_for_array_that_needs_coercion(parameter) is not None
# Sessions are "converted" by accessing the session repository.
or parameter["grpc_type"] == "repeated nidevice_grpc.Session"
# ViInt16s have a hardcoded copy convert routine that predates the coerced flag.
# Vi*Int16s have a hardcoded copy convert routine that predates the coerced flag.
or parameter["type"] == "ViInt16[]"
or parameter["type"] == "ViUInt16[]"
)

return False
Expand Down
10 changes: 5 additions & 5 deletions source/codegen/templates/service_helpers.mako
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ ${initialize_standard_input_param(function_name, parameter)}
${parameter_name}_request.end(),
std::back_inserter(${parameter_name}),
[](auto x) { return x ? VI_TRUE : VI_FALSE; });
% elif c_type == 'ViInt16[]':
% elif c_type in ['ViInt16[]', 'ViUInt16[]']:
auto ${parameter_name}_request = ${request_snippet};
std::vector<${c_type_underlying_type}> ${parameter_name};
std::transform(
Expand All @@ -616,11 +616,11 @@ ${initialize_standard_input_param(function_name, parameter)}
${c_type} ${parameter_name} = ${service_helpers.session_repository_field_name(parameter, config)}->access_session(${parameter_name}_grpc_session.name());\
% elif is_array and common_helpers.is_driver_typedef_with_same_size_but_different_qualifiers(c_type_underlying_type):
auto ${parameter_name} = const_cast<${c_type_pointer}>(reinterpret_cast<const ${c_type_pointer}>(${request_snippet}.data()));\
%elif c_type in ['const int32[]', 'const uInt32[]']:
% elif c_type in ['const int32[]', 'const uInt32[]']:
auto ${parameter_name} = reinterpret_cast<${c_type_pointer}>(${request_snippet}.data());\
%elif grpc_type == 'bytes':
% elif grpc_type == 'bytes':
auto ${parameter_name} = reinterpret_cast<const unsigned char*>(${request_snippet}.data());\
%elif service_helpers.is_scalar_input_that_needs_coercion(parameter):
% elif service_helpers.is_scalar_input_that_needs_coercion(parameter):
auto ${parameter_name}_raw = ${request_snippet};
if (${parameter_name}_raw < std::numeric_limits<${c_type}>::min() || ${parameter_name}_raw > std::numeric_limits<${c_type}>::max()) {
std::string message("value ");
Expand All @@ -630,7 +630,7 @@ ${initialize_standard_input_param(function_name, parameter)}
throw nidevice_grpc::ValueOutOfRangeException(message);
}
auto ${parameter_name} = static_cast<${c_type}>(${parameter_name}_raw);
%elif service_helpers.is_input_array_that_needs_coercion(parameter):
% elif service_helpers.is_input_array_that_needs_coercion(parameter):
auto ${parameter_name}_raw = ${request_snippet};
auto ${parameter_name} = std::vector<${c_element_type_that_needs_coercion}>();
${parameter_name}.reserve(${parameter_name}_raw.size());
Expand Down
55 changes: 53 additions & 2 deletions source/custom/visa_service.custom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ ::grpc::Status VisaService::Open(::grpc::ServerContext* context, const OpenReque
// NI-VISA writes the events followed by an extra "-1" value that we don't need.
std::vector<EventType> events(numEvents+1);
library->GetAttribute(vi, VI_ATTR_SUP_EVENTS, events.data());
for (ViUInt16 i = 0; i < numEvents; ++i) {
response->add_supported_events(events[i]);
for (ViUInt16 index = 0; index < numEvents; ++index) {
response->add_supported_events(events[index]);
}
}

Expand All @@ -284,6 +284,57 @@ ::grpc::Status VisaService::Open(::grpc::ServerContext* context, const OpenReque
}
}

//---------------------------------------------------------------------
//---------------------------------------------------------------------
::grpc::Status VisaService::MoveIn16(::grpc::ServerContext* context, const MoveIn16Request* request, MoveIn16Response* response)
{
if (context->IsCancelled()) {
return ::grpc::Status::CANCELLED;
}
ViSession vi = VI_NULL;
try {
auto vi_grpc_session = request->vi();
vi = session_repository_->access_session(vi_grpc_session.name());
ViUInt16 address_space;
switch (request->address_space_enum_case()) {
case visa_grpc::MoveIn16Request::AddressSpaceEnumCase::kAddressSpace: {
address_space = static_cast<ViUInt16>(request->address_space());
break;
}
case visa_grpc::MoveIn16Request::AddressSpaceEnumCase::kAddressSpaceRaw: {
address_space = static_cast<ViUInt16>(request->address_space_raw());
break;
}
case visa_grpc::MoveIn16Request::AddressSpaceEnumCase::ADDRESS_SPACE_ENUM_NOT_SET: {
return ::grpc::Status(::grpc::INVALID_ARGUMENT, "The value for address_space was not specified or out of range");
break;
}
}

ViBusAddress64 offset = request->offset();
ViBusSize count = request->count();
std::vector<ViUInt16> driver_buffer(count);
ViUInt16* buffer_pointer = driver_buffer.data();
auto status = library_->MoveIn16(vi, address_space, offset, count, buffer_pointer);
if (!status_ok(status)) {
return ConvertApiErrorStatusForViSession(context, status, vi);
}
auto response_buffer = response->mutable_buffer();
response_buffer->Resize(static_cast<int>(count), 0);
for (ViUInt32 index = 0; index < count; ++index) {
response_buffer->Set(index, *buffer_pointer++);
}
response->set_status(status);
return ::grpc::Status::OK;
}
catch (const std::bad_alloc&) {
return ConvertApiErrorStatusForViSession(context, VI_ERROR_ALLOC, vi);
}
catch (const nidevice_grpc::NonDriverException& ex) {
return ex.GetStatus();
}
}

//---------------------------------------------------------------------
//---------------------------------------------------------------------
::grpc::Status VisaService::ParseRsrc(::grpc::ServerContext* context, const ParseRsrcRequest* request, ParseRsrcResponse* response)
Expand Down