// File: /workspace/github_cpp_makefile_star2_O2/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 -0x78(%rbp), %rax
movq %rax, 0x8(%rax)
movq %rax, (%rax)
andq $0x0, 0x10(%rax)
movl 0x8(%rdi), %edx
leaq 0x3b07d(%rip), %rsi     # 0x61c88
leaq -0x180(%rbp), %rdi
xorl %eax, %eax
callq 0x8110
movq %rbx, -0x38(%rbp)
leaq 0x10(%rbx), %r15
movq %r15, %rdi
callq 0x4ef90
pushq $0x3
popq %rdx
leaq -0x180(%rbp), %rcx
movq %r15, %rdi
movl %edx, %esi
callq 0x4efdc
movq -0x38(%rbp), %rax
leaq 0xa0f40(%rax), %rcx
movq %rcx, -0x40(%rbp)
leaq 0xa0ec8(%rax), %rcx
movq %rcx, -0x48(%rbp)
addq $0x870, %rax            # imm = 0x870
movq %rax, -0x50(%rbp)
leaq -0x980(%rbp), %r14
leaq -0x78(%rbp), %rdi
callq 0x27cf6
movq -0x40(%rbp), %rdi
callq 0x8900
leaq -0x80(%rbp), %rdi
callq 0x85b0
movq -0x38(%rbp), %rcx
movq 0xa0ec8(%rcx), %rbx
movq -0x80(%rbp), %rax
movslq (%rcx), %rdx
movq -0x48(%rbp), %r13
movq %r13, %rcx
cmpq %rbx, %rcx
je 0x26ce1
movq 0x8(%rcx), %rcx
movq %rax, %rsi
subq 0x10(%rcx), %rsi
cmpq %rdx, %rsi
jl 0x26c9c
movq 0x18(%rcx), %r12
cmpq %r13, %rbx
je 0x26ce1
cmpq %r12, 0x18(%rbx)
jg 0x26ce1
leaq 0x10(%rbx), %rsi
leaq -0x78(%rbp), %rdi
callq 0x27cae
movq -0x48(%rbp), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0x27d18
movq %rax, %rbx
jmp 0x26cb5
movq -0x40(%rbp), %rdi
callq 0x84b0
movq -0x78(%rbp), %r12
movq -0x50(%rbp), %r13
leaq -0x78(%rbp), %rax
cmpq %rax, %r12
je 0x26e64
movl $0x400, %edx            # imm = 0x400
leaq -0x580(%rbp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x8390
movq 0x18(%r12), %rdi
movsd 0x20(%r12), %xmm0
movq %rbx, %rsi
pushq $0x2
popq %rdx
callq 0x47a48
callq 0x8570
leaq 0x3af54(%rip), %rdi     # 0x61c8c
movq %rax, %rsi
leaq -0x580(%rbp), %rdx
xorl %eax, %eax
callq 0x8070
movq -0x38(%rbp), %rax
cmpl $0x0, 0x4(%rax)
movq %r12, -0x58(%rbp)
je 0x26dac
movq 0x40(%r12), %rbx
addq $0x30, %r12
cmpq %r12, %rbx
je 0x26e57
movq 0x20(%rbx), %rsi
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rdx
movsd 0x20(%rax), %xmm0
leaq 0x40(%rbx), %rcx
movq %r13, %rdi
callq 0x195ce
testl %eax, %eax
je 0x26d9f
movq -0x38(%rbp), %rax
movl 0x1070(%rax), %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x51054
movq %rbx, %rdi
callq 0x8460
movq %rax, %rbx
jmp 0x26d60
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 0x27020
movl -0x2c(%rbp), %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0x51054
movq 0x40(%r12), %rbx
leaq 0x30(%r12), %rax
movq %rax, -0x60(%rbp)
cmpq -0x60(%rbp), %rbx
je 0x26e57
movq 0x58(%rbx), %r12
leaq 0x48(%rbx), %r13
cmpq %r13, %r12
je 0x26e46
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 0x27068
movl -0x2c(%rbp), %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0x51054
movq %r12, %rdi
callq 0x8460
movq %rax, %r12
jmp 0x26dfd
movq %rbx, %rdi
callq 0x8460
movq %rax, %rbx
movq -0x50(%rbp), %r13
jmp 0x26def
movq -0x58(%rbp), %r12
movq (%r12), %r12
jmp 0x26cf2
leaq 0x63145(%rip), %rax     # 0x89fb0
movq (%rax), %rcx
movl $0x3e8, %eax            # imm = 0x3E8
xorl %edx, %edx
idivl 0x8(%rcx)
cvtsi2sd %eax, %xmm0
xorl %ecx, %ecx
testl %eax, %eax
setg %cl
leal -0x1(%rcx,%rcx), %eax
cvtsi2sd %eax, %xmm1
mulsd 0x3ade5(%rip), %xmm1    # 0x61c78
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %edi
callq 0x47c59
jmp 0x26c68
jmp 0x26eaf
jmp 0x26eaf
jmp 0x26eaf
jmp 0x26eaf
jmp 0x26eaf
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x2813a
movq %rbx, %rdi
callq 0x8b30
nop