// File: /workspace/github_c_makefile_star2_O3/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 0x635c(%rip), %rsi      # 0x80f8
movl $0x1, %edi
xorl %eax, %eax
callq 0x13ba
movq 0xa539(%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, 0xa51b(%rip)      # 0xc2e8
testq %rcx, %rcx
sete %al
leaq 0x1(%rdx), %rsi
cmpq %rsi, %rcx
sete %sil
orb %al, %sil
jne 0x1df6
leaq 0x632f(%rip), %rsi      # 0x8119
movl $0x1, %edi
xorl %eax, %eax
callq 0x13ba
movzwl 0x5(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
testw %ax, %ax
movl $0x401, %edx            # imm = 0x401
cmovnel %eax, %edx
cmpl 0xa4de(%rip), %edx      # 0xc2f0
jne 0x1e1f
movb $0x1, %al
cmpl $0x0, 0xa4c3(%rip)      # 0xc2e0
jne 0x1e42
movl %edx, 0xa4cb(%rip)      # 0xc2f0
leaq 0x630d(%rip), %rsi      # 0x8139
movl $0x1, %edi
xorl %eax, %eax
callq 0x13ba
cmpl $0x0, 0xa4a1(%rip)      # 0xc2e0
setne %al
movzwl 0x7(%rbx), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
testw %cx, %cx
movl $0x402, %edx            # imm = 0x402
cmovnel %ecx, %edx
cmpl 0xa496(%rip), %edx      # 0xc2f4
jne 0x1e66
movb $0x1, %cl
testb %al, %al
jne 0x1e89
movl %edx, 0xa488(%rip)      # 0xc2f4
leaq 0x62ef(%rip), %rsi      # 0x8162
movl $0x1, %edi
xorl %eax, %eax
callq 0x13ba
cmpl $0x0, 0xa45a(%rip)      # 0xc2e0
setne %cl
movzwl 0x9(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
testw %ax, %ax
movl $0x403, %edx            # imm = 0x403
cmovnel %eax, %edx
cmpl 0xa453(%rip), %edx      # 0xc2f8
jne 0x1ead
movb $0x1, %al
testb %cl, %cl
jne 0x1ed0
movl %edx, 0xa445(%rip)      # 0xc2f8
leaq 0x62d1(%rip), %rsi      # 0x818b
movl $0x1, %edi
xorl %eax, %eax
callq 0x13ba
cmpl $0x0, 0xa413(%rip)      # 0xc2e0
setne %al
movzwl 0xb(%rbx), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
testw %cx, %cx
movl $0x401, %edx            # imm = 0x401
cmovnel %ecx, %edx
cmpl 0xa410(%rip), %edx      # 0xc2fc
jne 0x1ef4
movb $0x1, %cl
testb %al, %al
jne 0x1f17
movl %edx, 0xa402(%rip)      # 0xc2fc
leaq 0x62b3(%rip), %rsi      # 0x81b4
movl $0x1, %edi
xorl %eax, %eax
callq 0x13ba
cmpl $0x0, 0xa3cc(%rip)      # 0xc2e0
setne %cl
movzwl 0xd(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
testw %ax, %ax
movl $0x404, %edx            # imm = 0x404
cmovnel %eax, %edx
cmpl 0xa3cd(%rip), %edx      # 0xc300
jne 0x1f3b
movb $0x1, %al
testb %cl, %cl
jne 0x1f5e
movl %edx, 0xa3bf(%rip)      # 0xc300
leaq 0x6295(%rip), %rsi      # 0x81dd
movl $0x1, %edi
xorl %eax, %eax
callq 0x13ba
cmpl $0x0, 0xa385(%rip)      # 0xc2e0
setne %al
movzwl 0xf(%rbx), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
testw %cx, %cx
movl $0x405, %edx            # imm = 0x405
cmovnel %ecx, %edx
cmpl 0xa38a(%rip), %edx      # 0xc304
jne 0x1f82
movb $0x1, %cl
testb %al, %al
jne 0x1fa5
movl %edx, 0xa37c(%rip)      # 0xc304
leaq 0x6277(%rip), %rsi      # 0x8206
movl $0x1, %edi
xorl %eax, %eax
callq 0x13ba
cmpl $0x0, 0xa33e(%rip)      # 0xc2e0
setne %cl
movzwl 0x11(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
testw %ax, %ax
movl $0x40b, %edx            # imm = 0x40B
cmovnel %eax, %edx
cmpl 0xa347(%rip), %edx      # 0xc308
jne 0x1fc9
movb $0x1, %al
testb %cl, %cl
jne 0x1fec
movl %edx, 0xa339(%rip)      # 0xc308
leaq 0x6259(%rip), %rsi      # 0x822f
movl $0x1, %edi
xorl %eax, %eax
callq 0x13ba
cmpl $0x0, 0xa2f7(%rip)      # 0xc2e0
setne %al
movzwl 0x13(%rbx), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
testw %cx, %cx
movl $0x402, %edx            # imm = 0x402
cmovnel %ecx, %edx
cmpl 0xa304(%rip), %edx      # 0xc30c
jne 0x2010
movb $0x1, %cl
testb %al, %al
jne 0x2033
movl %edx, 0xa2f6(%rip)      # 0xc30c
leaq 0x623b(%rip), %rsi      # 0x8258
movl $0x1, %edi
xorl %eax, %eax
callq 0x13ba
cmpl $0x0, 0xa2b0(%rip)      # 0xc2e0
setne %cl
movzwl 0x15(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
testw %ax, %ax
movl $0x403, %edx            # imm = 0x403
cmovnel %eax, %edx
cmpl 0xa2c1(%rip), %edx      # 0xc310
jne 0x2058
movb $0x1, %sil
testb %cl, %cl
jne 0x207c
movl %edx, 0xa2b2(%rip)      # 0xc310
leaq 0x621c(%rip), %rsi      # 0x8281
movl $0x1, %edi
xorl %eax, %eax
callq 0x13ba
cmpl $0x0, 0xa268(%rip)      # 0xc2e0
setne %sil
movzbl 0x17(%rbx), %edx
cmpl %edx, 0xa28e(%rip)      # 0xc314
jne 0x208f
movb $0x1, %al
testb %sil, %sil
jne 0x20b2
movl %edx, 0xa27f(%rip)      # 0xc314
leaq 0x620e(%rip), %rsi      # 0x82aa
movl $0x1, %edi
xorl %eax, %eax
callq 0x13ba
cmpl $0x0, 0xa231(%rip)      # 0xc2e0
setne %al
movzwl 0x18(%rbx), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
testw %cx, %cx
movl $0x200, %edx            # imm = 0x200
cmovnel %ecx, %edx
cmpl 0xa24a(%rip), %edx      # 0xc318
jne 0x20d6
movb $0x1, %cl
testb %al, %al
jne 0x20f9
movl %edx, 0xa23c(%rip)      # 0xc318
leaq 0x61e7(%rip), %rsi      # 0x82ca
movl $0x1, %edi
xorl %eax, %eax
callq 0x13ba
cmpl $0x0, 0xa1ea(%rip)      # 0xc2e0
setne %cl
movzbl 0x1a(%rbx), %eax
testb %al, %al
movl $0x10, %edx
cmovnel %eax, %edx
movzbl %dl, %edx
cmpl %edx, 0xa20c(%rip)      # 0xc31c
jne 0x2118
movb $0x1, %al
testb %cl, %cl
jne 0x213b
movl %edx, 0xa1fe(%rip)      # 0xc31c
leaq 0x61c0(%rip), %rsi      # 0x82e5
movl $0x1, %edi
xorl %eax, %eax
callq 0x13ba
cmpl $0x0, 0xa1a8(%rip)      # 0xc2e0
setne %al
movzbl 0x1b(%rbx), %edx
cmpl %edx, 0xa1db(%rip)      # 0xc320
jne 0x214d
movb $0x1, %cl
testb %al, %al
jne 0x2170
movl %edx, 0xa1cd(%rip)      # 0xc320
leaq 0x61ab(%rip), %rsi      # 0x8305
movl $0x1, %edi
xorl %eax, %eax
callq 0x13ba
cmpl $0x0, 0xa173(%rip)      # 0xc2e0
setne %cl
movzbl 0x1c(%rbx), %edx
cmpl %edx, 0xa1aa(%rip)      # 0xc324
jne 0x2182
movb $0x1, %al
testb %cl, %cl
jne 0x21a5
movl %edx, 0xa19c(%rip)      # 0xc324
leaq 0x6196(%rip), %rsi      # 0x8325
movl $0x1, %edi
xorl %eax, %eax
callq 0x13ba
cmpl $0x0, 0xa13e(%rip)      # 0xc2e0
setne %al
movzwl 0x1d(%rbx), %ecx
rolw $0x8, %cx
movzwl %cx, %edx
cmpl 0xa172(%rip), %edx      # 0xc328
jne 0x21be
movb $0x1, %cl
testb %al, %al
jne 0x21e1
movl %edx, 0xa164(%rip)      # 0xc328
leaq 0x6172(%rip), %rsi      # 0x833d
movl $0x1, %edi
xorl %eax, %eax
callq 0x13ba
cmpl $0x0, 0xa102(%rip)      # 0xc2e0
setne %cl
movzwl 0x1f(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %edx
cmpl 0xa13a(%rip), %edx      # 0xc32c
jne 0x21fa
movb $0x1, %al
testb %cl, %cl
jne 0x221d
movl %edx, 0xa12c(%rip)      # 0xc32c
leaq 0x615a(%rip), %rsi      # 0x8361
movl $0x1, %edi
xorl %eax, %eax
callq 0x13ba
cmpl $0x0, 0xa0c6(%rip)      # 0xc2e0
setne %al
movzwl 0x21(%rbx), %ecx
rolw $0x8, %cx
movzwl %cx, %edx
cmpl 0xa102(%rip), %edx      # 0xc330
jne 0x2236
movb $0x1, %cl
testb %al, %al
jne 0x2259
movl %edx, 0xa0f4(%rip)      # 0xc330
leaq 0x6142(%rip), %rsi      # 0x8385
movl $0x1, %edi
xorl %eax, %eax
callq 0x13ba
cmpl $0x0, 0xa08a(%rip)      # 0xc2e0
setne %cl
movzwl 0x23(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %edx
cmpl 0xa0ca(%rip), %edx      # 0xc334
jne 0x2272
movb $0x1, %al
testb %cl, %cl
jne 0x2295
movl %edx, 0xa0bc(%rip)      # 0xc334
leaq 0x611f(%rip), %rsi      # 0x839e
movl $0x1, %edi
xorl %eax, %eax
callq 0x13ba
cmpl $0x0, 0xa04e(%rip)      # 0xc2e0
setne %al
movzbl 0x25(%rbx), %edx
cmpl %edx, 0xa099(%rip)      # 0xc338
jne 0x22a7
movb $0x1, %cl
testb %al, %al
jne 0x22ca
movl %edx, 0xa08b(%rip)      # 0xc338
leaq 0x6103(%rip), %rsi      # 0x83b7
movl $0x1, %edi
xorl %eax, %eax
callq 0x13ba
cmpl $0x0, 0xa019(%rip)      # 0xc2e0
setne %cl
movzbl 0x26(%rbx), %edx
cmpl %edx, 0xa068(%rip)      # 0xc33c
jne 0x22da
testb %cl, %cl
jne 0x22f3
movl %edx, 0xa05c(%rip)      # 0xc33c
leaq 0x60e4(%rip), %rsi      # 0x83cb
movl $0x1, %edi
xorl %eax, %eax
callq 0x13ba
movzbl 0x27(%rbx), %edx
testl %edx, %edx
je 0x2313
cmpl $0x3, %edx
je 0x2313
leaq 0x60e6(%rip), %rsi      # 0x83ed
movl $0x1, %edi
xorl %eax, %eax
callq 0x13ba
movzbl 0x3a(%rbx), %edx
andl $0x1, %edx
cmpl %edx, 0xa020(%rip)      # 0xc340
jne 0x232d
movb $0x1, %cl
cmpl $0x0, 0x9fb5(%rip)      # 0xc2e0
jne 0x2350
movl %edx, 0xa00d(%rip)      # 0xc340
leaq 0x60d6(%rip), %rsi      # 0x8410
movl $0x1, %edi
xorl %eax, %eax
callq 0x13ba
cmpl $0x0, 0x9f93(%rip)      # 0xc2e0
setne %cl
movzbl 0x3b(%rbx), %eax
movl %eax, %edx
andl $0x1, %edx
cmpl %edx, 0x9fe5(%rip)      # 0xc344
jne 0x2369
testb %cl, %cl
je 0x2369
movb $0x1, %cl
jmp 0x238f
movl %edx, 0x9fd5(%rip)      # 0xc344
leaq 0x60ad(%rip), %rsi      # 0x8423
movl $0x1, %edi
xorl %eax, %eax
callq 0x13ba
movb 0x3b(%rbx), %al
cmpl $0x0, 0x9f54(%rip)      # 0xc2e0
setne %cl
shrb %al
andb $0x1, %al
movzbl %al, %edx
cmpl %edx, 0x9fac(%rip)      # 0xc348
jne 0x23a2
testb %cl, %cl
jne 0x23bb
movl %edx, 0x9fa0(%rip)      # 0xc348
leaq 0x6092(%rip), %rsi      # 0x8441
movl $0x1, %edi
xorl %eax, %eax
callq 0x13ba
cmpq $0x0, 0x9f8d(%rip)      # 0xc350
jne 0x24d3
leaq 0x9f80(%rip), %rdi      # 0xc350
leaq 0xfe(%rip), %rdx        # 0x24d5
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x1160
testl %eax, %eax
jns 0x23f7
leaq 0x6074(%rip), %rsi      # 0x845f
movl $0x1, %edi
xorl %eax, %eax
callq 0x13ba
movq 0x9f52(%rip), %rdi      # 0xc350
callq 0x1120
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, 0x9f51(%rip)     # 0xc360
movdqa %xmm0, 0x9f59(%rip)     # 0xc370
movdqa %xmm0, 0x9f61(%rip)     # 0xc380
movdqa %xmm0, 0x9f69(%rip)     # 0xc390
movdqa %xmm0, 0x9f71(%rip)     # 0xc3a0
movdqa %xmm0, 0x9f79(%rip)     # 0xc3b0
movdqa %xmm0, 0x9f81(%rip)     # 0xc3c0
movdqa %xmm0, 0x9f89(%rip)     # 0xc3d0
movdqa %xmm0, 0x9f91(%rip)     # 0xc3e0
pxor %xmm0, %xmm0
movdqa %xmm0, 0x9f95(%rip)     # 0xc3f0
movdqa %xmm0, 0x9f9d(%rip)     # 0xc400
movdqa %xmm0, 0x9fa5(%rip)     # 0xc410
movdqa %xmm0, 0x9fad(%rip)     # 0xc420
movdqa %xmm0, 0x9fb5(%rip)     # 0xc430
movdqa %xmm0, 0x9fbd(%rip)     # 0xc440
movdqa %xmm0, 0x9fc5(%rip)     # 0xc450
movdqa %xmm0, 0x9fcd(%rip)     # 0xc460
movdqa %xmm0, 0xa045(%rip)     # 0xc4e0
movdqa %xmm0, 0xa02d(%rip)     # 0xc4d0
movdqa %xmm0, 0xa015(%rip)     # 0xc4c0
movdqa %xmm0, 0x9ffd(%rip)     # 0xc4b0
movdqa %xmm0, 0x9fe5(%rip)     # 0xc4a0
movdqa %xmm0, 0x9fcd(%rip)     # 0xc490
movdqa %xmm0, 0x9fb5(%rip)     # 0xc480
movdqa %xmm0, 0x9f9d(%rip)     # 0xc470
popq %rbx
retq