Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "LdmrsNtpTimeApp.hpp"
00016 #include "../tools/errorhandler.hpp"
00017 #include "../tools/toolbox.hpp"
00018 #include "../tools/MathToolbox.hpp"
00019 #include "../datatypes/Scan.hpp"
00020 #include "../datatypes/Object.hpp"
00021 #include "../datatypes/Msg.hpp"
00022 #include "../datatypes/Measurement.hpp"
00023 #include "../datatypes/Fields.hpp"
00024 #include "../datatypes/EvalCases.hpp"
00025 #include "../datatypes/EvalCaseResults.hpp"
00026 #include "../devices/LD_MRS.hpp"
00027 #include <time.h>
00028
00029 namespace application
00030 {
00031
00032
00033
00034
00035 LdmrsNtpTimeApp::LdmrsNtpTimeApp(Manager* manager) :
00036 m_manager(manager)
00037 {
00038 m_beVerbose = true;
00039
00040
00041 if (m_changeThread.isRunning() == false)
00042 {
00043 m_changeThread.run(this);
00044 }
00045
00046 printInfoMessage("LdmrsNtpTimeApp constructor done.", m_beVerbose);
00047 }
00048
00049
00050
00051
00052 LdmrsNtpTimeApp::~LdmrsNtpTimeApp()
00053 {
00054 printInfoMessage("LdmrsNtpTimeApp says Goodbye!", m_beVerbose);
00055 }
00056
00057
00058
00059
00060
00061 void LdmrsNtpTimeApp::setData(BasicData& data)
00062 {
00063
00064 switch (data.getDatatype())
00065 {
00066 case Datatype_Scan:
00067 {
00068
00069 Scan* scan = dynamic_cast<Scan*>(&data);
00070 const ScannerInfo* info = scan->getScannerInfoByDeviceId(1);
00071
00072 if (info != NULL)
00073 {
00074 const Time& time = info->getStartTimestamp();
00075 printInfoMessage("LdmrsApp::setData(): Scan start time: " + time.toLongString(), m_beVerbose);
00076 }
00077 break;
00078 }
00079 default:
00080 break;
00081 }
00082 }
00083
00084
00085
00086
00087
00088 ntp_time_t LdmrsNtpTimeApp::convertUnixTimeToNtpTime(struct timeval& unixTime)
00089 {
00090 ntp_time_t ntpTime;
00091 ntpTime.second = unixTime.tv_sec + 0x83AA7E80;
00092 ntpTime.fraction = (uint32_t)( (double)(unixTime.tv_usec+1) * (double)(1LL<<32) * 1.0e-6 );
00093 return ntpTime;
00094 }
00095
00096
00097
00098
00099 void LdmrsNtpTimeApp::changeThreadFunction(bool& endThread, UINT16& waitTimeMs)
00100 {
00101 printInfoMessage("LdmrsNtpTimeApp::changeThreadFunction(): Started.", m_beVerbose);
00102 bool result;
00103
00104 devices::LDMRS* ldmrs = dynamic_cast<devices::LDMRS*>(m_manager->getFirstDeviceByType(Sourcetype_LDMRS));
00105
00106
00107 if (ldmrs != NULL)
00108 {
00109
00110 UINT32 sleepTimeMs = 2000;
00111 usleep(sleepTimeMs * 1000);
00112
00113
00114 struct timeval now;
00115 now.tv_sec = 946681200;
00116 now.tv_usec = 0;
00117
00118 ntp_time_t ntpTime = convertUnixTimeToNtpTime(now);
00119 ntpTime.fraction = (uint32_t)0;
00120
00121
00122 result = ldmrs->setNtpTime(ntpTime.second, ntpTime.fraction);
00123
00124 if (result == true)
00125 {
00126
00127 printInfoMessage("LdmrsNtpTimeApp::changeThreadFunction(): Successfully set the NTP time.", true);
00128 }
00129 else
00130 {
00131
00132 printError("LdmrsNtpTimeApp::changeThreadFunction(): Failed to set NTP time!");
00133 }
00134 }
00135 else
00136 {
00137
00138 printError("LdmrsNtpTimeApp::changeThreadFunction(): Failed to get a valid pointer to the MRS, aborting!");
00139 }
00140
00141
00142 endThread = true;
00143 waitTimeMs = 0;
00144 printInfoMessage("LdmrsNtpTimeApp::changeThreadFunction(): All done, leaving.", m_beVerbose);
00145 }
00146
00147 }