// File: /workspace/github_cpp_makefile_star2_O1/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 0x400e3(%rip), %rsi     # 0x6bc88
leaq -0x180(%rbp), %rdi
xorl %eax, %eax
callq 0x8120
movq %rbx, -0x38(%rbp)
leaq 0x10(%rbx), %r15
movq %r15, %rdi
callq 0x58952
leaq -0x180(%rbp), %rcx
movq %r15, %rdi
movl $0x3, %esi
movl $0x3, %edx
callq 0x589a3
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 0x2d1e6
movq %r12, -0x58(%rbp)
movq %r12, -0x60(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x68(%rbp), %rdi
callq 0x8910
leaq -0x80(%rbp), %rdi
callq 0x85b0
movq -0x38(%rbp), %rax
movq 0xa0ec8(%rax), %rbx
movq -0x80(%rbp), %rcx
movslq (%rax), %rdx
movq -0x48(%rbp), %rsi
cmpq %rbx, %rsi
je 0x2bcba
movq %rsi, %rax
movq 0x8(%rsi), %rsi
movq %rcx, %rdi
subq 0x10(%rsi), %rdi
cmpq %rdx, %rdi
jl 0x2bc48
cmpq %rbx, %rax
je 0x2bcba
cmpq -0x48(%rbp), %rbx
je 0x2bcba
movq 0x8(%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq %rax, 0x18(%rbx)
jg 0x2bcba
leaq 0x10(%rbx), %rsi
leaq -0x60(%rbp), %r13
movq %r13, %rdi
callq 0x2d222
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 0x2d73a
movq %r13, %rbx
cmpq %r12, %r13
jne 0x2bc77
movq -0x68(%rbp), %rdi
callq 0x84b0
movq -0x60(%rbp), %r13
leaq -0x60(%rbp), %r12
cmpq %r12, %r13
je 0x2be46
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 0x50696
movq %r13, %r12
movq -0x70(%rbp), %r13
callq 0x8570
leaq 0x3ff78(%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 0x2bd8c
movq 0x40(%r12), %rbx
addq $0x30, %r12
cmpq %r12, %rbx
je 0x2be39
movq 0x20(%rbx), %rsi
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rdx
movsd 0x20(%rax), %xmm0
leaq 0x40(%rbx), %rcx
movq %r13, %rdi
callq 0x1c9c4
testl %eax, %eax
je 0x2bd77
movq -0x38(%rbp), %rax
movl 0x1070(%rax), %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x5abb7
movq %rbx, %rdi
callq 0x8460
movq %rax, %rbx
cmpq %r12, %rax
jne 0x2bd41
jmp 0x2be39
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 0x2c00e
movl -0x2c(%rbp), %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0x5abb7
movq 0x40(%r12), %rbx
leaq 0x30(%r12), %rax
movq %rax, -0x78(%rbp)
cmpq %rax, %rbx
je 0x2be39
movq 0x58(%rbx), %r12
leaq 0x48(%rbx), %r13
cmpq %r13, %r12
je 0x2be28
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 0x2c056
movl -0x2c(%rbp), %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0x5abb7
movq %r12, %rdi
callq 0x8460
movq %rax, %r12
cmpq %r13, %rax
jne 0x2bde1
movq %rbx, %rdi
callq 0x8460
movq %rax, %rbx
cmpq -0x78(%rbp), %rax
jne 0x2bdd4
movq -0x40(%rbp), %r13
movq (%r13), %r13
jmp 0x2bcc7
leaq 0x66153(%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 0x3fdfd(%rip), %xmm1    # 0x6bc78
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %edi
callq 0x508e9
jmp 0x2bc08
jmp 0x2be97
jmp 0x2be97
jmp 0x2be97
jmp 0x2be97
jmp 0x2be97
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x2d1e6
movq %rbx, %rdi
callq 0x8b40
nop