// File: /workspace/github_c_makefile_star2_O2/canboat[P]canboat/ikonvert-serial/ikonvert-serial.c
// Function: sendNextInitCommand
static void sendNextInitCommand(void)
{
  logDebug("sendNextInitCommand state=%d serial=%d\n", sendInitState, isSerialDevice);
  if (sendInitState > 0)
  {
    switch (sendInitState)
    {
      case 14:
        logInfo("iKonvert initialization start\n");
        sbAppendFormat(&writeBuffer, "%s\r\n", TX_OFFLINE_MSG);
        break;

      case 12:
        if (sbGetLength(&rxList) > 0 || sbGetLength(&txList) > 0)
        {
          sbAppendFormat(&writeBuffer, "%s\r\n", TX_RESET_MSG);
          break;
        }
        sendInitState = 10;
        // and fallthru

      case 10:
        if (sbGetLength(&rxList) > 0)
        {
          logInfo("iKonvert send RX list %s\n", sbGet(&rxList));
          sbAppendFormat(&writeBuffer, "%s,%s\r\n", TX_SET_RX_LIST_MSG, sbGet(&rxList));
          break;
        }
        sendInitState = 8;
        // and fallthru

      case 8:
        if (sbGetLength(&txList) > 0)
        {
          logInfo("iKonvert send TX list %s\n", sbGet(&txList));
          sbAppendFormat(&writeBuffer, "%s,%s\r\n", TX_SET_TX_LIST_MSG, sbGet(&txList));
          break;
        }
        sendInitState = 6;
        // and fallthru

      case 6:
        if (verbose || isLogLevelEnabled(LOG_DEBUG))
        {
          sbAppendFormat(&writeBuffer, "%s\r\n", TX_SHOWLISTS_MSG);
          break;
        }
        sendInitState = 4;
        // and fallthru

      case 4:
        sbAppendFormat(&writeBuffer, TX_ONLINE_MSG "\r\n", sbGetLength(&rxList) > 0 ? "NORMAL" : "ALL");
        break;

      case 2:
        if (rate_limit_off)
        {
          sbAppendFormat(&writeBuffer, "%s\r\n", TX_LIMIT_OFF);
          // Note: this has no confirmation, so reset init and set initstate to 0
        }
        sendInitState = 0;
        return;

      default:
        logInfo("Waiting for ack value %d\n", sendInitState);
        return;
    }
    sendInitState--;
  }
}

// Assembly:
pushq %rbx
movl 0x6c52(%rip), %esi      # 0xa260
movzbl 0x6c2c(%rip), %edx      # 0xa241
leaq 0x334f(%rip), %rdi      # 0x696b
xorl %eax, %eax
callq 0x3a00
movl 0x6c37(%rip), %esi      # 0xa260
testl %esi, %esi
jle 0x3809
leal -0x2(%rsi), %eax
cmpl $0xc, %eax
ja 0x367a
leaq 0x29c4(%rip), %rcx      # 0x6004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpb $0x1, 0x6bad(%rip)      # 0xa1fd
jne 0x366e
leaq 0x6bef(%rip), %rdi      # 0xa248
leaq 0x33f2(%rip), %rsi      # 0x6a52
leaq 0x33fb(%rip), %rdx      # 0x6a62
xorl %eax, %eax
callq 0x3e6e
andl $0x0, 0x6beb(%rip)      # 0xa260
jmp 0x3809
leaq 0x33f4(%rip), %rdi      # 0x6a75
xorl %eax, %eax
popq %rbx
jmp 0x38f3
movq 0x6b90(%rip), %rax      # 0xa220
orq 0x6b71(%rip), %rax      # 0xa208
je 0x3731
leaq 0x6ba4(%rip), %rdi      # 0xa248
leaq 0x33a7(%rip), %rsi      # 0x6a52
leaq 0x3314(%rip), %rdx      # 0x69c6
jmp 0x37fc
leaq 0x32d5(%rip), %rdi      # 0x6993
xorl %eax, %eax
callq 0x38f3
leaq 0x6b7c(%rip), %rdi      # 0xa248
leaq 0x337f(%rip), %rsi      # 0x6a52
leaq 0x32d8(%rip), %rdx      # 0x69b2
jmp 0x37fc
cmpq $0x0, 0x6b21(%rip)      # 0xa208
je 0x3731
movq 0x6b10(%rip), %rsi      # 0xa200
testq %rsi, %rsi
leaq 0x3053(%rip), %rbx      # 0x674d
cmoveq %rbx, %rsi
leaq 0x32d3(%rip), %rdi      # 0x69d8
xorl %eax, %eax
callq 0x38f3
movq 0x6aed(%rip), %rcx      # 0xa200
testq %rcx, %rcx
cmoveq %rbx, %rcx
leaq 0x6b27(%rip), %rdi      # 0xa248
leaq 0x32ca(%rip), %rsi      # 0x69f2
leaq 0x32cb(%rip), %rdx      # 0x69fa
jmp 0x378b
movl $0x8, 0x6b25(%rip)      # 0xa260
cmpq $0x0, 0x6add(%rip)      # 0xa220
je 0x3794
movq 0x6acc(%rip), %rsi      # 0xa218
testq %rsi, %rsi
leaq 0x2ff7(%rip), %rbx      # 0x674d
cmoveq %rbx, %rsi
leaq 0x32a7(%rip), %rdi      # 0x6a08
xorl %eax, %eax
callq 0x38f3
movq 0x6aa9(%rip), %rcx      # 0xa218
testq %rcx, %rcx
cmoveq %rbx, %rcx
leaq 0x6acb(%rip), %rdi      # 0xa248
leaq 0x326e(%rip), %rsi      # 0x69f2
leaq 0x3297(%rip), %rdx      # 0x6a22
xorl %eax, %eax
callq 0x3e6e
jmp 0x3803
movl $0x6, 0x6ac2(%rip)      # 0xa260
cmpb $0x0, 0x6a56(%rip)      # 0xa1fb
jne 0x37b3
pushq $0x7
popq %rdi
callq 0x3c2b
testb %al, %al
je 0x37ca
leaq 0x6a8e(%rip), %rdi      # 0xa248
leaq 0x3291(%rip), %rsi      # 0x6a52
leaq 0x3268(%rip), %rdx      # 0x6a30
jmp 0x37fc
movl $0x4, 0x6a8c(%rip)      # 0xa260
cmpq $0x0, 0x6a2c(%rip)      # 0xa208
leaq 0x327b(%rip), %rax      # 0x6a5e
leaq 0x326d(%rip), %rdx      # 0x6a57
cmoveq %rax, %rdx
leaq 0x6a53(%rip), %rdi      # 0xa248
leaq 0x3245(%rip), %rsi      # 0x6a41
xorl %eax, %eax
callq 0x3e6e
decl 0x6a57(%rip)            # 0xa260
popq %rbx
retq
nop