Skip to content

Commit

Permalink
Add model ID query (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
willeccles authored Dec 17, 2024
2 parents 2d6965b + 299a06b commit e07c127
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
13 changes: 13 additions & 0 deletions include/bci/abs/CInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,19 @@ int AbsScpiClient_UnloadModel(AbsScpiClientHandle handle);
int AbsScpiClient_GetModelInfo(AbsScpiClientHandle handle,
AbsModelInfo* model_info_out);

/**
* @brief Query the ID of the currently loaded model. This ID is user-defined
* and is not used by the unit. It is intended for use by tools.
*
* @param[in] handle SCPI client
* @param[out] id_buf buffer to store the null-terminated ID
* @param[in] buf_len length of @a id_buf
*
* @return 0 on success or a negative error code.
*/
int AbsScpiClient_GetModelId(AbsScpiClientHandle handle, char id_buf[],
unsigned int buf_len);

/**
* @brief Set a single global model input. Particularly useful with multicast to
* address multiple units at once.
Expand Down
8 changes: 8 additions & 0 deletions include/bci/abs/ScpiClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,14 @@ class ScpiClient {
*/
Result<ModelInfo> GetModelInfo() const;

/**
* @brief Query the ID of the currently loaded model. This ID is arbitrary and
* set in the config. It is primarily for tool use.
*
* @return Result containing the model ID or an error code.
*/
Result<std::string> GetModelId() const;

/**
* @brief Set a global model input.
*
Expand Down
27 changes: 27 additions & 0 deletions src/CInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,33 @@ int AbsScpiClient_GetModelInfo(AbsScpiClientHandle handle,
return static_cast<int>(ec::kUnexpectedException);
}

int AbsScpiClient_GetModelId(AbsScpiClientHandle handle, char id_buf[],
unsigned int buf_len) try {
if (!handle || !id_buf || buf_len == 0) {
return static_cast<int>(ec::kInvalidArgument);
}

std::memset(id_buf, '\0', buf_len);

if (auto id = GetClient(handle).GetModelId()) {
// must have enough space for the id + null terminator
if (buf_len < id->size() + 1) {
return static_cast<int>(ec::kBufferTooSmall);
}

id->copy(id_buf, id->size());
id_buf[id->size()] = '\0';
} else {
return static_cast<int>(id.error());
}

return static_cast<int>(ec::kSuccess);
} catch (const std::bad_alloc&) {
return static_cast<int>(ec::kAllocationFailed);
} catch (...) {
return static_cast<int>(ec::kUnexpectedException);
}

int AbsScpiClient_SetGlobalModelInput(AbsScpiClientHandle handle,
unsigned int index, float value) {
return WrapSet(&sc::SetGlobalModelInput, handle, index, value);
Expand Down
4 changes: 4 additions & 0 deletions src/ScpiClient_Modeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ Result<ModelInfo> ScpiClient::GetModelInfo() const {
return ModelInfo{std::move(res->at(0)), std::move(res->at(1))};
}

Result<std::string> ScpiClient::GetModelId() const {
return SendAndRecv("MOD:ID?\r\n").and_then(scpi::ParseStringResponse);
}

ErrorCode ScpiClient::SetGlobalModelInput(unsigned int index,
float value) const {
if (index >= kGlobalModelInputCount) {
Expand Down

0 comments on commit e07c127

Please sign in to comment.