comparison Discovery/Src/logbook.c @ 269:6e78137952af write-from-sim

cleanup: do not pass large struct by value Passing a huge struct by value is poor practice. Simply pass it by reference. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author Jan Mulder <jlmulder@xs4all.nl>
date Tue, 23 Apr 2019 21:03:24 +0200
parents 2bb1db22b5f5
children 2e58a4094770
comparison
equal deleted inserted replaced
268:1b9847d40e81 269:6e78137952af
369 ****************************************************************************** 369 ******************************************************************************
370 * 370 *
371 * @param SDiveState state: 371 * @param SDiveState state:
372 */ 372 */
373 373
374 void logbook_writeSample(SDiveState state) 374 void logbook_writeSample(SDiveState *state)
375 { 375 {
376 uint8_t sample[256]; 376 uint8_t sample[256];
377 // int position = 0; 377 // int position = 0;
378 int length = 0; 378 int length = 0;
379 // _Bool bEvent = 0; 379 // _Bool bEvent = 0;
383 bit8_Type eventByte1, eventByte2; 383 bit8_Type eventByte1, eventByte2;
384 bit8_Type profileByteFlag; 384 bit8_Type profileByteFlag;
385 int i = 0; 385 int i = 0;
386 for(i = 0; i <256 ;i++) 386 for(i = 0; i <256 ;i++)
387 sample[i] = 0; 387 sample[i] = 0;
388 addU16(sample, (uint16_t)(state.lifeData.depth_meter * 100)); 388 addU16(sample, (uint16_t)(state->lifeData.depth_meter * 100));
389 length += 2; 389 length += 2;
390 sample[2] = 0; 390 sample[2] = 0;
391 length++; 391 length++;
392 eventByte1.uw = 0; 392 eventByte1.uw = 0;
393 eventByte2.uw = 0; 393 eventByte2.uw = 0;
394 //uint16_t tmpU16 = 0; 394 //uint16_t tmpU16 = 0;
395 const SDecoinfo * pDecoinfo; // new hw 160620 395 const SDecoinfo * pDecoinfo; // new hw 160620
396 396
397 //BuildEevntyte 1 397 //BuildEevntyte 1
398 // sub old 0-3 only one at a time 398 // sub old 0-3 only one at a time
399 if(state.events.manualMarker) 399 if(state->events.manualMarker)
400 { 400 {
401 eventByte1.uw = 6; 401 eventByte1.uw = 6;
402 } 402 }
403 else 403 else
404 if(state.warnings.decoMissed) 404 if(state->warnings.decoMissed)
405 { 405 {
406 eventByte1.uw = 2; 406 eventByte1.uw = 2;
407 } 407 }
408 else 408 else
409 if(state.warnings.ppO2Low) 409 if(state->warnings.ppO2Low)
410 { 410 {
411 eventByte1.uw = 4; 411 eventByte1.uw = 4;
412 } 412 }
413 else 413 else
414 if(state.warnings.ppO2High) 414 if(state->warnings.ppO2High)
415 { 415 {
416 eventByte1.uw = 5; 416 eventByte1.uw = 5;
417 } 417 }
418 else 418 else
419 if(state.warnings.lowBattery) 419 if(state->warnings.lowBattery)
420 { 420 {
421 eventByte1.uw = 7; 421 eventByte1.uw = 7;
422 } 422 }
423 else 423 else
424 if(state.warnings.slowWarning) 424 if(state->warnings.slowWarning)
425 { 425 {
426 eventByte1.uw = 1; 426 eventByte1.uw = 1;
427 } 427 }
428 // sub bit 4 to 7 428 // sub bit 4 to 7
429 if(state.events.manuelGasSet) 429 if(state->events.manuelGasSet)
430 { 430 {
431 eventByte1.ub.bit4 = 1; 431 eventByte1.ub.bit4 = 1;
432 } 432 }
433 if(state.events.gasChange) 433 if(state->events.gasChange)
434 { 434 {
435 eventByte1.ub.bit5 = 1; 435 eventByte1.ub.bit5 = 1;
436 } 436 }
437 if(state.events.setpointChange) 437 if(state->events.setpointChange)
438 { 438 {
439 eventByte1.ub.bit6 = 1; 439 eventByte1.ub.bit6 = 1;
440 } 440 }
441 // sub bit 7 + eventbyte2 441 // sub bit 7 + eventbyte2
442 if(state.events.bailout) 442 if(state->events.bailout)
443 { 443 {
444 eventByte1.ub.bit7 = 1; 444 eventByte1.ub.bit7 = 1;
445 eventByte2.ub.bit0 = 1; 445 eventByte2.ub.bit0 = 1;
446 } 446 }
447 //Add EventByte 1 447 //Add EventByte 1
454 { 454 {
455 sample[length] = eventByte2.uw; 455 sample[length] = eventByte2.uw;
456 length++; 456 length++;
457 } 457 }
458 //Add EventInfos 458 //Add EventInfos
459 if(state.events.manuelGasSet) 459 if(state->events.manuelGasSet)
460 { 460 {
461 //manual gas in %O2 & %He 461 //manual gas in %O2 & %He
462 sample[length] = state.events.info_manuelGasSetO2; 462 sample[length] = state->events.info_manuelGasSetO2;
463 length += 1; 463 length += 1;
464 sample[length] = state.events.info_manuelGasSetHe; 464 sample[length] = state->events.info_manuelGasSetHe;
465 length += 1; 465 length += 1;
466 } 466 }
467 if(state.events.gasChange) 467 if(state->events.gasChange)
468 { 468 {
469 //Current gas (gasid) 469 //Current gas (gasid)
470 sample[length] = state.events.info_GasChange; 470 sample[length] = state->events.info_GasChange;
471 length += 1; 471 length += 1;
472 } 472 }
473 if(state.events.setpointChange) 473 if(state->events.setpointChange)
474 { 474 {
475 //New setpoint in cbar 475 //New setpoint in cbar
476 sample[length] = state.events.info_SetpointChange; 476 sample[length] = state->events.info_SetpointChange;
477 length += 1; 477 length += 1;
478 } 478 }
479 if(state.events.bailout) 479 if(state->events.bailout)
480 { 480 {
481 //bailout gas in % O2 & %He 481 //bailout gas in % O2 & %He
482 sample[length] = state.events.info_bailoutO2; 482 sample[length] = state->events.info_bailoutO2;
483 length += 1; 483 length += 1;
484 sample[length] = state.events.info_bailoutHe; 484 sample[length] = state->events.info_bailoutHe;
485 length += 1; 485 length += 1;
486 } 486 }
487 487
488 488
489 if(divisor.temperature == 0) 489 if(divisor.temperature == 0)
490 { 490 {
491 divisor.temperature = smallHeader.tempDivisor - 1; 491 divisor.temperature = smallHeader.tempDivisor - 1;
492 addS16(&sample[length], (int16_t)((state.lifeData.temperature_celsius * 10.0f) + 0.5f)); 492 addS16(&sample[length], (int16_t)((state->lifeData.temperature_celsius * 10.0f) + 0.5f));
493 length += 2; 493 length += 2;
494 } 494 }
495 else 495 else
496 { 496 {
497 divisor.temperature--; 497 divisor.temperature--;
554 { 554 {
555 divisor.ppo2 = smallHeader.ppo2Divisor - 1; 555 divisor.ppo2 = smallHeader.ppo2Divisor - 1;
556 556
557 for(int i = 0; i <3; i++) 557 for(int i = 0; i <3; i++)
558 { 558 {
559 sample[length] = (uint8_t)(state.lifeData.ppO2Sensor_bar[i] * 100.0f + 0.5f); 559 sample[length] = (uint8_t)(state->lifeData.ppO2Sensor_bar[i] * 100.0f + 0.5f);
560 length += 1; 560 length += 1;
561 addU16(&sample[length], (uint16_t)(state.lifeData.sensorVoltage_mV[i] * 10.0f + 0.5f)); 561 addU16(&sample[length], (uint16_t)(state->lifeData.sensorVoltage_mV[i] * 10.0f + 0.5f));
562 length += 2; 562 length += 2;
563 } 563 }
564 } 564 }
565 else 565 else
566 { 566 {
572 if(smallHeader.decoplanDivisor) 572 if(smallHeader.decoplanDivisor)
573 { 573 {
574 if(divisor.decoplan == 0) 574 if(divisor.decoplan == 0)
575 { 575 {
576 divisor.decoplan = smallHeader.decoplanDivisor - 1; 576 divisor.decoplan = smallHeader.decoplanDivisor - 1;
577 if(state.diveSettings.deco_type.ub.standard == VPM_MODE) 577 if(state->diveSettings.deco_type.ub.standard == VPM_MODE)
578 { 578 {
579 for(int i = 0; i <15; i++) 579 for(int i = 0; i <15; i++)
580 { 580 {
581 sample[length] = state.decolistVPM.output_stop_length_seconds[i] / 60; 581 sample[length] = state->decolistVPM.output_stop_length_seconds[i] / 60;
582 length += 1; 582 length += 1;
583 } 583 }
584 } 584 }
585 else if(state.diveSettings.deco_type.ub.standard == GF_MODE) 585 else if(state->diveSettings.deco_type.ub.standard == GF_MODE)
586 { 586 {
587 for(int i = 0; i <15; i++) 587 for(int i = 0; i <15; i++)
588 { 588 {
589 sample[length] = state.decolistBuehlmann.output_stop_length_seconds[i] / 60; 589 sample[length] = state->decolistBuehlmann.output_stop_length_seconds[i] / 60;
590 length += 1; 590 length += 1;
591 } 591 }
592 } 592 }
593 else 593 else
594 { 594 {
607 } 607 }
608 } 608 }
609 if(divisor.cns == 0) 609 if(divisor.cns == 0)
610 { 610 {
611 divisor.cns = smallHeader.cnsDivisor - 1; 611 divisor.cns = smallHeader.cnsDivisor - 1;
612 addU16(&sample[length], (uint16_t)state.lifeData.cns); 612 addU16(&sample[length], (uint16_t)state->lifeData.cns);
613 length += 2; 613 length += 2;
614 } 614 }
615 else 615 else
616 { 616 {
617 divisor.cns--; 617 divisor.cns--;
1150 //InitdiveProfile 1150 //InitdiveProfile
1151 pSettings->totalDiveCounter++; 1151 pSettings->totalDiveCounter++;
1152 logbook_initNewdiveProfile(pStateReal,settingsGetPointer()); 1152 logbook_initNewdiveProfile(pStateReal,settingsGetPointer());
1153 min_temperature_float_celsius = pStateReal->lifeData.temperature_celsius; 1153 min_temperature_float_celsius = pStateReal->lifeData.temperature_celsius;
1154 //Write logbook sample 1154 //Write logbook sample
1155 logbook_writeSample(*pStateReal); 1155 logbook_writeSample(pStateReal);
1156 resetEvents(); 1156 resetEvents();
1157 tickstart = HAL_GetTick(); 1157 tickstart = HAL_GetTick();
1158 bDiveMode = 1; 1158 bDiveMode = 1;
1159 } 1159 }
1160 } 1160 }
1164 ticksdiff = time_elapsed_ms(tickstart,lasttick); 1164 ticksdiff = time_elapsed_ms(tickstart,lasttick);
1165 // 1165 //
1166 if(ticksdiff >= 2000) 1166 if(ticksdiff >= 2000)
1167 { 1167 {
1168 //Write logbook sample 1168 //Write logbook sample
1169 logbook_writeSample(*pStateReal); 1169 logbook_writeSample(pStateReal);
1170 resetEvents(); 1170 resetEvents();
1171 if(min_temperature_float_celsius > pStateReal->lifeData.temperature_celsius) 1171 if(min_temperature_float_celsius > pStateReal->lifeData.temperature_celsius)
1172 min_temperature_float_celsius = pStateReal->lifeData.temperature_celsius; 1172 min_temperature_float_celsius = pStateReal->lifeData.temperature_celsius;
1173 tickstart = lasttick; 1173 tickstart = lasttick;
1174 if((bDiveMode == 1) && (pStateReal->lifeData.dive_time_seconds >= pSettings->divetimeToCreateLogbook)) 1174 if((bDiveMode == 1) && (pStateReal->lifeData.dive_time_seconds >= pSettings->divetimeToCreateLogbook))