// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathgps.cpp
// Function: get_ebolt_version()
void get_ebolt_version()
{   // ThunderBolt-E only
u08 rsvd1;
u08 major;
u08 minor;
u08 build;
u08 len;
int i;

   log_packet_id("Packet 0x1C (Tbolt-E version)");

   rev_month = rev_day = rev_hour = 0;
   rev_year = 0;

   subcode = tsip_byte();
   if(subcode == 0x81) {  // firmware version
      rsvd1 = tsip_byte();
      major = tsip_byte();
      minor = tsip_byte();
      build = tsip_byte();
      rev_month = tsip_byte();
      rev_day = tsip_byte();
      rev_year = tsip_word();
      len = tsip_byte();
  
      out[0] = 0;
      for(i=0; i<len; i++) {
         if(i >= MAX_TEXT_COLS) {
            tsip_byte();
            continue;
         }
         out[i] = tsip_byte();
         out[i+1] = 0;
      }
  
      strupr(out);
   }
   else if(subcode == 0x83) {  // hardware version
      ebolt_serno = tsip_dword();
      rev_day = tsip_byte();
      rev_month = tsip_byte();
      rev_year = tsip_word();
      rev_hour = tsip_byte();
      hw_code = tsip_word();
      len = tsip_byte();

      for(i=0; i<UNIT_LEN; i++) unit_name[i] = ' ';
      unit_name[UNIT_LEN] = 0;

      out[0] = 0;
      for(i=0; i<len; i++) {   // get hardware id
         if(i >= MAX_TEXT_COLS) {
            tsip_byte();
            continue;
         }
         out[i] = tsip_byte();  // string can have: ICM, RES SMT, RES360, ACUTIME
         out[i+1] = 0;
         if(i < UNIT_LEN) {
            unit_name[i] = out[i];
         }
      }

      strupr(out);
      if(ACU_GG) ;
      else if(ACU_360) ;       // ACUTIME GG/360 already detected
      else if(ACUTIME) ;  // ACUTIME already detected
      else if(PALISADE) ; // PALISADE already detected
      else if(res_t) ;    // res_t already detected
      else if(saw_icm) ;  // icm already detected
      else { // attempt to identify TSIP receiver type
         if(strstr(out, "ACUTIME")) {
            tsip_type = ACUTIME_TYPE;
            acu_type = '1';
            if(strstr(out, "360")) {  // Acutime 360
               acu_type = '3';
            }
            else if(strstr(out, "GG")) {  // Acutime GG
               acu_type = 'G';
            }

            config_msg_ofs();
            config_rcvr_plots();
         }
         else if(strstr(out, "ICM")) { // !!!!!! ICM RES SMT
            saw_icm = 1;
            saw_gpsdo = 2;
            config_msg_ofs();
            config_rcvr_plots();
         }
         else if(strstr(out, "PALISADE")) {  // PALISADE does not actually output 0x1C-83 messages
            tsip_type = PALISADE_TYPE;
            config_msg_ofs();
            config_rcvr_plots();
         }
         else if(strstr(out, "RESOLUTION")) {
            if(user_set_res_t) ;
            else if(strstr(out, "SMT")) res_t = RES_T_SMT;
            else                        res_t = RES_T;
            config_msg_ofs();
            config_rcvr_plots();
         }
         else if(strstr(out, "RES SMT")) {
            if(!user_set_res_t) res_t = RES_T_RES;
            config_msg_ofs();
            config_rcvr_plots();
         }
         else if(strstr(out, "RES360")) {
            if(!user_set_res_t) res_t = RES_T_360;
            config_msg_ofs();
            config_rcvr_plots();
         }
      }

      if(mini_t == 0) {
         if(strstr(out, "MINI")) {
            mini_t = 1;
            saw_mini = 1;
            config_msg_ofs();
            config_rcvr_plots();
         }
      }

      strncpy(unit_name, out, UNIT_LEN);
      unit_name[UNIT_LEN-1] = 0;
   }
   else {  // unknown
      //!!! process packet contents
   }

   check_tsip_end(1);   
   if(tsip_error) return;

   saw_ebolt();
   tbolt_e |= 0x08;
   saw_version |= 0x02;

   if(1) {  //!!!!!
      if(rev_month > 12) return;
      if(rev_month == 0) return;
      if(rev_day > 31) return;
      if(rev_day == 0) return;
      if(rev_year < 1990) return;
      if(rev_year > 2100) return;
      if(rev_hour > 24) return;
   }

   if(text_mode && first_key) return;
   if(zoom_screen) return;
   if(luxor) return;
   if(just_read) return;

   if(0 && (subcode == 0x83)) {  // !!! disabled since hw_code clashes with sn_prefix
      show_ebolt_info();
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
leaq 0xa37a1(%rip), %rdi     # 0x10b981
callq 0x520bf
xorl %eax, %eax
movb %al, 0x2edc13(%rip)     # 0x355e00
movb %al, 0x2edc0a(%rip)     # 0x355dfd
movb %al, 0x2edc03(%rip)     # 0x355dfc
andw $0x0, 0x2edbfd(%rip)    # 0x355dfe
callq 0x51c47
leaq 0x1c0d51(%rip), %rcx    # 0x228f5e
movb %al, (%rcx)
cmpb $-0x7d, %al
je 0x6829b
movzbl %al, %eax
cmpl $0x81, %eax
jne 0x6849c
callq 0x51c47
callq 0x51c47
callq 0x51c47
callq 0x51c47
callq 0x51c47
movb %al, 0x2edbb8(%rip)     # 0x355dfc
callq 0x51c47
movb %al, 0x2edbae(%rip)     # 0x355dfd
callq 0x51c63
movw %ax, 0x2edba3(%rip)     # 0x355dfe
callq 0x51c47
leaq 0x2bdfb9(%rip), %rbx    # 0x326220
movb $0x0, (%rbx)
movzbl %al, %r14d
xorl %r15d, %r15d
cmpq %r15, %r14
je 0x6828a
callq 0x51c47
movb %al, (%r15,%rbx)
movb $0x0, 0x1(%r15,%rbx)
incq %r15
jmp 0x68271
leaq 0x2bdf8f(%rip), %rdi    # 0x326220
callq 0x988f
jmp 0x6849c
callq 0x51cf3
movl %eax, 0x2edb5e(%rip)    # 0x355e04
callq 0x51c47
movb %al, 0x2edb4c(%rip)     # 0x355dfd
callq 0x51c47
movb %al, 0x2edb40(%rip)     # 0x355dfc
callq 0x51c63
movw %ax, 0x2edb36(%rip)     # 0x355dfe
callq 0x51c47
movb %al, 0x2edb2d(%rip)     # 0x355e00
callq 0x51c63
leaq 0x28f6c3(%rip), %rcx    # 0x2f79a2
movw %ax, (%rcx)
xorl %r14d, %r14d
callq 0x51c47
leaq 0x2be34f(%rip), %rbx    # 0x326640
cmpq $0x12, %r14
je 0x68301
movb $0x20, (%rbx,%r14)
incq %r14
jmp 0x682f1
xorl %r14d, %r14d
movb %r14b, 0x12(%rbx)
leaq 0x2bdf11(%rip), %r15    # 0x326220
movb %r14b, (%r15)
movzbl %al, %r12d
cmpq %r14, %r12
je 0x68339
callq 0x51c47
movb %al, (%r15,%r14)
movb $0x0, 0x1(%r15,%r14)
cmpq $0x12, %r14
jae 0x68334
movb %al, (%rbx,%r14)
incq %r14
jmp 0x68316
leaq 0x2bdee0(%rip), %rdi    # 0x326220
callq 0x988f
leaq 0x19a584(%rip), %rax    # 0x2028d0
movq (%rax), %rax
cmpq $0x1, %rax
sete %dl
leaq 0x19cc77(%rip), %r15    # 0x204fd4
movl (%r15), %ecx
cmpl $0x41, %ecx
sete %sil
testb %sil, %dl
jne 0x68449
cmpq $0x1, %rax
sete %al
cmpl $0x50, %ecx
sete %cl
testb %cl, %al
jne 0x68449
leaq 0x19a578(%rip), %r14    # 0x202904
cmpb $0x0, (%r14)
jne 0x68449
leaq 0x1c0b90(%rip), %r12    # 0x228f2d
cmpb $0x0, (%r12)
jne 0x68449
leaq 0x2bde71(%rip), %rdi    # 0x326220
leaq 0xa35e9(%rip), %rsi     # 0x10b99f
callq 0x9090
testq %rax, %rax
je 0x683f1
movl $0x41, (%r15)
leaq 0x19a52a(%rip), %r14    # 0x2028f8
movl $0x31, (%r14)
leaq 0x2bde44(%rip), %rdi    # 0x326220
leaq 0xb08b4(%rip), %rsi     # 0x118c97
callq 0x9090
testq %rax, %rax
je 0x68421
pushq $0x33
jmp 0x6843b
leaq 0x2bde28(%rip), %rdi    # 0x326220
leaq 0xa35a8(%rip), %rsi     # 0x10b9a7
callq 0x9090
testq %rax, %rax
je 0x684d1
movb $0x1, (%r12)
leaq 0x19cc1f(%rip), %rax    # 0x205038
movl $0x2, (%rax)
jmp 0x6843f
leaq 0x2bddf8(%rip), %rdi    # 0x326220
leaq 0xb0842(%rip), %rsi     # 0x118c71
callq 0x9090
testq %rax, %rax
je 0x6843f
pushq $0x47
popq %rax
movl %eax, (%r14)
callq 0x43898
callq 0x43cec
leaq 0x1c0ae8(%rip), %r14    # 0x228f38
cmpb $0x0, (%r14)
jne 0x68486
leaq 0x2bddc3(%rip), %rdi    # 0x326220
leaq 0xa356a(%rip), %rsi     # 0x10b9ce
callq 0x9090
testq %rax, %rax
je 0x68486
movb $0x1, %al
movb %al, (%r14)
leaq 0x1c0ac3(%rip), %rcx    # 0x228f3d
movb %al, (%rcx)
callq 0x43898
callq 0x43cec
leaq 0x2bdd93(%rip), %rsi    # 0x326220
pushq $0x12
popq %rdx
movq %rbx, %rdi
callq 0x9170
movb $0x0, 0x11(%rbx)
xorl %edi, %edi
callq 0x52194
leaq 0x1c0ac6(%rip), %rax    # 0x228f70
cmpl $0x0, (%rax)
jne 0x684c8
callq 0x56b98
leaq 0x19a445(%rip), %rax    # 0x202900
orb $0x8, (%rax)
leaq 0x28ef43(%rip), %rax    # 0x2f7408
orb $0x2, (%rax)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2bdd48(%rip), %rdi    # 0x326220
leaq 0xa34cc(%rip), %rsi     # 0x10b9ab
callq 0x9090
testq %rax, %rax
je 0x684f5
movl $0x50, (%r15)
jmp 0x6843f
leaq 0x2bdd24(%rip), %rdi    # 0x326220
leaq 0xa34b1(%rip), %rsi     # 0x10b9b4
callq 0x9090
testq %rax, %rax
je 0x68540
leaq 0x1c0a18(%rip), %rax    # 0x228f2c
cmpb $0x0, (%rax)
jne 0x6843f
leaq 0x2bdcfc(%rip), %rdi    # 0x326220
leaq 0xa3498(%rip), %rsi     # 0x10b9c3
callq 0x9090
cmpq $0x1, %rax
movb $0x2, %al
sbbb $0x0, %al
movb %al, (%r14)
jmp 0x6843f
leaq 0x2bdcd9(%rip), %rdi    # 0x326220
leaq 0xa3471(%rip), %rsi     # 0x10b9bf
callq 0x9090
testq %rax, %rax
je 0x68571
leaq 0x1c09cd(%rip), %rax    # 0x228f2c
cmpb $0x0, (%rax)
jne 0x6843f
movb $0x3, (%r14)
jmp 0x6843f
leaq 0x2bdca8(%rip), %rdi    # 0x326220
leaq 0xa3448(%rip), %rsi     # 0x10b9c7
callq 0x9090
testq %rax, %rax
je 0x68449
leaq 0x1c0998(%rip), %rax    # 0x228f2c
cmpb $0x0, (%rax)
jne 0x6843f
movb $0x4, (%r14)
jmp 0x6843f