소스 검색

Only return the ReturnCode from _send_command

Now that I've implemented the protocol, I see how commands actually give
return values isn't how I thought it would be.  Accordingly,
_send_command now only returns the ReturnCode rather than wrapping it in
a list.  This allowed me to remove a few [0]s.
Clara Hobbs 7 년 전
부모
커밋
cb98a96a7a
1개의 변경된 파일7개의 추가작업 그리고 8개의 파일을 삭제
  1. 7
    8
      alpaca_isp/__init__.py

+ 7
- 8
alpaca_isp/__init__.py 파일 보기

74
 
74
 
75
     def _send_command(self, cmd):
75
     def _send_command(self, cmd):
76
         """Send a command to the microcontroller, returning the result"""
76
         """Send a command to the microcontroller, returning the result"""
77
-        rr = self._send_command_raw(cmd)
78
-        lr = [int(n) for n in rr.split()]
79
-        lr[0] = ReturnCode(lr[0])
80
-        if lr[0] != ReturnCode.CMD_SUCCESS:
81
-            raise ISPError(lr)
82
-        return lr
77
+        r = self._send_command_raw(cmd)
78
+        r = ReturnCode(int(r))
79
+        if r != ReturnCode.CMD_SUCCESS:
80
+            raise ISPError(r)
81
+        return r
83
 
82
 
84
     def enter_isp(self, delay=0.01):
83
     def enter_isp(self, delay=0.01):
85
         """Enter ISP mode by controlling the DTR (/RST) and RTS (/ISP) lines
84
         """Enter ISP mode by controlling the DTR (/RST) and RTS (/ISP) lines
244
                 "utf-8"))
243
                 "utf-8"))
245
         except ISPError as e:
244
         except ISPError as e:
246
             # Return a tuple for SECTOR_NOT_BLANK
245
             # Return a tuple for SECTOR_NOT_BLANK
247
-            if e.args[0][0] == ReturnCode.SECTOR_NOT_BLANK:
246
+            if e.args[0] == ReturnCode.SECTOR_NOT_BLANK:
248
                 offset = int(self._readline())
247
                 offset = int(self._readline())
249
                 value = int(self._readline())
248
                 value = int(self._readline())
250
                 return (offset, value)
249
                 return (offset, value)
278
                 count).encode("utf-8"))
277
                 count).encode("utf-8"))
279
         except ISPError as e:
278
         except ISPError as e:
280
             # Return an offset for COMPARE_ERROR
279
             # Return an offset for COMPARE_ERROR
281
-            if e.args[0][0] == ReturnCode.COMPARE_ERROR:
280
+            if e.args[0] == ReturnCode.COMPARE_ERROR:
282
                 return int(self._readline())
281
                 return int(self._readline())
283
             raise
282
             raise
284
 
283
 

Loading…
취소
저장