1 //---------------------------------------------------------------------------
2 // Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 // IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
18 // OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 // OTHER DEALINGS IN THE SOFTWARE.
22 // Except as contained in this notice, the name of Dallas Semiconductor
23 // shall not be used except as stated in the Dallas Semiconductor
25 //---------------------------------------------------------------------------
27 // thermodl.c - This utility uses to download the results of the
28 // current mission of a DS1921 Thermochron iButton.
33 // 1.03 -> 2.00 Reorganization of Public Domain Kit
34 // Y2K update, display all histogram bins, debug
35 // dump. Supports multiple thermochons.
44 #define ExitProg(msg,exit_code) {printf("%s\n",msg); exit(exit_code);}
49 // local function prototypes
50 static void PrintResults(ThermoStateType *,FILE *,int);
52 //----------------------------------------------------------------------
53 // This is the Main routine for thermodl.
57 int Fahrenheit=FALSE,num,i,j;
60 ThermoStateType ThermoState;
61 uchar ThermoSN[MAXDEVICES][8]; //the serial numbers for the devices
64 // attempt to acquire the 1-Wire Net
65 if (!owAcquire(portnum,""))
70 //----------------------------------------
72 printf("\n/----------------------------------------------\n");
73 printf(" Find and download DS1921 Thermochron iButton(s)\n"
76 // check arguments for temperature conversion and filename
79 // get list of Thermochron's
80 num = FindDevices(portnum, &ThermoSN[0],THERMO_FAM, MAXDEVICES);
82 // check if not present or more then 1 present
84 ExitProg("Thermochron not present on 1-Wire\n",1);
86 // loop to download each Thermochron
87 for (i = 0; i < num; i++)
89 // set the serial number portion in the thermo state
90 printf("\nDownloading: ");
91 for (j = 7; j >= 0; j--)
93 ThermoState.MissStat.serial_num[j] = ThermoSN[i][j];
94 printf("%02X",ThermoSN[i][j]);
98 // download the Thermochron found
99 if (DownloadThermo(portnum,&ThermoSN[i][0],&ThermoState,stdout))
101 // interpret the results of the download
102 InterpretStatus(&ThermoState.MissStat);
103 InterpretAlarms(&ThermoState.AlarmData, &ThermoState.MissStat);
104 InterpretHistogram(&ThermoState.HistData);
105 InterpretLog(&ThermoState.LogData, &ThermoState.MissStat);
108 PrintResults(&ThermoState,fp,Fahrenheit);
112 fprintf(fp,"\nError downloading device: ");
113 for (j = 0; j < 8; j++)
114 fprintf(fp,"%02X",ThermoSN[i][j]);
119 // release the 1-Wire Net
121 printf("\n%s",return_msg);
122 ExitProg("End program normally\n",0);
127 //--------------------------------------------------------------------------
128 // Prints the mission data optionaly to a file or standard out
130 void PrintResults(ThermoStateType *ThermoState, FILE *fp, int ConvertToF)
135 // check if need to use standard out
139 // get big block to use as a buffer
144 printf("Insufficient memory available to print!\n");
150 MissionStatusToString(&ThermoState->MissStat, ConvertToF, &str[0]);
151 fprintf(fp,"\n%s\n",str);
154 AlarmsToString(&ThermoState->AlarmData, &str[0]);
155 fprintf(fp,"%s\n",str);
158 HistogramToString(&ThermoState->HistData, ConvertToF, &str[0]);
159 fprintf(fp,"%s\n",str);
162 LogToString(&ThermoState->LogData, ConvertToF, &str[0]);
163 fprintf(fp,"%s\n",str);
166 DebugToString(&ThermoState->MissStat, &ThermoState->AlarmData,
167 &ThermoState->HistData, &ThermoState->LogData, &str[0]);
168 fprintf(fp,"%s\n",str);
170 // free the memory block used