// File: /workspace/github_c_makefile_star2_O2/Openvario[P]sensord/compdata.c
// Function: pressure_measurement_handler
static void pressure_measurement_handler(int record)
{
	static unsigned int meas_counter=1, glitchstart=0,shutdown=0,deltaxmax=0;
	int x=0, deltax;
	double comp;

	// if early, wait
	// if more than 2ms late, increase the glitch counter
	if ((sensor_wait(12500))>2000) { glitchstart=8; glitch+=8; }
	if (meas_counter&1) {
		// read pressure sensors
		x|=ms5611_read_temp(&tep_sensor,glitch);
		x|=ms5611_read_pressure(&static_sensor);
		x|=ms5611_start_pressure(&tep_sensor);
		sensor_wait_mark();
		x|=ms5611_start_temp(&static_sensor);

		if (abs((int)static_sensor.D1l-(int) static_sensor.D1)<100e3) {
			if (glitch==0) {
				shutdown=0;
				if (tep_sensor.D2l>tep_sensor.D2+300) { glitchstart=8; glitch=8; }
			}
			if (glitchstart) {
				if (glitch>glitchstart)
					deltax=abs((int)tep_sensor.D2l-(int)tep_sensor.D2);
				else
					deltax=abs((int)tep_sensor.D2f-(int)tep_sensor.D2);
				if (deltax>deltaxmax) deltaxmax=deltax;
				if ((--glitchstart)==0) {
					if (deltaxmax>15)
						glitch += ((int) round(log((double)(deltaxmax)*config.timing_log)*config.timing_mult))+config.timing_off;
					deltaxmax=0;
				}
			}
			if (glitch>0) {
				if (--glitch>399) glitch=399;
				if (!glitch) ++urun;
				if (++shutdown==800) {
					glitch=shutdown=0;
					++orun;
				}
				if (tep_sensor.D2>(int)round(tep_sensor.D2f-15)) glitch=0;
				if (glitch && record && ((int)round(tep_sensor.D2f)>tep_sensor.D2+500)) {
					comp=static_sensor.p*1e-5;
					comp=comp*comp*static_sensor.Pcomp2+comp*static_sensor.Pcomp1+static_sensor.Pcomp0;
					statval[sidx][0]=((double)static_sensor.D1f-(double)static_sensor.D1)/comp;
					statval[sidx][1]=((double)tep_sensor.D2f-(double)tep_sensor.D2);
					statval[sidx++][2]=x;
				}
			} else {
				static_sensor.D1f=(static_sensor.D1f*7+static_sensor.D1)>>3;
				ms5611_calculate_pressure(&static_sensor);
			}
		}
	} else {
		// read pressure sensors
		x|=ms5611_read_pressure(&tep_sensor);
		x|=ms5611_read_temp(&static_sensor,glitch);
		x|=ms5611_start_temp(&tep_sensor);
		sensor_wait_mark();
		x|=ms5611_start_pressure(&static_sensor);

		if (abs((int)tep_sensor.D1l-(int) tep_sensor.D1)<100e3) {
			if (glitch==0) {
				shutdown=0;
				if (static_sensor.D2l>static_sensor.D2+300) { glitchstart=8; glitch=8; }
			}
			if (glitchstart) {
				if (glitch>glitchstart)
					deltax=abs((int)static_sensor.D2l-(int)static_sensor.D2);
				else
					deltax=abs((int)static_sensor.D2f-(int)static_sensor.D2);
				if (deltax>deltaxmax) deltaxmax=deltax;
				if ((--glitchstart)==0) {
					if (deltaxmax>15)
						glitch += ((int) round(log((double)(deltaxmax)*config.timing_log)*config.timing_mult))+config.timing_off;
					deltaxmax=0;
				}
			}
			if (glitch>0) {
				if (--glitch>399) glitch=399;
				if (!glitch) ++urun;
				if (++shutdown==800) {
					glitch=shutdown=0;
					++orun;
				}
				if (static_sensor.D2>(int)round(static_sensor.D2f-15)) glitch=0;
				if (glitch && record && ((int)round(static_sensor.D2f)>static_sensor.D2+500)) {
					comp=tep_sensor.p*1e-5;
					comp=comp*comp*tep_sensor.Pcomp2+comp*tep_sensor.Pcomp1+tep_sensor.Pcomp0;
					tepval[tidx][0]=((double)tep_sensor.D1f-(double)tep_sensor.D1)/comp;
					tepval[tidx][1]=((double)static_sensor.D2f-(double)static_sensor.D2);
					tepval[tidx++][2]=x;

				}
			} else {
				tep_sensor.D1f=(tep_sensor.D1f*7+tep_sensor.D1)>>3;
				ms5611_calculate_pressure(&tep_sensor);
			}
		}
	}
	if (glitch) noglitch=0; else noglitch++;
	meas_counter++;
	if (io_mode.sensordata_to_file) {
		if ((meas_counter%2==1) && (record))
			fprintf(fp_datalog, "%.4f %.4f %f %u %u %u %u %u %u %u %u %d\n",tep_sensor.p,static_sensor.p,dynamic_sensor.p,static_sensor.D1,static_sensor.D1f,tep_sensor.D1,tep_sensor.D1f,static_sensor.D2,static_sensor.D2f,tep_sensor.D2,tep_sensor.D2f,glitch);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edi, %ebx
movss 0x28b5(%rip), %xmm0     # 0x53cc
callq 0x138b
ucomiss 0x28b1(%rip), %xmm0     # 0x53d4
jbe 0x2b36
movl $0x8, 0x300586d(%rip)   # 0x300839c
addl $0x8, 0x3005872(%rip)   # 0x30083a8
testb $0x1, 0x5613(%rip)      # 0x8150
jne 0x2bee
leaq 0x56d6(%rip), %r15      # 0x8220
movq %r15, %rdi
callq 0x1c44
movl %eax, %r14d
movl 0x300584d(%rip), %esi   # 0x30083a8
leaq 0x561e(%rip), %r13      # 0x8180
movq %r13, %rdi
callq 0x1a08
movl %eax, %ebp
movq %r15, %rdi
callq 0x1960
movl %eax, %r15d
callq 0x137c
movq %r13, %rdi
callq 0x19b3
movl %eax, %r12d
movl 0x56b7(%rip), %eax      # 0x8244
subl 0x56a9(%rip), %eax      # 0x823c
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
cmpl $0x1869f, %ecx          # imm = 0x1869F
ja 0x305d
movl 0x30057fc(%rip), %eax   # 0x30083a8
testl %eax, %eax
jne 0x2c99
andl $0x0, 0x30057e5(%rip)   # 0x30083a0
movl $0x12c, %ecx            # imm = 0x12C
addl 0x55e2(%rip), %ecx      # 0x81a8
cmpl %ecx, 0x55e0(%rip)      # 0x81ac
jbe 0x2c99
movl $0x8, 0x30057cc(%rip)   # 0x30083a8
pushq $0x8
popq %rax
pushq $0x7
popq %rcx
leaq 0x55c7(%rip), %rdx      # 0x81b0
jmp 0x2cbb
movl 0x30057b4(%rip), %esi   # 0x30083a8
leaq 0x5625(%rip), %r13      # 0x8220
movq %r13, %rdi
callq 0x1a08
movl %eax, %r14d
leaq 0x5573(%rip), %r12      # 0x8180
movq %r12, %rdi
callq 0x1c44
movl %eax, %ebp
movq %r13, %rdi
callq 0x19b3
movl %eax, %r15d
callq 0x137c
movq %r12, %rdi
callq 0x1960
movl %eax, %r12d
movl 0x556c(%rip), %eax      # 0x81a4
subl 0x555e(%rip), %eax      # 0x819c
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
cmpl $0x1869f, %ecx          # imm = 0x1869F
ja 0x305d
movl 0x3005751(%rip), %eax   # 0x30083a8
testl %eax, %eax
jne 0x2e59
andl $0x0, 0x300573a(%rip)   # 0x30083a0
movl $0x12c, %ecx            # imm = 0x12C
addl 0x55d7(%rip), %ecx      # 0x8248
cmpl %ecx, 0x55d5(%rip)      # 0x824c
jbe 0x2e59
movl $0x8, 0x3005721(%rip)   # 0x30083a8
pushq $0x8
popq %rax
pushq $0x7
popq %rcx
leaq 0x55bc(%rip), %rdx      # 0x8250
jmp 0x2e7b
movl 0x30056fd(%rip), %ecx   # 0x300839c
testl %ecx, %ecx
je 0x2d36
xorl %edx, %edx
cmpl %ecx, %eax
setbe %dl
leaq 0x2c(,%rdx,4), %rdx
addq %r13, %rdx
decl %ecx
movl (%rdx), %edx
subl 0x54e5(%rip), %edx      # 0x81a8
movl %edx, %esi
negl %esi
cmovsl %edx, %esi
movl 0x30056d4(%rip), %edx   # 0x30083a4
cmpl %edx, %esi
jbe 0x2cdc
movl %esi, 0x30056ca(%rip)   # 0x30083a4
movl %esi, %edx
movl %ecx, 0x30056ba(%rip)   # 0x300839c
testl %ecx, %ecx
jne 0x2d36
cmpl $0x10, %edx
jb 0x2d2f
cvtsi2sd %edx, %xmm0
mulsd 0x55d9(%rip), %xmm0     # 0x82d0
callq 0x1110
mulsd 0x55d4(%rip), %xmm0     # 0x82d8
callq 0x1050
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
addsd 0x55c7(%rip), %xmm0     # 0x82e0
cvtsi2sdl 0x3005687(%rip), %xmm1 # 0x30083a8
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
movl %eax, 0x3005679(%rip)   # 0x30083a8
andl $0x0, 0x300566e(%rip)   # 0x30083a4
testl %eax, %eax
jle 0x301c
movl $0x190, %edx            # imm = 0x190
cmpl %edx, %eax
cmovbl %eax, %edx
decl %edx
movl %edx, 0x3005658(%rip)   # 0x30083a8
jne 0x2d58
incl 0x300563c(%rip)         # 0x3008394
movl 0x3005642(%rip), %eax   # 0x30083a0
incl %eax
movl %eax, 0x300563a(%rip)   # 0x30083a0
cmpl $0x320, %eax            # imm = 0x320
jne 0x2d83
andl $0x0, 0x300562c(%rip)   # 0x30083a0
andl $0x0, 0x300562d(%rip)   # 0x30083a8
incl 0x3005617(%rip)         # 0x3008398
xorl %edx, %edx
movl 0x541f(%rip), %eax      # 0x81a8
movl 0x5421(%rip), %ecx      # 0x81b0
leal -0xf(%rcx), %esi
cmpl %esi, %eax
jbe 0x2d9f
andl $0x0, 0x300560b(%rip)   # 0x30083a8
xorl %edx, %edx
leal 0x1f4(%rax), %esi
cmpl %esi, %ecx
jbe 0x305d
testl %ebx, %ebx
je 0x305d
testl %edx, %edx
je 0x305d
cvtss2sd 0x54e3(%rip), %xmm0     # 0x82a8
mulsd 0x2683(%rip), %xmm0     # 0x5450
movapd %xmm0, %xmm1
mulsd %xmm0, %xmm1
mulsd 0x54a3(%rip), %xmm0     # 0x8280
mulsd 0x5493(%rip), %xmm1     # 0x8278
addsd %xmm0, %xmm1
addsd 0x5497(%rip), %xmm1     # 0x8288
orl %r15d, %r14d
movl 0x5446(%rip), %edx      # 0x8240
cvtsi2sd %rdx, %xmm0
orl %r12d, %r14d
movl 0x5434(%rip), %edx      # 0x823c
cvtsi2sd %rdx, %xmm2
orl %r14d, %ebp
subsd %xmm2, %xmm0
divsd %xmm1, %xmm0
movslq 0x3005571(%rip), %rdx   # 0x3008390
imulq $0x18, %rdx, %rsi
movl %ecx, %ecx
cvtsi2sd %rcx, %xmm1
leaq 0x180555f(%rip), %rcx   # 0x1808390
movl %eax, %eax
cvtsi2sd %rax, %xmm2
movsd %xmm0, (%rsi,%rcx)
subsd %xmm2, %xmm1
cvtsi2sd %ebp, %xmm0
movsd %xmm1, 0x8(%rsi,%rcx)
leal 0x1(%rdx), %eax
movl %eax, 0x300553c(%rip)   # 0x3008390
jmp 0x3014
movl 0x300553d(%rip), %ecx   # 0x300839c
testl %ecx, %ecx
je 0x2ef6
xorl %edx, %edx
cmpl %ecx, %eax
setbe %dl
leaq 0x2c(,%rdx,4), %rdx
addq %r13, %rdx
decl %ecx
movl (%rdx), %edx
subl 0x53c5(%rip), %edx      # 0x8248
movl %edx, %esi
negl %esi
cmovsl %edx, %esi
movl 0x3005514(%rip), %edx   # 0x30083a4
cmpl %edx, %esi
jbe 0x2e9c
movl %esi, 0x300550a(%rip)   # 0x30083a4
movl %esi, %edx
movl %ecx, 0x30054fa(%rip)   # 0x300839c
testl %ecx, %ecx
jne 0x2ef6
cmpl $0x10, %edx
jb 0x2eef
cvtsi2sd %edx, %xmm0
mulsd 0x5419(%rip), %xmm0     # 0x82d0
callq 0x1110
mulsd 0x5414(%rip), %xmm0     # 0x82d8
callq 0x1050
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
addsd 0x5407(%rip), %xmm0     # 0x82e0
cvtsi2sdl 0x30054c7(%rip), %xmm1 # 0x30083a8
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
movl %eax, 0x30054b9(%rip)   # 0x30083a8
andl $0x0, 0x30054ae(%rip)   # 0x30083a4
testl %eax, %eax
jle 0x303b
movl $0x190, %edx            # imm = 0x190
cmpl %edx, %eax
cmovbl %eax, %edx
decl %edx
movl %edx, 0x3005498(%rip)   # 0x30083a8
jne 0x2f18
incl 0x300547c(%rip)         # 0x3008394
movl 0x3005482(%rip), %eax   # 0x30083a0
incl %eax
movl %eax, 0x300547a(%rip)   # 0x30083a0
cmpl $0x320, %eax            # imm = 0x320
jne 0x2f43
andl $0x0, 0x300546c(%rip)   # 0x30083a0
andl $0x0, 0x300546d(%rip)   # 0x30083a8
incl 0x3005457(%rip)         # 0x3008398
xorl %edx, %edx
movl 0x52ff(%rip), %eax      # 0x8248
movl 0x5301(%rip), %ecx      # 0x8250
leal -0xf(%rcx), %esi
cmpl %esi, %eax
jbe 0x2f5f
andl $0x0, 0x300544b(%rip)   # 0x30083a8
xorl %edx, %edx
leal 0x1f4(%rax), %esi
cmpl %esi, %ecx
jbe 0x305d
testl %ebx, %ebx
je 0x305d
testl %edx, %edx
je 0x305d
cvtss2sd 0x5283(%rip), %xmm0     # 0x8208
mulsd 0x24c3(%rip), %xmm0     # 0x5450
movapd %xmm0, %xmm1
mulsd %xmm0, %xmm1
mulsd 0x5243(%rip), %xmm0     # 0x81e0
mulsd 0x5233(%rip), %xmm1     # 0x81d8
addsd %xmm0, %xmm1
addsd 0x5237(%rip), %xmm1     # 0x81e8
orl %r15d, %ebp
movl 0x51e6(%rip), %edx      # 0x81a0
cvtsi2sd %rdx, %xmm0
orl %r12d, %ebp
movl 0x51d4(%rip), %edx      # 0x819c
cvtsi2sd %rdx, %xmm2
orl %r14d, %ebp
subsd %xmm2, %xmm0
divsd %xmm1, %xmm0
movslq 0x53a9(%rip), %rdx      # 0x8388
imulq $0x18, %rdx, %rsi
movl %ecx, %ecx
cvtsi2sd %rcx, %xmm1
leaq 0x539f(%rip), %rcx      # 0x8390
movl %eax, %eax
cvtsi2sd %rax, %xmm2
movsd %xmm0, (%rsi,%rcx)
subsd %xmm2, %xmm1
cvtsi2sd %ebp, %xmm0
movsd %xmm1, 0x8(%rsi,%rcx)
leal 0x1(%rdx), %eax
movl %eax, 0x5374(%rip)      # 0x8388
movsd %xmm0, 0x10(%rsi,%rcx)
jmp 0x305d
leaq 0x51fd(%rip), %rdi      # 0x8220
imull $0x7, 0x5216(%rip), %eax # 0x8240
addl 0x520c(%rip), %eax      # 0x823c
shrl $0x3, %eax
movl %eax, 0x5207(%rip)      # 0x8240
jmp 0x3058
leaq 0x513e(%rip), %rdi      # 0x8180
imull $0x7, 0x5157(%rip), %eax # 0x81a0
addl 0x514d(%rip), %eax      # 0x819c
shrl $0x3, %eax
movl %eax, 0x5148(%rip)      # 0x81a0
callq 0x1cdb
movl 0x3005344(%rip), %r10d  # 0x30083a8
movl 0x5322(%rip), %eax      # 0x838c
incl %eax
xorl %ecx, %ecx
testl %r10d, %r10d
cmovel %eax, %ecx
movl %ecx, 0x5312(%rip)      # 0x838c
movl 0x50d0(%rip), %eax      # 0x8150
leal 0x1(%rax), %ecx
movl %ecx, 0x50c7(%rip)      # 0x8150
cmpb $0x0, 0x5258(%rip)      # 0x82e8
je 0x311a
testl %ebx, %ebx
sete %cl
orb %al, %cl
testb $0x1, %cl
jne 0x311a
leaq 0x3005317(%rip), %rax   # 0x30083c0
movq (%rax), %rdi
cvtss2sd 0x51f4(%rip), %xmm0     # 0x82a8
cvtss2sd 0x514c(%rip), %xmm1     # 0x8208
cvtss2sd 0x5240(%rip), %xmm2     # 0x8304
movl 0x50d2(%rip), %edx      # 0x819c
movl 0x50d0(%rip), %ecx      # 0x81a0
movl 0x5165(%rip), %r8d      # 0x823c
movl 0x5162(%rip), %r9d      # 0x8240
movl 0x50c3(%rip), %r11d     # 0x81a8
movl 0x50c5(%rip), %ebx      # 0x81b0
movl 0x5156(%rip), %r14d     # 0x8248
movl 0x5157(%rip), %r15d     # 0x8250
subq $0x8, %rsp
leaq 0x2823(%rip), %rsi      # 0x5927
movb $0x3, %al
pushq %r10
pushq %r15
pushq %r14
pushq %rbx
pushq %r11
callq 0x1150
addq $0x38, %rsp
jmp 0x311e
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq