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

Last change on this file since 2514 was 2514, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 2.7 KB
Line 
1#include "MCeCoCom.h"
2
3#include <iostream>
4
5using namespace std;
6
7bool MCeCoCom::InterpreteCmd(TString cmd, TString str)
8{
9 cout << cmd << ": " << str << endl;
10 return true;
11}
12
13bool MCeCoCom::InterpreteStr(TString str)
14{
15 const Ssiz_t tok = str.First(' ');
16 const TString cmd = str(0, tok);
17 str.Remove(0, tok+1);
18
19 if (cmd==(TString)"CC-REPORT" && str.EndsWith("OVER"))
20 {
21 cout << cmd << ": " << str << endl;
22 int y, m, d, h, min, s, ms, len;
23
24 int n=sscanf(str.Data(),
25 "%02d %04d %02d %02d %02d %02d %02d %03d %n",
26 &fCCStatus, &y, &m, &d, &h, &min, &s, &ms, &len);
27 if (n!=8)
28 {
29 cout << "Communication Problem: Wrong number of arguments" << endl;
30 fComStat = kComProblem;
31 return false;
32 }
33 str.Remove(0, len+1);
34
35 fT.SetTimer(y, m, d, h, min, s, ms/1000.);
36
37 // Remove the 29 tokens of the subsystem status
38 // table 12.1 p59
39 for (int i=0; i<29; i++)
40 str.Remove(0, str.First(' ')+1);
41
42 // skip solar_irr_Wm2, wind_speed, UPS
43 float zd, az, dec, ra, temp, hum;
44 n=sscanf(str.Data(),
45 "%f %f %f %f %f %*f %*f %f %*f %n",
46 &zd, &az, &dec, &ra, &temp, &hum, &len);
47 if (n!=6)
48 {
49 cout << "Communication Problem: Wrong number of arguments" << endl;
50 fComStat = kComProblem;
51 return false;
52 }
53 str.Remove(0, len);
54
55 if (str!=(TString)"OVER")
56 {
57 cout << "Communication Problem: Termination (OVER) not found." << endl;
58 fComStat = kComProblem;
59 return false;
60 }
61
62 cout << "Zd/Az: " << zd << "/" << az << " ";
63 cout << "Ra/Dec: " << ra << "/" << dec << " ";
64 cout << "Temp: " << temp << "'C ";
65 cout << "Hum: " << hum << "%" << endl;
66
67 fHumidity = hum;
68 fTemperature = temp;
69
70 fComStat = kCmdReceived;
71 return true;
72 }
73
74 const bool rc = InterpreteCmd(cmd, str);
75 fComStat = rc ? kCmdReceived : kComProblem;
76 return rc;
77}
78
79bool MCeCoCom::Send(const char *str)
80{
81 Timer t;
82 t.Now();
83
84 const char *msg =
85 Form("%s "
86 "%02d %04d %02d %02d %02d %02d %02d %03d "
87 "%02d %04d %02d %02d %02d %02d %02d %03d "
88 "%s\n", (const char*)fCommand,
89 fStatus, t.Year(), t.Month(), t.Day(), t.H(), t.M(), t.S(), t.MilliSec(),
90 fComStat, fT.Year(), fT.Month(), fT.Day(), fT.H(), fT.M(), fT.S(), fT.MilliSec(),
91 str);
92
93 const bool rc = MTcpIpIO::Send(msg);
94 fComStat = rc ? kNoCmdReceived : kComProblem;
95 return rc;
96}
Note: See TracBrowser for help on using the repository browser.