123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576 |
- #include "StdAfx.h"
- #include "HRMSensor.h"
- void HRMSensor::ANT_eventNotification(UCHAR ucEventCode_, UCHAR* pucEventBuffer_)
- {
- switch(ucEventCode_)
- {
- case EVENT_TX:
- HandleTransmit((UCHAR*) pucEventBuffer_);
- break;
- default:
- break;
- }
- }
- void HRMSensor::InitializeSim()
- {
- ulTimerInterval = 833;
- ucReserved = HRM_RESERVED;
- ulRunTime = 0;
- ulRunTime16000 = 0;
- ucBackgroundCount = 0;
- ucNextBackgroundPage = 1;
- ucEventCount = 0;
- ucMinPulse = System::Convert::ToByte(this->numericUpDown_Prm_MinPulse->Text);
- ucCurPulse = System::Convert::ToByte(this->numericUpDown_Prm_CurPulse->Text);
- ucMaxPulse = System::Convert::ToByte(this->numericUpDown_Prm_MaxPulse->Text);
- ucBPM = ucCurPulse;
- ulElapsedTime2 = 0;
- usTime1024 = 0;
- usPreviousTime1024 = 0;
- ucMfgID = System::Convert::ToByte(this->textBox_ManfIDChange->Text);
- ucHwVersion = System::Convert::ToByte(this->textBox_HardwareVerChange->Text);
- ucSwVersion = System::Convert::ToByte(this->textBox_SoftwareVerChange->Text);
- ucModelNum = System::Convert::ToByte(this->textBox_ModelNumChange->Text);
- usSerialNum = System::Convert::ToUInt16(this->textBox_SerialNumChange->Text);
- ucSimDataType = SIM_FIXED;
- bLegacy = FALSE;
- bTxMinimum = FALSE;
- bSweepAscending = TRUE;
- }
- void HRMSensor::HandleTransmit(UCHAR* pucTxBuffer_)
- {
- static UCHAR ucMessageNum = 0;
- static UCHAR ucPageToggle = 0;
- UCHAR ucPageNum;
- if(bLegacy || bTxMinimum)
- ucPageNum = HRM_PAGE0;
- else
- ucPageNum = HRM_PAGE4;
-
-
- if(!bLegacy)
- {
- if(ucMessageNum++ == HRM_BACKGROUND_INTERVAL - 1)
- {
- ucMessageNum = 0;
- switch(ucNextBackgroundPage)
- {
- case 1:
-
- ucPageNum = HRM_PAGE1;
- ucNextBackgroundPage++;
- break;
- case 2:
- ucPageNum = HRM_PAGE2;
- if(bTxMinimum)
- {
-
- if(++ucBackgroundCount > 2)
- {
- ucBackgroundCount = 0;
- ucNextBackgroundPage ++;
- }
- }
- else
- {
-
- ucNextBackgroundPage++;
- }
- break;
- case 3:
- ucPageNum = HRM_PAGE3;
- if(bTxMinimum)
- {
-
- if(++ucBackgroundCount > 2)
- {
- ucBackgroundCount = 0;
- ucNextBackgroundPage = HRM_PAGE2;
- }
- }
- else
- {
-
- ucNextBackgroundPage = HRM_PAGE1;
- }
- break;
- default:
- break;
- }
- }
- }
-
- pucTxBuffer_[4] = (UCHAR) (usTime1024 & 0xFF);
- pucTxBuffer_[5] = (UCHAR) (usTime1024 >> 8) & 0xFF;
- pucTxBuffer_[6] = ucEventCount;
- pucTxBuffer_[7] = ucBPM;
-
- switch(ucPageNum)
- {
- case HRM_PAGE0:
-
- if(bLegacy)
- pucTxBuffer_[0] = ucReserved;
- else
- pucTxBuffer_[0] = HRM_PAGE0;
-
- pucTxBuffer_[1] = ucReserved;
- pucTxBuffer_[2] = ucReserved;
- pucTxBuffer_[3] = ucReserved;
- break;
- case HRM_PAGE1:
- pucTxBuffer_[0] = HRM_PAGE1;
- pucTxBuffer_[1] = (ulElapsedTime2 & 0xFF);
- pucTxBuffer_[2] = (ulElapsedTime2 >> 8) & 0xFF;
- pucTxBuffer_[3] = (ulElapsedTime2 >> 16) & 0xFF;
- break;
- case HRM_PAGE2:
- pucTxBuffer_[0] = HRM_PAGE2;
- pucTxBuffer_[1] = ucMfgID;
- pucTxBuffer_[2] = usSerialNum & 0x00FF;
- pucTxBuffer_[3] = (usSerialNum & 0xFF00) >>8;
- break;
- case HRM_PAGE3:
- pucTxBuffer_[0] = HRM_PAGE3;
- pucTxBuffer_[1] = ucHwVersion;
- pucTxBuffer_[2] = ucSwVersion;
- pucTxBuffer_[3] = ucModelNum;
- break;
- case HRM_PAGE4:
- pucTxBuffer_[0] = HRM_PAGE4;
- pucTxBuffer_[1] = ucReserved;
- pucTxBuffer_[2] = usPreviousTime1024 & 0xFF;
- pucTxBuffer_[3] = (usPreviousTime1024 >> 8) & 0xFF;
- break;
- default:
- break;
- }
-
- if(!bLegacy)
- {
- ucPageToggle += 0x20;
- pucTxBuffer_[0] += (ucPageToggle & HRM_TOGGLE_MASK);
- }
- }
- void HRMSensor::onTimerTock(USHORT usEventTime_)
- {
- UCHAR tempOffset = 0;
-
- ++ucEventCount;
-
- usPreviousTime1024 = usTime1024;
-
-
- ulRunTime16000 += (ulTimerInterval << 4);
- usTime1024 = (USHORT) ((ulRunTime16000 << 3) / 125);
- ulRunTime += ulTimerInterval;
- while(ulRunTime/2000)
- {
- ++ulElapsedTime2;
- ulRunTime -=2000;
- }
-
- switch(ucSimDataType)
- {
- case SIM_FIXED:
-
- ucBPM = ucCurPulse;
- break;
- case SIM_STEP:
-
- if(ucEventCount & 0x10)
- ucBPM = ucMinPulse;
- else
- ucBPM = ucMaxPulse;
- break;
- case SIM_SWEEP:
-
-
- tempOffset = ucMaxPulse - ucCurPulse;
- tempOffset = ((tempOffset & 0xC0) >> 6) + ((tempOffset & 0x20) >>5) + ((tempOffset & 0x10) >>4)+1;
- if(bSweepAscending)
- ucCurPulse += tempOffset;
- else
- ucCurPulse -= tempOffset;
-
- if(ucCurPulse >= ucMaxPulse)
- {
- ucCurPulse = ucMaxPulse;
- bSweepAscending = FALSE;
- }
- if(ucCurPulse <= ucMinPulse)
- {
- ucCurPulse = ucMinPulse;
- bSweepAscending = TRUE;
- }
- ucBPM = ucCurPulse;
- break;
- default:
- break;
- }
-
-
- if(ucBPM)
- ulTimerInterval = (ULONG) 60000/ucBPM;
-
-
- UpdateDisplay();
- }
- void HRMSensor::UpdateDisplay()
- {
- label_EventCount->Text = ucEventCount.ToString();
- this->label_ElapsedSecsDisplay->Text = ((ulElapsedTime2 & 0x00FFFFFF) << 1).ToString();
- this->numericUpDown_Prm_CurPulse->Value = ucCurPulse;
- label_PulseTxd->Text = ucBPM.ToString();
- this->label_CurrentTimeDisplay->Text = usTime1024.ToString();
- if(bTxMinimum || bLegacy)
- this->label_LastTimeDisplay->Text = "---";
- else
- this->label_LastTimeDisplay->Text = usPreviousTime1024.ToString();
- }
- void HRMSensor::radioButton_SimTypeChanged (System::Object^ sender, System::EventArgs^ e)
- {
- if(radioButton_HRFixed->Checked)
- {
- this->numericUpDown_Prm_CurPulse->Enabled = true;
- this->numericUpDown_Prm_MinPulse->Enabled = false;
- this->numericUpDown_Prm_MaxPulse->Enabled = false;
- ucSimDataType = SIM_FIXED;
- }
- else if(this->radioButton_HRSweep->Checked)
- {
- this->numericUpDown_Prm_CurPulse->Enabled = false;
- this->numericUpDown_Prm_MinPulse->Enabled = true;
- this->numericUpDown_Prm_MaxPulse->Enabled = true;
- ucSimDataType = SIM_SWEEP;
- bSweepAscending = TRUE;
- }
- else if(this->radioButton_HRStep->Checked)
- {
- this->numericUpDown_Prm_CurPulse->Enabled = false;
- this->numericUpDown_Prm_MinPulse->Enabled = true;
- this->numericUpDown_Prm_MaxPulse->Enabled = true;
- ucSimDataType = SIM_STEP;
- }
- }
- System::Void HRMSensor::button_UpdateTime_Click(System::Object^ sender, System::EventArgs^ e)
- {
- ULONG ulCumulativeTime = 0;
- label_AdvancedError->Visible = false;
- try{
- ulCumulativeTime = System::Convert::ToUInt32(this->textBox_ElpTimeChange->Text);
- if(ulCumulativeTime > 33554430)
- throw "Cumulative operating time exceeds rollover value";
- ulElapsedTime2 = ulCumulativeTime >> 1;
-
- label_ElapsedSecsDisplay->Text = ((ulElapsedTime2 & 0x00FFFFFF) << 1).ToString();
- }
- catch(...){
- label_AdvancedError->Text = "Error: Time";
- label_AdvancedError->Visible = true;
- }
- }
- System::Void HRMSensor::button_AdvancedUpdate_Click(System::Object^ sender, System::EventArgs^ e)
- {
- this->label_AdvancedError->Visible = false;
- this->label_AdvancedError->Text = "Error: ";
-
- try{
- ucMfgID = System::Convert::ToByte(this->textBox_ManfIDChange->Text);
- }
- catch(...){
- this->label_AdvancedError->Text = System::String::Concat(label_AdvancedError->Text, " MFID");
- this->label_AdvancedError->Visible = true;
- }
- try{
- usSerialNum = System::Convert::ToUInt16(this->textBox_SerialNumChange->Text);
- }
- catch(...){
- label_AdvancedError->Text = System::String::Concat(label_AdvancedError->Text, " Ser#");
- label_AdvancedError->Visible = true;
- }
- try{
- ucHwVersion = System::Convert::ToByte(this->textBox_HardwareVerChange->Text);
- }
- catch(...){
- label_AdvancedError->Text = System::String::Concat(label_AdvancedError->Text, " HWVr");
- label_AdvancedError->Visible = true;
- }
- try{
- ucSwVersion = System::Convert::ToByte(this->textBox_SoftwareVerChange->Text);
- }
- catch(...){
- label_AdvancedError->Text = System::String::Concat(label_AdvancedError->Text, " SWVr");
- label_AdvancedError->Visible = true;
- }
- try{
- ucModelNum = System::Convert::ToByte(this->textBox_ModelNumChange->Text);
- }
- catch(...){
- label_AdvancedError->Text = System::String::Concat(label_AdvancedError->Text, " Mdl#");
- label_AdvancedError->Visible = true;
- }
- }
- System::Void HRMSensor::numericUpDown_Prm_CurPulse_ValueChanged(System::Object^ sender, System::EventArgs^ e)
- {
-
-
- if(this->numericUpDown_Prm_CurPulse->Enabled)
- {
- ucCurPulse = System::Convert::ToByte(this->numericUpDown_Prm_CurPulse->Value);
- ForceUpdate();
- }
- }
- System::Void HRMSensor::numericUpDown_Prm_MinMaxPulse_ValueChanged(System::Object^ sender, System::EventArgs^ e)
- {
-
-
- if(this->numericUpDown_Prm_MinPulse->Value < this->numericUpDown_Prm_MaxPulse->Value)
- {
- ucMinPulse = System::Convert::ToByte(this->numericUpDown_Prm_MinPulse->Value);
- ucMaxPulse = System::Convert::ToByte(this->numericUpDown_Prm_MaxPulse->Value);
- if(ucCurPulse > ucMaxPulse)
- {
- ucCurPulse = ucMaxPulse;
- this->numericUpDown_Prm_CurPulse->Value = ucCurPulse;
- ForceUpdate();
- }
- else if(ucCurPulse < ucMinPulse)
- {
- ucCurPulse = ucMinPulse;
- this->numericUpDown_Prm_CurPulse->Value = ucCurPulse;
- ForceUpdate();
- }
-
- }
- else
- {
-
- this->numericUpDown_Prm_MinPulse->Value = ucMinPulse;
- this->numericUpDown_Prm_MaxPulse->Value = ucMaxPulse;
- }
-
- }
- System::Void HRMSensor::checkBox_Legacy_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
- {
- if(checkBox_Legacy->Checked)
- {
- System::Windows::Forms::DialogResult result = MessageBox::Show(L"This option is available for backward compatibility testing.\nIt should not be used as a reference in the development of new sensors.", L"Warning", MessageBoxButtons::OKCancel);
- if( result == ::DialogResult::OK )
- {
- bLegacy = TRUE;
-
-
-
- srand(ulElapsedTime2);
- ucReserved = (UCHAR) ((rand() % 240) + 16);
- checkBox_SendBasicPage->Checked = FALSE;
- checkBox_SendBasicPage->Enabled = FALSE;
- }
- else
- {
- bLegacy = FALSE;
- ucReserved = HRM_RESERVED;
- checkBox_Legacy->Checked = FALSE;
- checkBox_SendBasicPage->Enabled = TRUE;
- }
- }
- else
- {
- bLegacy = FALSE;
- ucReserved = HRM_RESERVED;
- checkBox_SendBasicPage->Enabled = TRUE;
- }
-
- }
- System::Void HRMSensor::checkBox_SendBasicPage_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
- {
- if(checkBox_SendBasicPage->Checked)
- {
- bTxMinimum = TRUE;
- ucNextBackgroundPage = 2;
- ucBackgroundCount = 0;
- }
- else
- {
- bTxMinimum = FALSE;
- ucNextBackgroundPage = 1;
- ucBackgroundCount = 0;
- }
-
- }
- void HRMSensor::ForceUpdate()
- {
- timerHandle->Interval = 250;
- }
|