• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2021-2022 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# -----------------------------------------------------------------------------
16# Imports
17# -----------------------------------------------------------------------------
18from bumble.rfcomm import RFCOMM_Frame
19
20
21# -----------------------------------------------------------------------------
22def basic_frame_check(x):
23    serialized = bytes(x)
24    if len(serialized) < 500:
25        print('Original:', x)
26        print('Serialized:', serialized.hex())
27    parsed = RFCOMM_Frame.from_bytes(serialized)
28    if len(serialized) < 500:
29        print('Parsed:', parsed)
30    parsed_bytes = bytes(parsed)
31    if len(serialized) < 500:
32        print('Parsed Bytes:', parsed_bytes.hex())
33    assert(parsed_bytes == serialized)
34    x_str = str(x)
35    parsed_str = str(parsed)
36    assert(x_str == parsed_str)
37
38
39# -----------------------------------------------------------------------------
40def test_frames():
41    data = bytes.fromhex('033f011c')
42    frame = RFCOMM_Frame.from_bytes(data)
43    basic_frame_check(frame)
44
45
46# -----------------------------------------------------------------------------
47if __name__ == '__main__':
48    test_frames()
49