// File: rthoelen[P]NXCore_Icom/main.cc
// Function: timing_thread(void*)
void *timing_thread(void *t_id)
{
	int i;
	unsigned int seconds = 0;
	char h_buf[20];
	
	
        memset((char *)&h_buf[0], 0, sizeof(h_buf));
	h_buf[0] = 'N';
	h_buf[1] = 'X';
	h_buf[2] = 'D';
	h_buf[3] = 'N';
	h_buf[4] = 0x00;
	h_buf[5] = 0x99;
	h_buf[6] = 0x00;
	h_buf[7] = 'N';
	h_buf[8] = '1';
	h_buf[9] = 'X';
	h_buf[10] = 'D';
	h_buf[11] = 'N';

	for(;;)
	{
		for( i = 0; i < repeater_count; i++)
		{
			repeater[i].time_since_rx++;
			repeater[i].time_since_tx++;

			if(repeater[i].time_since_rx > repeater[i].hold_time)
			{
				repeater[i].time_since_rx = repeater[i].hold_time;
				repeater[i].rx_activity = 0;
			}

			while(tx_busy_sem == 1)
				usleep(1);
			if(repeater[i].time_since_tx > repeater[i].tx_hold_time)
			{
				repeater[i].time_since_tx = repeater[i].tx_hold_time;
				repeater[i].tx_busy = 0;
			}


		}	
		if((++seconds % 30) == 0)
		{
			for( i = 0; i < repeater_count; i++)
				{
					if(repeater[i].stealth)
						sendto(socket_00, h_buf, sizeof(h_buf), 0, (struct sockaddr *)&repeater[i].rpt_addr_00,
							sizeof(repeater[i].rpt_addr_00));
				}
		}


		sleep(1);
	}

	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl $0x0, -0x10(%rbp)
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
movl $0x14, %edx
callq 0x5200
movb $0x4e, -0x30(%rbp)
movb $0x58, -0x2f(%rbp)
movb $0x44, -0x2e(%rbp)
movb $0x4e, -0x2d(%rbp)
movb $0x0, -0x2c(%rbp)
movb $-0x67, -0x2b(%rbp)
movb $0x0, -0x2a(%rbp)
movb $0x4e, -0x29(%rbp)
movb $0x31, -0x28(%rbp)
movb $0x58, -0x27(%rbp)
movb $0x44, -0x26(%rbp)
movb $0x4e, -0x25(%rbp)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
cmpl 0x22155(%rip), %eax     # 0x29498
jge 0x7484
movq 0x22128(%rip), %rax     # 0x29478
movslq -0xc(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x18(%rax)
movq 0x2210d(%rip), %rax     # 0x29478
movslq -0xc(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x1c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x1c(%rax)
movq 0x220f2(%rip), %rax     # 0x29478
movslq -0xc(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
movq 0x220dd(%rip), %rcx     # 0x29478
movslq -0xc(%rbp), %rdx
imulq $0x70, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x20(%rcx), %eax
jle 0x73ee
movq 0x220c6(%rip), %rax     # 0x29478
movslq -0xc(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %ecx
movq 0x220b1(%rip), %rax     # 0x29478
movslq -0xc(%rbp), %rdx
imulq $0x70, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x18(%rax)
movq 0x2209c(%rip), %rax     # 0x29478
movslq -0xc(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x28(%rax)
jmp 0x73f0
cmpl $0x1, 0x220ad(%rip)     # 0x294a4
jne 0x7405
movl $0x1, %edi
callq 0x55c0
jmp 0x73f0
movq 0x2206c(%rip), %rax     # 0x29478
movslq -0xc(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x1c(%rax), %eax
movq 0x22057(%rip), %rcx     # 0x29478
movslq -0xc(%rbp), %rdx
imulq $0x70, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x24(%rcx), %eax
jle 0x7474
movq 0x22040(%rip), %rax     # 0x29478
movslq -0xc(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x24(%rax), %ecx
movq 0x2202b(%rip), %rax     # 0x29478
movslq -0xc(%rbp), %rdx
imulq $0x70, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x1c(%rax)
movq 0x22016(%rip), %rax     # 0x29478
movslq -0xc(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x2c(%rax)
jmp 0x7476
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x733a
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
movl $0x1e, %ecx
xorl %edx, %edx
divl %ecx
cmpl $0x0, %edx
jne 0x7502
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
cmpl 0x21fed(%rip), %eax     # 0x29498
jge 0x7500
movq 0x21fc4(%rip), %rax     # 0x29478
movslq -0xc(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x58(%rax)
je 0x74f3
movl 0x21fd5(%rip), %edi     # 0x294a0
leaq -0x30(%rbp), %rsi
movq 0x21fa2(%rip), %r8      # 0x29478
movslq -0xc(%rbp), %rax
imulq $0x70, %rax, %rax
addq %rax, %r8
movl $0x14, %edx
xorl %ecx, %ecx
movl $0x10, %r9d
callq 0x5090
jmp 0x74f5
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x74a2
jmp 0x7502
movl $0x1, %edi
callq 0x5310
jmp 0x7333
nopw %cs:(%rax,%rax)