Skip to content

dcsbios

Classes:

Name Description
IntegerBuffer

Integer buffer for DCS-BIOS protocol.

ParserState

Protocol parser states.

ProtocolParser

DCS_BIOS protocol parser.

StringBuffer

String buffer for DCS-BIOS protocol.

IntegerBuffer

Integer buffer for DCS-BIOS protocol.

Initialize instance.

Parameters:

Name Type Description Default

parser

ProtocolParser
required

address

int
required

mask

int
required

shift_by

int
required

callback

Callable
required

Methods:

Name Description
on_dcsbios_write

Set a callback function.

Source code in src/dcspy/dcsbios.py
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
def __init__(self, parser: ProtocolParser, address: int, mask: int, shift_by: int, callback: Callable) -> None:
    """
    Initialize instance.

    :param parser:
    :param address:
    :param mask:
    :param shift_by:
    :param callback:
    """
    self.__address = address
    self.__mask = mask
    self.__shift_by = shift_by
    self.__value = int()
    self.callbacks: set[Callable] = set()
    self.callbacks.add(callback)
    parser.write_callbacks.add(partial(self.on_dcsbios_write))

on_dcsbios_write

on_dcsbios_write(address: int, data: int) -> None

Set a callback function.

Parameters:

Name Type Description Default

address

int
required

data

int
required
Source code in src/dcspy/dcsbios.py
196
197
198
199
200
201
202
203
204
205
206
207
208
def on_dcsbios_write(self, address: int, data: int) -> None:
    """
    Set a callback function.

    :param address:
    :param data:
    """
    if address == self.__address:
        value = (data & self.__mask) >> self.__shift_by
        if self.__value != value:
            self.__value = value
            for callback in self.callbacks:
                callback(value)

ParserState

Bases: Enum

Protocol parser states.

ProtocolParser

ProtocolParser()

DCS_BIOS protocol parser.

Initialize instance.

Methods:

Name Description
process_byte

State machine - processing of byte.

Source code in src/dcspy/dcsbios.py
22
23
24
25
26
27
28
29
30
def __init__(self) -> None:
    """Initialize instance."""
    self.state = ParserState.WAIT_FOR_SYNC
    self.sync_byte_count = 0
    self.address = 0
    self.count = 0
    self.data = 0
    self.write_callbacks: set[Callable[[int, int], None]] = set()
    self.frame_sync_callbacks: set[Callable] = set()

process_byte

process_byte(int_byte: int) -> None

State machine - processing of byte.

Allowed states are: ParserState

Parameters:

Name Type Description Default

int_byte

int
required
Source code in src/dcspy/dcsbios.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def process_byte(self, int_byte: int) -> None:
    """
    State machine - processing of byte.

    Allowed states are: ParserState
    :param int_byte:
    """
    state_handling = getattr(self, f'_{self.state.name.lower()}')
    if self.state == ParserState.WAIT_FOR_SYNC:
        state_handling()
    else:
        state_handling(int_byte)

    if int_byte == 0x55:
        self.sync_byte_count += 1
    else:
        self.sync_byte_count = 0

    self._wait_for_sync()

StringBuffer

String buffer for DCS-BIOS protocol.

Initialize instance.

Parameters:

Name Type Description Default

parser

ProtocolParser
required

address

int
required

max_length

int
required

callback

Callable
required

Methods:

Name Description
on_dcsbios_write

Set a callback function.

set_char

Set char.

Source code in src/dcspy/dcsbios.py
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
def __init__(self, parser: ProtocolParser, address: int, max_length: int, callback: Callable) -> None:
    """
    Initialize instance.

    :param parser:
    :param address:
    :param max_length:
    :param callback:
    """
    self.__address = address
    self.__length = max_length
    self.__dirty = False
    self.buffer = bytearray(max_length)
    self.callbacks: set[Callable] = set()
    self.callbacks.add(callback)
    parser.write_callbacks.add(partial(self.on_dcsbios_write))

on_dcsbios_write

on_dcsbios_write(address: int, data: int) -> None

Set a callback function.

Parameters:

Name Type Description Default

address

int
required

data

int
required
Source code in src/dcspy/dcsbios.py
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
def on_dcsbios_write(self, address: int, data: int) -> None:
    """
    Set a callback function.

    :param address:
    :param data:
    """
    if self.__address <= address < self.__address + self.__length:
        data_bytes = pack('<H', data)
        self.set_char(address - self.__address, data_bytes[0])
        if self.__address + self.__length > (address + 1):
            self.set_char(address - self.__address + 1, data_bytes[1])

    if address == 0xfffe and self.__dirty:
        self.__dirty = False
        str_buff = self.buffer.split(sep=b'\x00', maxsplit=1)[0].decode('latin-1')
        for callback in self.callbacks:
            callback(str_buff)

set_char

set_char(index: int, char: int) -> None

Set char.

Parameters:

Name Type Description Default

index

int
required

char

int
required
Source code in src/dcspy/dcsbios.py
145
146
147
148
149
150
151
152
153
154
def set_char(self, index: int, char: int) -> None:
    """
    Set char.

    :param index:
    :param char:
    """
    if self.buffer[index] != char:
        self.buffer[index] = char
        self.__dirty = True