Skip to content

Commit 328b11f

Browse files
Making DPDCfgApplyDPDUserLookupTableInterleavedIQ as special (#1210)
* Making DPDCfgApplyDPDUserLookupTableInterleavedIQ as special * Correcting the special metadata in functions_addon.py of nifrmxspecan and generating proto file * Correcting the special metadata and generating gRPC Service code --------- Co-authored-by: rnagaraj <[email protected]>
1 parent 5545f26 commit 328b11f

File tree

5 files changed

+110
-56
lines changed

5 files changed

+110
-56
lines changed

generated/nirfmxspecan/nirfmxspecan_compilation_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ int32 DPDCfgApplyDPDUserLookupTable(niRFmxInstrHandle instrumentHandle, char sel
704704

705705
int32 DPDCfgApplyDPDUserLookupTableInterleavedIQ(niRFmxInstrHandle instrumentHandle, char selectorString[], float32 lutInputPowers[], float32 lutComplexGains[], int32 arraySize)
706706
{
707-
return RFmxSpecAn_DPDCfgApplyDPDUserLookupTable(instrumentHandle, selectorString, lutInputPowers, reinterpret_cast<NIComplexSingle*>(lutComplexGains), arraySize/2);
707+
return RFmxSpecAn_DPDCfgApplyDPDUserLookupTable(instrumentHandle, selectorString, lutInputPowers, reinterpret_cast<NIComplexSingle*>(lutComplexGains), arraySize);
708708
}
709709

710710
int32 DPDCfgApplyDPDUserLookupTableSplit(niRFmxInstrHandle instrumentHandle, char selectorString[], float32 lutInputPowers[], float32 lutComplexGainsI[], float32 lutComplexGainsQ[], int32 arraySize)

generated/nirfmxspecan/nirfmxspecan_library.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ int32 NiRFmxSpecAnLibrary::DPDCfgApplyDPDUserLookupTableInterleavedIQ(niRFmxInst
16481648
if (!function_pointers_.DPDCfgApplyDPDUserLookupTableInterleavedIQ) {
16491649
throw nidevice_grpc::LibraryLoadException("Could not find RFmxSpecAn_DPDCfgApplyDPDUserLookupTable.");
16501650
}
1651-
return function_pointers_.DPDCfgApplyDPDUserLookupTableInterleavedIQ(instrumentHandle, selectorString, lutInputPowers, reinterpret_cast<NIComplexSingle*>(lutComplexGains), arraySize/2);
1651+
return function_pointers_.DPDCfgApplyDPDUserLookupTableInterleavedIQ(instrumentHandle, selectorString, lutInputPowers, reinterpret_cast<NIComplexSingle*>(lutComplexGains), arraySize);
16521652
}
16531653

16541654
int32 NiRFmxSpecAnLibrary::DPDCfgApplyDPDUserLookupTableSplit(niRFmxInstrHandle instrumentHandle, char selectorString[], float32 lutInputPowers[], float32 lutComplexGainsI[], float32 lutComplexGainsQ[], int32 arraySize)

generated/nirfmxspecan/nirfmxspecan_service.cpp

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5622,49 +5622,6 @@ namespace nirfmxspecan_grpc {
56225622
}
56235623
}
56245624

5625-
//---------------------------------------------------------------------
5626-
//---------------------------------------------------------------------
5627-
::grpc::Status NiRFmxSpecAnService::DPDCfgApplyDPDUserLookupTableInterleavedIQ(::grpc::ServerContext* context, const DPDCfgApplyDPDUserLookupTableInterleavedIQRequest* request, DPDCfgApplyDPDUserLookupTableInterleavedIQResponse* response)
5628-
{
5629-
if (context->IsCancelled()) {
5630-
return ::grpc::Status::CANCELLED;
5631-
}
5632-
try {
5633-
auto instrument_grpc_session = request->instrument();
5634-
niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.name());
5635-
auto selector_string_mbcs = convert_from_grpc<std::string>(request->selector_string());
5636-
char* selector_string = (char*)selector_string_mbcs.c_str();
5637-
auto lut_input_powers = const_cast<float32*>(request->lut_input_powers().data());
5638-
auto lut_complex_gains = const_cast<float32*>(request->lut_complex_gains().data());
5639-
auto array_size_determine_from_sizes = std::array<int, 2>
5640-
{
5641-
request->lut_input_powers_size(),
5642-
request->lut_complex_gains_size()
5643-
};
5644-
const auto array_size_size_calculation = calculate_linked_array_size(array_size_determine_from_sizes, true);
5645-
5646-
if (array_size_size_calculation.match_state == MatchState::MISMATCH) {
5647-
return ::grpc::Status(::grpc::INVALID_ARGUMENT, "The sizes of linked repeated fields [lut_input_powers, lut_complex_gains] do not match");
5648-
}
5649-
// NULL out optional params with zero sizes.
5650-
if (array_size_size_calculation.match_state == MatchState::MATCH_OR_ZERO) {
5651-
lut_input_powers = request->lut_input_powers_size() ? std::move(lut_input_powers) : nullptr;
5652-
lut_complex_gains = request->lut_complex_gains_size() ? std::move(lut_complex_gains) : nullptr;
5653-
}
5654-
auto array_size = array_size_size_calculation.size;
5655-
5656-
auto status = library_->DPDCfgApplyDPDUserLookupTableInterleavedIQ(instrument, selector_string, lut_input_powers, lut_complex_gains, array_size);
5657-
if (!status_ok(status)) {
5658-
return ConvertApiErrorStatusForNiRFmxInstrHandle(context, status, instrument);
5659-
}
5660-
response->set_status(status);
5661-
return ::grpc::Status::OK;
5662-
}
5663-
catch (nidevice_grpc::NonDriverException& ex) {
5664-
return ex.GetStatus();
5665-
}
5666-
}
5667-
56685625
//---------------------------------------------------------------------
56695626
//---------------------------------------------------------------------
56705627
::grpc::Status NiRFmxSpecAnService::DPDCfgApplyDPDUserLookupTableSplit(::grpc::ServerContext* context, const DPDCfgApplyDPDUserLookupTableSplitRequest* request, DPDCfgApplyDPDUserLookupTableSplitResponse* response)

source/codegen/metadata/nirfmxspecan/functions_addon.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,53 @@
5555
],
5656
'returns': 'int32'
5757
},
58+
'DPDCfgApplyDPDUserLookupTableInterleavedIQ': {
59+
'cname': 'RFmxSpecAn_DPDCfgApplyDPDUserLookupTable',
60+
'codegen_method': 'CustomCode',
61+
'parameters': [
62+
{
63+
'direction': 'in',
64+
'grpc_name': 'instrument',
65+
'name': 'instrumentHandle',
66+
'type': 'niRFmxInstrHandle'
67+
},
68+
{
69+
'direction': 'in',
70+
'name': 'selectorString',
71+
'type': 'char[]'
72+
},
73+
{
74+
'direction': 'in',
75+
'name': 'lutInputPowers',
76+
'size': {
77+
'mechanism': 'custom-code',
78+
'tags': [
79+
'optional'
80+
],
81+
'value': 'arraySize'
82+
},
83+
'type': 'float32[]'
84+
},
85+
{
86+
'direction': 'in',
87+
'name': 'lutComplexGains',
88+
'size': {
89+
'mechanism': 'custom-code',
90+
'tags': [
91+
'optional'
92+
],
93+
'value': 'arraySize'
94+
},
95+
'type': 'float32[]',
96+
'value_converted_to_c_representation': 'reinterpret_cast<NIComplexSingle*>(lutComplexGains)'
97+
},
98+
{
99+
'direction': 'in',
100+
'include_in_proto': False,
101+
'name': 'arraySize',
102+
'type': 'int32',
103+
}
104+
],
105+
'returns': 'int32'
106+
},
58107
}
Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,66 @@
11
#include <nirfmxspecan/nirfmxspecan_service.h>
2+
using nidevice_grpc::converters::convert_to_grpc;
3+
using nidevice_grpc::converters::convert_from_grpc;
4+
using nidevice_grpc::converters::calculate_linked_array_size;
5+
using nidevice_grpc::converters::MatchState;
26

37
namespace nirfmxspecan_grpc {
48

5-
::grpc::Status NiRFmxSpecAnService::ConvertApiErrorStatusForNiRFmxInstrHandle(::grpc::ServerContextBase* context, int32_t status, niRFmxInstrHandle instrumentHandle)
6-
{
7-
ViStatus error_code{};
8-
std::string description(nidevice_grpc::kMaxGrpcErrorDescriptionSize, '\0');
9-
// Try first to get the most recent error with a dynamic message.
10-
library_->GetError(instrumentHandle, &error_code, nidevice_grpc::kMaxGrpcErrorDescriptionSize, &description[0]);
11-
if (error_code != status) {
12-
// Since another thread has changed the status, fall back to the static message lookup.
13-
library_->GetErrorString(instrumentHandle, status, nidevice_grpc::kMaxGrpcErrorDescriptionSize, &description[0]);
9+
// Returns true if it's safe to use outputs of a method with the given status.
10+
inline bool status_ok(int32 status)
11+
{
12+
return status >= 0;
13+
}
14+
15+
::grpc::Status NiRFmxSpecAnService::ConvertApiErrorStatusForNiRFmxInstrHandle(::grpc::ServerContextBase* context, int32_t status, niRFmxInstrHandle instrumentHandle)
16+
{
17+
ViStatus error_code{};
18+
std::string description(nidevice_grpc::kMaxGrpcErrorDescriptionSize, '\0');
19+
// Try first to get the most recent error with a dynamic message.
20+
library_->GetError(instrumentHandle, &error_code, nidevice_grpc::kMaxGrpcErrorDescriptionSize, &description[0]);
21+
if (error_code != status) {
22+
// Since another thread has changed the status, fall back to the static message lookup.
23+
library_->GetErrorString(instrumentHandle, status, nidevice_grpc::kMaxGrpcErrorDescriptionSize, &description[0]);
24+
}
25+
return nidevice_grpc::ApiErrorAndDescriptionToStatus(context, status, description);
26+
}
27+
28+
//---------------------------------------------------------------------
29+
//---------------------------------------------------------------------
30+
::grpc::Status NiRFmxSpecAnService::DPDCfgApplyDPDUserLookupTableInterleavedIQ(::grpc::ServerContext*context, const DPDCfgApplyDPDUserLookupTableInterleavedIQRequest* request, DPDCfgApplyDPDUserLookupTableInterleavedIQResponse* response)
31+
{
32+
if (context->IsCancelled()) {
33+
return ::grpc::Status::CANCELLED;
34+
}
35+
try {
36+
auto instrument_grpc_session = request->instrument();
37+
niRFmxInstrHandle instrument = session_repository_->access_session(instrument_grpc_session.name());
38+
auto selector_string_mbcs = convert_from_grpc<std::string>(request->selector_string());
39+
char* selector_string = (char*)selector_string_mbcs.c_str();
40+
auto lut_input_powers = const_cast<float32*>(request->lut_input_powers().data());
41+
auto lut_complex_gains = const_cast<float32*>(request->lut_complex_gains().data());
42+
auto array_size = 0;
43+
if (request->lut_input_powers_size()) {
44+
array_size = request->lut_input_powers_size() * 2;
45+
if (request->lut_complex_gains_size()) {
46+
if (request->lut_complex_gains_size() != array_size) {
47+
return ::grpc::Status(::grpc::INVALID_ARGUMENT, "lut_complex_gains size must be twice the size of lut_input_powers.");
48+
}
49+
}
50+
}
51+
else if (request->lut_complex_gains_size()) {
52+
array_size = request->lut_complex_gains_size();
53+
}
54+
auto status = library_->DPDCfgApplyDPDUserLookupTableInterleavedIQ(instrument, selector_string, lut_input_powers, lut_complex_gains, array_size);
55+
if (!status_ok(status)) {
56+
return ConvertApiErrorStatusForNiRFmxInstrHandle(context, status, instrument);
57+
}
58+
response->set_status(status);
59+
return ::grpc::Status::OK;
60+
}
61+
catch (nidevice_grpc::NonDriverException& ex) {
62+
return ex.GetStatus();
63+
}
1464
}
15-
return nidevice_grpc::ApiErrorAndDescriptionToStatus(context, status, description);
16-
}
1765

1866
} // namespace nirfmxspecan_grpc

0 commit comments

Comments
 (0)