source: trunk/MagicSoft/Cosy/tcpip/MCeCoCom.cc@ 8255

Last change on this file since 8255 was 6844, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 3.5 KB
Line 
1#include "MCeCoCom.h"
2
3#include <iostream>
4
5#include "MString.h"
6
7using namespace std;
8
9bool MCeCoCom::InterpreteCmd(TString cmd, TString str)
10{
11 cout << cmd << ": " << str << endl;
12 return true;
13}
14
15bool MCeCoCom::InterpreteReport(TString &str)
16{
17 int y, m, d, h, min, s, ms, len;
18
19 int n=sscanf(str.Data(),
20 "%02d %04d %02d %02d %02d %02d %02d %03d %n",
21 &fCCStatus, &y, &m, &d, &h, &min, &s, &ms, &len);
22 if (n!=8)
23 {
24 cout << "Communication Problem: Wrong number of arguments" << endl;
25 fComStat = kComProblem;
26 return false;
27 }
28 str.Remove(0, len);
29
30 fT.Set(y, m, d, h, min, s, ms);
31
32 // Remove the 30 tokens of the subsystem status
33 // table 12.1 p59
34 for (int i=0; i<31; i++)
35 str.Remove(0, str.First(' ')+1);
36
37 // skip solar_irr_Wm2, wind_speed, UPS
38 float zd, az, dec, ra, temp, solar, wind, hum;
39 n=sscanf(str.Data(),
40 /*"%f %f %f %f %f %f %f %f %*f %*f %*s %*s %*s %*s %n",*/
41 "%f %f %f %f %f %f %f %f %*f %*f %n",
42 &zd, &az, &dec, &ra, &temp, &solar, &wind, &hum, &len);
43 if (n!=8)
44 {
45 cout << "Communication Problem: Wrong number of arguments" << endl;
46 fComStat = kComProblem;
47 return false;
48 }
49 str.Remove(0, len);
50
51 if (str!=(TString)"OVER")
52 {
53 cout << "Communication Problem: Termination (OVER) too far away." << endl;
54 fComStat = kComProblem;
55 return false;
56 }
57
58 fHumidity = hum;
59 fTemperature = temp;
60 fSolarRadiation = solar;
61 fWindSpeed = wind;
62
63 if (fWindSpeed>50)
64 fAlarmCounter++;
65 else
66 fAlarmCounter=0;
67
68 cout << "Zd/Az: " << zd << "/" << az << " ";
69 cout << "Ra/Dec: " << ra/15 << "h/" << dec << " ";
70 cout << "SolRad: " << solar << "W/m²" << endl;
71
72 fComStat = kCmdReceived;
73 return true;
74}
75
76bool MCeCoCom::InterpreteStr(TString str)
77{
78 const Ssiz_t tok = str.First(' ');
79 const TString cmd = tok<0 ? str : str(0, tok);
80 if (tok<0)
81 str = "";
82 else
83 str.Remove(0, tok+1);
84
85 if (cmd==(TString)"CC-REPORT" && str.EndsWith("OVER"))
86 return InterpreteReport(str);
87
88 const bool rc = InterpreteCmd(cmd, str.Strip(TString::kBoth));
89 fComStat = rc ? kCmdReceived : kComProblem;
90 return rc;
91}
92
93bool MCeCoCom::Send(const char *cmd, const char *str, bool force=kFALSE)
94{
95 MTime t;
96 t.Now();
97
98 UShort_t y1, y2, ms1, ms2;
99 Byte_t mon1, mon2, d1, d2, h1, h2, m1, m2, s1, s2;
100
101 t.GetDate(y1, mon1, d1);
102 t.GetTime(h1, m1, s1, ms1);
103
104 fT.GetDate(y2, mon2, d2);
105 fT.GetTime(h2, m2, s2, ms2);
106
107 MString msg;
108 msg.Print("%s "
109 "%02d %04d %02d %02d %02d %02d %02d %03d "
110 "%02d %04d %02d %02d %02d %02d %02d %03d "
111 "%s\n", cmd,
112 fStatus, y1, mon1, d1, h1, m1, s1, ms1,
113 fComStat, y2, mon2, d2, h2, m2, s2, ms2,
114 str);
115
116 const bool rc = MTcpIpIO::Send(msg, force);
117 fComStat = rc ? kNoCmdReceived : kComProblem;
118 return rc;
119}
120
121TString MCeCoCom::GetWeather() const
122{
123 if (fSolarRadiation<0 || (double)MTime(-1)-(double)fT>11)
124 return "";
125
126 MString str;
127 return str.Print("Temp: %.1f'C Hum: %.1f%% Wind: %.1fkm/h",
128 fTemperature, fHumidity, fWindSpeed);
129}
130
131Int_t MCeCoCom::GetWeatherStatus() const
132{
133 if (fSolarRadiation<0 || (double)MTime(-1)-(double)fT>11)
134 return 0;
135
136 Int_t rc = 0;
137 if (fHumidity>80)
138 rc++;
139 if (fWindSpeed>30)
140 rc++;
141 if (fWindSpeed>40)
142 rc++;
143 if (fWindSpeed>50)
144 rc++;
145
146 return rc;
147}
Note: See TracBrowser for help on using the repository browser.