Mostly minor fixes up until version 0.8.10.
[irreco.git] / irtrans / irserver / src / errormessage.c
blobd79aa6963ea5804cfbbaf6bd3d8cc6ba799c7757
1 /*
2 * Copyright (c) 2007, IRTrans GmbH
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of IRTrans GmbH nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY IRTrans GmbH ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL IRTrans GmbH BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #ifdef WIN32
31 #include <windows.h>
32 #include <time.h>
33 #include <sys/timeb.h>
34 #endif
36 #ifdef WINCE
37 #include <windows.h>
38 #endif
40 #ifdef LINUX
41 #include <stdlib.h>
42 #include <sys/types.h>
43 #include <sys/socket.h>
44 #include <netinet/in.h>
45 #include <sys/un.h>
46 #include <arpa/inet.h>
47 #include <dirent.h>
48 #include <sys/stat.h>
49 #include <errno.h>
50 #include <fcntl.h>
51 #include <signal.h>
52 #include <stdint.h>
53 #include <time.h>
54 #include <sys/timeb.h>
55 #endif
57 #include <stdio.h>
59 #include "remote.h"
60 #include "lowlevel.h"
61 #include "global.h"
63 #include "errcode.h"
65 #ifdef WIN32
66 #include "winio.h"
67 #include "winusbio.h"
68 #endif
71 void log_print (char msg[],int level)
73 FILE *fp;
74 time_t tv;
75 int ms = 0;
76 struct tm *tmpnt;
77 #ifdef WIN32
78 struct _timeb tb;
79 #endif
80 #ifdef LINUX
81 struct timeb tb;
82 #endif
84 if (logfp) fp = logfp;
85 else fp = stderr;
87 if (!fp) return;
89 if (level > (int)(mode_flag & LOG_MASK)) return;
91 if (mode_flag & TIMESTAMP) {
92 tv = time (0);
93 #ifdef WIN32
94 _ftime (&tb);
95 #endif
96 #ifdef LINUX
97 ftime (&tb);
98 #endif
99 tv = tb.time;
100 ms = tb.millitm;
101 tmpnt = localtime (&tv);
103 fprintf (fp,"%4d-%02d-%02d %02d:%02d:%02d.%03d %s",tmpnt->tm_year+1900,tmpnt->tm_mon+1,tmpnt->tm_mday,tmpnt->tm_hour,tmpnt->tm_min,tmpnt->tm_sec,ms,msg);
105 else fprintf (fp,"%s",msg);
107 fflush (fp);
110 void GetError (int res,char st[])
113 switch (res) {
114 case ERR_OPEN:
115 sprintf (st,"Error opening COM/USB Port / LAN Device\n");
116 break;
117 case ERR_RESET:
118 sprintf (st,"No IR Transceiver found (Reset not possible)\n");
119 break;
120 case ERR_READVERSION:
121 sprintf (st,"Could not get Transceiver Version\n");
122 break;
123 case ERR_VERSION:
124 sprintf (st,"Wrong IR Transceiver SW Version. Minimum Version: %s\n",MINIMUM_SW_VERSION);
125 break;
126 case ERR_TIMEOUT:
127 sprintf (st,"Timeout (Connection lost ?)\n");
128 break;
129 case ERR_OPENUSB:
130 sprintf (st,"Error opening USB Device / Device not found\n");
131 break;
132 case ERR_DBOPENINPUT:
133 sprintf (st,"Error opening Database file (Access rights ?)\n");
134 break;
135 case ERR_REMOTENOTFOUND:
136 sprintf (st,"Specified Remote Control [%%s] not found\n");
137 break;
138 case ERR_COMMANDNOTFOUND:
139 sprintf (st,"Specified Remote Command [%%s] not found\n");
140 break;
141 case ERR_TIMINGNOTFOUND:
142 sprintf (st,"Specified Remote Timing not found\n");
143 break;
144 case ERR_OPENASCII:
145 sprintf (st,"Could not create new Remote file (Access rights ?)\n");
146 break;
147 case ERR_NODATABASE:
148 sprintf (st,"Could not open Remote Database (No folder 'remotes' / Access rights ?)\n");
149 break;
150 case ERR_TOGGLE_DUP:
151 sprintf (st,"Could not record Toggle Command (No commands yet learned ?)\n");
152 break;
153 case ERR_DBOPENINCLUDE:
154 sprintf (st,"Specified Include File not found\n");
155 break;
156 case ERR_NOFILEOPEN:
157 sprintf (st,"No Remote opened to learn new commands\n");
158 break;
159 case ERR_FLOCK:
160 sprintf (st,"Could not lock input file (USB / TTY)\n");
161 break;
162 case ERR_STTY:
163 sprintf (st,"Could not set serial parameters\n");
164 break;
165 case ERR_OPENSOCKET:
166 sprintf (st,"Could not open IP socket\n");
167 break;
168 case ERR_BINDSOCKET:
169 sprintf (st,"Could not bind to IP socket (Another server running ?)\n");
170 break;
171 case ERR_HOTCODE:
172 sprintf (st,"Hotcode %%s-%%s not found\n");
173 break;
174 case ERR_NOTIMING:
175 sprintf (st,"No timing learned for new commands\n");
176 break;
177 case ERR_TEMPCOMMAND:
178 sprintf (st,"Illegal Temparature Command: %%s\n");
179 break;
180 case ERR_OPENTRANS:
181 sprintf (st,"Error opening translation table file\n");
182 break;
183 case ERR_WRONGBUS:
184 sprintf (st,"Specified Bus %%d does not exist\n");
185 break;
186 case ERR_ISMACRO:
187 sprintf (st,"Cannot get the Device Data for a macro\n");
188 break;
189 case ERR_DEVICEUNKNOWN:
190 sprintf (st,"IR Code received from unknown device: %%s\n");
191 break;
192 case ERR_BINDWEB:
193 sprintf (st,"Cannot bind to Web Port. Another Webserver running ? Try -no_web.\n");
194 break;
195 case ERR_OVERWRITE:
196 sprintf (st,"File already exists. Overwrite ?\n");
197 break;
198 case ERR_NO_RS232:
199 sprintf (st,"No IRTrans Device with AUX RS232 port connected\n");
200 break;
201 default:
202 sprintf (st,"Error %d\n",res);
203 break;