// File: /workspace/github_c_makefile_star2_O2/canboat[P]canboat/analyzer/../common/parse.c
// Function: parseRawFormatActisenseN2KAscii
int parseRawFormatActisenseN2KAscii(char *msg, RawMessage *m, bool showJson)
{
  char         *nexttoken;
  char         *p;
  char         *token;
  int           i;
  int           r;
  static time_t tiden = 0;
  struct tm     tm;
  time_t        now;
  unsigned int  millis = 0;
  unsigned int  secs;
  unsigned long n;

  // parse timestamp. Actisense doesn't give us date so let's figure it out ourself
  token = strtok_r(msg, " ", &nexttoken);
  if (!token || token[0] != 'A')
  {
    logError("No message or does not start with 'A'\n");
    return -1;
  }
  token++;

  r = sscanf(token, "%u.%u", &secs, &millis);
  if (r < 1)
  {
    return -1;
  }

  if (tiden == 0)
  {
    tiden = (time_t) (getNow() / UINT64_C(1000)) - secs;
  }
  now = tiden + secs;

  localtime_r(&now, &tm);
  strftime(m->timestamp, sizeof(m->timestamp), "%Y-%m-%dT%H:%M:%S", &tm);
  sprintf(m->timestamp + strlen(m->timestamp), ",%3.3u", millis);

  // parse <SRC><DST><P>
  token = strtok_r(NULL, " ", &nexttoken);
  if (!token)
  {
    return -1;
  }
  n       = strtoul(token, NULL, 16);
  m->prio = n & 0xf;
  m->dst  = (n >> 4) & 0xff;
  m->src  = (n >> 12) & 0xff;

  // parse <PGN>
  token = strtok_r(NULL, " ", &nexttoken);
  if (!token)
  {
    logError("Incomplete message\n");
    if (!showJson)
      fprintf(stdout, "%s", msg);
    return -1;
  }
  m->pgn = strtoul(token, NULL, 16);

  // parse DATA
  p = nexttoken;
  for (i = 0; i < FASTPACKET_MAX_SIZE; i++)
  {
    if (*p == '\0' || isspace((unsigned char) *p))
    {
      break;
    }
    if (scanHex(&p, &m->data[i]))
    {
      logError("Error reading message, scanned %zu bytes from %s/%s, index %u", p - msg, msg, p, i);
      if (!showJson)
        fprintf(stdout, "%s", msg);
      return 2;
    }
  }
  m->len = i;

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
andl $0x0, 0xc(%rsp)
leaq 0x49a4(%rip), %rsi      # 0x22409
leaq 0x10(%rsp), %rdx
callq 0xd190
testq %rax, %rax
je 0x1dab1
cmpb $0x41, (%rax)
jne 0x1dab1
incq %rax
leaq 0x1422c(%rip), %rsi     # 0x31caf
leaq 0x8(%rsp), %rdx
leaq 0xc(%rsp), %rcx
movq %rax, %rdi
xorl %eax, %eax
callq 0xd220
pushq $-0x1
popq %r15
testl %eax, %eax
jle 0x1dac3
movq 0x73e2a(%rip), %rax     # 0x918d0
testq %rax, %rax
je 0x1dad5
movl 0x8(%rsp), %ecx
jmp 0x1daf2
leaq 0x141d0(%rip), %rdi     # 0x31c88
xorl %eax, %eax
callq 0x1bdd9
pushq $-0x1
popq %r15
movl %r15d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1bb54
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divq %rcx
movl 0x8(%rsp), %ecx
subq %rcx, %rax
movq %rax, 0x73dde(%rip)     # 0x918d0
addq %rax, %rcx
leaq 0x28(%rsp), %rdi
movq %rcx, (%rdi)
leaq 0x30(%rsp), %r12
movq %r12, %rsi
callq 0xd0a0
leaq 0x13cf7(%rip), %rdx     # 0x31808
pushq $0x3c
popq %rsi
movq %r14, %rdi
movq %r12, %rcx
callq 0xd260
movq %r14, %rdi
callq 0xd0f0
leaq (%rax,%r14), %rdi
movl 0xc(%rsp), %edx
leaq 0x14043(%rip), %rsi     # 0x31b79
xorl %eax, %eax
callq 0xd2c0
leaq 0x48c5(%rip), %rsi      # 0x22409
leaq 0x10(%rsp), %rdx
xorl %edi, %edi
callq 0xd190
testq %rax, %rax
je 0x1dac3
pushq $0x10
popq %rdx
movq %rax, %rdi
xorl %esi, %esi
callq 0xd2a0
movl %eax, %ecx
andb $0xf, %cl
movb %cl, 0x3c(%r14)
movl %eax, %ecx
shrl $0x4, %ecx
movb %cl, 0x44(%r14)
shrl $0xc, %eax
movb %al, 0x45(%r14)
leaq 0x4883(%rip), %rsi      # 0x22409
leaq 0x10(%rsp), %rdx
xorl %edi, %edi
callq 0xd190
testq %rax, %rax
je 0x1dbfb
movl %ebp, 0x1c(%rsp)
xorl %r15d, %r15d
pushq $0x10
popq %rdx
movq %rax, %rdi
xorl %esi, %esi
callq 0xd2a0
movl %eax, 0x40(%r14)
movq 0x10(%rsp), %rax
leaq 0x20(%rsp), %r12
movq %rax, (%r12)
leaq 0x47(%r14), %r13
cmpq $0xdf, %r15
je 0x1dc14
movq 0x20(%rsp), %rax
movzbl (%rax), %ebp
testq %rbp, %rbp
je 0x1dc17
callq 0xd350
movq (%rax), %rax
testb $0x20, 0x1(%rax,%rbp,2)
jne 0x1dc17
leaq (%r15,%r13), %rsi
movq %r12, %rdi
callq 0x1ca7b
testl %eax, %eax
jne 0x1dc23
incq %r15
jmp 0x1dbc1
leaq 0x140b3(%rip), %rdi     # 0x31cb5
xorl %eax, %eax
callq 0x1bdd9
testb %bpl, %bpl
jne 0x1dac3
jmp 0x1dc51
movb $-0x21, %r15b
movb %r15b, 0x46(%r14)
xorl %r15d, %r15d
jmp 0x1dac3
movq 0x20(%rsp), %rcx
movq %rcx, %rsi
subq %rbx, %rsi
leaq 0x13ea3(%rip), %rdi     # 0x31ad8
movq %rbx, %rdx
movl %r15d, %r8d
xorl %eax, %eax
callq 0x1bdd9
pushq $0x2
popq %r15
cmpb $0x0, 0x1c(%rsp)
jne 0x1dac3
movq 0x1c370(%rip), %rax     # 0x39fc8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0xd170
jmp 0x1dac3