3232#define BUFFERLENGTH 512 // The length of string buffers
3333#define DELIMITER ' \n '
3434#define SEPARATOR " ,"
35+ #define LEAVE_AS_IS " ="
3536#define ADC_NAME " ASGARD" // The name of the ADC device
3637#define PROTOCOL_VERSION " 0.4" // The version of the communication protocol
3738#define DEFAULT_LOGFILE " DATALOG.CSV" // The default log file name
@@ -150,7 +151,7 @@ void acquisition()
150151 }
151152
152153 // Differential Pressure sensor
153- if (AirDataComputer._status [AIRDC_STATUS_TDELTAP ] == ' 1' ) { // Differential pressure sensor present
154+ if (AirDataComputer._status [AIRDC_STATUS_DELTAP ] == ' 1' ) { // Differential pressure sensor present
154155 diffp.update ();
155156 AirDataComputer._qc = diffp.pressure ();
156157 AirDataComputer._qcRaw = diffp.pressure_Raw ();
@@ -463,6 +464,7 @@ void loop() {
463464 // #5 – STS – STATUS_SET --> Reply STA - STATUS_ASSERT
464465 // --------------------------------------------------
465466 // $STS,0,1,1,1,1,1,0,0,0
467+ // $STS,=,=,=,0,=,=,=,=,= Deactivate the external temperature sensor. Don't touch other fields
466468
467469 if (!strcmp (command, " $STS" )) {
468470 int i;
@@ -522,26 +524,50 @@ void loop() {
522524 // --------------------------------------------------
523525 // #8 – DTS – DATA_SET
524526 // --------------------------------------------------
525- // $DTS,0,0,0,0,0,0,0,0 ,300,0 Sets the external temperature to 300 [K] (if the sensor is not present)
527+ // $DTS,=,=,=,=,=,=,=,= ,300 Sets the external temperature to 300 [K] (if the sensor is not present)
526528
527529 if (!strcmp (command, " $DTS" )) {
528530 int i;
529531 i=0 ;
530532 for (i=0 ; i<AIRDC_DATA_VECTOR_SIZE; i++) { // Check the fields
531533 command = strtok (NULL , SEPARATOR);
532534 if (strlen (command)<1 ) goto endeval;
533-
534- switch (i) {
535- case AIRDC_DATA_TAT:
536- if (AirDataComputer._status [AIRDC_STATUS_TAT] == ' 0' ) {
537- AirDataComputer._TAT = atol (command);
538- AirDataComputer._TRaw = 0l ;
539- }
540- break ;
535+ if (strcmp (command, LEAVE_AS_IS)) {
536+ switch (i) {
537+ case AIRDC_DATA_TAT: // External Temperature
538+ if (AirDataComputer._status [AIRDC_STATUS_TAT] == ' 0' ) {
539+ AirDataComputer._TAT = atol (command);
540+ AirDataComputer._TRaw = 0l ;
541+ }
542+ break ;
543+ case AIRDC_DATA_QC: // Differential pressure
544+ if (AirDataComputer._status [AIRDC_STATUS_DELTAP] == ' 0' ) {
545+ AirDataComputer._qc = atol (command);
546+ AirDataComputer._qcRaw = 0l ;
547+ }
548+ break ;
549+ case AIRDC_DATA_TDELTAP: // Temperature differential pressure sensor
550+ if (AirDataComputer._status [AIRDC_STATUS_TDELTAP] == ' 0' ) {
551+ AirDataComputer._Tdeltap = atol (command);
552+ AirDataComputer._TdeltapRaw = 0l ;
553+ }
554+ break ;
555+ case AIRDC_DATA_P: // Absolute pressure
556+ if (AirDataComputer._status [AIRDC_STATUS_P] == ' 0' ) {
557+ AirDataComputer._p = atol (command);
558+ AirDataComputer._pRaw = 0l ;
559+ }
560+ break ;
561+ case AIRDC_DATA_TABSP: // Temperature absolute pressure sensor
562+ if (AirDataComputer._status [AIRDC_STATUS_TABSP] == ' 0' ) {
563+ AirDataComputer._Tabsp = atol (command);
564+ AirDataComputer._TabspRaw = 0l ;
565+ }
566+ break ;
567+ default : // IT DOES NOTHING
568+ break ;
541569
542- default :
543- break ;
544- // IT DOES NOTHING
570+ }
545571 }
546572 }
547573 goto endeval;
@@ -556,38 +582,40 @@ void loop() {
556582 // $DTQ,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
557583 // Request time, deltap, p, ext temperature
558584 // $DTQ,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
585+ // Toggle ON the ext temperature field
586+ // $DTQ,=,=,=,=,=,=,=,=,1
559587 // Request a $DTA string
560588 // $DTQ
561589
562590 if (!strcmp (command, " $DTQ" )) {
563- strcpy (Answer, p_Data);
591+ if (!strcmp (command, " $DTQ," )) {
592+ strcpy (Answer, p_Data); // Simply return the data
593+ goto endeval;
594+ }
595+ strcpy (Answer, " " );
564596 int i;
565597 i=0 ;
566598 for (i=0 ; i<AIRDC_DATA_VECTOR_SIZE; i++) {
567599 command = strtok (NULL , SEPARATOR);
568600 if (strlen (command)<1 ) goto endeval;
569- AirDataComputer._datasel [i]=command[0 ];
570- workbuff[2 *i]=command[0 ];
571- workbuff[2 *i+1 ]=' ,' ;
601+ if (strcmp (command, LEAVE_AS_IS)) AirDataComputer._datasel [i]=command[0 ];
572602 }
573- workbuff[2 *i-1 ]=' \0 ' ;
574- strcpy (Answer, " " );
575603
576604 // Save to the SD the configuration data
577- SDCardCheck ();
578- if (isSDCardPresent) {
579- SD.remove (DEFAULT_CONFIGFILE);
580- File dataFile = SD.open (DEFAULT_CONFIGFILE, FILE_WRITE);
581- if (dataFile) { // if the file is available, write to it:
582- AirDataComputer._status [AIRDC_STATUS_SD] = ' 1' ; // SD Card present
583- dataFile.print (" $DTQ," );
584- dataFile.println (workbuff);
585- dataFile.close ();
586- } else { // if the file isn't open, pop up an error:
587- AirDataComputer._status [AIRDC_STATUS_SD] = ' 0' ; // SD Card not present
588- goto endeval;
589- }
590- }
605+ // SDCardCheck();
606+ // if (isSDCardPresent) {
607+ // SD.remove(DEFAULT_CONFIGFILE);
608+ // File dataFile = SD.open(DEFAULT_CONFIGFILE, FILE_WRITE);
609+ // if (dataFile) { // if the file is available, write to it:
610+ // AirDataComputer._status[AIRDC_STATUS_SD] = '1'; // SD Card present
611+ // dataFile.print("$DTQ,");
612+ // dataFile.println(workbuff);
613+ // dataFile.close();
614+ // } else { // if the file isn't open, pop up an error:
615+ // AirDataComputer._status[AIRDC_STATUS_SD] = '0'; // SD Card not present
616+ // goto endeval;
617+ // }
618+ // }
591619 // Modified #10 reply message. No data will be transmitted. It is a plain acknowledge.
592620 // strcpy (outstr,"$DTA,");
593621 // strcat (Answer, workbuff);
@@ -663,18 +691,18 @@ void loop() {
663691 // --------------------------------------------------
664692 // $DFS,Serial_freq,Bluetooth_freq,SD_freq <-- SPECS CHANGED
665693 // $DFS,5,0.5,0 Serial = 1 Hz Bluetooth = 0.5 Hz No SD logging
666- // $DFS,-1 ,0.5,5 Serial = leave as is Bluetooth = 0.5 Hz SD = 5 Hz
694+ // $DFS,= ,0.5,5 Serial = leave as is Bluetooth = 0.5 Hz SD = 5 Hz
667695
668696 if (!strcmp (command, " $DFS" )) { // $DFS,Serial,Bluetooth,SD
669697 command = strtok (NULL , SEPARATOR);
670698 if (command != NULL ) {
671- float DataFrequency_COM = atof ( command); // Read the value after the comma
699+ float DataFrequency_COM = ( strcmp ( command, LEAVE_AS_IS) ? atof (command) : - 1 ); // Read the freq value
672700 command = strtok (NULL , SEPARATOR);
673701 if (command != NULL ) {
674- float DataFrequency_BT = atof ( command); // Read the value after the comma
702+ float DataFrequency_BT = ( strcmp ( command, LEAVE_AS_IS) ? atof (command) : - 1 ); // Read the freq value
675703 command = strtok (NULL , SEPARATOR);
676704 if (command != NULL ) {
677- float DataFrequency_SD = atof ( command); // Read the value after the comma
705+ float DataFrequency_SD = ( strcmp ( command, LEAVE_AS_IS) ? atof (command) : - 1 ); // Read the freq value
678706 // Change frequencies
679707 if ((DataFrequency_COM >= 0 ) && (DataFrequency_COM != sendtoserial_freq)) {
680708 sendtoserial_freq = DataFrequency_COM;
0 commit comments