// File: Pyboon[P]sage/isi_sage.cpp
// Function: IsiSage::ConfigInit(int, int, int, int, int, int, double, double, double)
void IsiSage::ConfigInit(int spot, int cycle_idx, int Tx, int Rx, int pn_code, int cyc_num, 
double fc, double bd, double cycle_rate){
    Util::log("config init...");
    this->spot = spot;
    this->cycle_idx = cycle_idx;
    // to be modified config
    config.Tx = Tx;
    config.Rx = Rx;
    config.cycle_num = cyc_num;
    config.PN_CODE = pn_code;
    config.fc = fc;
    config.bandwidth = bd;
    config.cycle_rate = cycle_rate;
    config.is_pg = true;
    // fixed config
    config.sample_codes = config.PN_CODE * 2;
    config.lambda = SPEED_OF_LIGHT / config.fc;    
    config.subchannel_num = config.Tx * config.Rx;
    config.subchannel_withPG_num = config.Tx * (config.Rx + 1);
    // souder 的采样原理设置了一个保护间隔
    config.channel_num = config.Tx * (config.Rx + 1) * config.cycle_num;
    // 此处的T为chip rate 就是一个码片的时间，一个PN序列有PN_CODE长度的码片
    config.T = 1 / config.bandwidth;
    // 收端一个天线阵列的扫描时间，即接收一个PN序列的时间，但是由于需要满足采样定理，因此为2倍的PN序列长度
    // 以下有关时间的都以码片为单位
    config.Tsc = config.sample_codes;
    config.switch_interval = config.Tsc;
    config.Tr = config.Tsc + config.switch_interval;
    config.Tt = config.Tr * (config.Rx + 1);
    config.Tcy = (int)(1/config.cycle_rate/config.T);
    config.cycle_interval = 1/config.cycle_rate;
    config.max_doppler = ceil(config.cycle_rate / 2);
    config.max_phi_rx = 180;
    config.min_phi_rx = -180;
    config.max_theta_rx = 75;
    config.min_theta_rx = -75;
    config.max_phi_tx = 75;
    config.min_phi_tx = -75;
    config.max_theta_tx = 75;
    config.min_theta_tx = -75;
    config.doppler_step = 1; // hz
    config.angle_step = 2; // degree
    config.delay_step = 1; // one T period 
    Util::log("config init done");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movl %r9d, -0x1c(%rbp)
movsd %xmm0, -0x28(%rbp)
movsd %xmm1, -0x30(%rbp)
movsd %xmm2, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0x59(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
callq 0x9dd0
movq -0xa0(%rbp), %rdx
leaq 0x56f35(%rip), %rsi     # 0x6fab0
leaq -0x58(%rbp), %rdi
callq 0xb320
jmp 0x18b86
leaq -0x58(%rbp), %rdi
callq 0x13b80
jmp 0x18b91
leaq -0x58(%rbp), %rdi
callq 0x9470
leaq -0x59(%rbp), %rdi
callq 0x9840
movq -0xa8(%rbp), %rax
movl -0xc(%rbp), %ecx
movl %ecx, 0x150(%rax)
movl -0x10(%rbp), %ecx
movl %ecx, 0x154(%rax)
movl -0x14(%rbp), %ecx
movl %ecx, 0xc(%rax)
movl -0x18(%rbp), %ecx
movl %ecx, 0x8(%rax)
movl 0x10(%rbp), %ecx
movl %ecx, 0x10(%rax)
movl -0x1c(%rbp), %ecx
movl %ecx, 0x18(%rax)
movsd -0x28(%rbp), %xmm0
movsd %xmm0, 0x88(%rax)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, 0x98(%rax)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, 0xd0(%rax)
movb $0x1, 0x40(%rax)
movl 0x18(%rax), %ecx
addl %ecx, %ecx
movl %ecx, 0x1c(%rax)
movsd 0x88(%rax), %xmm1
movsd 0x56c49(%rip), %xmm0    # 0x6f860
divsd %xmm1, %xmm0
movsd %xmm0, 0x90(%rax)
movl 0x8(%rax), %edx
movl 0xc(%rax), %ecx
imull %edx, %ecx
movl %ecx, 0xa0(%rax)
movl 0x8(%rax), %edx
movl 0xc(%rax), %ecx
incl %edx
imull %edx, %ecx
movl %ecx, 0xa4(%rax)
movl 0x8(%rax), %edx
movl 0xc(%rax), %ecx
incl %edx
imull %edx, %ecx
movl 0x10(%rax), %edx
imull %edx, %ecx
movl %ecx, 0x14(%rax)
movsd 0x98(%rax), %xmm2
movsd 0x553c1(%rip), %xmm0    # 0x6e028
movaps %xmm0, %xmm1
divsd %xmm2, %xmm1
movsd %xmm1, 0xa8(%rax)
movl 0x1c(%rax), %ecx
movl %ecx, 0xb0(%rax)
movl 0xb0(%rax), %ecx
movl %ecx, 0xc0(%rax)
movl 0xb0(%rax), %ecx
movl 0xc0(%rax), %edx
addl %edx, %ecx
movl %ecx, 0xb8(%rax)
movl 0x8(%rax), %edx
movl 0xb8(%rax), %ecx
incl %edx
imull %edx, %ecx
movl %ecx, 0xb4(%rax)
movsd 0xa8(%rax), %xmm2
movsd 0xd0(%rax), %xmm3
movaps %xmm0, %xmm1
divsd %xmm3, %xmm1
divsd %xmm2, %xmm1
cvttsd2si %xmm1, %ecx
movl %ecx, 0xbc(%rax)
movsd 0xd0(%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0xc8(%rax)
movsd 0xd0(%rax), %xmm0
movsd 0x56b6c(%rip), %xmm1    # 0x6f868
mulsd %xmm1, %xmm0
callq 0x9100
movq -0xa8(%rbp), %rax
movsd %xmm0, 0xd8(%rax)
movabsq $0x4066800000000000, %rcx # imm = 0x4066800000000000
movq %rcx, 0x118(%rax)
movabsq $-0x3f99800000000000, %rcx # imm = 0xC066800000000000
movq %rcx, 0x110(%rax)
movabsq $0x4052c00000000000, %rdx # imm = 0x4052C00000000000
movq %rdx, 0x108(%rax)
movabsq $-0x3fad400000000000, %rcx # imm = 0xC052C00000000000
movq %rcx, 0x100(%rax)
movq %rdx, 0xf8(%rax)
movq %rcx, 0xf0(%rax)
movq %rdx, 0xe8(%rax)
movq %rcx, 0xe0(%rax)
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, 0x120(%rax)
movabsq $0x4000000000000000, %rcx # imm = 0x4000000000000000
movq %rcx, 0x128(%rax)
movl $0x1, 0x130(%rax)
leaq -0x91(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x9dd0
movq -0xb0(%rbp), %rdx
leaq 0x56cfe(%rip), %rsi     # 0x6fabf
leaq -0x90(%rbp), %rdi
callq 0xb320
jmp 0x18dcf
leaq -0x90(%rbp), %rdi
callq 0x13b80
jmp 0x18ddd
leaq -0x90(%rbp), %rdi
callq 0x9470
leaq -0x91(%rbp), %rdi
callq 0x9840
addq $0xb0, %rsp
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x18e21
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x9470
leaq -0x59(%rbp), %rdi
callq 0x9840
jmp 0x18e5e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x18e52
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x9470
leaq -0x91(%rbp), %rdi
callq 0x9840
movq -0x68(%rbp), %rdi
callq 0x9dc0
nopw (%rax,%rax)