| 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::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 | fComStat = kCmdReceived;
|
|---|
| 68 | return true;
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | const bool rc = InterpreteCmd(cmd, str);
|
|---|
| 72 | fComStat = rc ? kCmdReceived : kComProblem;
|
|---|
| 73 | return rc;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | bool MCeCoCom::Send(const char *str)
|
|---|
| 77 | {
|
|---|
| 78 | Timer t;
|
|---|
| 79 | t.Now();
|
|---|
| 80 |
|
|---|
| 81 | const char *msg =
|
|---|
| 82 | Form("%s "
|
|---|
| 83 | "%02d %04d %02d %02d %02d %02d %02d %03d "
|
|---|
| 84 | "%02d %04d %02d %02d %02d %02d %02d %03d "
|
|---|
| 85 | "%s\n", (const char*)fCommand,
|
|---|
| 86 | fStatus, t.Year(), t.Month(), t.Day(), t.H(), t.M(), t.S(), t.MilliSec(),
|
|---|
| 87 | fComStat, fT.Year(), fT.Month(), fT.Day(), fT.H(), fT.M(), fT.S(), fT.MilliSec(),
|
|---|
| 88 | str);
|
|---|
| 89 |
|
|---|
| 90 | const bool rc = MTcpIpIO::Send(msg);
|
|---|
| 91 | fComStat = rc ? kNoCmdReceived : kComProblem;
|
|---|
| 92 | return rc;
|
|---|
| 93 | }
|
|---|