Skip to content
Snippets Groups Projects
Commit 25fca63a authored by Emily Anne Thompson's avatar Emily Anne Thompson
Browse files

Fix for other char sizes too

parent 14fafe52
Branches
No related tags found
2 merge requests!316Merge devel into main,!302Add developments for cold box
Pipeline #5911444 passed
......@@ -215,11 +215,21 @@ std::string SerialCom::receive() {
std::string response = std::string(m_tmpbuf, n_read);
// Convert response if communication uses charsize different from 8
if (m_charsize == mapCHARSIZE.at("CS7")) {
if (m_charsize != mapCHARSIZE.at("CS8")) {
std::string decoded_response;
for (size_t i = 0; i < response.length(); i++) {
unsigned char original = static_cast<unsigned char>(response[i]);
unsigned char fixed = original & 0x7F;
unsigned char original =
static_cast<unsigned char>(response[i]);
unsigned char fixed;
if (m_charsize == mapCHARSIZE.at("CS7"))
fixed = original & 0x7F;
else if (m_charsize == mapCHARSIZE.at("CS6"))
fixed = original & 0x6F;
else if (m_charsize == mapCHARSIZE.at("CS5"))
fixed = original & 0x5F;
else
throw std::runtime_error(
"CharSize not recognized! Unable to decode response");
decoded_response.push_back(fixed);
}
response = decoded_response;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment