// File: /workspace/github_cpp_makefile_star2_O3/DoubleString[P]RtConverter/src/RtConverter/RtConverter.cpp
// Function: bamboo::RtConverter::routineObs()
void RtConverter::routineObs() {
	time_t now;
	int nbyte;
	char cmd[256];
	unsigned char buff[1024];
	list<RtConvItem> item_sd;
	sprintf(cmd, ":%d", port);
	strinit(&svr);
	stropen(&svr, STR_TCPSVR, STR_MODE_RW, cmd);
	while (true) {
		/* test for re-read configures*/
		item_sd.clear();
		def_lock(&_mutex);
		time(&now);
		list<RtConvItem>::reverse_iterator itrlist = obsqueue.rbegin();
		while (itrlist != obsqueue.rend()) {
			if (now - (*itrlist).gent >= obsdelay) {
				break;
			}
			++itrlist;
		}
		if (itrlist != obsqueue.rend()) {
			gtime_t sd_t = (*itrlist).curt;
			list<RtConvItem>::iterator itr = obsqueue.begin();
			while (itr != obsqueue.end()) {
				if ((*itr).curt.time > sd_t.time)  break;
				item_sd.push_back(*itr);
				itr = obsqueue.erase(itr);
			}
		}
		def_unlock(&_mutex);

		/// here to sending the observation 
		list<RtConvItem>::iterator itr = item_sd.begin();
		while (itr != item_sd.end()) {
			char strbuf[1024] = { 0 };
			time2str((*itr).curt, strbuf, 2);
			printf("Thread %010d,begin to sending observation %s\n", def_pthread_id_self(), strbuf);
			/// generate the buff here
			if(this->type == ConvType::obsbnc){
				memset(buff, 0, sizeof(buff));
				makeupTimeBuffer((*itr).curt, (char*)buff, nbyte);
				strwrite(&svr, buff, nbyte);
				std::map<std::string, std::map<std::string, RtSatObs> >::iterator obitr_tosend = (*itr).obslist.begin();
				while (obitr_tosend != (*itr).obslist.end()) {
					map<string, RtSatObs>::iterator satitr = (*obitr_tosend).second.begin();
					while (satitr != (*obitr_tosend).second.end()) {
						memset(buff, 0, sizeof(buff));
						makeupObsBuffer((*obitr_tosend).first.c_str(), (*satitr).first.c_str(), (*satitr).second, (char*)buff, nbyte);
						strwrite(&svr, buff, nbyte);
						++satitr;
					}
					obitr_tosend++;
				}
			}
			else{
				std::map<std::string, std::map<std::string, RtSatObs> >::iterator obitr_tosend = (*itr).obslist.begin();
				while (obitr_tosend != (*itr).obslist.end()) {
					if(rtcmexEncoder.m_encodeRtcmExMsg((*obitr_tosend).first.c_str(),(*itr).curt,(*obitr_tosend).second)){
						strwrite(&svr,(unsigned char*)rtcmexEncoder.buff,rtcmexEncoder.nbyte);
					}
					obitr_tosend++;
				}
			}
			++itr;
		}
		sleepms(NINT(1000 / Deploy::s_getSpeed()));
	}
	strclose(&svr);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x958, %rsp            # imm = 0x958
movq %rdi, %rbx
leaq -0x60(%rbp), %r12
movq %r12, 0x8(%r12)
movq %r12, (%r12)
movq $0x0, 0x10(%r12)
movl 0x8(%rdi), %edx
leaq 0x405ad(%rip), %rsi     # 0x6bc88
leaq -0x180(%rbp), %rdi
xorl %eax, %eax
callq 0x8120
movq %rbx, -0x38(%rbp)
leaq 0x10(%rbx), %r15
movq %r15, %rdi
callq 0x57d6e
leaq -0x180(%rbp), %rcx
movq %r15, %rdi
movl $0x3, %esi
movl $0x3, %edx
callq 0x57dbf
movq -0x38(%rbp), %rax
leaq 0xa0f40(%rax), %rcx
movq %rcx, -0x68(%rbp)
leaq 0xa0ec8(%rax), %rcx
movq %rcx, -0x48(%rbp)
leaq 0x870(%rax), %r13
leaq -0x980(%rbp), %r14
movq %r13, -0x70(%rbp)
movq %r12, %rdi
callq 0x2cd5c
movq %r12, -0x58(%rbp)
movq %r12, -0x60(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x68(%rbp), %rdi
callq 0x8900
leaq -0x80(%rbp), %rdi
callq 0x85b0
movq -0x38(%rbp), %rax
movq 0xa0ec8(%rax), %rbx
movq -0x80(%rbp), %rcx
movslq (%rax), %rdx
movq -0x48(%rbp), %rax
cmpq %rbx, %rax
je 0x2b7e4
movq 0x8(%rax), %rax
movq %rcx, %rsi
subq 0x10(%rax), %rsi
cmpq %rdx, %rsi
jl 0x2b77e
cmpq -0x48(%rbp), %rbx
je 0x2b7e4
movq 0x18(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq %rax, 0x18(%rbx)
jg 0x2b7e4
leaq 0x10(%rbx), %rsi
leaq -0x60(%rbp), %r13
movq %r13, %rdi
callq 0x2cd98
movq %rax, %rdi
movq %r13, %rsi
callq 0x80c0
incq -0x50(%rbp)
movq (%rbx), %r13
movq -0x48(%rbp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2d2b0
movq %r13, %rbx
cmpq %r12, %r13
jne 0x2b7a1
movq -0x68(%rbp), %rdi
callq 0x84b0
movq -0x60(%rbp), %r13
leaq -0x60(%rbp), %r12
cmpq %r12, %r13
je 0x2b970
movl $0x400, %edx            # imm = 0x400
leaq -0x580(%rbp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x8390
movq 0x18(%r13), %rdi
movsd 0x20(%r13), %xmm0
movq %rbx, %rsi
movl $0x2, %edx
callq 0x4fcf1
movq %r13, %r12
movq -0x70(%rbp), %r13
callq 0x8570
leaq 0x4044e(%rip), %rdi     # 0x6bc8c
movq %rax, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x8080
movq -0x38(%rbp), %rax
cmpl $0x0, 0x4(%rax)
movq %r12, -0x40(%rbp)
je 0x2b8b6
movq 0x40(%r12), %rbx
addq $0x30, %r12
cmpq %r12, %rbx
je 0x2b963
movq 0x20(%rbx), %rsi
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rdx
movsd 0x20(%rax), %xmm0
leaq 0x40(%rbx), %rcx
movq %r13, %rdi
callq 0x1c348
testl %eax, %eax
je 0x2b8a1
movq -0x38(%rbp), %rax
movl 0x1070(%rax), %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x59f9f
movq %rbx, %rdi
callq 0x8460
movq %rax, %rbx
cmpq %r12, %rax
jne 0x2b86b
jmp 0x2b963
movl $0x400, %edx            # imm = 0x400
movq %r14, %rdi
xorl %esi, %esi
callq 0x8390
movq 0x18(%r12), %rsi
movsd 0x20(%r12), %xmm0
movq %r14, %rdx
leaq -0x2c(%rbp), %rcx
callq 0x2bb38
movl -0x2c(%rbp), %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0x59f9f
movq 0x40(%r12), %rbx
leaq 0x30(%r12), %rax
movq %rax, -0x78(%rbp)
cmpq %rax, %rbx
je 0x2b963
movq 0x58(%rbx), %r12
leaq 0x48(%rbx), %r13
cmpq %r13, %r12
je 0x2b952
movl $0x400, %edx            # imm = 0x400
movq %r14, %rdi
xorl %esi, %esi
callq 0x8390
movq 0x20(%rbx), %rsi
movq 0x20(%r12), %rdx
leaq 0x40(%r12), %rcx
movq %r14, %r8
leaq -0x2c(%rbp), %r9
callq 0x2bb80
movl -0x2c(%rbp), %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0x59f9f
movq %r12, %rdi
callq 0x8460
movq %rax, %r12
cmpq %r13, %rax
jne 0x2b90b
movq %rbx, %rdi
callq 0x8460
movq %rax, %rbx
cmpq -0x78(%rbp), %rax
jne 0x2b8fe
movq -0x40(%rbp), %r13
movq (%r13), %r13
jmp 0x2b7f1
leaq 0x66629(%rip), %rax     # 0x91fa0
movq (%rax), %rcx
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0x8(%rcx)
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
xorl %ecx, %ecx
testl %eax, %eax
setg %cl
leal -0x1(%rcx,%rcx), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd 0x402d3(%rip), %xmm1    # 0x6bc78
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %edi
callq 0x4ff28
jmp 0x2b73e
jmp 0x2b9c1
jmp 0x2b9c1
jmp 0x2b9c1
jmp 0x2b9c1
jmp 0x2b9c1
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x2cd5c
movq %rbx, %rdi
callq 0x8b30
nop