// File: /workspace/github_cpp_makefile_star2_O1/jkingan[P]ladyheather/heathgps.cpp
// Function: echo_stream(unsigned int)
void echo_stream(unsigned c)
{
static char buf[16];
int i;
char fmt[SLEN];

   // This routine dumps the serial port data stream to a file and/or com 
   // device.  

   if(log_stream) ;
else if(zoom_screen == 'H') ;
   else if((rcvr_type == THERMO_RCVR) && (enviro_type == LFS_ENVIRO)) ;
   else if(ASCII_RCVR && (crlf_seen == 0)) return;  // !!!! dont start logging until a full message has been seen
   else if(0 && (saw_rcvr_msg == 0)) {  //lfs
      return;  // !!!! dont start logging until a full message has been seen 
   }

   if((log_stream & LOG_RAW_STREAM) && raw_file) {  // recording raw receiver data
      fprintf(raw_file, "%c", c);
      if(raw_flush_mode) fflush(raw_file);  // sync raw data stream to disk every byte (for crash analysis)
//else fflush(raw_file);
   }

   if((com[ECHO_PORT].com_running > 0) && (com[RCVR_PORT].com_running > 0)) { // echo receiver data to another com device
      // see if we have a byte that indicates a possible packet boundary
      // that can be used to send the buffered characters
      if(pkt_end2 >= 0) {  // packets end in a two byte sequence
         if(c == (unsigned) pkt_end2) sendout(ECHO_PORT, c, EOM);  // flush buffer on packet end
         else                         sendout(ECHO_PORT, c, ADD_CHAR);
      }
      else if(pkt_end1 >= 0) {  // packets end with a known byte
         if(c == (unsigned) pkt_end1) sendout(ECHO_PORT, c, EOM);  // flush buffer on packet end 
         else                         sendout(ECHO_PORT, c, ADD_CHAR);
      }
      else if(pkt_start1 >= 0) {  // packets start with a known byte
         if(c == (unsigned) pkt_start1) sendout(ECHO_PORT, c, EOM); // flush buffer on packet start... kludge
         else                           sendout(ECHO_PORT, c, ADD_CHAR);
      }
      else {  // packets have no known start/end markers
         sendout(ECHO_PORT, c, EOM);  // ship them out byte-by-byte
      }

      drain_port(ECHO_PORT);
   }                                                    

   if(zoom_screen != 'H') {
      if((log_stream & LOG_HEX_STREAM) == 0) return;
      if(log_file == 0) return;
   }

   // logging hex data to log_file or zoom screen
   if(0 && TSIP_FMT_RCVR) {  // we can pretty-print format the packets
      ++kol;
      if(last_was_dle) {  
         if(c == DLE) {
            if(kol >= 16) {
               echo_log("\n      ");
               kol = (-1);
            }
            sprintf(fmt, "%02X:%02X ", c,c);
            echo_log(fmt);
         }
         else if(c == ETX) {
            sprintf(fmt, "%02X:%02X ", DLE,(unsigned) (c&0xFF));
            echo_log(fmt);
         }
         else {
            sprintf(fmt, "\n%02X:%02X", DLE,(unsigned) (c&0xFF));
            echo_log(fmt);
            if(c == 0x8F) echo_log("-");
            else          echo_log(" ");
            kol = (-1);
         }
         if(log_flush_mode && log_file) fflush(log_file);
         last_was_dle = 0;
      }
      else if(c == DLE) last_was_dle = 1;
      else {
         if(kol >= 16) {
            echo_log("\n      ");
            kol = 0;
         }
         sprintf(fmt, "%02X ", (unsigned) (c&0xFF));
         echo_log(fmt);
         if(log_flush_mode && log_file) fflush(log_file);
      }
   }
   else {  // hex dump the packets
      if((last_was_dle == 2) || (kol >= 16) || packet_end) {
         for(i=kol; i<16; i++) {
            if((i % 4) == 0) echo_log(" ");
            echo_log("   ");
         }

         for(i=0; i<kol; i++) {
            if((i % 4) == 0) echo_log(" ");
            if((buf[i] >= ' ') && (buf[i] <= 0x7E)) {
               sprintf(fmt, "%c", buf[i]);
               echo_log(fmt);
            }
            else echo_log(".");
         }

         if(packet_end) {
            sprintf(fmt, "   {%s}\n", packet_id);
            echo_log(fmt);
            strcpy(packet_id, "");
            packet_end = 0;
         }
         else echo_log("\n");

         if(last_was_dle == 2) {
            echo_log("\n");
            last_was_dle = 0;
         }
         if(log_flush_mode && log_file) fflush(log_file);

         kol = 0;
      }
      if((kol % 4) == 0) echo_log(" ");
//    if((kol % 8) == 0) echo_log(" ");
      sprintf(fmt, "%02X ", (unsigned) (c&0xFF));
      echo_log(fmt);
      if(log_flush_mode && log_file) fflush(log_file);
      buf[kol] = c;
      ++kol;

      if(last_was_dle) {  // used to do pretty printing some packet boundaries
         if(c == (unsigned) pkt_end2) last_was_dle = 2;
         else last_was_dle = 0;
      }
      else if(c == (unsigned) pkt_end1) last_was_dle = 1;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movl %edi, %r12d
leaq 0x1e62bd(%rip), %r14    # 0x23e410
movl (%r14), %eax
leaq 0x2b464b(%rip), %r15    # 0x30c7a8
testl %eax, %eax
jne 0x5818e
cmpb $0x48, (%r15)
je 0x5818e
leaq 0x1c0762(%rip), %rcx    # 0x2188d0
movq (%rcx), %rcx
cmpq $0x80000, %rcx          # imm = 0x80000
jne 0x58210
leaq 0x1c078f(%rip), %rdx    # 0x218914
cmpl $0x3, (%rdx)
jne 0x58210
shrb $0x3, %al
leaq 0x1e61d8(%rip), %rbx    # 0x23e370
movq (%rbx), %rsi
testq %rsi, %rsi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x581c4
movl %r12d, %edi
callq 0x9480
leaq 0x1e6265(%rip), %rax    # 0x23e41c
cmpl $0x0, (%rax)
je 0x581c4
movq (%rbx), %rdi
callq 0x9420
leaq 0x2b6115(%rip), %rax    # 0x30e2e0
cmpl $0x0, 0x19c50(%rax)
jle 0x5824e
cmpl $0x0, 0x179f0(%rax)
jle 0x5824e
leaq 0x1c2e5c(%rip), %rax    # 0x21b040
movl (%rax), %eax
testl %eax, %eax
jns 0x581fb
leaq 0x1c2e4b(%rip), %rax    # 0x21b03c
movl (%rax), %eax
testl %eax, %eax
js 0x58485
movzbl %r12b, %esi
cmpl %r12d, %eax
jne 0x58238
movl $0xb, %edi
movl $0x1, %edx
jmp 0x5823f
movabsq $0x5fb3f521a, %rdx      # imm = 0x5FB3F521A
testq %rdx, %rcx
je 0x5818e
leaq 0x1e6d6a(%rip), %rcx    # 0x23ef94
cmpl $0x0, (%rcx)
je 0x58473
jmp 0x5818e
movl $0xb, %edi
xorl %edx, %edx
callq 0xbcc0
movl $0xb, %edi
callq 0x5804f
cmpb $0x48, (%r15)
je 0x5826f
testb $0x1, (%r14)
je 0x58473
leaq 0x1e60fb(%rip), %rax    # 0x23e360
cmpq $0x0, (%rax)
je 0x58473
leaq 0x1e6cea(%rip), %r15    # 0x23ef60
cmpl $0x2, (%r15)
leaq 0x1e6ce3(%rip), %r13    # 0x23ef64
movl (%r13), %ebx
je 0x58299
cmpl $0xf, %ebx
jg 0x58299
cmpl $0x0, 0x313a01(%rip)    # 0x36bc94
je 0x583d1
cmpl $0xf, %ebx
jg 0x582c8
leaq 0xca7cf(%rip), %r14     # 0x122a74
leaq 0xca7c6(%rip), %r15     # 0x122a72
testb $0x3, %bl
jne 0x582b9
movq %r14, %rdi
callq 0x5809d
movq %r15, %rdi
callq 0x5809d
incl %ebx
cmpl $0x10, %ebx
jne 0x582ac
movl %r12d, -0x2c(%rbp)
cmpl $0x0, (%r13)
jle 0x5832d
xorl %r15d, %r15d
leaq 0x317d23(%rip), %r12    # 0x370000
leaq 0xdae8c(%rip), %rbx     # 0x133170
leaq -0x130(%rbp), %r14
testb $0x3, %r15b
jne 0x582fd
leaq 0xca77c(%rip), %rdi     # 0x122a74
callq 0x5809d
movb (%r15,%r12), %al
leal -0x7f(%rax), %ecx
movq %rbx, %rdi
cmpb $-0x5f, %cl
jb 0x5831c
movb %al, -0x130(%rbp)
movb $0x0, -0x12f(%rbp)
movq %r14, %rdi
callq 0x5809d
incq %r15
movslq (%r13), %rax
cmpq %rax, %r15
jl 0x582eb
cmpl $0x0, 0x313960(%rip)    # 0x36bc94
leaq 0x1e6c25(%rip), %r15    # 0x23ef60
je 0x58377
leaq 0xc7d84(%rip), %rsi     # 0x1200c8
leaq 0x313955(%rip), %rdx    # 0x36bca0
leaq -0x130(%rbp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x9060
movq %r14, %rdi
callq 0x5809d
movb $0x0, 0x313935(%rip)    # 0x36bca0
movl $0x0, 0x31391f(%rip)    # 0x36bc94
jmp 0x58383
leaq 0xdd626(%rip), %rdi     # 0x1359a4
callq 0x5809d
cmpl $0x2, (%r15)
movl -0x2c(%rbp), %r12d
jne 0x583a0
leaq 0xdd610(%rip), %rdi     # 0x1359a4
callq 0x5809d
movl $0x0, (%r15)
leaq 0x1e6079(%rip), %rax    # 0x23e420
cmpl $0x0, (%rax)
setne %al
leaq 0x1e5fac(%rip), %rcx    # 0x23e360
movq (%rcx), %rdi
testq %rdi, %rdi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x583c9
callq 0x9420
movl $0x0, (%r13)
testb $0x3, (%r13)
jne 0x583e4
leaq 0xca695(%rip), %rdi     # 0x122a74
callq 0x5809d
movzbl %r12b, %edx
leaq 0xc7ce2(%rip), %rsi     # 0x1200d1
leaq -0x130(%rbp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x9060
movq %r14, %rdi
callq 0x5809d
leaq 0x1e6011(%rip), %rax    # 0x23e420
cmpl $0x0, (%rax)
setne %al
leaq 0x1e5f44(%rip), %rcx    # 0x23e360
movq (%rcx), %rdi
testq %rdi, %rdi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x58431
callq 0x9420
movslq (%r13), %rax
leaq 0x317bc4(%rip), %rcx    # 0x370000
movb %r12b, (%rax,%rcx)
incl %eax
movl %eax, (%r13)
cmpl $0x0, (%r15)
je 0x5845f
leaq 0x1c2bed(%rip), %rcx    # 0x21b040
xorl %eax, %eax
cmpl %r12d, (%rcx)
sete %al
addl %eax, %eax
jmp 0x58470
leaq 0x1c2bd6(%rip), %rcx    # 0x21b03c
movl $0x1, %eax
cmpl %r12d, (%rcx)
jne 0x58473
movl %eax, (%r15)
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1c2bb8(%rip), %rax    # 0x21b044
movl (%rax), %eax
movzbl %r12b, %esi
testl %eax, %eax
jns 0x581ff
jmp 0x58204