1 | #include "MCeCoCom.h"
|
---|
2 |
|
---|
3 | #include <iostream>
|
---|
4 |
|
---|
5 | using namespace std;
|
---|
6 |
|
---|
7 | bool MCeCoCom::InterpreteCmd(TString cmd, TString str)
|
---|
8 | {
|
---|
9 | cout << cmd << ": " << str << endl;
|
---|
10 | return true;
|
---|
11 | }
|
---|
12 |
|
---|
13 | bool MCeCoCom::InterpreteReport(TString &str)
|
---|
14 | {
|
---|
15 | int y, m, d, h, min, s, ms, len;
|
---|
16 |
|
---|
17 | int n=sscanf(str.Data(),
|
---|
18 | "%02d %04d %02d %02d %02d %02d %02d %03d %n",
|
---|
19 | &fCCStatus, &y, &m, &d, &h, &min, &s, &ms, &len);
|
---|
20 | if (n!=8)
|
---|
21 | {
|
---|
22 | cout << "Communication Problem: Wrong number of arguments" << endl;
|
---|
23 | fComStat = kComProblem;
|
---|
24 | return false;
|
---|
25 | }
|
---|
26 | str.Remove(0, len);
|
---|
27 |
|
---|
28 | fT.Set(y, m, d, h, min, s, ms);
|
---|
29 |
|
---|
30 | // Remove the 30 tokens of the subsystem status
|
---|
31 | // table 12.1 p59
|
---|
32 | for (int i=0; i<30; i++)
|
---|
33 | str.Remove(0, str.First(' ')+1);
|
---|
34 |
|
---|
35 | // skip solar_irr_Wm2, wind_speed, UPS
|
---|
36 | float zd, az, dec, ra, temp, solar, wind, hum;
|
---|
37 | n=sscanf(str.Data(),
|
---|
38 | "%f %f %f %f %f %f %f %f %*f %*f %n",
|
---|
39 | &zd, &az, &dec, &ra, &temp, &solar, &wind, &hum, &len);
|
---|
40 | if (n!=8)
|
---|
41 | {
|
---|
42 | cout << "Communication Problem: Wrong number of arguments" << endl;
|
---|
43 | fComStat = kComProblem;
|
---|
44 | return false;
|
---|
45 | }
|
---|
46 | str.Remove(0, len);
|
---|
47 |
|
---|
48 | if (str!=(TString)"OVER")
|
---|
49 | {
|
---|
50 | cout << "Communication Problem: Termination (OVER) too far away." << endl;
|
---|
51 | fComStat = kComProblem;
|
---|
52 | return false;
|
---|
53 | }
|
---|
54 |
|
---|
55 | cout << "Zd/Az: " << zd << "/" << az << " ";
|
---|
56 | cout << "Ra/Dec: " << ra << "/" << dec << " ";
|
---|
57 | cout << "Temp: " << temp << "'C ";
|
---|
58 | cout << "Hum: " << hum << "% ";
|
---|
59 | cout << "SolRad: " << solar << "W/m² ";
|
---|
60 | cout << "Wind: " << wind << "km/h" << endl;
|
---|
61 |
|
---|
62 | fHumidity = hum;
|
---|
63 | fTemperature = temp;
|
---|
64 | fSolarRadiation = solar;
|
---|
65 | fWindSpeed = wind;
|
---|
66 |
|
---|
67 | fComStat = kCmdReceived;
|
---|
68 | return true;
|
---|
69 | }
|
---|
70 |
|
---|
71 | bool MCeCoCom::InterpreteStr(TString str)
|
---|
72 | {
|
---|
73 | const Ssiz_t tok = str.First(' ');
|
---|
74 | const TString cmd = tok<0 ? str : str(0, tok);
|
---|
75 | if (tok<0)
|
---|
76 | str = "";
|
---|
77 | else
|
---|
78 | str.Remove(0, tok+1);
|
---|
79 |
|
---|
80 | if (cmd==(TString)"CC-REPORT" && str.EndsWith("OVER"))
|
---|
81 | return InterpreteReport(str);
|
---|
82 |
|
---|
83 | const bool rc = InterpreteCmd(cmd, str.Strip(TString::kBoth));
|
---|
84 | fComStat = rc ? kCmdReceived : kComProblem;
|
---|
85 | return rc;
|
---|
86 | }
|
---|
87 |
|
---|
88 | bool MCeCoCom::Send(const char *str)
|
---|
89 | {
|
---|
90 | MTime t;
|
---|
91 | t.Now();
|
---|
92 |
|
---|
93 | UShort_t y1, y2, ms1, ms2;
|
---|
94 | Byte_t mon1, mon2, d1, d2, h1, h2, m1, m2, s1, s2;
|
---|
95 |
|
---|
96 | t.GetDate(y1, mon1, d1);
|
---|
97 | t.GetTime(h1, m1, s1, ms1);
|
---|
98 |
|
---|
99 | fT.GetDate(y2, mon2, d2);
|
---|
100 | fT.GetTime(h2, m2, s2, ms2);
|
---|
101 |
|
---|
102 | const char *msg =
|
---|
103 | Form("%s "
|
---|
104 | "%02d %04d %02d %02d %02d %02d %02d %03d "
|
---|
105 | "%02d %04d %02d %02d %02d %02d %02d %03d "
|
---|
106 | "%s\n", (const char*)fCommand,
|
---|
107 | fStatus, y1, mon1, d1, h1, m1, s1, ms1,
|
---|
108 | fComStat, y2, mon2, d2, h2, m2, s2, ms2,
|
---|
109 | str);
|
---|
110 |
|
---|
111 | const bool rc = MTcpIpIO::Send(msg);
|
---|
112 | fComStat = rc ? kNoCmdReceived : kComProblem;
|
---|
113 | return rc;
|
---|
114 | }
|
---|