Package nxt :: Module error

Source Code for Module nxt.error

 1  # nxt.error module -- LEGO Mindstorms NXT error handling 
 2  # Copyright (C) 2006,2007  Douglas P Lau 
 3  # Copyright (C) 2009  Marcus Wanner 
 4  # 
 5  # This program is free software: you can redistribute it and/or modify 
 6  # it under the terms of the GNU General Public License as published by 
 7  # the Free Software Foundation, either version 3 of the License, or 
 8  # (at your option) any later version. 
 9  # 
10  # This program is distributed in the hope that it will be useful, 
11  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
13  # GNU General Public License for more details. 
14   
15  'Declarations for the errors' 
16   
17 -class ProtocolError(Exception):
18 pass
19
20 -class SysProtError(ProtocolError):
21 pass
22
23 -class FileExistsError(SysProtError):
24 pass
25
26 -class FileNotFound(SysProtError):
27 pass
28
29 -class ModuleNotFound(SysProtError):
30 pass
31
32 -class DirProtError(ProtocolError):
33 pass
34
35 -class I2CError(DirProtError):
36 pass
37
38 -class I2CPendingError(I2CError):
39 pass
40 41 CODES = { 42 0x00: None, 43 0x20: I2CPendingError('Pending communication transaction in progress'), 44 0x40: DirProtError('Specified mailbox queue is empty'), 45 0x81: SysProtError('No more handles'), 46 0x82: SysProtError('No space'), 47 0x83: SysProtError('No more files'), 48 0x84: SysProtError('End of file expected'), 49 0x85: SysProtError('End of file'), 50 0x86: SysProtError('Not a linear file'), 51 0x87: FileNotFound('File not found'), 52 0x88: SysProtError('Handle already closed'), 53 0x89: SysProtError('No linear space'), 54 0x8A: SysProtError('Undefined error'), 55 0x8B: SysProtError('File is busy'), 56 0x8C: SysProtError('No write buffers'), 57 0x8D: SysProtError('Append not possible'), 58 0x8E: SysProtError('File is full'), 59 0x8F: FileExistsError('File exists'), 60 0x90: ModuleNotFound('Module not found'), 61 0x91: SysProtError('Out of bounds'), 62 0x92: SysProtError('Illegal file name'), 63 0x93: SysProtError('Illegal handle'), 64 0xBD: DirProtError('Request failed (i.e. specified file not found)'), 65 0xBE: DirProtError('Unknown command opcode'), 66 0xBF: DirProtError('Insane packet'), 67 0xC0: DirProtError('Data contains out-of-range values'), 68 0xDD: DirProtError('Communication bus error'), 69 0xDE: DirProtError('No free memory in communication buffer'), 70 0xDF: DirProtError('Specified channel/connection is not valid'), 71 0xE0: I2CError('Specified channel/connection not configured or busy'), 72 0xEC: DirProtError('No active program'), 73 0xED: DirProtError('Illegal size specified'), 74 0xEE: DirProtError('Illegal mailbox queue ID specified'), 75 0xEF: DirProtError('Attempted to access invalid field of a structure'), 76 0xF0: DirProtError('Bad input or output specified'), 77 0xFB: DirProtError('Insufficient memory available'), 78 0xFF: DirProtError('Bad arguments'), 79 } 80
81 -def check_status(status):
82 if status: 83 ex = CODES.get(status) 84 if ex: 85 raise ex 86 else: 87 raise ProtocolError, status
88