Skip to content

Commit

Permalink
flesh out error string reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
d-perl committed Nov 13, 2024
1 parent a1c3db5 commit b7055f2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 14 deletions.
37 changes: 25 additions & 12 deletions src/rtc6_fastcs/bindings/rtc6_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,31 @@ std::string parse_error(int errorCode)
{
std::string out = "";
std::bitset<32> errorBits(errorCode);
if (errorBits[0])
{
out += "No board found. ";
}
if (errorBits[1])
{
out += "Access denied. Could indicate wrong program files. ";
}
if (errorBits[2])
std::string errorStrings[32] = {
"No board found", // 0
"Access denied. Could indicate wrong program files. ", // 1
"Command not forwarded. ", // 2
"No response from board. ", // 3
"Invalid parameter. ", // 4
"Busy: list processing in wrong state for command. ", // 5
"List command rejected: invalid input pointer. ", // 6
"Ignored: list command converted to nop. ", // 7
"Version mismatch error. ", // 8
"Download verification error. ", // 9
"PCIe command sent to Eth board or vice-versa. ", // 10
"Windows memory request failed. ", // 11
"Download error. The values have possibly not been saved.", // 12
"General ethernet error", // 13
"", // 14: Reserved
"Unsupported Windows version. ", // 15
};
for (int i = 0; i != 32; i++)
{
out += "Command not forwarded. ";
}
if (errorBits[i])
{
out += errorStrings[i];
}
};
return out;
}

Expand Down Expand Up @@ -155,7 +168,7 @@ int connect(const char *ipStr, char *programFilePath, char *correctionFilePath)
int error = get_error();
if (result != cardNo || error != 0)
{
throw RtcError(str(format("select_rtc for card %1% failed with error: %2%. Most likely, a card was not found at the given IP address: %3%. Alternatively, it may already be acquired by another process. Error code: %4%") % cardNo % result % ipStr % error));
throw RtcError(str(format("select_rtc for card %1% failed with error: %2%. Most likely, a card was not found at the given IP address: %3%. Alternatively, it may already be acquired by another process. Error code: %4%. Description: %5%") % cardNo % result % ipStr % error % parse_error(error)));
}
return load_program_and_correction_files(cardNo, programFilePath, correctionFilePath);
error = get_error();
Expand Down
Binary file not shown.
4 changes: 4 additions & 0 deletions src/rtc6_fastcs/controller/rtc_connection.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import asyncio
import logging

from rtc6_fastcs.bindings.rtc6_bindings import CardInfo, RtcError

LOGGER = logging.getLogger(__name__)


class RtcConnection:
def __init__(
Expand Down Expand Up @@ -35,6 +38,7 @@ async def connect(self) -> None:
except RtcError as e:
if not self._retry_connect:
raise Exception("Not retrying failed connection") from e
LOGGER.warning(f"Connection failed: {e.args[0]}! Retrying...")
await asyncio.sleep(1)

async def close(self) -> None:
Expand Down
20 changes: 18 additions & 2 deletions src/rtc6_fastcs/controller/rtc_controller.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import asyncio

from fastcs.attributes import AttrR
from fastcs.attributes import AttrR, AttrW
from fastcs.controller import Controller, SubController
from fastcs.datatypes import Bool, Int, String
from fastcs.datatypes import Bool, Float, Int, String

from rtc6_fastcs.controller.rtc_connection import RtcConnection

Expand All @@ -27,6 +27,21 @@ def __init__(self, conn: RtcConnection) -> None:
self._conn = conn


class RtcControlSettings(SubController):
# laser_mode = AttrR(Float(), group="Information") should be an enum
jump_speed = AttrW(Float(), group="LaserControl") # set_jump_speed_ctrl
mark_speed = AttrW(Float(), group="LaserControl") # set_mark_speed_ctrl
# set_scanner_delays(jump, mark, polygon) in 10us increments
jump_delay = AttrW(Int(), group="LaserControl")
mark_delay = AttrW(Int(), group="LaserControl")
polygon_delay = AttrW(Int(), group="LaserControl")
sky_writing_mode = AttrW(Int(), group="LaserControl") # set_sky_writing_mode

def __init__(self, conn: RtcConnection) -> None:
super().__init__()
self._conn = conn


class RtcController(Controller):
def __init__(
self,
Expand All @@ -41,6 +56,7 @@ def __init__(
)
self._info_controller = RtcInfoController(self._conn)
self.register_sub_controller("INFO", self._info_controller)
self.register_sub_controller("CONTROL", RtcControlSettings(self._conn))

async def connect(self) -> None:
await self._conn.connect()
Expand Down

0 comments on commit b7055f2

Please sign in to comment.