Exemple #1
0
 def apply_bitmask_to_list(reqIdrs: List, mask: bitarray):
     if mask.length() == 0:
         return reqIdrs, []
     if len(reqIdrs) != mask.length():
         raise LogicError(
             "Length of reqIdr list and bitmask is not the same")
     return BitmaskHelper.get_valid_reqs(
         reqIdrs, mask), BitmaskHelper.get_invalid_reqs(reqIdrs, mask)
Exemple #2
0
    def store(self, address: int, size: str, value: bitarray):
        points = self._get_pixels_by_address(address)
        tmp = value[value.length() - 8:value.length()]
        tmp_pos = 0
        for point in points:
            self._image.setPixel(
                point[0], point[1],
                int(tmp[tmp_pos:tmp_pos + self._mode.depth].to01(), 2))
            tmp_pos += self._mode.depth

        if size == 'word':
            self.store(address=address + 1, size="byte", value=value[0:8])
def __zipBits(lng: bitarray, lat: bitarray):
    latindex = 0
    lngindex = 0
    length = lng.length() + lat.length()
    bits = bitarray(length)

    for index in range(length):
        if index % 2 == 0:
            bits[index] = lng[lngindex]
            lngindex += 1
        else:
            bits[index] = lat[latindex]
            latindex += 1
    return bits
def __calculateAdjacent(bits: bitarray, type):

    positive = bits.copy()
    negative = bits.copy()
    length = bits.length()
    index = -1
    count = bits.count()

    carrySubtract = True
    carryAdd = True
    if count == length and type == 'lat':
        carryAdd = False
    elif count == 0 and type == 'lat':
        carrySubtract = False

    while (carrySubtract or carryAdd) and abs(index) <= length:
        value = bits[index]
        if carrySubtract:
            if value:
                negative[index] = False
                carrySubtract = False
            else:
                negative[index] = True
        if carryAdd:
            if value:
                positive[index] = False
            else:
                positive[index] = True
                carryAdd = False
        index += -1
    return negative, positive
def __splitBits(bits: bitarray):
    lats = bitarray()
    lngs = bitarray()
    for index in range(bits.length()):
        if index % 2 == 0:
            lngs.append(bits[index])
        else:
            lats.append(bits[index])
    return (lngs, lats)
 def decode(self, coded_text: ba.bitarray) -> str:
     """
     docstring
     """
     reversed_dict = {v.to01(): k for k, v in self.code.items()}
     result = []
     for i in range(0, coded_text.length(), self.code_length):
         try:
             char_code = coded_text[i:i + self.code_length].to01()
             result.append(reversed_dict[char_code])
         except KeyError:
             continue
     return ''.join(result)
 def decode(self, coded_text: ba.bitarray) -> str:
     """
     docstring
     """
     reversed_dict = {v.to01(): k for k, v in self.code.items()}
     result = []
     buffer = 0
     for i in range(0, coded_text.length()):
         try:
             char_code = coded_text[i - buffer:i + 1].to01()
             result.append(reversed_dict[char_code])
             buffer = 0
         except KeyError:
             buffer += 1
             continue
     return ''.join(result)
Exemple #8
0
def decode_msg_1(bit_arr: bitarray.bitarray) -> Dict[str, Any]:
    """
    AIS Vessel position report using SOTDMA (Self-Organizing Time Division Multiple Access)
    Src: https://gpsd.gitlab.io/gpsd/AIVDM.html#_types_1_2_and_3_position_report_class_a
    """
    get_int_from_data = partial(get_int, bit_arr)
    return {
        'type': get_int_from_data(0, 6),
        'repeat': get_int_from_data(6, 8),
        'mmsi': get_int_from_data(8, 38),
        'status': NavigationStatus(get_int_from_data(38, 42)),
        'turn': get_int_from_data(42, 50, signed=True),
        'speed': get_int_from_data(50, 60) / 10.0,
        'accuracy': bit_arr[60],
        'lon': get_int_from_data(61, 89, signed=True) / 600000.0,
        'lat': get_int_from_data(89, 116, signed=True) / 600000.0,
        'course': get_int_from_data(116, 128) * 0.1,
        'heading': get_int_from_data(128, 137),
        'second': get_int_from_data(137, 143),
        'maneuver': ManeuverIndicator(get_int_from_data(143, 145)),
        'raim': bit_arr[148],
        'radio': get_int_from_data(149, bit_arr.length()),
    }
Exemple #9
0
 def get_valid_count(mask: bitarray, len_reqIdr=0):
     if mask.length() == 0:
         return len_reqIdr
     return mask.count(0)
Exemple #10
0
 def set_word(self, value: bitarray):
     self._reset_integer_representations()
     if value.length() != 16:
         raise RegisterWrongNumberBits(16)
     self._data[0:16] = value
Exemple #11
0
 def set_byte(self, value: bitarray):
     self._reset_integer_representations()
     if value.length() != 8:
         raise RegisterWrongNumberBits(8)
     self._data[8:16] = value
Exemple #12
0
 def set_word(self, value: bitarray):
     if value.length() > 0 and value[-1] is True:
         raise RegisterOddValue()
     super().set_word(value)