Imported Upstream version 2.9.0
[debian/cc1111] / device / examples / ds390 / ow390 / thermo21.h
1 //---------------------------------------------------------------------------
2 // Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
3 // 
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:
10 // 
11 // The above copyright notice and this permission notice shall be included 
12 // in all copies or substantial portions of the Software.
13 // 
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.
21 // 
22 // Except as contained in this notice, the name of Dallas Semiconductor 
23 // shall not be used except as stated in the Dallas Semiconductor 
24 // Branding Policy. 
25 //---------------------------------------------------------------------------
26 //
27 //  thermo.h - Include file for Thermochron demo.
28 //
29 //  Version: 2.00
30 //
31 //    History:
32 //           1.03 -> 2.00  Reorganization of Public Domain Kit
33
34 #ifndef THERMO_TYPES
35
36 #define THERMO_TYPES
37
38 // hacks for sdcc->TINI
39 #define FILE void
40 #define stdin ((void *)0)
41 #define stdout ((void *)0)
42 #define stderr ((void *)0)
43 int fprintf (FILE *fp, char *format, ...) reentrant;
44 FILE *fopen (char *, char *);
45 int fclose (FILE *);
46
47 // defines
48 #define STATUS_PAGE    16
49 #define THERMO_FAM     0x21
50
51 #include <stdlib.h>
52
53 // Typedefs
54 #ifndef OW_UCHAR
55    #define OW_UCHAR
56    typedef unsigned char  uchar;
57    #ifdef WIN32
58       typedef unsigned short ushort;
59       typedef unsigned long  ulong;
60    #endif
61 #endif
62
63 // structure to hold the mission status 
64 typedef struct 
65 {
66    uchar serial_num[8];          // serial number of thermochron
67
68    uchar mission_in_progress;    // 1 mission in progres, 0 mission over
69
70    uchar sample_rate;            // minutes between samples
71
72    uchar rollover_enable;        // 1 if roll-over enabled
73    uchar rollover_occurred;      // 1 if roll-over occurred
74
75    ushort start_delay;           // minutes before mission starts
76
77    ulong mission_start_time;     // date/time when mission started
78    ulong current_time;           // current real-time clock value
79    ulong download_time;          // download stations time of reading
80
81    ulong mission_samples;        // number of samples in this mission
82    ulong samples_total;          // total number of samples taken by device
83     
84    uchar high_threshold;         // raw temp of high threshold
85    uchar low_threshold;          // raw temp of low threshold
86
87    // skip alarm modes and status for now
88
89    uchar status_raw[32];
90
91 } MissionStatus;
92
93 // structure to hold the histogram data 
94 typedef struct 
95 {
96    ushort bin_count[56];    // counter per bin 0 to 55 
97    float  start_range[56];  // start temp range (C) in bin 0 to 55
98    float  end_range[56];    // end temp range (C) in bin 0 to 55
99
100    uchar  hist_raw[128];    // raw data for histogram
101
102 } Histogram;
103
104 // structure to hold the histogram data 
105 typedef struct 
106 {
107    int num_low;               // number of low events
108    ulong low_start_time[12];  // start time of event 0 to 12
109    ulong low_end_time[12];    // end time of event 0 to 12 
110    int num_high;              // number of high events
111    ulong high_start_time[12]; // start time of event 0 to 12
112    ulong high_end_time[12];   // end time of event 0 to 12
113
114    uchar  alarm_raw[96];     // raw data for alarm events
115
116 } TempAlarmEvents;
117
118 // structure to hold the log data 
119 typedef struct 
120 {
121    int   num_log;             // number of logs
122    float temp[2048];          // temperature log in (C) 
123    ulong start_time;          // start time of log
124    int   interval;            // interval in seconds between logs
125
126    uchar log_raw[2048];       // raw data for log
127
128 } Log;
129
130 // structure to hold all of the thermochron data state
131 typedef struct
132 {
133    MissionStatus MissStat;    // mission state
134    Histogram HistData;        // histogram data
135    TempAlarmEvents AlarmData; // temperature alarm event data
136    Log LogData;               // log data
137
138 } ThermoStateType;
139
140 // type structure to holde time/date 
141 typedef struct          
142 {
143      ushort  second;
144      ushort  minute;
145      ushort  hour;
146      ushort  day;
147      ushort  month;
148      ushort  year;
149 } timedate;
150
151 // structure to hold each state in the StateMachine
152 typedef struct
153 {
154    int  Step;
155    char StepDescription[50];
156
157 } ThermoScript;
158
159 // Global Function Prototypes 
160  int DownloadThermo(int,uchar *,ThermoStateType *, FILE *);
161 int ReadThermoStatus(int,uchar *,ThermoStateType *, FILE *);
162 int MissionThermo(int,uchar *,ThermoStateType *, FILE *);
163 void  SecondsToDate(timedate *, ulong);
164 ulong DateToSeconds(timedate *);
165 uchar BCDToBin(uchar);
166  void  InterpretStatus(MissionStatus *);
167  void  MissionStatusToString(MissionStatus *, int, char *);
168 void  FormatMission(MissionStatus *);
169  void  InterpretHistogram(Histogram *);
170  void  HistogramToString(Histogram *, int, char *);
171  void  InterpretAlarms(TempAlarmEvents *, MissionStatus *);
172  void  AlarmsToString(TempAlarmEvents *, char *);
173  void  InterpretLog(Log *, MissionStatus *);
174  void  LogToString(Log *, int, char *);
175  void  DebugToString(MissionStatus *, TempAlarmEvents *, Histogram *, Log *, char *); 
176 float TempToFloat(uchar, int);
177 float CToF(float);
178 uchar ToBCD(short);
179
180 #endif