Changeset 2517
- Timestamp:
- 11/17/03 13:40:14 (21 years ago)
- Location:
- trunk/MagicSoft/Cosy/tcpip
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/tcpip/MCeCoCom.cc
r2514 r2517 11 11 } 12 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.SetTimer(y, m, d, h, min, s, ms/1000.); 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 13 71 bool MCeCoCom::InterpreteStr(TString str) 14 72 { 15 73 const Ssiz_t tok = str.First(' '); 16 const TString cmd = str(0, tok); 17 str.Remove(0, tok+1); 74 const TString cmd = tok<0 ? str : str(0, tok); 75 if (tok<0) 76 str = ""; 77 else 78 str.Remove(0, tok+1); 18 79 19 80 if (cmd==(TString)"CC-REPORT" && str.EndsWith("OVER")) 20 { 21 cout << cmd << ": " << str << endl; 22 int y, m, d, h, min, s, ms, len; 81 return InterpreteReport(str); 23 82 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); 83 const bool rc = InterpreteCmd(cmd, str.Strip(TString::kBoth)); 75 84 fComStat = rc ? kCmdReceived : kComProblem; 76 85 return rc; -
trunk/MagicSoft/Cosy/tcpip/MCeCoCom.h
r2514 r2517 31 31 ComStatus_t fComStat; // communication status 32 32 33 Float_t fHumidity; // [%] 34 Float_t fTemperature; // degrees celsius 33 Float_t fHumidity; // [%] 34 Float_t fTemperature; // [deg] celsius 35 Float_t fWindSpeed; // [km/h] 36 Float_t fSolarRadiation; // [W/m^2] IR-Radiation 35 37 36 38 virtual bool InterpreteCmd(TString cmd, TString str); 37 39 40 bool InterpreteReport(TString &str); 38 41 bool InterpreteStr(TString str); 39 42 -
trunk/MagicSoft/Cosy/tcpip/MDriveCom.cc
r2384 r2517 5 5 #include "coord.h" 6 6 #include "Slalib.h" 7 #include "MCosy.h" 7 8 8 9 using namespace std; 9 10 11 bool MDriveCom::ReadAngle(TString &str, Double_t &ret) 12 { 13 Char_t sgn; 14 Int_t d, len; 15 UInt_t m; 16 Float_t s; 17 18 // Skip whitespaces before %c and after %f 19 int n=sscanf(str.Data(), " %c %d %d %f %n", &sgn, &d, &m, &s, &len); 20 21 if (n!=4 || (sgn!='+' && sgn!='-')) 22 return false; 23 24 str.Remove(0, len); 25 26 ret = Slalib::Dms2Deg(d, m, s, sgn); 27 return true; 28 } 29 30 bool MDriveCom::ReadPosition(TString &str, Double_t &d1, Double_t &d2) 31 { 32 if (!ReadAngle(str, d1)) 33 return false; 34 35 if (!ReadAngle(str, d2)) 36 return false; 37 38 return true; 39 } 40 41 bool MDriveCom::CommandRADEC(TString &str) 42 { 43 Double_t ra, dec; 44 if (!ReadPosition(str, ra, dec)) 45 { 46 cout << "ERROR - Reading position from RADEC" << endl; 47 return false; 48 } 49 if (!str.IsNull()) 50 { 51 cout << "ERROR - Too many bytes in command RADEC" << endl; 52 return false; 53 } 54 55 cout << "CC-COMMAND: Track " << ra << "h " << dec << "deg '" << str << "'" << endl; 56 57 ra *= 15; // h -> deg 58 59 RaDec rd[2] = { RaDec(ra, dec), RaDec(ra, dec) }; 60 61 cout << "MDriveCom - TRACK... start." << endl; 62 fQueue->PostMsg(WM_TRACK, &rd, sizeof(rd)); 63 cout << "MDriveCom - TRACK... done." << endl; 64 return true; 65 } 66 67 bool MDriveCom::CommandZDAZ(TString &str) 68 { 69 Double_t zd, az; 70 if (!ReadPosition(str, zd, az)) 71 { 72 cout << "ERROR - Reading position from ZDAZ" << endl; 73 return false; 74 } 75 76 if (!str.IsNull()) 77 { 78 cout << "ERROR - Too many bytes in command ZDAZ" << endl; 79 return false; 80 } 81 82 cout << "CC-COMMAND: Move " << zd << "deg " << az << "deg" << endl; 83 84 ZdAz za(zd, az); 85 86 cout << "MDriveCom - POSITION... start." << endl; 87 fQueue->PostMsg(WM_POSITION, &za, sizeof(za)); 88 cout << "MDriveCom - POSITION... done." << endl; 89 return true; 90 } 91 10 92 bool MDriveCom::InterpreteCmd(TString cmd, TString str) 11 93 { 12 if (cmd==(TString)" STOP!")94 if (cmd==(TString)"WAIT" && str.IsNull()) 13 95 { 14 cout << "Stop! " << str << endl; 96 cout << "MDriveCom - WAIT... start." << endl; 97 fQueue->PostMsg(WM_WAIT); 98 cout << "MDriveCom - WAIT... done." << endl; 99 return true; 100 } 101 102 if (cmd==(TString)"STOP!" && str.IsNull()) 103 { 104 cout << "MDriveCom - STOP!... start." << endl; 105 fQueue->PostMsg(WM_STOP); 106 cout << "MDriveCom - STOP!... done." << endl; 15 107 return true; 16 108 } 17 109 18 110 if (cmd==(TString)"RADEC") 111 return CommandRADEC(str); 112 113 if (cmd==(TString)"ZDAZ") 114 return CommandZDAZ(str); 115 116 if (cmd==(TString)"PREPS") 19 117 { 20 cout << " RaDec: " << str << endl;118 cout << "Prepos: " << str << endl; 21 119 return true; 22 120 } 23 if (cmd==(TString)"ZDAZ") 121 122 if (cmd.IsNull() && str.IsNull()) 24 123 { 25 cout << " ZdAz: " << str<< endl;26 return true;124 cout << "Empty command (single '\\n') received." << endl; 125 return false; 27 126 } 28 if (cmd==(TString)"PREPS") 29 { 30 cout << "Preposs: " << str << endl; 31 return true; 32 } 33 cout << "Unknown Command: " << cmd << str << endl; 127 128 cout << "Unknown Command: '" << cmd << "':'" << str << "'" << endl; 34 129 return false; 35 130 } -
trunk/MagicSoft/Cosy/tcpip/MDriveCom.h
r2384 r2517 8 8 class RaDec; 9 9 class ZdAz; 10 class MsgQueue; 10 11 11 12 class MDriveCom : public MCeCoCom 12 13 { 13 14 private: 15 MsgQueue *fQueue; 16 17 bool ReadAngle(TString &str, Double_t &d); 18 bool ReadPosition(TString &str, Double_t &d1, Double_t &d2); 19 14 20 bool InterpreteCmd(TString cmd, TString str); 15 21 void Print(TString &str, Double_t deg) const; 22 23 bool CommandRADEC(TString &str); 24 bool CommandZDAZ(TString &str); 16 25 17 26 public: … … 25 34 }; 26 35 27 MDriveCom(M Log &out=gLog) : MCeCoCom("DRIVE-REPORT", out) {}36 MDriveCom(MsgQueue *q, MLog &out=gLog) : MCeCoCom("DRIVE-REPORT", out), fQueue(q) {} 28 37 29 38 bool SendReport(UInt_t stat, RaDec rd, ZdAz so, ZdAz is, ZdAz er); -
trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.cc
r2514 r2517 40 40 MTcpIpIO::~MTcpIpIO() 41 41 { 42 cout << "Delete TxSocket..." << flush; 42 // 43 // Make sure, that no loop waiting for connection 44 // is running anymore! 45 // 46 Stop(); 47 48 // 49 // Now delete all TCP/IP objects 50 // 51 cout << "Delete TxSocket " << fTxSocket << "..." << flush; 43 52 delete fTxSocket; 44 53 cout << "Done." << endl; 45 54 if (fServSock) 46 55 { 47 cout << "Delete ServSock ..." << flush;56 cout << "Delete ServSock " << fServSock << "..." << flush; 48 57 delete fServSock; 49 58 cout << "Done." << endl; … … 51 60 if (fRxSocket) 52 61 { 53 cout << "Delete RxSocket ..." << flush;62 cout << "Delete RxSocket " << fRxSocket << "..." << flush; 54 63 delete fRxSocket; 55 64 cout << "Done." << endl; … … 123 132 if (fRxSocket==0) 124 133 cout << "Error: TServerSock::Accept" << endl; 125 usleep(1); 126 } 134 usleep(10); 135 } 136 137 // Can happen in case of HasStopFlag() 138 if (fRxSocket==(void*)-1) 139 fRxSocket=NULL; 127 140 128 141 if (fRxSocket==NULL) -
trunk/MagicSoft/Cosy/tcpip/Makefile
r2384 r2517 20 20 # @endcode 21 21 22 INCLUDES = -I. -I../base -I../catalog 22 INCLUDES = -I. -I../base -I../catalog -I../main -I../candrv -I../incl 23 23 24 24 # @code
Note:
See TracChangeset
for help on using the changeset viewer.