-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDdeserv.c
289 lines (244 loc) · 7.18 KB
/
Ddeserv.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/*
DDE Server
This module uses the DDEML library to implement a DDE server
*/
#include "sunclock.h"
#include <ddeml.h>
#include "wrapper.h"
#define ddeUpdateInterval 5 // Hot link information update interval (seconds)
static double ijdate, igmst, sunra, sundec, sunrv, sunlong, subslong,
moonphase, cphase, aom, cdist, cdister, cangdia, csund, csuang, phasar[5],
nptime = 0, moonra, moondec, moonlong, moonclong, moonclat, mooncrv;
static int lunation;
int ddeActive = FALSE; // Set true when first DDE request occurs
// Forward functions
static void ddeAdviseSelective(int service, int topic);
// #define AniDDE // Define to have animation affect DDE calculation
/* UPDATEDDEINFO -- Recalculate information we make available via DDE. */
void updateDDEInfo(void)
{
struct tm gt;
struct tm *ct;
time_t cctime;
static time_t lctime = 0;
V time(&cctime);
if (
#ifdef AniDDE
TRUE
#else
(cctime - lctime) > ddeUpdateInterval
#endif
) {
set_tm_time(>, FALSE);
ct = >
lctime = cctime;
#ifdef AniDDE
ijdate = faketime;
#else
ijdate = jtime(ct);
#endif
sunpos(ijdate, TRUE, &sunra, &sundec, &sunrv, &sunlong);
igmst = gmst(ijdate);
subslong = (igmst * 15) - sunra;
if (subslong > 180) {
subslong = -(360 - subslong);
} else if (subslong < -180) {
subslong += 360;
}
moonphase = phase(ijdate, &cphase, &aom, &cdist, &cangdia, &csund, &csuang);
// cdister = cdist / EarthRad;
if (ijdate > nptime) {
phasehunt(ijdate + 0.5, phasar);
lunation = (int) floor(((phasar[0] + 7) - LunatBase) / SynMonth) + 1;
nptime = phasar[4];
}
highmoon(ijdate, &moonclong, &moonclat, &mooncrv);
cdister = mooncrv / EarthRad;
ecliptoeq(ijdate, moonclong, moonclat, &moonra, &moondec);
moonlong = (igmst * 15) - moonra;
if (moonlong > 180) {
moonlong = -(360 - moonlong);
} else if (moonlong < -180) {
moonlong += 360;
}
ddeAdvise();
}
}
// UPDATESCOPEDDE -- Update DDE info when telescope status changes
void updateScopeDDE(void)
{
ddeAdviseSelective(0, 3); // Just notify scope watchers
}
/* iDDE -- Initialise DDE if required and perform first calculation. */
static void iDDE(void)
{
if (!ddeActive) {
ddeActive = TRUE;
updateDDEInfo();
}
}
#define DDESvcF(x) static HDDEDATA PASCAL Rq_DDE_##x(HDDEDATA hDataOut) { char sz[40]; \
iDDE(); sprintf(sz, Format(12), (x)); \
return DdeAddData(hDataOut, (LPBYTE)sz, (DWORD) (strlen(sz) + 1), 0L); }
#define DDESvcI(x) static HDDEDATA PASCAL Rq_DDE_##x(HDDEDATA hDataOut) { char sz[40]; \
iDDE(); sprintf(sz, Format(21), (x)); \
return DdeAddData(hDataOut, (LPBYTE)sz, (DWORD) (strlen(sz) + 1), 0L); }
#define DDESvcFa(x, e) static HDDEDATA PASCAL Rq_DDE_##x(HDDEDATA hDataOut) { char sz[40]; \
iDDE(); sprintf(sz, Format(12), (e)); \
return DdeAddData(hDataOut, (LPBYTE)sz, (DWORD) (strlen(sz) + 1), 0L); }
DDESvcFa(ijdate, ijdate/*JD + 0.5*/)
DDESvcF(igmst)
DDESvcF(sunra)
DDESvcF(sundec)
DDESvcF(sunrv)
DDESvcF(sunlong)
DDESvcF(subslong)
DDESvcF(moonphase)
DDESvcF(cphase)
DDESvcF(aom)
DDESvcF(cdist)
DDESvcF(cdister)
DDESvcF(cangdia)
DDESvcF(csund)
DDESvcF(csuang)
DDESvcF(moonra)
DDESvcF(moondec)
DDESvcF(moonlong)
DDESvcF(moonclong)
DDESvcF(moonclat)
DDESvcI(lunation)
DDESvcFa(phlnew, phasar[0]/*JD + 0.5*/)
DDESvcFa(phq1, phasar[1]/*JD + 0.5*/)
DDESvcFa(phhalf, phasar[2]/*JD + 0.5*/)
DDESvcFa(phq2, phasar[3]/*JD + 0.5*/)
DDESvcFa(phnnew, phasar[4]/*JD + 0.5*/)
DDESvcI(telActive)
DDESvcF(telra)
DDESvcF(teldec)
DDESvcF(telalt)
DDESvcF(telazi)
static HDDEDATA PASCAL RequestHelp(HDDEDATA hDataOut)
{
static char szHelp[] = "DDE Help for the Home Planet Service.\r\r\n\t"
"Topics are Time, Sun, Moon, and Telescope\r\n\t"
"Updates are every 60 seconds or when Telescope moves\r\n\t"
"See Home Planet Help for details of items.";
return(DdeAddData(hDataOut, (LPBYTE) szHelp, (DWORD) sizeof(szHelp), 0L));
}
static DDEFORMATTBL SystopicHelpFormats[] = {
"TEXT", CF_TEXT, 0, NULL, RequestHelp
};
static DDEITEMTBL SystopicItems[] = {
SZDDESYS_ITEM_HELP, 0, NULL, ELEMENTS(SystopicHelpFormats), 0, SystopicHelpFormats
};
#define FTAB(x) static DDEFORMATTBL x##_FMT_t[] = { { "TEXT", CF_TEXT, 0, NULL, Rq_DDE_##x} }
FTAB(ijdate);
FTAB(igmst);
FTAB(sunra);
FTAB(sundec);
FTAB(sunrv);
FTAB(sunlong);
FTAB(subslong);
FTAB(moonphase);
FTAB(cphase);
FTAB(aom);
FTAB(cdist);
FTAB(cdister);
FTAB(cangdia);
FTAB(csund);
FTAB(csuang);
FTAB(moonra);
FTAB(moondec);
FTAB(moonlong);
FTAB(moonclong);
FTAB(moonclat);
FTAB(lunation);
FTAB(phlnew);
FTAB(phq1);
FTAB(phhalf);
FTAB(phq2);
FTAB(phnnew);
FTAB(telActive);
FTAB(telra);
FTAB(teldec);
FTAB(telalt);
FTAB(telazi);
#define F(n, x) { n, 0, NULL, ELEMENTS(x##_FMT_t), 0, x##_FMT_t }
static DDEITEMTBL TimeItems[] = {
F("Jdate", ijdate),
F("Gmst", igmst)
};
static DDEITEMTBL SunItems[] = {
F("RA", sunra),
F("Dec", sundec),
F("DistanceAU", sunrv),
F("DistanceKM", csund),
F("Subtends", csuang),
F("Elong", sunlong),
F("Long", subslong),
};
static DDEITEMTBL MoonItems[] = {
F("RA", moonra),
F("Dec", moondec),
F("Phase", cphase),
F("Age", aom),
F("DistanceER", cdister),
F("DistanceKM", cdist),
F("Subtends", cangdia),
F("Long", moonlong),
F("ELat", moonclat),
F("ELong", moonclong),
F("Lunation", lunation),
F("PhLastNew", phlnew),
F("PhFQuarter", phq1),
F("PhHalf", phhalf),
F("PhLQuarter", phq2),
F("PhNextNew", phnnew)
};
static DDEITEMTBL TelescopeItems[] = {
F("Active", telActive),
F("RA", telra),
F("Dec", teldec),
F("Azi", telazi),
F("Alt", telalt)
};
static DDETOPICTBL Topics[] = {
{ "Time", 0, ELEMENTS(TimeItems), 0, TimeItems },
{ "Sun", 0, ELEMENTS(SunItems), 0, SunItems },
{ "Moon", 0, ELEMENTS(MoonItems), 0, MoonItems },
{ "Telescope", 0, ELEMENTS(TelescopeItems), 0, TelescopeItems },
{ SZDDESYS_TOPIC, 0, ELEMENTS(SystopicItems), 0, SystopicItems },
};
static DDESERVICETBL MyServiceInfo[] = {
{ "HPlanet", 0, ELEMENTS(Topics), 0, Topics }
};
extern DWORD idInst;
void ddeAdvise(void)
{
int h, i, j;
for (h = 0; h < ELEMENTS(MyServiceInfo); h++) {
for (i = 0; i < (int) (MyServiceInfo[h].cTopics - 1); i++) {
for (j = 0; j < ((int) MyServiceInfo[h].topic[i].cItems); j++) {
DdePostAdvise(idInst, MyServiceInfo[h].topic[i].hszTopic,
MyServiceInfo[h].topic[i].item[j].hszItem);
}
}
}
}
static void ddeAdviseSelective(int service, int topic)
{
int j;
for (j = 0; j < ((int) MyServiceInfo[service].topic[topic].cItems); j++) {
DdePostAdvise(idInst, MyServiceInfo[service].topic[topic].hszTopic,
MyServiceInfo[service].topic[topic].item[j].hszItem);
}
}
void ddeInit(HINSTANCE hInstance)
{
InitializeDDE(NULL, &idInst, MyServiceInfo,
CBF_FAIL_EXECUTES | CBF_SKIP_ALLNOTIFICATIONS, hInstance);
}
void ddeTerm(void)
{
UninitializeDDE();
}