Changeset 4076 for trunk/MagicSoft/Cosy/tcpip
- Timestamp:
- 05/15/04 16:46:27 (21 years ago)
- Location:
- trunk/MagicSoft/Cosy/tcpip
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/tcpip/MCeCoCom.cc
r2615 r4076 2 2 3 3 #include <iostream> 4 5 #include "MString.h" 4 6 5 7 using namespace std; … … 53 55 } 54 56 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 57 fHumidity = hum; 63 58 fTemperature = temp; 64 59 fSolarRadiation = solar; 65 60 fWindSpeed = wind; 61 62 cout << "Zd/Az: " << zd << "/" << az << " "; 63 cout << "Ra/Dec: " << ra/15 << "h/" << dec << " "; 64 cout << "SolRad: " << solar << "W/m²" << endl; 66 65 67 66 fComStat = kCmdReceived; … … 86 85 } 87 86 88 bool MCeCoCom::Send(const char * str)87 bool MCeCoCom::Send(const char *cmd, const char *str) 89 88 { 90 89 MTime t; … … 100 99 fT.GetTime(h2, m2, s2, ms2); 101 100 102 const char *msg =103 Form("%s "101 MString msg; 102 msg.Print("%s " 104 103 "%02d %04d %02d %02d %02d %02d %02d %03d " 105 104 "%02d %04d %02d %02d %02d %02d %02d %03d " 106 "%s\n", (const char*)fCommand,105 "%s\n", cmd, 107 106 fStatus, y1, mon1, d1, h1, m1, s1, ms1, 108 107 fComStat, y2, mon2, d2, h2, m2, s2, ms2, … … 113 112 return rc; 114 113 } 114 115 TString MCeCoCom::GetWeather() const 116 { 117 if (fSolarRadiation<0 || (double)MTime(-1)-(double)fT>11) 118 return ""; 119 120 MString str; 121 return str.Print("Temp: %.1f'C Hum: %.1f%% Wind: %.1fkm/h", 122 fTemperature, fHumidity, fWindSpeed); 123 } 124 125 Int_t MCeCoCom::GetWeatherStatus() const 126 { 127 if (fSolarRadiation<0 || (double)MTime(-1)-(double)fT>11) 128 return 0; 129 130 Int_t rc = 0; 131 if (fHumidity>80) 132 rc++; 133 if (fWindSpeed>20) 134 rc++; 135 if (fWindSpeed>30) 136 rc++; 137 if (fWindSpeed>50) 138 rc++; 139 140 return rc; 141 } -
trunk/MagicSoft/Cosy/tcpip/MCeCoCom.h
r2615 r4076 24 24 }; 25 25 26 TString fCommand; // report string of the current system26 //TString fCommand; // report string of the current system 27 27 MTime fT; // time of last report received 28 28 char fStatus; // current status of this system … … 43 43 public: 44 44 MCeCoCom::MCeCoCom(const char *cmd, MLog &out=gLog) 45 : MTcpIpIO(out), fCommand(cmd), fStatus(0), fComStat(kNoCmdReceived)45 : MTcpIpIO(out), /*fCommand(cmd),*/ fStatus(0), fComStat(kNoCmdReceived), fSolarRadiation(-1) 46 46 { 47 47 } 48 48 49 bool Send(const char * str);49 bool Send(const char *cmd, const char *str); 50 50 void SetStatus(Byte_t s) { fStatus=s; } 51 51 52 52 Float_t GetHumidity() const { return fHumidity; } 53 53 Float_t GetTemperature() const { return fTemperature; } 54 Float_t GetWindSpeed() const { return fWindSpeed; } 55 56 TString GetWeather() const; 57 Int_t GetWeatherStatus() const; 54 58 }; 55 59 -
trunk/MagicSoft/Cosy/tcpip/MDriveCom.cc
r2618 r4076 6 6 #include "MAstro.h" 7 7 #include "MCosy.h" 8 #include "MString.h" 8 9 9 10 using namespace std; … … 53 54 } 54 55 55 lout << "CC-COMMAND: Track " << ra << "h " << dec << "deg '" << str 56 << "'" << endl; 56 cout << "CC-COMMAND " << MTime(-1) << " RADEC " << ra << "h " << dec << "d '" << str << "'" << endl; 57 57 58 58 ra *= 15; // h -> deg … … 60 60 RaDec rd[2] = { RaDec(ra, dec), RaDec(ra, dec) }; 61 61 62 cout << "MDriveCom - TRACK... start." << endl;62 //cout << "MDriveCom - TRACK... start." << endl; 63 63 fQueue->PostMsg(WM_TRACK, &rd, sizeof(rd)); 64 cout << "MDriveCom - TRACK... done." << endl;64 //cout << "MDriveCom - TRACK... done." << endl; 65 65 return true; 66 66 } … … 81 81 } 82 82 83 lout << "CC-COMMAND: Move" << zd << "deg " << az << "deg" << endl;83 cout << "CC-COMMAND " << MTime(-1) << " ZDAZ " << zd << "deg " << az << "deg" << endl; 84 84 85 85 ZdAz za(zd, az); 86 86 87 cout << "MDriveCom - POSITION... start." << endl;87 //cout << "MDriveCom - POSITION... start." << endl; 88 88 fQueue->PostMsg(WM_POSITION, &za, sizeof(za)); 89 cout << "MDriveCom - POSITION... done." << endl;89 //cout << "MDriveCom - POSITION... done." << endl; 90 90 return true; 91 91 } … … 95 95 if (cmd==(TString)"WAIT" && str.IsNull()) 96 96 { 97 cout << "MDriveCom - WAIT... start." << endl; 97 //cout << "MDriveCom - WAIT... start." << endl; 98 cout << "CC-COMMAND " << MTime(-1) << " WAIT" << endl; 98 99 fQueue->PostMsg(WM_WAIT); 99 cout << "MDriveCom - WAIT... done." << endl;100 //cout << "MDriveCom - WAIT... done." << endl; 100 101 return true; 101 102 } … … 103 104 if (cmd==(TString)"STOP!" && str.IsNull()) 104 105 { 105 cout << "MDriveCom - STOP!... start." << endl;106 lout << "CC-COMMAND: STOP!" << endl;106 //cout << "MDriveCom - STOP!... start." << endl; 107 cout << "CC-COMMAND " << MTime(-1) << " STOP!" << endl; 107 108 fQueue->PostMsg(WM_STOP); 108 cout << "MDriveCom - STOP!... done." << endl;109 //cout << "MDriveCom - STOP!... done." << endl; 109 110 return true; 110 111 } … … 124 125 if (cmd.IsNull() && str.IsNull()) 125 126 { 126 cout << " Empty command (single '\\n') received." << endl;127 cout << "CC-COMMAND " << MTime(-1) << " Empty command (single '\\n') received." << endl; 127 128 return false; 128 129 } 129 130 130 cout << " Unknown Command: '" << cmd << "':'" << str << "'" << endl;131 cout << "CC-COMMAND " << MTime(-1) << " Syntax error: '" << cmd << "':'" << str << "'" << endl; 131 132 return false; 132 133 } … … 139 140 MAstro::Deg2Dms(deg, sgn, d, m, s); 140 141 141 str += Form("%c %03d %02d %03d ", sgn, d, m, s); 142 MString txt; 143 str += txt.Print("%c %03d %02d %03d ", sgn, d, m, s); 142 144 } 143 145 … … 148 150 // is [deg] 149 151 // er [rad] 152 const MTime t(-1); 150 153 151 154 rd *= kRad2Deg; … … 165 168 SetStatus(4); 166 169 167 MTime t; 168 t.Now(); 170 MString txt; 169 171 170 172 TString str; … … 172 174 Print(str, rd.Dec()); // Dec 173 175 Print(str, 0); // HA 174 str += Form("%12.6f ", t.GetMjd()); // mjd176 str += txt.Print("%12.6f ", t.GetMjd()); // mjd 175 177 Print(str, so.Zd()); 176 178 Print(str, so.Az()); 177 179 Print(str, is.Zd()); 178 180 Print(str, is.Az()); 179 str += Form("%08.3f ", er.Zd());180 str += Form("%08.3f", er.Az());181 str += txt.Print("%08.3f ", er.Zd()); 182 str += txt.Print("%08.3f", er.Az()); 181 183 182 return Send( str);184 return Send("DRIVE-REPORT", str); 183 185 } 186 187 bool MDriveCom::SendStatus(const char *stat) 188 { 189 return Send("DRIVE-STATUS", stat); 190 } -
trunk/MagicSoft/Cosy/tcpip/MDriveCom.h
r2517 r4076 37 37 38 38 bool SendReport(UInt_t stat, RaDec rd, ZdAz so, ZdAz is, ZdAz er); 39 bool SendStatus(const char *stat); 39 40 }; 40 41 -
trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.cc
r2517 r4076 33 33 */ 34 34 35 MTcpIpIO::MTcpIpIO(MLog &out) : MThread(false), Log(out), fRxSocket(NULL), fServSock(NULL) 35 MTcpIpIO::MTcpIpIO(MLog &out) 36 : MThread(false), Log(out), fRxSocket(NULL), fServSock(NULL), fSendInterval(1000) 36 37 { 37 38 fTxSocket = new TSocket("ceco", 7304); … … 49 50 // Now delete all TCP/IP objects 50 51 // 51 cout << "Delete TxSocket " << fTxSocket << "..." << flush;52 //cout << "Delete TxSocket " << fTxSocket << "..." << flush; 52 53 delete fTxSocket; 53 cout << "Done." << endl;54 //cout << "Done." << endl; 54 55 if (fServSock) 55 56 { 56 cout << "Delete ServSock " << fServSock << "..." << flush;57 //cout << "Delete ServSock " << fServSock << "..." << flush; 57 58 delete fServSock; 58 cout << "Done." << endl;59 //cout << "Done." << endl; 59 60 } 60 61 if (fRxSocket) 61 62 { 62 cout << "Delete RxSocket " << fRxSocket << "..." << flush;63 //cout << "Delete RxSocket " << fRxSocket << "..." << flush; 63 64 delete fRxSocket; 64 cout << "Done." << endl;65 //cout << "Done." << endl; 65 66 } 66 67 } … … 68 69 bool MTcpIpIO::Send(const char *msg) 69 70 { 71 const MTime t(-1); 72 73 if ((double)t-(double)fTime<0.001*fSendInterval) 74 return true; 75 76 const Int_t rc = lout.IsOutputDeviceEnabled(MLog::eGui); 77 lout.DisableOutputDevice(MLog::eGui); 78 lout.Lock(); 79 lout << msg << flush; 80 lout.UnLock(); 81 if (rc) 82 lout.EnableOutputDevice(MLog::eGui); 83 84 fTime = t; 85 70 86 if (!fTxSocket->IsValid()) 71 87 return false; … … 112 128 switch (fServSock->GetErrorCode()) 113 129 { 114 case 0: cout << "No error." << endl; break;130 case 0: cout << "No error." << endl; break; 115 131 case -1: cout << "low level socket() call failed." << endl; break; 116 132 case -2: cout << "low level bind() call failed." << endl; break; -
trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.h
r2384 r4076 7 7 #ifndef COSY_Log 8 8 #include "log.h" 9 #endif 10 #ifndef MARS_MTime 11 #include "MTime.h" 9 12 #endif 10 13 … … 19 22 TSocket *fRxSocket; 20 23 TServerSocket *fServSock; 24 25 MTime fTime; 26 Int_t fSendInterval; // [ms] 21 27 22 28 void Clear();
Note:
See TracChangeset
for help on using the changeset viewer.