27 #include "model/ais_bitstring.h"
29 AisBitstring::AisBitstring(
const char *str) {
30 byte_length = strlen(str);
32 for (
int i = 0; i < byte_length; i++) {
33 bitbytes[i] = to_6bit(str[i]);
37 int AisBitstring::GetBitCount() {
return byte_length * 6; }
41 unsigned char AisBitstring::to_6bit(
const char c) {
42 if (c < 0x30)
return (
unsigned char)-1;
43 if (c > 0x77)
return (
unsigned char)-1;
44 if ((0x57 < c) && (c < 0x60))
return (
unsigned char)-1;
54 return (
unsigned char)(cp & 0x3f);
63 for (
int i = 0; i < len; i++) {
67 c0 = (cx >> (5 - ((s0p + i) % 6))) & 1;
68 if (i == 0 && signed_flag &&
77 int AisBitstring::GetStr(
int sp,
int bit_len,
char *dest,
int max_len) {
79 char *temp_str = dest;
88 while (i < bit_len && k < max_len) {
90 for (
int j = 0; j < 6; j++) {
94 cs = 5 - ((s0p + i) % 6);
100 temp_str[k] = (char)(acc & 0x3f);
102 if (acc < 32) temp_str[k] += 0x40;
int GetInt(int sp, int len, bool signed_flag=false)
sp is starting bit, 1-based