Skip to content

Commit c29ca44

Browse files
committed
Improve camera handling and response mapping in server. Get Tests passing again.
1 parent 044bb85 commit c29ca44

3 files changed

Lines changed: 65 additions & 63 deletions

File tree

deapi/client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,12 @@ def connect(self, host: str = "127.0.0.1", port: int = 13240, read_only=False):
173173
self.socket.setblocking(False)
174174
self.socket.settimeout(2)
175175

176-
self.cameras = self.__getStrings(self.LIST_CAMERAS)
176+
cameras = self.__getStrings(self.LIST_CAMERAS)
177+
if not cameras:
178+
raise ValueError("No cameras returned")
179+
return
180+
else:
181+
self.cameras = cameras
177182
if logLevel == logging.DEBUG:
178183
log.debug("Available cameras: %s", self.cameras)
179184
self.currCamera = self.cameras[0]

deapi/simulated_server/fake_server.py

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ def add_parameter(ack, value):
1919
Add a parameter to a protobuffer
2020
"""
2121
param = ack.parameter.add()
22-
if isinstance(value, str):
22+
if isinstance(value, bool): # must be before int — bool is a subclass of int
23+
param.type = pb.AnyParameter.P_BOOL
24+
param.p_bool = value
25+
elif isinstance(value, str):
2326
param.type = pb.AnyParameter.P_STRING
2427
param.p_string = value
2528
elif isinstance(value, int):
2629
param.type = pb.AnyParameter.P_INT
2730
param.p_int = value
28-
elif isinstance(value, bool):
29-
param.type = pb.AnyParameter.P_BOOL
30-
param.p_bool = value
3131
elif isinstance(value, float):
3232
param.type = pb.AnyParameter.P_FLOAT
3333
param.p_float = value
@@ -559,23 +559,23 @@ def _fake_get_result(self, command):
559559
acknowledge_return.type = pb.DEPacket.P_ACKNOWLEDGE
560560
ack1 = acknowledge_return.acknowledge.add()
561561
ack1.command_id = command.command[0].command_id
562-
frame_type = command.command[0].parameter[0].p_int
563-
pixel_format = command.command[0].parameter[1].p_int
564-
center_x = command.command[0].parameter[2].p_int
565-
center_y = command.command[0].parameter[3].p_int
566-
zoom = command.command[0].parameter[4].p_float
567-
windowWidth = command.command[0].parameter[5].p_int
568-
windowHeight = command.command[0].parameter[6].p_int
569-
fft = command.command[0].parameter[7].p_int
570-
stretchType = command.command[0].parameter[8].p_int
571-
stretch_min = command.command[0].parameter[9].p_float
572-
stretch_max = command.command[0].parameter[10].p_float
573-
stretch_gama = command.command[0].parameter[11].p_float
574-
outlier = command.command[0].parameter[12].p_float
575-
timeout = command.command[0].parameter[13].p_int
576-
histo_min = command.command[0].parameter[14].p_float
577-
histo_max = command.command[0].parameter[15].p_float
578-
histo_bins = command.command[0].parameter[16].p_int
562+
frame_type = command.command[0].parameter[0].p_int # [0] frame_type
563+
pixel_format = command.command[0].parameter[1].p_int # [1] pixel_format
564+
center_x = command.command[0].parameter[2].p_int # [2] centerX
565+
center_y = command.command[0].parameter[3].p_int # [3] centerY
566+
zoom = command.command[0].parameter[4].p_float # [4] zoom
567+
windowWidth = command.command[0].parameter[5].p_int # [5] windowWidth
568+
windowHeight = command.command[0].parameter[6].p_int # [6] windowHeight
569+
fft = command.command[0].parameter[7].p_int # [7] fft
570+
stretchType = command.command[0].parameter[8].p_int # [8] stretchType
571+
stretch_min = command.command[0].parameter[9].p_float # [9] manualStretchMin
572+
stretch_max = command.command[0].parameter[10].p_float # [10] manualStretchMax
573+
stretch_gama = command.command[0].parameter[11].p_float # [11] manualStretchGamma
574+
outlier = command.command[0].parameter[12].p_float # [12] outlierPercentage
575+
timeout = command.command[0].parameter[13].p_int # [13] timeoutMsec
576+
histo_min = command.command[0].parameter[14].p_float # [14] histo_min
577+
histo_max = command.command[0].parameter[15].p_float # [15] histo_max
578+
histo_bins = command.command[0].parameter[16].p_int # [16] histo_bins
579579

580580
pixel_format_dict = {1: np.int8, 5: np.int16, 13: np.float32}
581581

@@ -666,41 +666,41 @@ def _fake_get_result(self, command):
666666
eps = np.sum(image) / 208 * float(self["Frames Per Second"])
667667
eppixps = eppix * float(self["Frames Per Second"])
668668
response_mapping = [
669-
int(pixel_format), # pix format 0
670-
int(windowWidth), # window width 1
671-
int(windowHeight), # window height 2
672-
"Test", # name 3
673-
int(0), # acquisition index 4
674-
bool(self.acquisition_status == "Acquiring"), # status 5
675-
int(flat_index), # frame number 6
676-
int(1), # frame count 7
677-
float(0), # image min 8
678-
float(2**15), # image max 9
679-
float(100), # image mean 10
680-
float(5), # image std 11
681-
float(100), # eppix 12
682-
float(1000), # eps 13
683-
float(500), # eppixps 14
684-
0.0, # epa2 15
685-
float(500), # eppixpf 16
686-
0.0, # eppix_incident 17
687-
0.0, # eps_incident 18
688-
0.0, # eppixps_incident 19
689-
0.0, # epa2_incident 20
690-
0.0, # eppixpf_incident 21
691-
0.0, # red sat warning 22
692-
0.0, # orange sat warning 23
693-
0.0, # saturation 24
694-
"2.187026", # current time 25
695-
0.0, # autoStretchMin 26
696-
0.0, # autoStretchMax 27
697-
0.0, # autoStretchGamma 28
698-
0.0, # histogram min 29
699-
float(np.min(image)), # histogram max 30
700-
float(np.max(image)), # histogram upper local max 31
669+
int(pixel_format), # [0] pixel_format
670+
int(windowWidth), # [1] frameWidth
671+
int(windowHeight), # [2] frameHeight
672+
"Test", # [3] datasetName
673+
int(0), # [4] acqIndex
674+
bool(self.acquisition_status == "Acquiring"), # [5] acqFinished
675+
int(flat_index), # [6] imageIndex
676+
int(1), # [7] frameCount
677+
float(0), # [8] imageMin
678+
float(2**15), # [9] imageMax
679+
float(100), # [10] imageMean
680+
float(5), # [11] imageStd
681+
float(100), # [12] eppix
682+
float(1000), # [13] eps
683+
float(500), # [14] eppixps
684+
0.0, # [15] epa2
685+
float(500), # [16] eppixpf
686+
0.0, # [17] eppix_incident
687+
0.0, # [18] eps_incident
688+
0.0, # [19] eppixps_incident
689+
0.0, # [20] epa2_incident
690+
0.0, # [21] eppixpf_incident
691+
0.0, # [22] redSatWarningValue
692+
0.0, # [23] orangeSatWarningValue
693+
0.0, # [24] saturation
694+
"2.187026", # [25] timestamp
695+
0.0, # [26] autoStretchMin
696+
0.0, # [27] autoStretchMax
697+
0.0, # [28] autoStretchGamma
698+
0.0, # [29] histogram min
699+
float(np.max(image)), # [30] histogram max (FIXED: was np.min(image))
700+
float(np.max(image)), # [31] histogram upperMostLocalMaxima
701701
]
702702
for i in range(histo_bins):
703-
response_mapping.append(int(0))
703+
response_mapping.append(int(0)) # [32..31+histo_bins] histogram data
704704
# Then histogram...
705705
for val in response_mapping:
706706
ack1 = acknowledge_return.acknowledge.add()

deapi/simulated_server/initialize_server.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,17 @@
1212
def main(port=13240):
1313
parser = argparse.ArgumentParser()
1414
parser.add_argument("--port", type=int, help="Port to listen on")
15-
try:
16-
args = parser.parse_args()
17-
if args.port:
18-
port = args.port
19-
except:
20-
pass
15+
args, _ = parser.parse_known_args()
16+
if args.port:
17+
port = args.port
2118

2219
HOST = "127.0.0.1" # Standard loopback interface address (localhost)
2320
PORT = port # Port to listen on (non-privileged ports are > 1023)
2421
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server_socket:
2522
server_socket.bind((HOST, PORT))
2623
server_socket.listen()
27-
sys.stderr.write("started .... \n\n")
28-
sys.stderr.flush()
24+
sys.stdout.write("started .... \n\n")
25+
sys.stdout.flush()
2926
sys.stderr.write(
3027
"Waiting for a Connection to: \n"
3128
f" Host: {HOST}\n"

0 commit comments

Comments
 (0)