#ifndef FREEZER
#define FREEZER 1

#define UNIX 1
#define LINUX 1

const int ALARMS   = 100;
const int FREEZERS_PER_PORT = 4;
const int PORTS    = 2;
const int FREEZERS = 8;

//// Add any additional ports here
const char SERIAL_PORT_0[64] = "/dev/ttyS0";
const char SERIAL_PORT_1[64] = "/dev/ttyS1";
const int MAX_PORTS = 10;

//---------------Include files-------------------------------------------//
#include <stdio.h>
#include <string.h>
#include <strings.h>        // For index() in Solaris
#include <math.h>
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
#include <errno.h>
#include <time.h>
#include <sys/time.h>
#include <sys/times.h>
#include <signal.h>         // Needed for semaphores & ipc
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <curses.h>

#ifndef __u32
#define __u32 unsigned int
#endif

// These are needed for serial I/O
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/syslog.h>     // For syslog
#include <linux/serial.h>

//---------------#define's-------------------------//
#define min(a,b) (((a)<(b)) ? (a) : (b))
#define max(a,b) (((a)>(b)) ? (a) : (b))
#define swapbyte(a,b){ ccc=(a);  (a)=(b); (b)=ccc; }  
#define swap(a,b)  { g.swap_temp=(a);  (a)=(b); (b)=g.swap_temp; }  
#define fswap(a,b) { g.fswap_temp=(a); (a)=(b); (b)=g.fswap_temp; }  
#define dswap(a,b) { g.dswap_temp=(a); (a)=(b); (b)=g.dswap_temp; } 
#define sgn(a) ( (a)>0 ? (1) : ( (a)<0 ? (-1) : (0) ) )
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
#define ushort unsigned short int

typedef struct Alarm
{
  char *command;             // command line
  double threshold;          // Temp above which to send alarm
  int freezer;               // 0 to 3 freezer number
  int state;                 // 0=0ff 1=on 2=ringing  

};

typedef struct Freezer
{
    int    port;            // 0,1,2,3 for ttyS0, etc
    char   *location;
    char   *alarm_state_string;
    double temperature;
    int    alarm_state;       // 0=0ff 1=on 2=alarm command sent  
};

const int FILENAMELENGTH=1024;  // max. length of a filename

int between(int a,int b,int c);
int open_port(const char *port_name);
void initialize_app_globals(void);
void initialize_curses(void);
void alarm_ring(int alarm);
void print(int row, int col, int number);
void print(int row, int col, double number);
void print(int row, int col, char *string);
void print_status(int freezer);
void remove_terminal_cr(char *s);
void clear_screen(void);
void monitor(int fd[]);
void log_temperatures(void);
int find_command_start(char *string);

#endif  // ifndef FREEZER
