Changeset 2831 in ntrip for trunk/BNC/bnccaster.cpp
- Timestamp:
- Dec 25, 2010, 5:45:22 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/bnccaster.cpp
r2829 r2831 41 41 #include <math.h> 42 42 #include <unistd.h> 43 #include <iostream> 44 #include <iomanip> 45 #include <sstream> 43 46 44 47 #include "bnccaster.h" … … 49 52 #include "bncsettings.h" 50 53 #include "RTCM/GPSDecoder.h" 54 55 using namespace std; 51 56 52 57 // Constructor … … 158 163 long newTime = obs.GPSWeek * 7*24*3600 + iSec; 159 164 160 // Rename the Station161 // ------------------162 strncpy(obs.StatID, staID.constData(),sizeof(obs.StatID));163 obs.StatID[sizeof(obs.StatID)-1] = '\0';164 165 const char begObs[] = "BEGOBS";166 const int begObsNBytes = sizeof(begObs) - 1;167 168 165 // Output into the socket 169 166 // ---------------------- 170 167 if (_uSockets) { 168 169 ostringstream oStr; 170 oStr.setf(ios::showpoint | ios::fixed); 171 oStr << obs.StatID << " " 172 << obs.GPSWeek << " " 173 << setprecision(7) << obs.GPSWeeks << " " 174 << bncRinex::rinexSatLine(obs, false, ' ', ' ', ' ') << endl; 175 176 string hlpStr = oStr.str(); 177 171 178 QMutableListIterator<QTcpSocket*> is(*_uSockets); 172 179 while (is.hasNext()) { 173 180 QTcpSocket* sock = is.next(); 174 181 if (sock->state() == QAbstractSocket::ConnectedState) { 175 bool ok = true; 176 if (myWrite(sock, begObs, begObsNBytes) != begObsNBytes) { 177 ok = false; 178 } 179 int numBytes = sizeof(obs); 180 if (myWrite(sock, (const char*)(&obs), numBytes) != numBytes) { 181 ok = false; 182 } 183 if (!ok) { 182 int numBytes = hlpStr.length(); 183 if (myWrite(sock, hlpStr.c_str(), numBytes) != numBytes) { 184 184 delete sock; 185 185 is.remove(); … … 307 307 void bncCaster::dumpEpochs(long minTime, long maxTime) { 308 308 309 const char begEpoch[] = "BEGEPOCH";310 const char endEpoch[] = "ENDEPOCH";311 312 const int begEpochNBytes = sizeof(begEpoch) - 1;313 const int endEpochNBytes = sizeof(endEpoch) - 1;314 315 309 for (long sec = minTime; sec <= maxTime; sec++) { 316 310 … … 324 318 if (_samplingRate == 0 || sec % _samplingRate == 0) { 325 319 326 if (first) {327 QTime enomtime = QTime(0,0,0).addSecs(static_cast<int>(floor(obs.GPSWeeks+0.5)));328 // emit( newMessage( QString("Epoch %1 dumped").arg(enomtime.toString("HH:mm:ss")).toAscii(), true) ); // weber 329 } 330 // Output into the file331 // --------------------332 if (_out) {333 if ( first) {334 _out->setFieldWidth(1); *_out << begEpoch<< endl;320 if (_out || _sockets) { 321 ostringstream oStr; 322 oStr.setf(ios::showpoint | ios::fixed); 323 oStr << obs.StatID << " " 324 << obs.GPSWeek << " " 325 << setprecision(7) << obs.GPSWeeks << " " 326 << bncRinex::rinexSatLine(obs, false, ' ', ' ', ' ') << endl; 327 if (!it.hasNext()) { 328 oStr << endl; 335 329 } 336 337 *_out << obs.StatID << " " << obs.GPSWeek << " "; 338 _out->setRealNumberPrecision(7); 339 *_out << obs.GPSWeeks << " "; 340 341 *_out << bncRinex::rinexSatLine(obs, ' ', ' ', ' ').c_str() 342 << endl; 343 344 if (!it.hasNext()) { 345 _out->setFieldWidth(1); *_out << endEpoch << endl; 330 string hlpStr = oStr.str(); 331 332 // Output into the File 333 // -------------------- 334 if (_out) { 335 *_out << hlpStr.c_str(); 336 _out->flush(); 346 337 } 347 _out->flush(); 348 } 349 350 // Output into the socket 351 // ---------------------- 352 if (_sockets) { 353 QMutableListIterator<QTcpSocket*> is(*_sockets); 354 while (is.hasNext()) { 355 QTcpSocket* sock = is.next(); 356 if (sock->state() == QAbstractSocket::ConnectedState) { 357 bool ok = true; 358 if (first) { 359 if (myWrite(sock, begEpoch, begEpochNBytes) != begEpochNBytes) { 360 ok = false; 338 339 // Output into the socket 340 // ---------------------- 341 if (_sockets) { 342 QMutableListIterator<QTcpSocket*> is(*_sockets); 343 while (is.hasNext()) { 344 QTcpSocket* sock = is.next(); 345 if (sock->state() == QAbstractSocket::ConnectedState) { 346 int numBytes = hlpStr.length(); 347 if (myWrite(sock, hlpStr.c_str(), numBytes) != numBytes) { 348 delete sock; 349 is.remove(); 361 350 } 362 351 } 363 int numBytes = sizeof(obs); 364 if (myWrite(sock, (const char*)(&obs), numBytes) != numBytes) { 365 ok = false; 366 } 367 if (!it.hasNext()) { 368 if (myWrite(sock, endEpoch, endEpochNBytes) != endEpochNBytes) { 369 ok = false; 370 } 371 } 372 if (!ok) { 352 else if (sock->state() != QAbstractSocket::ConnectingState) { 373 353 delete sock; 374 354 is.remove(); 375 355 } 376 }377 else if (sock->state() != QAbstractSocket::ConnectingState) {378 delete sock;379 is.remove();380 356 } 381 357 }
Note:
See TracChangeset
for help on using the changeset viewer.