// File: /workspace/github_c_makefile_star2_O2/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 0x6428(%rip), %rsi      # 0x8100
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x131a
movq 0xb5ff(%rip), %rdx      # 0xd2e8
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, 0xb5e1(%rip)      # 0xd2e8
testq %rcx, %rcx
sete %al
leaq 0x1(%rdx), %rsi
cmpq %rsi, %rcx
sete %sil
orb %al, %sil
jne 0x1d2e
leaq 0x63fd(%rip), %rsi      # 0x8121
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x131a
movzwl 0x5(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
testw %ax, %ax
movl $0x401, %edx            # imm = 0x401
cmovnel %eax, %edx
cmpl 0xb5a6(%rip), %edx      # 0xd2f0
jne 0x1d57
movb $0x1, %al
cmpl $0x0, 0xb58b(%rip)      # 0xd2e0
jne 0x1d78
movl %edx, 0xb593(%rip)      # 0xd2f0
leaq 0x63dd(%rip), %rsi      # 0x8141
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x131a
cmpl $0x0, 0xb56b(%rip)      # 0xd2e0
setne %al
movzwl 0x7(%rbx), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
testw %cx, %cx
movl $0x402, %edx            # imm = 0x402
cmovnel %ecx, %edx
cmpl 0xb560(%rip), %edx      # 0xd2f4
jne 0x1d9c
movb $0x1, %cl
testb %al, %al
jne 0x1dbd
movl %edx, 0xb552(%rip)      # 0xd2f4
leaq 0x63c1(%rip), %rsi      # 0x816a
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x131a
cmpl $0x0, 0xb526(%rip)      # 0xd2e0
setne %cl
movzwl 0x9(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
testw %ax, %ax
movl $0x403, %edx            # imm = 0x403
cmovnel %eax, %edx
cmpl 0xb51f(%rip), %edx      # 0xd2f8
jne 0x1de1
movb $0x1, %al
testb %cl, %cl
jne 0x1e02
movl %edx, 0xb511(%rip)      # 0xd2f8
leaq 0x63a5(%rip), %rsi      # 0x8193
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x131a
cmpl $0x0, 0xb4e1(%rip)      # 0xd2e0
setne %al
movzwl 0xb(%rbx), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
testw %cx, %cx
movl $0x401, %edx            # imm = 0x401
cmovnel %ecx, %edx
cmpl 0xb4de(%rip), %edx      # 0xd2fc
jne 0x1e26
movb $0x1, %cl
testb %al, %al
jne 0x1e47
movl %edx, 0xb4d0(%rip)      # 0xd2fc
leaq 0x6389(%rip), %rsi      # 0x81bc
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x131a
cmpl $0x0, 0xb49c(%rip)      # 0xd2e0
setne %cl
movzwl 0xd(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
testw %ax, %ax
movl $0x404, %edx            # imm = 0x404
cmovnel %eax, %edx
cmpl 0xb49d(%rip), %edx      # 0xd300
jne 0x1e6b
movb $0x1, %al
testb %cl, %cl
jne 0x1e8c
movl %edx, 0xb48f(%rip)      # 0xd300
leaq 0x636d(%rip), %rsi      # 0x81e5
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x131a
cmpl $0x0, 0xb457(%rip)      # 0xd2e0
setne %al
movzwl 0xf(%rbx), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
testw %cx, %cx
movl $0x405, %edx            # imm = 0x405
cmovnel %ecx, %edx
cmpl 0xb45c(%rip), %edx      # 0xd304
jne 0x1eb0
movb $0x1, %cl
testb %al, %al
jne 0x1ed1
movl %edx, 0xb44e(%rip)      # 0xd304
leaq 0x6351(%rip), %rsi      # 0x820e
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x131a
cmpl $0x0, 0xb412(%rip)      # 0xd2e0
setne %cl
movzwl 0x11(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
testw %ax, %ax
movl $0x40b, %edx            # imm = 0x40B
cmovnel %eax, %edx
cmpl 0xb41b(%rip), %edx      # 0xd308
jne 0x1ef5
movb $0x1, %al
testb %cl, %cl
jne 0x1f16
movl %edx, 0xb40d(%rip)      # 0xd308
leaq 0x6335(%rip), %rsi      # 0x8237
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x131a
cmpl $0x0, 0xb3cd(%rip)      # 0xd2e0
setne %al
movzwl 0x13(%rbx), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
testw %cx, %cx
movl $0x402, %edx            # imm = 0x402
cmovnel %ecx, %edx
cmpl 0xb3da(%rip), %edx      # 0xd30c
jne 0x1f3a
movb $0x1, %cl
testb %al, %al
jne 0x1f5b
movl %edx, 0xb3cc(%rip)      # 0xd30c
leaq 0x6319(%rip), %rsi      # 0x8260
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x131a
cmpl $0x0, 0xb388(%rip)      # 0xd2e0
setne %cl
movzwl 0x15(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
testw %ax, %ax
movl $0x403, %edx            # imm = 0x403
cmovnel %eax, %edx
cmpl 0xb399(%rip), %edx      # 0xd310
jne 0x1f80
movb $0x1, %sil
testb %cl, %cl
jne 0x1fa2
movl %edx, 0xb38a(%rip)      # 0xd310
leaq 0x62fc(%rip), %rsi      # 0x8289
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x131a
cmpl $0x0, 0xb342(%rip)      # 0xd2e0
setne %sil
movzbl 0x17(%rbx), %edx
cmpl %edx, 0xb368(%rip)      # 0xd314
jne 0x1fb5
movb $0x1, %al
testb %sil, %sil
jne 0x1fd6
movl %edx, 0xb359(%rip)      # 0xd314
leaq 0x62f0(%rip), %rsi      # 0x82b2
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x131a
cmpl $0x0, 0xb30d(%rip)      # 0xd2e0
setne %al
movzwl 0x18(%rbx), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
testw %cx, %cx
movl $0x200, %edx            # imm = 0x200
cmovnel %ecx, %edx
cmpl 0xb326(%rip), %edx      # 0xd318
jne 0x1ffa
movb $0x1, %cl
testb %al, %al
jne 0x201b
movl %edx, 0xb318(%rip)      # 0xd318
leaq 0x62cb(%rip), %rsi      # 0x82d2
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x131a
cmpl $0x0, 0xb2c8(%rip)      # 0xd2e0
setne %cl
movzbl 0x1a(%rbx), %eax
testb %al, %al
pushq $0x10
popq %rdx
cmovnel %eax, %edx
movzbl %dl, %edx
cmpl %edx, 0xb2ec(%rip)      # 0xd31c
jne 0x2038
movb $0x1, %al
testb %cl, %cl
jne 0x2059
movl %edx, 0xb2de(%rip)      # 0xd31c
leaq 0x62a8(%rip), %rsi      # 0x82ed
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x131a
cmpl $0x0, 0xb28a(%rip)      # 0xd2e0
setne %al
movzbl 0x1b(%rbx), %edx
cmpl %edx, 0xb2bd(%rip)      # 0xd320
jne 0x206b
movb $0x1, %cl
testb %al, %al
jne 0x208c
movl %edx, 0xb2af(%rip)      # 0xd320
leaq 0x6295(%rip), %rsi      # 0x830d
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x131a
cmpl $0x0, 0xb257(%rip)      # 0xd2e0
setne %cl
movzbl 0x1c(%rbx), %edx
cmpl %edx, 0xb28e(%rip)      # 0xd324
jne 0x209e
movb $0x1, %al
testb %cl, %cl
jne 0x20bf
movl %edx, 0xb280(%rip)      # 0xd324
leaq 0x6282(%rip), %rsi      # 0x832d
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x131a
cmpl $0x0, 0xb224(%rip)      # 0xd2e0
setne %al
movzwl 0x1d(%rbx), %ecx
rolw $0x8, %cx
movzwl %cx, %edx
cmpl 0xb258(%rip), %edx      # 0xd328
jne 0x20d8
movb $0x1, %cl
testb %al, %al
jne 0x20f9
movl %edx, 0xb24a(%rip)      # 0xd328
leaq 0x6260(%rip), %rsi      # 0x8345
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x131a
cmpl $0x0, 0xb1ea(%rip)      # 0xd2e0
setne %cl
movzwl 0x1f(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %edx
cmpl 0xb222(%rip), %edx      # 0xd32c
jne 0x2112
movb $0x1, %al
testb %cl, %cl
jne 0x2133
movl %edx, 0xb214(%rip)      # 0xd32c
leaq 0x624a(%rip), %rsi      # 0x8369
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x131a
cmpl $0x0, 0xb1b0(%rip)      # 0xd2e0
setne %al
movzwl 0x21(%rbx), %ecx
rolw $0x8, %cx
movzwl %cx, %edx
cmpl 0xb1ec(%rip), %edx      # 0xd330
jne 0x214c
movb $0x1, %cl
testb %al, %al
jne 0x216d
movl %edx, 0xb1de(%rip)      # 0xd330
leaq 0x6234(%rip), %rsi      # 0x838d
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x131a
cmpl $0x0, 0xb176(%rip)      # 0xd2e0
setne %cl
movzwl 0x23(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %edx
cmpl 0xb1b6(%rip), %edx      # 0xd334
jne 0x2186
movb $0x1, %al
testb %cl, %cl
jne 0x21a7
movl %edx, 0xb1a8(%rip)      # 0xd334
leaq 0x6213(%rip), %rsi      # 0x83a6
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x131a
cmpl $0x0, 0xb13c(%rip)      # 0xd2e0
setne %al
movzbl 0x25(%rbx), %edx
cmpl %edx, 0xb187(%rip)      # 0xd338
jne 0x21b9
movb $0x1, %cl
testb %al, %al
jne 0x21da
movl %edx, 0xb179(%rip)      # 0xd338
leaq 0x61f9(%rip), %rsi      # 0x83bf
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x131a
cmpl $0x0, 0xb109(%rip)      # 0xd2e0
setne %cl
movzbl 0x26(%rbx), %edx
cmpl %edx, 0xb158(%rip)      # 0xd33c
jne 0x21ea
testb %cl, %cl
jne 0x2201
movl %edx, 0xb14c(%rip)      # 0xd33c
leaq 0x61dc(%rip), %rsi      # 0x83d3
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x131a
movzbl 0x27(%rbx), %edx
testl %edx, %edx
je 0x221f
cmpl $0x3, %edx
je 0x221f
leaq 0x61e0(%rip), %rsi      # 0x83f5
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x131a
movzbl 0x3a(%rbx), %edx
andl $0x1, %edx
cmpl %edx, 0xb114(%rip)      # 0xd340
jne 0x2239
movb $0x1, %cl
cmpl $0x0, 0xb0a9(%rip)      # 0xd2e0
jne 0x225a
movl %edx, 0xb101(%rip)      # 0xd340
leaq 0x61d2(%rip), %rsi      # 0x8418
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x131a
cmpl $0x0, 0xb089(%rip)      # 0xd2e0
setne %cl
movzbl 0x3b(%rbx), %eax
movl %eax, %edx
andl $0x1, %edx
cmpl %edx, 0xb0db(%rip)      # 0xd344
jne 0x2273
testb %cl, %cl
je 0x2273
movb $0x1, %cl
jmp 0x2297
movl %edx, 0xb0cb(%rip)      # 0xd344
leaq 0x61ab(%rip), %rsi      # 0x842b
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x131a
movb 0x3b(%rbx), %al
cmpl $0x0, 0xb04c(%rip)      # 0xd2e0
setne %cl
shrb %al
andb $0x1, %al
movzbl %al, %edx
cmpl %edx, 0xb0a4(%rip)      # 0xd348
jne 0x22aa
testb %cl, %cl
jne 0x22c1
movl %edx, 0xb098(%rip)      # 0xd348
leaq 0x6192(%rip), %rsi      # 0x8449
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x131a
cmpq $0x0, 0xb087(%rip)      # 0xd350
jne 0x23d7
leaq 0xb07a(%rip), %rdi      # 0xd350
leaq 0xfc(%rip), %rdx        # 0x23d9
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x1160
testl %eax, %eax
jns 0x22fb
leaq 0x6176(%rip), %rsi      # 0x8467
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x131a
movq 0xb04e(%rip), %rdi      # 0xd350
callq 0x1120
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, 0xb04d(%rip)     # 0xd360
movdqa %xmm0, 0xb055(%rip)     # 0xd370
movdqa %xmm0, 0xb05d(%rip)     # 0xd380
movdqa %xmm0, 0xb065(%rip)     # 0xd390
movdqa %xmm0, 0xb06d(%rip)     # 0xd3a0
movdqa %xmm0, 0xb075(%rip)     # 0xd3b0
movdqa %xmm0, 0xb07d(%rip)     # 0xd3c0
movdqa %xmm0, 0xb085(%rip)     # 0xd3d0
movdqa %xmm0, 0xb08d(%rip)     # 0xd3e0
pxor %xmm0, %xmm0
movdqa %xmm0, 0xb091(%rip)     # 0xd3f0
movdqa %xmm0, 0xb099(%rip)     # 0xd400
movdqa %xmm0, 0xb0a1(%rip)     # 0xd410
movdqa %xmm0, 0xb0a9(%rip)     # 0xd420
movdqa %xmm0, 0xb0b1(%rip)     # 0xd430
movdqa %xmm0, 0xb0b9(%rip)     # 0xd440
movdqa %xmm0, 0xb0c1(%rip)     # 0xd450
movdqa %xmm0, 0xb0c9(%rip)     # 0xd460
movdqa %xmm0, 0xb141(%rip)     # 0xd4e0
movdqa %xmm0, 0xb129(%rip)     # 0xd4d0
movdqa %xmm0, 0xb111(%rip)     # 0xd4c0
movdqa %xmm0, 0xb0f9(%rip)     # 0xd4b0
movdqa %xmm0, 0xb0e1(%rip)     # 0xd4a0
movdqa %xmm0, 0xb0c9(%rip)     # 0xd490
movdqa %xmm0, 0xb0b1(%rip)     # 0xd480
movdqa %xmm0, 0xb099(%rip)     # 0xd470
popq %rbx
retq