1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204 |
- /*
- This software is subject to the license described in the License.txt file
- included with this software distribution. You may not use this file except in compliance
- with this license.
- Copyright (c) Dynastream Innovations Inc. 2012
- All rights reserved.
- */
- #pragma once
- #include "StdAfx.h"
- #include "MSMSensor.h"
- /**************************************************************************
- * MSMSensor::InitializeSim
- *
- * Initialize the simulator variables
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::InitializeSim()
- {
- ulTimerInterval = 250; // in ms - simulates the sensor sending the most relevant information every message period
- dbDispAcumTime = 0;
- dbDispAcumDist = 0;
- usLastEventTime = 0;
- msmData->usInstSpeed1000 = System::Convert::ToUInt16 (this->numericUpDownSpeed->Value * msmData->SPEED_SCALE_FACTOR); // Set the speed to the what is shown in the menu
- eCalStatus = MSM::CalibrationStatus::NONE;
- ulTotalTime = 0;
- // required common pages
- commonData->ulSerialNum = System::Convert::ToUInt32(this->textBox_Glb_SerialNumChange->Text);
- commonData->ucSwVersion = System::Convert::ToByte(this->textBox_Glb_SoftwareVerChange->Text);
- commonData->ucHwVersion = System::Convert::ToByte(this->textBox_Glb_HardwareVerChange->Text);
- commonData->usMfgID = System::Convert::ToUInt16(this->textBox_Glb_ManfIDChange->Text);
- commonData->usModelNum = System::Convert::ToUInt16(this->textBox_Glb_ModelNumChange->Text);
- //battery common page
- commonData->eTimeResolution = CommonData::TimeResolution::TWO;
- commonData->ulOpTime = ulTotalTime;
- commonData->bBattPageEnabled = FALSE;
- // time common page
- commonData->bTimePageEnabled = FALSE;
- commonData->ucSeconds = System::Convert::ToByte(this->numericUpDownSeconds->Value);
- commonData->ucMinutes = System::Convert::ToByte(this->numericUpDownMinutes->Value);
- commonData->ucHours = System::Convert::ToByte(this->numericUpDownHours->Value);
- UpdateDayOfWeek();
- commonData->ucDays = System::Convert::ToByte(this->numericUpDownDay->Value);
- commonData->ucMonth = System::Convert::ToByte(this->numericUpDownMonth->Value);
- commonData->ucYears = System::Convert::ToByte(this->numericUpDownYear->Value);
- UpdateTxPattern();
- UpdateCommonPattern();
- }
- /**************************************************************************
- * MSMSensor::ANT_eventNotification
- *
- * Process ANT channel event
- *
- * ucEventCode_: code of ANT channel event
- * pucEventBuffer_: pointer to buffer containing data received from ANT,
- * or a pointer to the transmit buffer in the case of an EVENT_TX
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::ANT_eventNotification(UCHAR ucEventCode_, UCHAR* pucEventBuffer_)
- {
- switch(ucEventCode_)
- {
- case EVENT_TX:
- HandleTransmit((UCHAR*) pucEventBuffer_);
- UpdateDisplay();
- break;
- case EVENT_RX_ACKNOWLEDGED:
- HandleCalibration((UCHAR*) pucEventBuffer_);
- break;
- case EVENT_TRANSFER_TX_COMPLETED:
- UpdateDisplayAckStatus(msmData->ACK_SUCCESS);
- break;
- case EVENT_ACK_TIMEOUT:
- case EVENT_TRANSFER_TX_FAILED: // intentional fall through
- UpdateDisplayAckStatus(msmData->ACK_FAIL);
- break;
- default:
- break;
- }
- }
- /**************************************************************************
- * MSMSensor::HandleTransmit
- *
- * Encode data generated by simulator for transmission
- *
- * ucPageNum_: The page number to be transmitted
- * pucTxBuffer_: pointer to the transmit buffer
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::HandleTransmit(UCHAR* pucTxBuffer_)
- {
- static ULONG ulMessageCount = 1;
- static UCHAR ucMsmPatternCount = 0;
- static UCHAR ucCommonPatternCount = 0;
- if (ulMessageCount % 65)
- {
- if(ucMsmPatternCount >= ucTxPattern.Count)
- ucMsmPatternCount = 0;
- // send MSM data pages
- switch (ucTxPattern[ucMsmPatternCount])
- {
- case msmData->PAGE_1:
- msmData->EncodeData(msmData->PAGE_1, pucTxBuffer_);
- break;
- case msmData->PAGE_2:
- msmData->EncodeData(msmData->PAGE_2, pucTxBuffer_);
- break;
- case msmData->PAGE_3:
- msmData->EncodeData(msmData->PAGE_3, pucTxBuffer_);
- break;
- default:
- break;
- }
- ucMsmPatternCount++;
- //if (ucMsmPatternCount >= ucTxPattern.Count)
- // ucMsmPatternCount = 0; // reset the message count at the end
- }
- else
- {
- if(ucCommonPatternCount >= ucCommonPattern.Count)
- ucCommonPatternCount = 0;
- switch(ucCommonPattern[ucCommonPatternCount])
- {
- case commonData->PAGE80:
- commonData->Encode(commonData->PAGE80, pucTxBuffer_);
- break;
- case commonData->PAGE81:
- commonData->Encode(commonData->PAGE81, pucTxBuffer_);
- break;
- case commonData->PAGE82:
- commonData->Encode(commonData->PAGE82, pucTxBuffer_);
- break;
- case commonData->PAGE83:
- commonData->Encode(commonData->PAGE83, pucTxBuffer_);
- break;
- }
- ucCommonPatternCount++;
- }
- ulMessageCount++;
- static UCHAR ucTimeCount = 0;
- // update the batt op time every second
- if (ucTimeCount == 3)
- {
- ulTotalTime++;
- commonData->ulOpTime = ulTotalTime / (UCHAR) commonData->eTimeResolution;
- ucTimeCount = 0;
- }
- else
- ucTimeCount++;
- }
- /**************************************************************************
- * MSMSensor::Update Display
- *
- * Update the GUI with all the changes
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::UpdateDisplay()
- {
- this->labelAcumTime->Text = dbDispAcumTime.ToString("N2"); // Update the accumulated time label
- this->labelAcumDistance->Text = dbDispAcumDist.ToString("N2"); // Update the accumulated distance label
- // the tx variables will show the raw transmitted data decoded, but not scaled into proper units
- this->labelTxDist->Text = msmData->usAcumDist10.ToString(); // Update the tx box distance label
- this->labelTxTime->Text = msmData->usAcumTime1024.ToString(); // update the tx box time label
- this->labelTxSpeed->Text = msmData->usInstSpeed1000.ToString(); // update the tx box speed label
- if (msmData->IsCalScaleValid(msmData->usScaleFactor10000))
- this->labelCurrentScaleFactor->Text = ((double) msmData->usScaleFactor10000 / msmData->CAL_SF_SCALE_FACTOR).ToString("N4");
- else
- this->labelCurrentScaleFactor->Text = "Invalid";
- if (msmData->bPage2Enabled)
- {
- this->labelTxLat->Text = msmData->slLatitude_SC.ToString();
- this->lableTxLon->Text = msmData->slLongitude_SC.ToString();
- }
- if (msmData->bPage3Enabled)
- {
- this->labelTxElev->Text = msmData->usElevation5.ToString();
- this->labelTxHeading->Text = msmData->usHeading10.ToString();
- this->labelTxFix->Text = msmData->ucFixType.ToString();
- }
- // update the operating time for the battery common page
- this->label_Bat_ElpTimeDisplay->Text = ulTotalTime.ToString();
- }
- /**************************************************************************
- * MSMSensor::onTimerTock
- *
- * Simulates a sensor event, updating simulator data based on this event
- * Modifications to the timer interval are applied immediately after this
- * at ANTChannel
- *
- * usEventTime_: current time (ms)
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::onTimerTock(USHORT eventTime)
- {
- msmData->usAcumTime1024 += (USHORT) (ulTimerInterval << 10 / 1000); // time base is 1/1024 second
- dbDispAcumTime += (double) ulTimerInterval / 1000; // Update the display time
- dbDispAcumDist += (double) (msmData->usInstSpeed1000 * ulTimerInterval) / 1000000;
- msmData->usAcumDist10 = (USHORT) (dbDispAcumDist * 10); // distance is transmitted in 0.1m intervals
- }
- /**************************************************************************
- * MSMSensor::HandleCalibration
- *
- * Handlest teh Calibration mode of the MSM
- *
- * pucEventBuffer_: data buffer after receving an acknowleged message
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::HandleCalibration(UCHAR* pucEventBuffer_)
- {
- msmData->Decode(pucEventBuffer_);
- // check if the sensor supports calibration
- if (this->checkBoxCalibrationSupport->Checked == FALSE)
- {
- // set scale factor to unsupported value
- msmData->usScaleFactor10000 = msmData->CAL_SCALE_INVALID;
- msmData->ucMode = msmData->CAL_MODE_INVALID;
- eCalStatus = MSM::CalibrationStatus::NONE;
- // send the response
- msmData->EncodeData(msmData->PAGE_CALIBRATION, pucEventBuffer_);
- requestAckMsg(pucEventBuffer_);
- this->labelCalibrationProgress->Text = "Calibration is not supported";
- this->labelCalibrationProgress->BackColor = System::Drawing::SystemColors::Control;
- }
- else
- {
- // check if the mode is supported
- if (this->checkBoxModeStorageSupport->Checked == FALSE)
- {
- // only if mode storage is not supported does the mode need to change from the decoded value
- msmData->ucMode = msmData->CAL_MODE_INVALID;
- }
- // check if it is a Set Scale Command
- if ((msmData->usScaleFactor10000 != msmData->CAL_SCALE_REQUEST) && (msmData->IsCalScaleValid(msmData->usScaleFactor10000)))
- {
- // set the status
- eCalStatus = MSM::CalibrationStatus::SET_SCALE_IN_PROGRESS;
- // calibration request response state
- this->labelCalibrationProgress->Text = "Set Scale Factor Received";
- this->labelCalibrationProgress->BackColor = System::Drawing::Color::Yellow;
-
- // send the calibration request response
- msmData->EncodeData(msmData->PAGE_CALIBRATION, pucEventBuffer_);
- requestAckMsg(pucEventBuffer_);
- // update the display values
- this->labelCalibrationProgress->Text = "Scale Factor \nConfirmation Sent";
- this->labelCalibrationProgress->BackColor = System::Drawing::Color::Orange;
- }
- // check if it is a calibration request
- if (msmData->usScaleFactor10000 == msmData->CAL_SCALE_REQUEST && eCalStatus != MSM::CalibrationStatus::SET_SCALE_IN_PROGRESS)
- {
- // set the status
- eCalStatus = MSM::CalibrationStatus::REQUEST_IN_PROGRESS;
- // calibration request response state
- this->labelCalibrationProgress->Text = "Calibration Request Received";
- this->labelCalibrationProgress->BackColor = System::Drawing::Color::Yellow;
- msmData->usScaleFactor10000 = msmData->CAL_SCALE_CONF;
- // the mode will already be decoded by msmData->Decode()
- // send the calibration request response
- msmData->EncodeData(msmData->PAGE_CALIBRATION, pucEventBuffer_);
- requestAckMsg(pucEventBuffer_);
-
- // update the display values
- this->labelCalibrationProgress->Text = "Calibration Request \nResponse Sent";
- this->labelCalibrationProgress->BackColor = System::Drawing::Color::Orange;
- }
- }
- // update the display variables
- UpdateCalibDisplay();
- }
- /**************************************************************************
- * MSMSensor::UpdateCalibDisplay
- *
- * Adjusts the current speed via the GUI
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::UpdateCalibDisplay()
- {
- ULONG ulNewSpeed;
- // update the mode label
- if (msmData->IsCalModeValid(msmData->ucMode))
- this->labelCurrentMode->Text = msmData->ucMode.ToString();
- else
- this->labelCurrentMode->Text = "Mode Invalid";
-
- // update the scale factor label
- if (msmData->IsCalScaleValid(msmData->usScaleFactor10000))
- this->labelCurrentScaleFactor->Text = ((double) msmData->usScaleFactor10000 / msmData->CAL_SF_SCALE_FACTOR).ToString("N4");
- else
- this->labelCurrentScaleFactor->Text = "Scale Factor Invalid";
- if (eCalStatus != MSM::CalibrationStatus::COMPLETE)
- {
- // set the scale to change the speed and distance data that is now sent
- if (msmData->IsCalScaleValid(msmData->usScaleFactor10000))
- {
- // calc the new speed
- ulNewSpeed = System::Convert::ToUInt32(this->numericUpDownSpeed->Value * msmData->SPEED_SCALE_FACTOR * (System::Convert::ToDecimal(msmData->usScaleFactor10000) / msmData->CAL_SF_SCALE_FACTOR));
- // check if the new speed is within the range
- if (ulNewSpeed < msmData->INVALID_SPEED)
- msmData->usInstSpeed1000 = System::Convert::ToUInt16(this->numericUpDownSpeed->Value * msmData->SPEED_SCALE_FACTOR * (System::Convert::ToDecimal(msmData->usScaleFactor10000) / msmData->CAL_SF_SCALE_FACTOR));
- else
- {
- msmData->usInstSpeed1000 = msmData->MAX_SPEED;
- MessageBox::Show("Maximum speed reached. \nTx speed set to max speed: 65.534 m/s", "Speed Error", MessageBoxButtons::OK,MessageBoxIcon::Error, MessageBoxDefaultButton::Button1);
- }
- }
- else
- msmData->usInstSpeed1000 = System::Convert::ToUInt16(this->numericUpDownSpeed->Value * msmData->SPEED_SCALE_FACTOR);
- }
- // if process completed
- else if (eCalStatus == MSM::CalibrationStatus::COMPLETE)
- {
- this->labelCalibrationProgress->Text = "Calibration Process \nSuccessfully Completed";
- this->labelCalibrationProgress->BackColor = System::Drawing::SystemColors::Control;
- }
- }
- /**************************************************************************
- * MSMSensor::UpdateDisplayAckStatus
- *
- * Adjusts the GUI depending on the ACK status of the tx message
- *
- * UCHAR status_: gives the success or fail status of the tx message
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::UpdateDisplayAckStatus(UCHAR status_)
- {
- switch (eCalStatus)
- {
- case MSM::CalibrationStatus::REQUEST_IN_PROGRESS:
- if (status_ == msmData->ACK_FAIL)
- {
- this->labelCalibrationProgress->Text = "Cal Request Response \nFailed to Transmit";
- this->labelCalibrationProgress->BackColor = System::Drawing::Color::Red;
- }
- if (status_ == msmData->ACK_SUCCESS)
- {
- this->labelCalibrationProgress->Text = "Cal Request Response \nTransmission Success";
- this->labelCalibrationProgress->BackColor = System::Drawing::Color::Green;
- }
- break;
-
- case MSM::CalibrationStatus::SET_SCALE_IN_PROGRESS:
- if (status_ == msmData->ACK_FAIL)
- {
- this->labelCalibrationProgress->Text = "Set Scale Response \nFailed to Transmit";
- this->labelCalibrationProgress->BackColor = System::Drawing::Color::Red;
- }
- if (status_ == msmData->ACK_SUCCESS)
- {
- this->labelCalibrationProgress->Text = "Set Scale Response \nTransmission Success";
- this->labelCalibrationProgress->BackColor = System::Drawing::Color::Green;
-
- // update the display to tell the user the calibration has successfully finished
- eCalStatus = MSM::CalibrationStatus::COMPLETE;
- UpdateCalibDisplay();
- }
- break;
- default:
- break;
- }
- }
- /**************************************************************************
- * MSMSensor::numericUpDownSpeed_ValueChanged
- *
- * Adjusts the current speed via the GUI
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::numericUpDownSpeed_ValueChanged(System::Object^ sender, System::EventArgs^ e)
- {
- ULONG ulNewSpeed;
- if (msmData->IsCalScaleValid(msmData->usScaleFactor10000))
- {
- // calc the new speed
- ulNewSpeed = System::Convert::ToUInt32(this->numericUpDownSpeed->Value * msmData->SPEED_SCALE_FACTOR * (System::Convert::ToDecimal(msmData->usScaleFactor10000) / msmData->CAL_SF_SCALE_FACTOR));
- // check if the new speed is within the range
- if (ulNewSpeed < msmData->INVALID_SPEED)
- msmData->usInstSpeed1000 = System::Convert::ToUInt16(this->numericUpDownSpeed->Value * msmData->SPEED_SCALE_FACTOR * (System::Convert::ToDecimal(msmData->usScaleFactor10000) / msmData->CAL_SF_SCALE_FACTOR));
- else
- {
- msmData->usInstSpeed1000 = msmData->MAX_SPEED;
- MessageBox::Show("Maximum speed reached. \nTx speed set to max speed: 65.534 m/s", "Speed Error", MessageBoxButtons::OK,MessageBoxIcon::Error, MessageBoxDefaultButton::Button1);
- }
- }
- else
- msmData->usInstSpeed1000 = System::Convert::ToUInt16(this->numericUpDownSpeed->Value * msmData->SPEED_SCALE_FACTOR);
- }
- /**************************************************************************
- * MSMSensor::checkBoxTxSpeed_CheckedChanged
- *
- * Adjusts the value if the speed data is invalid or not
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::checkBoxTxSpeed_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
- {
- if (this->checkBoxTxSpeed->Checked == FALSE)
- msmData->usInstSpeed1000 = msmData->INVALID_SPEED;
- else
- msmData->usInstSpeed1000 = System::Convert::ToUInt16(this->numericUpDownSpeed->Value * msmData->SPEED_SCALE_FACTOR);
- }
- /**************************************************************************
- * MSMSensor::checkBoxCalibrationSupport_CheckedChanged
- *
- * Sets the calibration to be enabled or not
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::checkBoxCalibrationSupport_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
- {
- if (this->checkBoxCalibrationSupport->Checked == FALSE)
- {
- msmData->usScaleFactor10000 = msmData->CAL_SCALE_INVALID;
- msmData->ucMode = msmData->CAL_MODE_INVALID;
- this->checkBoxModeStorageSupport->Checked = FALSE;
- this->checkBoxModeStorageSupport->Enabled = FALSE;
- // make the speed not use a scale factor any longer
- msmData->usInstSpeed1000 = System::Convert::ToUInt16(this->numericUpDownSpeed->Value * msmData->SPEED_SCALE_FACTOR);
- }
- else
- {
- this->checkBoxModeStorageSupport->Enabled = TRUE;
- }
- }
- /**************************************************************************
- * MSMSensor::checkBoxModeStorageSupport_CheckedChanged
- *
- * Sets the calibration to be enabled or not
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::checkBoxModeStorageSupport_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
- {
- if (this->checkBoxModeStorageSupport->Checked == FALSE)
- msmData->ucMode = msmData->CAL_MODE_INVALID;
- }
- /**************************************************************************
- * MSMSensor::checkBoxSecondaryData_CheckedChanged
- *
- * Enables and sets the GPS parameters
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::checkBoxSecondaryData_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
- {
- if (this->checkBoxSecondaryData->Checked == TRUE)
- {
- this->numericUpDownLatitude->Enabled = TRUE;
- this->numericUpDownLongitude->Enabled = TRUE;
- this->checkBoxPage3Enable->Enabled = TRUE;
- msmData->slLatitude_SC = System::Convert::ToInt32(double (this->numericUpDownLatitude->Value) * msmData->SEMI_CIRCLE_CONVERSION);
- msmData->slLongitude_SC = System::Convert::ToInt32(double (this->numericUpDownLongitude->Value) * msmData->SEMI_CIRCLE_CONVERSION);
- }
- else
- {
- this->numericUpDownLatitude->Enabled = FALSE;
- this->numericUpDownLongitude->Enabled = FALSE;
- msmData->slLatitude_SC = 0;
- msmData->slLongitude_SC = 0;
- // also disable the page 3 stuff
- this->checkBoxPage3Enable->Enabled = FALSE;
- this->checkBoxPage3Enable->Checked = FALSE;
- this->groupBoxPage3->Enabled = FALSE;
- }
- UpdateTxPattern();
- }
- /**************************************************************************
- * MSMSensor::checkBoxPage3Enable_CheckedChanged
- *
- * Sets the calibration to be enabled or not
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::checkBoxPage3Enable_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
- {
- if (this->checkBoxPage3Enable->Checked == TRUE)
- {
- this->groupBoxPage3->Enabled = TRUE;
- msmData->usElevation5 = System::Convert::ToUInt16((this->numericUpDownElevation->Value + msmData->ELEVATION_OFFSET) * msmData->ELEVATION_SCALE_FACTOR);
- msmData->usHeading10 = System::Convert::ToUInt16(this->numericUpDownHeading->Value * msmData->HEADING_SCALE_FACTOR);
- UpdateGpsFixType();
- }
- else
- {
- this->groupBoxPage3->Enabled = FALSE;
- }
- UpdateTxPattern();
- }
- /**************************************************************************
- * MSMSensor::UpdateGpsFixType
- *
- * Updates the gps fix based on the settings in the combo box
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::UpdateGpsFixType()
- {
- if (this->comboBoxGPSFix->SelectedItem->Equals("None"))
- msmData->ucFixType = System::Convert::ToByte(MSM::GpsFix::NONE);
- else if (this->comboBoxGPSFix->SelectedItem->Equals("Propagating"))
- msmData->ucFixType = System::Convert::ToByte(MSM::GpsFix::PROPAGATING);
- else if (this->comboBoxGPSFix->SelectedItem->Equals("Searching"))
- msmData->ucFixType = System::Convert::ToByte(MSM::GpsFix::SEARCHING);
- else if (this->comboBoxGPSFix->SelectedItem->Equals("Last Known"))
- msmData->ucFixType = System::Convert::ToByte(MSM::GpsFix::LAST_KNOWN);
- else if (this->comboBoxGPSFix->SelectedItem->Equals("3D"))
- msmData->ucFixType = System::Convert::ToByte(MSM::GpsFix::THREE_D);
- else if (this->comboBoxGPSFix->SelectedItem->Equals("3D WAAS"))
- msmData->ucFixType = System::Convert::ToByte(MSM::GpsFix::THREE_D_WAAS);
- else if (this->comboBoxGPSFix->SelectedItem->Equals("3D Differential"))
- msmData->ucFixType = System::Convert::ToByte(MSM::GpsFix::THREE_D_DIF);
- else if (this->comboBoxGPSFix->SelectedItem->Equals("2D"))
- msmData->ucFixType = System::Convert::ToByte(MSM::GpsFix::TWO_D);
- else if (this->comboBoxGPSFix->SelectedItem->Equals("2D WAAS"))
- msmData->ucFixType = System::Convert::ToByte(MSM::GpsFix::TWO_D_WAAS);
- else if (this->comboBoxGPSFix->SelectedItem->Equals("2D Differential"))
- msmData->ucFixType = System::Convert::ToByte(MSM::GpsFix::TWO_D_DIF);
- else if (this->comboBoxGPSFix->SelectedItem->Equals("Invalid"))
- msmData->ucFixType = System::Convert::ToByte(MSM::GpsFix::INVALID);
- }
- /**************************************************************************
- * MSMSensor::numericUpDownLongitude_ValueChanged
- *
- * Adjusts the current longitude via the GUI
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::numericUpDownLongitude_ValueChanged(System::Object^ sender, System::EventArgs^ e)
- {
- msmData->slLongitude_SC = System::Convert::ToInt32(double (this->numericUpDownLongitude->Value) * msmData->SEMI_CIRCLE_CONVERSION);
- }
- /**************************************************************************
- * MSMSensor::numericUpDownLatitude_ValueChanged
- *
- * Adjusts the current latitude via the GUI
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::numericUpDownLatitude_ValueChanged(System::Object^ sender, System::EventArgs^ e)
- {
- msmData->slLatitude_SC = System::Convert::ToInt32(double (this->numericUpDownLatitude->Value) * msmData->SEMI_CIRCLE_CONVERSION);
- }
- /**************************************************************************
- * MSMSensor::numericUpDownElevation_ValueChanged
- *
- * Adjusts the current elevation via the GUI
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::numericUpDownElevation_ValueChanged(System::Object^ sender, System::EventArgs^ e)
- {
- msmData->usElevation5 = System::Convert::ToUInt16((this->numericUpDownElevation->Value + msmData->ELEVATION_OFFSET) * msmData->ELEVATION_SCALE_FACTOR);
- }
- /**************************************************************************
- * MSMSensor::numericUpDownHeading_ValueChanged
- *
- * Adjusts the current heading via the GUI
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::numericUpDownHeading_ValueChanged(System::Object^ sender, System::EventArgs^ e)
- {
- msmData->usHeading10 = System::Convert::ToUInt16(this->numericUpDownHeading->Value * msmData->HEADING_SCALE_FACTOR);
- }
- /**************************************************************************
- * MSMSensor::comboBoxGPSFix_SelectedIndexChanged
- *
- * Adjusts the current heading via the GUI
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::comboBoxGPSFix_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e)
- {
- UpdateGpsFixType();
- }
- /**************************************************************************
- * MSMSensor::button_Glb_GlobalDataUpdate_Click
- *
- * Adjusts the global pages 80 and 81 via the GUI
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::button_Glb_GlobalDataUpdate_Click(System::Object^ sender, System::EventArgs^ e)
- {
- this->label_Error->Visible = false;
- // required common pages
- try{
- if(this->checkBox_InvalidSerial->Checked)
- commonData->ulSerialNum = 0xFFFFFFFF;
- else
- commonData->ulSerialNum = System::Convert::ToUInt32(this->textBox_Glb_SerialNumChange->Text);
- commonData->ucSwVersion = System::Convert::ToByte(this->textBox_Glb_SoftwareVerChange->Text);
- commonData->ucHwVersion = System::Convert::ToByte(this->textBox_Glb_HardwareVerChange->Text);
- commonData->usMfgID = System::Convert::ToUInt16(this->textBox_Glb_ManfIDChange->Text);
- commonData->usModelNum = System::Convert::ToUInt16(this->textBox_Glb_ModelNumChange->Text);
- }
- catch(...)
- {
- label_Error->Visible = true;
- }
- }
- /**************************************************************************
- * MSMSensor::checkBox_Bat_Status_CheckedChanged
- *
- * Enables and disables the battery voltage GUI elements
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::checkBox_Bat_Status_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
- {
- if (this->checkBox_Bat_Status->Checked == TRUE)
- {
- commonData->bBattPageEnabled = TRUE;
- this->comboBoxBatStatus->Enabled = TRUE;
- this->label_Bat_ElpTimeDisplay->Enabled = TRUE;
- this->textBox_Bat_ElpTimeChange->Enabled = TRUE;
- this->checkBox_Bat_Voltage->Enabled = TRUE;
- this->checkBox_Bat_Voltage->Checked = TRUE;
- this->numericUpDown_Bat_VoltFrac->Enabled = TRUE;
- this->numericUpDown_Bat_VoltInt->Enabled = TRUE;
- this->groupBox_Resol->Enabled = TRUE;
- this->button_Bat_ElpTimeUpdate->Enabled = TRUE;
- // update the variables
- UpdateBatStatus();
- if (this->radioButton_Bat_Elp16Units->Checked)
- commonData->eTimeResolution = CommonData::TimeResolution::SIXTEEN;
-
- if (this->radioButton_Bat_Elp2Units->Checked)
- commonData->eTimeResolution = CommonData::TimeResolution::TWO;
- commonData->ulOpTime = ulTotalTime / (UCHAR) commonData->eTimeResolution;
- commonData->usBatVoltage256 = ((USHORT) System::Convert::ToByte(this->numericUpDown_Bat_VoltInt->Value)) << 8 | (commonData->usBatVoltage256 & 0xFF); // Integer portion in high byte
- commonData->usBatVoltage256 = System::Convert::ToByte(this->numericUpDown_Bat_VoltFrac->Value) | (commonData->usBatVoltage256 & 0xFF00); // Fractional portion in low byte
- }
- else
- {
- commonData->bBattPageEnabled = FALSE;
- this->comboBoxBatStatus->Enabled = FALSE;
- this->label_Bat_ElpTimeDisplay->Enabled = FALSE;
- this->textBox_Bat_ElpTimeChange->Enabled = FALSE;
- this->checkBox_Bat_Voltage->Enabled = FALSE;
- this->checkBox_Bat_Voltage->Checked = FALSE;
- this->numericUpDown_Bat_VoltFrac->Enabled = FALSE;
- this->numericUpDown_Bat_VoltInt->Enabled = FALSE;
- this->groupBox_Resol->Enabled = FALSE;
- this->button_Bat_ElpTimeUpdate->Enabled = FALSE;
- }
- UpdateCommonPattern();
- }
- /**************************************************************************
- * MSMSensor::checkBox_Bat_Voltage_CheckedChanged
- *
- * Enables and disables the battery voltage numeric upDown
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::checkBox_Bat_Voltage_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
- {
- if (this->checkBox_Bat_Voltage->Checked == TRUE)
- {
- this->numericUpDown_Bat_VoltInt->Enabled = TRUE;
- this->numericUpDown_Bat_VoltFrac->Enabled = TRUE;
- commonData->usBatVoltage256 = ((USHORT) System::Convert::ToByte(this->numericUpDown_Bat_VoltInt->Value)) << 8 | (commonData->usBatVoltage256 & 0xFF); // Integer portion in high byte
- commonData->usBatVoltage256 = System::Convert::ToByte(this->numericUpDown_Bat_VoltFrac->Value) | (commonData->usBatVoltage256 & 0xFF00); // Fractional portion in low byte
- }
- else
- {
- this->numericUpDown_Bat_VoltInt->Enabled = FALSE;
- this->numericUpDown_Bat_VoltFrac->Enabled = FALSE;
- commonData->usBatVoltage256 = commonData->BATTERY_VOLTAGE_INVALID;
- }
- }
- /**************************************************************************
- * MSMSensor::numericUpDown_Bat_VoltInt_ValueChanged
- *
- * changes the coarse battery voltage
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::numericUpDown_Bat_VoltInt_ValueChanged(System::Object^ sender, System::EventArgs^ e)
- {
- commonData->usBatVoltage256 = ((USHORT) System::Convert::ToByte(this->numericUpDown_Bat_VoltInt->Value)) << 8 | (commonData->usBatVoltage256 & 0xFF); // Integer portion in high byte
- }
- /**************************************************************************
- * MSMSensor::numericUpDown_Bat_VoltFrac_ValueChanged
- *
- * changes the fractional battery voltage
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::numericUpDown_Bat_VoltFrac_ValueChanged(System::Object^ sender, System::EventArgs^ e)
- {
- commonData->usBatVoltage256 = System::Convert::ToByte(this->numericUpDown_Bat_VoltFrac->Value) | (commonData->usBatVoltage256 & 0xFF00); // Fractional portion in low byte
- }
- /**************************************************************************
- * MSMSensor::comboBoxBatStatus_SelectedIndexChanged
- *
- * changes the battery status
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::comboBoxBatStatus_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e)
- {
- UpdateBatStatus();
- }
- /**************************************************************************
- * MSMSensor::UpdateBatStatus
- *
- * Updates the battery status
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::UpdateBatStatus()
- {
- if (this->comboBoxBatStatus->Text->Equals("New"))
- {
- commonData->eBatStatus = CommonData::BatStatus::NEW;
- }
- else if (this->comboBoxBatStatus->Text->Equals("Good"))
- {
- commonData->eBatStatus = CommonData::BatStatus::GOOD;
- }
- else if (this->comboBoxBatStatus->Text->Equals("Ok"))
- {
- commonData->eBatStatus = CommonData::BatStatus::OK;
- }
- else if (this->comboBoxBatStatus->Text->Equals("Low"))
- {
- commonData->eBatStatus = CommonData::BatStatus::LOW;
- }
- else if (this->comboBoxBatStatus->Text->Equals("Critical"))
- {
- commonData->eBatStatus = CommonData::BatStatus::CRITICAL;
- }
- else if (this->comboBoxBatStatus->Text->Equals("Invalid"))
- {
- commonData->eBatStatus = CommonData::BatStatus::INVALID;
- }
- }
- /**************************************************************************
- * MSMSensor::button_Bat_ElpTimeUpdate_Click
- *
- * changes the elapsed battery time
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::button_Bat_ElpTimeUpdate_Click(System::Object^ sender, System::EventArgs^ e)
- {
- ulTotalTime = System::Convert::ToUInt32(this->textBox_Bat_ElpTimeChange->Text);
- commonData->ulOpTime = ulTotalTime / (UCHAR) commonData->eTimeResolution;
- }
- /**************************************************************************
- * MSMSensor::radioButton_Bat_Elp2Units_CheckedChanged
- *
- * changes the elapsed battery time units
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::radioButton_Bat_Elp2Units_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
- {
- if (this->radioButton_Bat_Elp2Units->Checked)
- commonData->eTimeResolution = CommonData::TimeResolution::TWO;
- }
- /**************************************************************************
- * MSMSensor::radioButton_Bat_Elp2Units_CheckedChanged
- *
- * changes the elapsed battery time units
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::radioButton_Bat_Elp16Units_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
- {
- if (this->radioButton_Bat_Elp16Units->Checked)
- commonData->eTimeResolution = CommonData::TimeResolution::SIXTEEN;
- }
- /**************************************************************************
- * MSMSensor::checkBoxEnableDateTime_CheckedChanged
- *
- * Checks if the date and time page should be enabled and sent
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::checkBoxEnableDateTime_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
- {
- if (this->checkBoxEnableDateTime->Checked == TRUE)
- {
- // enable all of the parameters
- commonData->bTimePageEnabled = TRUE;
- this->panelTimeDate->Enabled = TRUE;
- }
- else
- {
- commonData->bTimePageEnabled = FALSE;
- this->panelTimeDate->Enabled = FALSE;
- }
- UpdateCommonPattern();
- }
- /**************************************************************************
- * MSMSensor::comboBoxDayOfWeek_SelectedIndexChanged
- *
- * Sets the day of the week
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::comboBoxDayOfWeek_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e)
- {
- UpdateDayOfWeek();
- }
- /**************************************************************************
- * MSMSensor::UpdateDayOfWeek
- *
- * Sets the day of the week
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::UpdateDayOfWeek()
- {
- if (this->comboBoxDayOfWeek->Text->Equals("Monday"))
- commonData->eDayOfWeek = CommonData::DayOfWeek::MONDAY;
- else if (this->comboBoxDayOfWeek->Text->Equals("Tuesday"))
- commonData->eDayOfWeek = CommonData::DayOfWeek::TUESDAY;
- else if (this->comboBoxDayOfWeek->Text->Equals("Wednesday"))
- commonData->eDayOfWeek = CommonData::DayOfWeek::WEDNESDAY;
- else if (this->comboBoxDayOfWeek->Text->Equals("Thursday"))
- commonData->eDayOfWeek = CommonData::DayOfWeek::THURSDAY;
- else if (this->comboBoxDayOfWeek->Text->Equals("Friday"))
- commonData->eDayOfWeek = CommonData::DayOfWeek::FRIDAY;
- else if (this->comboBoxDayOfWeek->Text->Equals("Saturday"))
- commonData->eDayOfWeek = CommonData::DayOfWeek::SATURDAY;
- else if (this->comboBoxDayOfWeek->Text->Equals("Sunday"))
- commonData->eDayOfWeek = CommonData::DayOfWeek::SUNDAY;
- else if (this->comboBoxDayOfWeek->Text->Equals("Invalid"))
- commonData->eDayOfWeek = CommonData::DayOfWeek::INVALID;
- }
- /**************************************************************************
- * MSMSensor::numericUpDownDay_ValueChanged
- *
- * Sets value of the day
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::numericUpDownDay_ValueChanged(System::Object^ sender, System::EventArgs^ e)
- {
- commonData->ucDays = System::Convert::ToByte(this->numericUpDownDay->Value);
- }
- /**************************************************************************
- * MSMSensor::numericUpDownMonth_ValueChanged
- *
- * Sets value of the month
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::numericUpDownMonth_ValueChanged(System::Object^ sender, System::EventArgs^ e)
- {
- commonData->ucMonth = System::Convert::ToByte(this->numericUpDownMonth->Value);
- }
- /**************************************************************************
- * MSMSensor::numericUpDownYear_ValueChanged
- *
- * Sets value of the year
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::numericUpDownYear_ValueChanged(System::Object^ sender, System::EventArgs^ e)
- {
- commonData->ucYears = System::Convert::ToByte(this->numericUpDownYear->Value);
- }
- /**************************************************************************
- * MSMSensor::numericUpDownHours_ValueChanged
- *
- * Sets value of the hours
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::numericUpDownHours_ValueChanged(System::Object^ sender, System::EventArgs^ e)
- {
- commonData->ucHours = System::Convert::ToByte(this->numericUpDownHours->Value);
- }
- /**************************************************************************
- * MSMSensor::numericUpDownMinutes_ValueChanged
- *
- * Sets value of the minutes
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::numericUpDownMinutes_ValueChanged(System::Object^ sender, System::EventArgs^ e)
- {
- commonData->ucMinutes = System::Convert::ToByte(this->numericUpDownMinutes->Value);
- }
- /**************************************************************************
- * MSMSensor::numericUpDownSeconds_ValueChanged
- *
- * Sets value of the minutes
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::numericUpDownSeconds_ValueChanged(System::Object^ sender, System::EventArgs^ e)
- {
- commonData->ucSeconds = System::Convert::ToByte(this->numericUpDownSeconds->Value);
- }
- /**************************************************************************
- * MSMSensor::UpdateTxPattern
- *
- * Updates the transmission timing pattern according to what pages are
- * enabled.
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::UpdateTxPattern()
- {
- if(this->checkBoxSecondaryData->Checked)
- {
- if(this->checkBoxPage3Enable->Checked)
- {
- //Data pages 1, 2, and 3 enabled
- ucTxPattern.Clear();
- ucTxPattern.Add(msmData->PAGE_1);
- ucTxPattern.Add(msmData->PAGE_1);
- ucTxPattern.Add(msmData->PAGE_2);
- ucTxPattern.Add(msmData->PAGE_3);
- ucTxPattern.Add(msmData->PAGE_1);
- ucTxPattern.Add(msmData->PAGE_1);
- ucTxPattern.Add(msmData->PAGE_3);
- ucTxPattern.Add(msmData->PAGE_2);
- ucTxPattern.TrimExcess();
- }
- else
- {
- //Data pages 1 and 2 enabled
- ucTxPattern.Clear();
- ucTxPattern.Add(msmData->PAGE_1);
- ucTxPattern.Add(msmData->PAGE_1);
- ucTxPattern.Add(msmData->PAGE_2);
- ucTxPattern.Add(msmData->PAGE_2);
- ucTxPattern.TrimExcess();
- }
- }
- else
- {
- if(this->checkBoxPage3Enable->Checked)
- {
- //Data pages 1 and 3 enabled
- ucTxPattern.Clear();
- ucTxPattern.Add(msmData->PAGE_1);
- ucTxPattern.Add(msmData->PAGE_1);
- ucTxPattern.Add(msmData->PAGE_3);
- ucTxPattern.Add(msmData->PAGE_3);
- ucTxPattern.TrimExcess();
- }
- else
- {
- //Only data page 1 enabled
- ucTxPattern.Clear();
- ucTxPattern.Add(msmData->PAGE_1);
- ucTxPattern.TrimExcess();
- }
- }
- }
- /**************************************************************************
- * MSMSensor::UpdateCommonPattern
- *
- * Updates the common pages pattern depending on which common pages
- * are supported.
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::UpdateCommonPattern()
- {
- switch(this->checkBox_Bat_Status->Checked)
- {
- case TRUE:
- switch(this->checkBoxEnableDateTime->Checked)
- {
- case TRUE:
- //All common pages enabled
- ucCommonPattern.Clear();
- ucCommonPattern.Add(commonData->PAGE80);
- ucCommonPattern.Add(commonData->PAGE80);
- ucCommonPattern.Add(commonData->PAGE81);
- ucCommonPattern.Add(commonData->PAGE81);
- ucCommonPattern.Add(commonData->PAGE82);
- ucCommonPattern.Add(commonData->PAGE82);
- ucCommonPattern.Add(commonData->PAGE83);
- ucCommonPattern.Add(commonData->PAGE83);
- ucCommonPattern.TrimExcess();
- break;
- default:
- //Common Time NOT enabled
- ucCommonPattern.Clear();
- ucCommonPattern.Add(commonData->PAGE80);
- ucCommonPattern.Add(commonData->PAGE80);
- ucCommonPattern.Add(commonData->PAGE81);
- ucCommonPattern.Add(commonData->PAGE81);
- ucCommonPattern.Add(commonData->PAGE82);
- ucCommonPattern.Add(commonData->PAGE82);
- ucCommonPattern.TrimExcess();
- break;
- }
- break;
- default:
- switch(this->checkBoxEnableDateTime->Checked)
- {
- case TRUE:
- //Common Battery page NOT enabled
- ucCommonPattern.Clear();
- ucCommonPattern.Add(commonData->PAGE80);
- ucCommonPattern.Add(commonData->PAGE80);
- ucCommonPattern.Add(commonData->PAGE81);
- ucCommonPattern.Add(commonData->PAGE81);
- ucCommonPattern.Add(commonData->PAGE83);
- ucCommonPattern.Add(commonData->PAGE83);
- ucCommonPattern.TrimExcess();
- break;
- default:
- //No additional common pages enabled
- ucCommonPattern.Clear();
- ucCommonPattern.Add(commonData->PAGE80);
- ucCommonPattern.Add(commonData->PAGE80);
- ucCommonPattern.Add(commonData->PAGE81);
- ucCommonPattern.Add(commonData->PAGE81);
- ucCommonPattern.TrimExcess();
- break;
- }
- break;
- }
- }
- /**************************************************************************
- * MSMSensor::checkBox_InvalidSerial_CheckedChanged
- *
- * Handles the CheckedChanged event for the checkBox
- *
- * returns: N/A
- *
- **************************************************************************/
- void MSMSensor::checkBox_InvalidSerial_CheckedChanged(System::Object ^sender, System::EventArgs ^e)
- {
- if(this->checkBox_InvalidSerial->Checked)
- this->textBox_Glb_SerialNumChange->Enabled = false;
- else
- this->textBox_Glb_SerialNumChange->Enabled = true;
- }
|