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.
46 // local function prototypes
47 void PrintResults(ThermoStateType *,FILE *,int);
50 #define ExitProg(msg,exit_code) {printf("%s\n",msg); exit(exit_code);}
52 char *argv[]={__FILE__, "exow"};
54 //----------------------------------------------------------------------
55 // This is the Main routine for thermodl.
57 int main() //short argc, char **argv)
59 int Fahrenheit=FALSE,filenum,num,i,j;
62 ThermoStateType ThermoState;
63 uchar ThermoSN[MAXDEVICES][8]; //the serial numbers for the devices
66 // check arguments to see if request instruction with '?' or too many
67 if ((argc < 2) || (argc > 4) || ((argc > 1) && (argv[1][0] == '?' || argv[1][1] == '?')))
68 ExitProg("\nusage: thermodl 1wire_net_name <output_filename> </Fahrenheit>\n"
69 " - Thermochron download on the 1-Wire Net port\n"
70 " - 1wire_net_port required port name\n"
71 " example: \"COM1\" (Win32 DS2480),\"/dev/cua0\" \n"
72 " (Linux DS2480),\"1\" (Win32 TMEX)\n"
73 " - <output_filename> optional output filename\n"
74 " - </Fahrenheit> optional Fahrenheit mode (default Celsius)\n"
75 " - version 2.00\n",1);
77 // attempt to acquire the 1-Wire Net
78 if (!owAcquire(portnum,argv[1],return_msg))
79 ExitProg(return_msg,1);
82 printf("%s",return_msg);
84 //----------------------------------------
86 printf("\n/----------------------------------------------\n");
87 printf(" Find and download DS1921 Thermochron iButton(s)\n"
90 // check arguments for temperature conversion and filename
95 if (argv[2][0] != '/')
97 else if ((argv[2][1] == 'F') || (argv[2][1] == 'f'))
102 if (argv[3][0] != '/')
104 else if ((argv[3][1] == 'F') || (argv[3][1] == 'f'))
109 // open the output file
113 fp = fopen(argv[filenum],"w+");
116 printf("ERROR, Could not open output file!\n");
120 printf("File '%s' opened to write mission results.\n",
124 // get list of Thermochron's
125 num = FindDevices(portnum, &ThermoSN[0],THERMO_FAM, MAXDEVICES);
127 // check if not present or more then 1 present
129 ExitProg("Thermochron not present on 1-Wire\n",1);
131 // loop to download each Thermochron
133 for (i = 0; i < num; i++)
135 // set the serial number portion in the thermo state
136 printf("\nDownloading: ");
137 for (j = 7; j >= 0; j--)
139 ThermoState.MissStat.serial_num[j] = ThermoSN[i][j];
140 printf("%02X",ThermoSN[i][j]);
144 // download the Thermochron found
145 if (DownloadThermo(portnum,&ThermoSN[i][0],&ThermoState,stdout))
147 // interpret the results of the download
148 InterpretStatus(&ThermoState.MissStat);
149 InterpretAlarms(&ThermoState.AlarmData, &ThermoState.MissStat);
150 InterpretHistogram(&ThermoState.HistData);
151 InterpretLog(&ThermoState.LogData, &ThermoState.MissStat);
154 PrintResults(&ThermoState,fp,Fahrenheit);
158 fprintf(fp,"\nError downloading device: ");
159 for (j = 0; j < 8; j++)
160 fprintf(fp,"%02X",ThermoSN[i][j]);
168 printf("File '%s' closed.\n",
173 // release the 1-Wire Net
174 owRelease(portnum,return_msg);
175 printf("\n%s",return_msg);
176 ExitProg("End program normally\n",0);
180 //--------------------------------------------------------------------------
181 // Prints the mission data optionaly to a file or standard out
183 void PrintResults(ThermoStateType *ThermoState, FILE *fp, int ConvertToF)
185 // aslink only can handle 64k, so we use the second 64k bank
186 char *str=(char*)0x190000;
188 // check if need to use standard out
193 // get big block to use as a buffer
197 printf("Insufficient memory available to print!\n");
203 MissionStatusToString(&ThermoState->MissStat, ConvertToF, &str[0]);
204 fprintf(fp,"\n%s\n",str);
207 AlarmsToString(&ThermoState->AlarmData, &str[0]);
208 fprintf(fp,"%s\n",str);
211 HistogramToString(&ThermoState->HistData, ConvertToF, &str[0]);
212 fprintf(fp,"%s\n",str);
215 LogToString(&ThermoState->LogData, ConvertToF, &str[0]);
216 fprintf(fp,"%s\n",str);
219 DebugToString(&ThermoState->MissStat, &ThermoState->AlarmData,
220 &ThermoState->HistData, &ThermoState->LogData, &str[0]);
221 fprintf(fp,"%s\n",str);
224 // free the memory block used