10
10
from artiq .language .context import *
11
11
from artiq .coredevice .runtime import Environment
12
12
from artiq .coredevice import runtime_exceptions
13
+ from artiq .coredevice .rpc_wrapper import RPCWrapper
13
14
14
15
15
16
logger = logging .getLogger (__name__ )
@@ -69,6 +70,7 @@ def build(self):
69
70
self .port .flush ()
70
71
self .set_remote_baud (self .baud_rate )
71
72
self .set_baud (self .baud_rate )
73
+ self .rpc_wrapper = RPCWrapper ()
72
74
73
75
def set_baud (self , baud ):
74
76
self .port .baudrate = baud
@@ -183,19 +185,18 @@ def _receive_rpc_values(self):
183
185
if type_tag == "l" :
184
186
r .append (self ._receive_rpc_values ())
185
187
186
- def _serve_rpc (self , rpc_map ):
187
- ( rpc_num , ) = struct .unpack (">h" , _read_exactly (self .port , 2 ))
188
+ def _serve_rpc (self , rpc_map , user_exception_map ):
189
+ rpc_num = struct .unpack (">h" , _read_exactly (self .port , 2 ))[ 0 ]
188
190
args = self ._receive_rpc_values ()
189
191
logger .debug ("rpc service: {} ({})" .format (rpc_num , args ))
190
- r = rpc_map [rpc_num ](* args )
191
- if r is None :
192
- r = 0
193
- _write_exactly (self .port , struct .pack (">l" , r ))
192
+ eid , r = self .rpc_wrapper .run_rpc (user_exception_map , rpc_map [rpc_num ], args )
193
+ _write_exactly (self .port , struct .pack (">ll" , eid , r ))
194
194
logger .debug ("rpc service: {} ({}) == {}" .format (
195
195
rpc_num , args , r ))
196
196
197
197
def _serve_exception (self , user_exception_map ):
198
- (eid , ) = struct .unpack (">l" , _read_exactly (self .port , 4 ))
198
+ eid = struct .unpack (">l" , _read_exactly (self .port , 4 ))[0 ]
199
+ self .rpc_wrapper .filter_rpc_exception (eid )
199
200
if eid < core_language .first_user_eid :
200
201
exception = runtime_exceptions .exception_map [eid ]
201
202
else :
@@ -206,7 +207,7 @@ def serve(self, rpc_map, user_exception_map):
206
207
while True :
207
208
msg = self ._get_device_msg ()
208
209
if msg == _D2HMsgType .RPC_REQUEST :
209
- self ._serve_rpc (rpc_map )
210
+ self ._serve_rpc (rpc_map , user_exception_map )
210
211
elif msg == _D2HMsgType .KERNEL_EXCEPTION :
211
212
self ._serve_exception (user_exception_map )
212
213
elif msg == _D2HMsgType .KERNEL_FINISHED :
0 commit comments