mirror of
https://github.com/lowobservable/coax.git
synced 2026-03-10 21:03:24 +00:00
Fix terminal model mapping
This commit is contained in:
@@ -76,15 +76,30 @@ class KeystrokePollResponse(PollResponse):
|
||||
class TerminalId:
|
||||
"""Terminal model and keyboard."""
|
||||
|
||||
_MODEL_MAP = {
|
||||
0b010: 2,
|
||||
0b011: 3,
|
||||
0b111: 4,
|
||||
0b110: 5
|
||||
}
|
||||
|
||||
def __init__(self, value):
|
||||
if (value & 0x1) != 0:
|
||||
raise ValueError('Invalid terminal identifier')
|
||||
|
||||
self.value = value
|
||||
|
||||
self.model = (value & 0x0e) >> 1
|
||||
model = (value & 0x0e) >> 1
|
||||
|
||||
if model not in TerminalId._MODEL_MAP:
|
||||
raise ValueError('Invalid model')
|
||||
|
||||
self.model = TerminalId._MODEL_MAP[model]
|
||||
self.keyboard = (value & 0xf0) >> 4
|
||||
|
||||
def __repr__(self):
|
||||
return f'<TerminalId model={self.model}, keyboard={self.keyboard}>'
|
||||
|
||||
def poll(interface, **kwargs):
|
||||
"""Execute a POLL command."""
|
||||
response = _execute_read_command(interface, Command.POLL, allow_trta_response=True,
|
||||
|
||||
@@ -4,7 +4,7 @@ from unittest.mock import Mock
|
||||
import context
|
||||
|
||||
from coax import PollResponse, KeystrokePollResponse, ProtocolError
|
||||
from coax.protocol import Command, _execute_read_command, _execute_write_command, _pack_command_word, _unpack_data_words, _unpack_data_word
|
||||
from coax.protocol import Command, TerminalId, _execute_read_command, _execute_write_command, _pack_command_word, _unpack_data_words, _unpack_data_word
|
||||
|
||||
class PollResponseTestCase(unittest.TestCase):
|
||||
def test_is_power_on_reset_complete(self):
|
||||
@@ -25,6 +25,35 @@ class KeystrokePollResponseTestCase(unittest.TestCase):
|
||||
with self.assertRaisesRegex(ValueError, 'Invalid keystroke poll response'):
|
||||
response = KeystrokePollResponse(0b0000001000)
|
||||
|
||||
class TerminalIdTestCase(unittest.TestCase):
|
||||
def test_model_2(self):
|
||||
terminal_id = TerminalId(0b00000100)
|
||||
|
||||
self.assertEqual(terminal_id.model, 2)
|
||||
|
||||
def test_model_3(self):
|
||||
terminal_id = TerminalId(0b00000110)
|
||||
|
||||
self.assertEqual(terminal_id.model, 3)
|
||||
|
||||
def test_model_4(self):
|
||||
terminal_id = TerminalId(0b00001110)
|
||||
|
||||
self.assertEqual(terminal_id.model, 4)
|
||||
|
||||
def test_model_5(self):
|
||||
terminal_id = TerminalId(0b00001100)
|
||||
|
||||
self.assertEqual(terminal_id.model, 5)
|
||||
|
||||
def test_invalid_identifier(self):
|
||||
with self.assertRaisesRegex(ValueError, 'Invalid terminal identifier'):
|
||||
terminal_id = TerminalId(0b00000001)
|
||||
|
||||
def test_invalid_model(self):
|
||||
with self.assertRaisesRegex(ValueError, 'Invalid model'):
|
||||
terminal_id = TerminalId(0b00000000)
|
||||
|
||||
class ExecuteReadCommandTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.interface = Mock()
|
||||
|
||||
Reference in New Issue
Block a user