123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
-
- #include "StdAfx.h"
- #include "CustomSensor.h"
- void CustomSensor::ANT_eventNotification(UCHAR ucEventCode_, UCHAR* pucEventBuffer_)
- {
- switch(ucEventCode_)
- {
- case EVENT_TX:
- HandleTransmit((UCHAR*) pucEventBuffer_);
- break;
- default:
- break;
- }
- }
- void CustomSensor::InitializeSim()
- {
- ulEventCounter = 0;
- bSendHex = FALSE;
- ValidateInput();
- }
- void CustomSensor::HandleTransmit(UCHAR* pucTxBuffer_)
- {
- UCHAR i;
-
- for(i=0; i<8; i++)
- {
- pucTxBuffer_[i] = arrayUserData[i];
- }
- }
- void CustomSensor::onTimerTock(USHORT usEventTime_)
- {
- ++ulEventCounter;
- label_EventCount->Text = ulEventCounter.ToString();
- }
- System::Void CustomSensor::button_UpdateData_Click(System::Object^ sender, System::EventArgs^ e)
- {
- ValidateInput();
- }
- System::Void CustomSensor::radioButton_TranslateSelect_CheckedChanged(System::Object^ sender, System::EventArgs^ e) {
- if(this->radioButton_asChar->Checked){
- this->textBox_customTxData->Text = "Max8Char";
- this->textBox_customTxData->MaxLength = 8;
- bSendHex = FALSE;
- }
- else if(this->radioButton_asHex->Checked){
- this->textBox_customTxData->Text = "00,00,00,00,00,00,00,00";
- this->textBox_customTxData->MaxLength = 23;
- bSendHex = TRUE;
- }
- }
- System::Void CustomSensor::button_SendAck_Click(System::Object^ sender, System::EventArgs^ e)
- {
- UCHAR i;
- UCHAR aucTxBuffer[8] = {0,0,0,0,0,0,0,0};
- ValidateInput();
-
- for(i=0; i<8; i++)
- {
- aucTxBuffer[i] = arrayUserData[i];
- }
-
-
- requestAckMsg(aucTxBuffer);
- }
- void CustomSensor::ValidateInput()
- {
- UCHAR i;
-
- if(System::String::IsNullOrEmpty(this->textBox_customTxData->Text))
- {
- this->label_InputError->Text = "Error: Empty String";
- return;
- }
-
- if(!bSendHex)
- {
- UCHAR textLength = textBox_customTxData->Text->Length;
- for(i=0; i < textLength; ++i)
- arrayUserData[i] = (UCHAR)textBox_customTxData->Text[i];
- while(i<8)
- arrayUserData[i++] = 0x00;
- this->label_InputError->Text = "";
- this->label_DataTxd->Text = this->textBox_customTxData->Text;
- }
-
- else
- {
- array<System::String^>^ hexes;
- hexes = this->textBox_customTxData->Text->Split(',');
- try
- {
- int hexLength = hexes->Length;
- if(hexLength >8)
- throw "Too many commas";
- for(i=0; i<hexLength; ++i)
- {
- if(hexes[i]->Length >2)
- throw "Too many letters between commas";
- arrayUserData[i] = Byte::Parse(hexes[i],System::Globalization::NumberStyles::HexNumber);
- }
- while(i<8)
- arrayUserData[i++] = 0x00;
- this->label_InputError->Text = "";
- this->label_DataTxd->Text = "Hex";
- }
- catch(...)
- {
- this->label_InputError->Visible = true;
- this->label_InputError->Text = "Error: Invalid Input";
- for(i=0; i<8; ++i)
- arrayUserData[i] = 0x00;
- }
- }
- }
|