// File: /workspace/github_c_makefile_star2_O1/hiperiondev[P]hpsdrsim/src/hpsdr_newprotocol.c
// Function: new_protocol_general_packet
void new_protocol_general_packet(unsigned char *buffer) {
    dbg_printf(1, "-- new protocol packet received\n");
    static unsigned long seqnum = 0;
    unsigned long seqold;
    int rc;

    seqold = seqnum;
    seqnum = (buffer[0] >> 24) + (buffer[1] << 16) + (buffer[2] << 8) + buffer[3];
    if (seqnum != 0 && seqnum != seqold + 1) {
        dbg_printf(1, "GP: SEQ ERROR, old=%lu new=%lu\n", seqold, seqnum);
    }

    rc = (buffer[5] << 8) + buffer[6];
    if (rc == 0)
        rc = 1025;
    if (rc != ddc_port || !run) {
        ddc_port = rc;
        dbg_printf(1, "GP: RX specific rcv        port is  %4d\n", rc);
    }
    rc = (buffer[7] << 8) + buffer[8];
    if (rc == 0)
        rc = 1026;
    if (rc != duc_port || !run) {
        duc_port = rc;
        dbg_printf(1, "GP: TX specific rcv        port is  %4d\n", rc);
    }
    rc = (buffer[9] << 8) + buffer[10];
    if (rc == 0)
        rc = 1027;
    if (rc != hp_port || !run) {
        hp_port = rc;
        dbg_printf(1, "GP: HighPrio Port rcv      port is  %4d\n", rc);
    }
    rc = (buffer[11] << 8) + buffer[12];
    if (rc == 0)
        rc = 1025;
    if (rc != shp_port || !run) {
        shp_port = rc;
        dbg_printf(1, "GP: HighPrio Port snd      port is  %4d\n", rc);
    }
    rc = (buffer[13] << 8) + buffer[14];
    if (rc == 0)
        rc = 1028;
    if (rc != audio_port || !run) {
        audio_port = rc;
        dbg_printf(1, "GP: Audio rcv              port is  %4d\n", rc);
    }
    rc = (buffer[15] << 8) + buffer[16];
    if (rc == 0)
        rc = 1029;
    if (rc != duc0_port || !run) {
        duc0_port = rc;
        dbg_printf(1, "GP: TX data rcv base       port is  %4d\n", rc);
    }
    rc = (buffer[17] << 8) + buffer[18];
    if (rc == 0)
        rc = 1035;
    if (rc != ddc0_port || !run) {
        ddc0_port = rc;
        dbg_printf(1, "GP: RX data snd base       port is  %4d\n", rc);
    }
    rc = (buffer[19] << 8) + buffer[20];
    if (rc == 0)
        rc = 1026;
    if (rc != mic_port || !run) {
        mic_port = rc;
        dbg_printf(1, "GP: Microphone data snd    port is  %4d\n", rc);
    }
    rc = (buffer[21] << 8) + buffer[22];
    if (rc == 0)
        rc = 1027;
    if (rc != wide_port || !run) {
        wide_port = rc;
        dbg_printf(1, "GP: Wideband data snd      port is  %4d\n", rc);
    }
    rc = buffer[23];
    if (rc != wide_enable || !run) {
        wide_enable = rc;
        dbg_printf(1, "GP: Wideband Enable Flag is %d\n", rc);
    }
    rc = (buffer[24] << 8) + buffer[25];
    if (rc == 0)
        rc = 512;
    if (rc != wide_len || !run) {
        wide_len = rc;
        dbg_printf(1, "GP: WideBand Length is %d\n", rc);
    }
    rc = buffer[26];
    if (rc == 0)
        rc = 16;
    if (rc != wide_size || !run) {
        wide_size = rc;
        dbg_printf(1, "GP: Wideband sample size is %d\n", rc);
    }
    rc = buffer[27];
    if (rc != wide_rate || !run) {
        wide_rate = rc;
        dbg_printf(1, "GP: Wideband sample rate is %d\n", rc);
    }
    rc = buffer[28];
    if (rc != wide_ppf || !run) {
        wide_ppf = rc;
        dbg_printf(1, "GP: Wideband PPF is %d\n", rc);
    }
    rc = (buffer[29] << 8) + buffer[30];
    if (rc != port_mm || !run) {
        port_mm = rc;
        dbg_printf(1, "MemMapped Registers rcv port is %d\n", rc);
    }
    rc = (buffer[31] << 8) + buffer[32];
    if (rc != port_smm || !run) {
        port_smm = rc;
        dbg_printf(1, "MemMapped Registers snd port is %d\n", rc);
    }
    rc = (buffer[33] << 8) + buffer[34];
    if (rc != pwm_min || !run) {
        pwm_min = rc;
        dbg_printf(1, "GP: PWM Min value is %d\n", rc);
    }
    rc = (buffer[35] << 8) + buffer[36];
    if (rc != pwm_max || !run) {
        pwm_max = rc;
        dbg_printf(1, "GP: PWM Max value is %d\n", rc);
    }
    rc = buffer[37];
    if (rc != bits || !run) {
        bits = rc;
        dbg_printf(1, "GP: ModeBits=x%02x\n", rc);
    }
    rc = buffer[38];
    if (rc != hwtim || !run) {
        hwtim = rc;
        dbg_printf(1, "GP: Hardware Watchdog enabled=%d\n", rc);
    }

    iqform = buffer[39];
    if (iqform == 0)
        iqform = 3;
    if (iqform != 3)
        dbg_printf(1, "GP: Wrong IQ Format requested: %d\n", iqform);

    rc = (buffer[58] & 0x01);
    if (rc != pa_enable || !run) {
        pa_enable = rc;
        dbg_printf(1, "GP: PA enabled=%d\n", rc);
    }

    rc = buffer[59] & 0x01;
    if (rc != alex0_enable || !run) {
        alex0_enable = rc;
        dbg_printf(1, "GP: ALEX0 register enable=%d\n", rc);
    }
    rc = (buffer[59] & 0x02) >> 1;
    if (rc != alex1_enable || !run) {
        alex1_enable = rc;
        dbg_printf(1, "GP: ALEX1 register enable=%d\n", rc);
    }

    // Start HighPrio thread if we arrive here for the first time
    // The HighPrio thread keeps running all the time.
    if (!highprio_thread_id) {
        if (pthread_create(&highprio_thread_id, NULL, highprio_thread, NULL) < 0) {
            dbg_printf(1, "***** ERROR: Create HighPrio thread");
        }
        pthread_detach(highprio_thread_id);

        // init state arrays to zero for the first time
        memset(adcdither, -1, 8 * sizeof(int));
        memset(adcrandom, -1, 8 * sizeof(int));
        memset(ddcenable, -1, NUMRECEIVERS * sizeof(int));
        memset(adcmap, -1, NUMRECEIVERS * sizeof(int));
        memset(syncddc, -1, NUMRECEIVERS * sizeof(int));

        memset(rxfreq, -1, NUMRECEIVERS * sizeof(unsigned long));
        memset(alex0, 0, 32 * sizeof(int));
        memset(alex1, 0, 32 * sizeof(int));
    }
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
leaq 0x636c(%rip), %rsi      # 0x80f8
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movq 0xa549(%rip), %rdx      # 0xc2e8
movzbl 0x1(%rbx), %eax
shll $0x10, %eax
movzbl 0x2(%rbx), %esi
shll $0x8, %esi
orl %eax, %esi
movzbl 0x3(%rbx), %ecx
orq %rsi, %rcx
movq %rcx, 0xa52b(%rip)      # 0xc2e8
testq %rcx, %rcx
sete %al
leaq 0x1(%rdx), %rsi
cmpq %rsi, %rcx
sete %sil
orb %al, %sil
jne 0x1de6
leaq 0x633f(%rip), %rsi      # 0x8119
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movzwl 0x5(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
testw %ax, %ax
movl $0x401, %edx            # imm = 0x401
cmovnel %eax, %edx
cmpl 0xa4ee(%rip), %edx      # 0xc2f0
jne 0x1e0d
cmpl $0x0, 0xa4d5(%rip)      # 0xc2e0
jne 0x1e26
movl %edx, 0xa4dd(%rip)      # 0xc2f0
leaq 0x631f(%rip), %rsi      # 0x8139
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movzwl 0x7(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
testw %ax, %ax
movl $0x402, %edx            # imm = 0x402
cmovnel %eax, %edx
cmpl 0xa4b2(%rip), %edx      # 0xc2f4
jne 0x1e4d
cmpl $0x0, 0xa495(%rip)      # 0xc2e0
jne 0x1e66
movl %edx, 0xa4a1(%rip)      # 0xc2f4
leaq 0x6308(%rip), %rsi      # 0x8162
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movzwl 0x9(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
testw %ax, %ax
movl $0x403, %edx            # imm = 0x403
cmovnel %eax, %edx
cmpl 0xa476(%rip), %edx      # 0xc2f8
jne 0x1e8d
cmpl $0x0, 0xa455(%rip)      # 0xc2e0
jne 0x1ea6
movl %edx, 0xa465(%rip)      # 0xc2f8
leaq 0x62f1(%rip), %rsi      # 0x818b
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movzwl 0xb(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
testw %ax, %ax
movl $0x401, %edx            # imm = 0x401
cmovnel %eax, %edx
cmpl 0xa43a(%rip), %edx      # 0xc2fc
jne 0x1ecd
cmpl $0x0, 0xa415(%rip)      # 0xc2e0
jne 0x1ee6
movl %edx, 0xa429(%rip)      # 0xc2fc
leaq 0x62da(%rip), %rsi      # 0x81b4
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movzwl 0xd(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
testw %ax, %ax
movl $0x404, %edx            # imm = 0x404
cmovnel %eax, %edx
cmpl 0xa3fe(%rip), %edx      # 0xc300
jne 0x1f0d
cmpl $0x0, 0xa3d5(%rip)      # 0xc2e0
jne 0x1f26
movl %edx, 0xa3ed(%rip)      # 0xc300
leaq 0x62c3(%rip), %rsi      # 0x81dd
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movzwl 0xf(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
testw %ax, %ax
movl $0x405, %edx            # imm = 0x405
cmovnel %eax, %edx
cmpl 0xa3c2(%rip), %edx      # 0xc304
jne 0x1f4d
cmpl $0x0, 0xa395(%rip)      # 0xc2e0
jne 0x1f66
movl %edx, 0xa3b1(%rip)      # 0xc304
leaq 0x62ac(%rip), %rsi      # 0x8206
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movzwl 0x11(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
testw %ax, %ax
movl $0x40b, %edx            # imm = 0x40B
cmovnel %eax, %edx
cmpl 0xa386(%rip), %edx      # 0xc308
jne 0x1f8d
cmpl $0x0, 0xa355(%rip)      # 0xc2e0
jne 0x1fa6
movl %edx, 0xa375(%rip)      # 0xc308
leaq 0x6295(%rip), %rsi      # 0x822f
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movzwl 0x13(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
testw %ax, %ax
movl $0x402, %edx            # imm = 0x402
cmovnel %eax, %edx
cmpl 0xa34a(%rip), %edx      # 0xc30c
jne 0x1fcd
cmpl $0x0, 0xa315(%rip)      # 0xc2e0
jne 0x1fe6
movl %edx, 0xa339(%rip)      # 0xc30c
leaq 0x627e(%rip), %rsi      # 0x8258
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movzwl 0x15(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
testw %ax, %ax
movl $0x403, %edx            # imm = 0x403
cmovnel %eax, %edx
cmpl 0xa30e(%rip), %edx      # 0xc310
jne 0x200d
cmpl $0x0, 0xa2d5(%rip)      # 0xc2e0
jne 0x2026
movl %edx, 0xa2fd(%rip)      # 0xc310
leaq 0x6267(%rip), %rsi      # 0x8281
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movzbl 0x17(%rbx), %edx
cmpl %edx, 0xa2e4(%rip)      # 0xc314
jne 0x203b
cmpl $0x0, 0xa2a7(%rip)      # 0xc2e0
jne 0x2054
movl %edx, 0xa2d3(%rip)      # 0xc314
leaq 0x6262(%rip), %rsi      # 0x82aa
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movzwl 0x18(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
testw %ax, %ax
movl $0x200, %edx            # imm = 0x200
cmovnel %eax, %edx
cmpl 0xa2a8(%rip), %edx      # 0xc318
jne 0x207b
cmpl $0x0, 0xa267(%rip)      # 0xc2e0
jne 0x2094
movl %edx, 0xa297(%rip)      # 0xc318
leaq 0x6242(%rip), %rsi      # 0x82ca
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movzbl 0x1a(%rbx), %eax
testb %al, %al
movl $0x10, %ecx
cmovnel %eax, %ecx
movzbl %cl, %edx
cmpl %edx, 0xa271(%rip)      # 0xc31c
jne 0x20b6
cmpl $0x0, 0xa22c(%rip)      # 0xc2e0
jne 0x20cf
movl %edx, 0xa260(%rip)      # 0xc31c
leaq 0x6222(%rip), %rsi      # 0x82e5
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movzbl 0x1b(%rbx), %edx
cmpl %edx, 0xa247(%rip)      # 0xc320
jne 0x20e4
cmpl $0x0, 0xa1fe(%rip)      # 0xc2e0
jne 0x20fd
movl %edx, 0xa236(%rip)      # 0xc320
leaq 0x6214(%rip), %rsi      # 0x8305
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movzbl 0x1c(%rbx), %edx
cmpl %edx, 0xa21d(%rip)      # 0xc324
jne 0x2112
cmpl $0x0, 0xa1d0(%rip)      # 0xc2e0
jne 0x212b
movl %edx, 0xa20c(%rip)      # 0xc324
leaq 0x6206(%rip), %rsi      # 0x8325
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movzwl 0x1d(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %edx
cmpl 0xa1ec(%rip), %edx      # 0xc328
jne 0x2147
cmpl $0x0, 0xa19b(%rip)      # 0xc2e0
jne 0x2160
movl %edx, 0xa1db(%rip)      # 0xc328
leaq 0x61e9(%rip), %rsi      # 0x833d
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movzwl 0x1f(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %edx
cmpl 0xa1bb(%rip), %edx      # 0xc32c
jne 0x217c
cmpl $0x0, 0xa166(%rip)      # 0xc2e0
jne 0x2195
movl %edx, 0xa1aa(%rip)      # 0xc32c
leaq 0x61d8(%rip), %rsi      # 0x8361
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movzwl 0x21(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %edx
cmpl 0xa18a(%rip), %edx      # 0xc330
jne 0x21b1
cmpl $0x0, 0xa131(%rip)      # 0xc2e0
jne 0x21ca
movl %edx, 0xa179(%rip)      # 0xc330
leaq 0x61c7(%rip), %rsi      # 0x8385
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movzwl 0x23(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %edx
cmpl 0xa159(%rip), %edx      # 0xc334
jne 0x21e6
cmpl $0x0, 0xa0fc(%rip)      # 0xc2e0
jne 0x21ff
movl %edx, 0xa148(%rip)      # 0xc334
leaq 0x61ab(%rip), %rsi      # 0x839e
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movzbl 0x25(%rbx), %edx
cmpl %edx, 0xa12f(%rip)      # 0xc338
jne 0x2214
cmpl $0x0, 0xa0ce(%rip)      # 0xc2e0
jne 0x222d
movl %edx, 0xa11e(%rip)      # 0xc338
leaq 0x6196(%rip), %rsi      # 0x83b7
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movzbl 0x26(%rbx), %edx
cmpl %edx, 0xa105(%rip)      # 0xc33c
jne 0x2242
cmpl $0x0, 0xa0a0(%rip)      # 0xc2e0
jne 0x225b
movl %edx, 0xa0f4(%rip)      # 0xc33c
leaq 0x617c(%rip), %rsi      # 0x83cb
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movzbl 0x27(%rbx), %edx
testl %edx, %edx
je 0x227b
cmpl $0x3, %edx
je 0x227b
leaq 0x617e(%rip), %rsi      # 0x83ed
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movzbl 0x3a(%rbx), %edx
andl $0x1, %edx
cmpl %edx, 0xa0b8(%rip)      # 0xc340
jne 0x2293
cmpl $0x0, 0xa04f(%rip)      # 0xc2e0
jne 0x22ac
movl %edx, 0xa0a7(%rip)      # 0xc340
leaq 0x6170(%rip), %rsi      # 0x8410
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movzbl 0x3b(%rbx), %edx
andl $0x1, %edx
cmpl %edx, 0xa08b(%rip)      # 0xc344
jne 0x22c4
cmpl $0x0, 0xa01e(%rip)      # 0xc2e0
jne 0x22dd
movl %edx, 0xa07a(%rip)      # 0xc344
leaq 0x6152(%rip), %rsi      # 0x8423
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movzbl 0x3b(%rbx), %edx
shrl %edx
andl $0x1, %edx
cmpl %edx, 0xa05c(%rip)      # 0xc348
jne 0x22f7
cmpl $0x0, 0x9feb(%rip)      # 0xc2e0
jne 0x2310
movl %edx, 0xa04b(%rip)      # 0xc348
leaq 0x613d(%rip), %rsi      # 0x8441
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
cmpq $0x0, 0xa038(%rip)      # 0xc350
jne 0x2428
leaq 0xa02b(%rip), %rdi      # 0xc350
leaq 0xfe(%rip), %rdx        # 0x242a
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x1160
testl %eax, %eax
jns 0x234c
leaq 0x611f(%rip), %rsi      # 0x845f
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movq 0x9ffd(%rip), %rdi      # 0xc350
callq 0x1120
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, 0x9ffc(%rip)     # 0xc360
movdqa %xmm0, 0xa004(%rip)     # 0xc370
movdqa %xmm0, 0xa00c(%rip)     # 0xc380
movdqa %xmm0, 0xa014(%rip)     # 0xc390
movdqa %xmm0, 0xa01c(%rip)     # 0xc3a0
movdqa %xmm0, 0xa024(%rip)     # 0xc3b0
movdqa %xmm0, 0xa02c(%rip)     # 0xc3c0
movdqa %xmm0, 0xa034(%rip)     # 0xc3d0
movdqa %xmm0, 0xa03c(%rip)     # 0xc3e0
pxor %xmm0, %xmm0
movdqa %xmm0, 0xa040(%rip)     # 0xc3f0
movdqa %xmm0, 0xa048(%rip)     # 0xc400
movdqa %xmm0, 0xa050(%rip)     # 0xc410
movdqa %xmm0, 0xa058(%rip)     # 0xc420
movdqa %xmm0, 0xa060(%rip)     # 0xc430
movdqa %xmm0, 0xa068(%rip)     # 0xc440
movdqa %xmm0, 0xa070(%rip)     # 0xc450
movdqa %xmm0, 0xa078(%rip)     # 0xc460
movdqa %xmm0, 0xa0f0(%rip)     # 0xc4e0
movdqa %xmm0, 0xa0d8(%rip)     # 0xc4d0
movdqa %xmm0, 0xa0c0(%rip)     # 0xc4c0
movdqa %xmm0, 0xa0a8(%rip)     # 0xc4b0
movdqa %xmm0, 0xa090(%rip)     # 0xc4a0
movdqa %xmm0, 0xa078(%rip)     # 0xc490
movdqa %xmm0, 0xa060(%rip)     # 0xc480
movdqa %xmm0, 0xa048(%rip)     # 0xc470
popq %rbx
retq