⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.h

📁 zigbee在cc2430下的演示程序。
💻 H
📖 第 1 页 / 共 2 页
字号:
		// 
		// Form1
		// 
		this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
		this->ClientSize = System::Drawing::Size(488, 126);
		this->Controls->Add(this->rxEnable);
		this->Controls->Add(this->led2);
		this->Controls->Add(this->led1);
		this->Controls->Add(this->wdbg_Btn);
		this->Controls->Add(this->rdbg_Btn);
		this->Controls->Add(this->dbgText);
		this->Controls->Add(this->label1);
		this->Controls->Add(this->disconnBtn);
		this->Controls->Add(this->sw2ChkBox);
		this->Controls->Add(this->sw1ChkBox);
		this->Controls->Add(this->statusBar);
		this->Controls->Add(this->connectBtn);
		this->Controls->Add(this->label2);
		this->Controls->Add(this->evbText);
		this->Name = S"Form1";
		this->Text = S"Virtual Evaluation Board";
		this->Load += new System::EventHandler(this, Form1_Load);
		(__try_cast<System::ComponentModel::ISupportInitialize *  >(this->timer1))->EndInit();
		this->ResumeLayout(false);

	}	

	void MyInit(void){
		statusBar->Text = S"Ready..";
		disconnBtn->Enabled = FALSE;
		connectBtn->Text = S"Connect To EVBSim (unconnected)";
		connectBtn->Update();
		disconnBtn->Text = S"Disconnect from EVBSim";
        rdbg_Btn->Enabled = FALSE;
		wdbg_Btn->Enabled = FALSE;
       
	}

private: System::Void Form1_Load(System::Object *  sender, System::EventArgs *  e)
		 {
		 }

private: System::Void connectBtn_Click(System::Object *  sender, System::EventArgs *  e)
		 {
			 //try to connect to shared memory segment
			 			 
			 String *smemName = String::Concat(S"EVBSMEM_",evbText->get_Text());
			 System::Text::ASCIIEncoding* encoder = new System::Text::ASCIIEncoding();
			 System::Byte bytes[] = encoder->GetBytes(smemName);
			 Byte __pin* abytes = &bytes[0];


			 smemH = OpenFileMapping(
				 FILE_MAP_ALL_ACCESS,   // read/write access
				 FALSE,                 // do not inherit the name
				 (char *)abytes);               // name of mapping object 

			 if (smemH == NULL) 
			 { 

				 statusBar->Text = S"Can't open EVB shared memory connection!";
				 return;

			 } else {
                   statusBar->Text = S"Connection succeeded!";
			 }
			 //get the mutex handle as well
			 String  *aName = String::Concat(S"EVBMUTEX_",evbText->get_Text());
             System::Byte more_bytes[] = encoder->GetBytes(aName);
			 Byte __pin* p_more_bytes = &more_bytes[0];

             hMutex = CreateMutex(NULL, FALSE, (char *)p_more_bytes);
		     if(!hMutex) statusBar->Text= S"Mutex grab failed!";
			 connectBtn->Text = S"Connect To EVBSim (connected)";
			 connectBtn->Enabled = FALSE; //disable this button
			 disconnBtn->Enabled = TRUE; //enable disconnect button
			 rdbg_Btn->Enabled = TRUE;
		     wdbg_Btn->Enabled = TRUE;
		   	 	                 
		  }

private: System::Void sw1Btn_CheckedChanged(System::Object *  sender, System::EventArgs *  e)
		 {
			 
		 }

private: System::Boolean grab_mutex(void) 
		 {
			 DWORD rc;
			 //access to shared memory
			 //grab the mutex first.
			 rc = WaitForSingleObject(hMutex,INFINITE);
			 switch(rc) {
				case WAIT_OBJECT_0:
					break;
				case WAIT_FAILED:
				case WAIT_ABANDONED:
				case WAIT_TIMEOUT:
					statusBar->Text = S"EVB Mutex grab failed!";
					return FALSE;
			 }
           return TRUE;
		 }

 private: System::Void release_mutex(void) {
			  ReleaseMutex(hMutex);
		  }

  //update the state of a switch in shared memory
  private: System::Void update_switch(Boolean sw, Byte mask)
		   {
			   //now update the shared memory
			 if (smemH == NULL) return;
             if (!grab_mutex()) return;
			
			 Byte __pin* pSharedMem;

			 pSharedMem = (BYTE *) MapViewOfFile(smemH,   // handle to map object
				 FILE_MAP_ALL_ACCESS, // read/write permission
				 0,                   
				 0,                   
				 16);      //last value is shared memory size   

			 if (pSharedMem == NULL) 
			 { 
				 statusBar->Text = S"Cannot read EVB shared memory!";
				 release_mutex();
				  return;
			 }

			 if (sw){ *pSharedMem |= mask;}
			 else { *pSharedMem &= ( ~mask);}
			 release_mutex();
			 UnmapViewOfFile(pSharedMem);

		   }

private: System::Void sw1ChkBox_CheckedChanged(System::Object *  sender, System::EventArgs *  e)
		 {

			 if (sw1ChkBox->Checked){
				 sw1ChkBox->Text=S"SW1 (pressed)";
			 }else {
				 sw1ChkBox->Text=S"SW1 (released)";
			 }
			 sw1ChkBox->Update();
			 update_switch(sw1ChkBox->Checked, BTN1_MASK);
		 }

private: System::Void sw2ChkBox_CheckedChanged(System::Object *  sender, System::EventArgs *  e)
		 {

			 if (sw2ChkBox->Checked){
				 sw2ChkBox->Text=S"SW2 (pressed)";
			 }else {
				 sw2ChkBox->Text=S"SW2 (released)";
			 }
			 sw2ChkBox->Update();
			 update_switch(sw2ChkBox->Checked, BTN2_MASK);			 
		 }


private: System::Void disconnBtn_Click(System::Object *  sender, System::EventArgs *  e)
		 {
			CloseHandle(smemH);
			smemH = NULL;
		    disconnBtn->Enabled = FALSE;
			rdbg_Btn->Enabled = FALSE;
		    wdbg_Btn->Enabled = FALSE;
		    connectBtn->Enabled = TRUE;
			connectBtn->Text = S"Connect To EVBSim (unconnected)";
			statusBar->Text = S"Disconnect succeeded!";
		 }

#define WRITE_DBG 1

private: Byte do_debug_level(Boolean Write_flag, Byte newval)
		 {
		   Byte rval;

		   if (smemH == NULL)  return(0);
           grab_mutex();
		   Byte __pin* pSharedMem;

			 pSharedMem = (BYTE *) MapViewOfFile(smemH,   // handle to map object
				 FILE_MAP_ALL_ACCESS, // read/write permission
				 0,                   
				 0,                   
				 16);      //last value is shared memory size   

			 if (pSharedMem == NULL) 
			 { 
				 statusBar->Text = S"Cannot read EVB shared memory!";
				 release_mutex();
				  return(0);
			 }

			 if (Write_flag) {
				 *(pSharedMem+1) = WRITE_DBG;
				 *(pSharedMem+2) = newval;
			 } else {
				 rval = *(pSharedMem+2);
			 }
			 
			 UnmapViewOfFile(pSharedMem);

		   release_mutex();
		  
           return(rval);
		 }

private: System::Void rdbg_Btn_Click(System::Object *  sender, System::EventArgs *  e)
		 {
			 Byte newval;

             newval = do_debug_level(FALSE, 0);
			 dbgText->Text = Convert::ToString(newval);
		 }

private: System::Void wdbg_Btn_Click(System::Object *  sender, System::EventArgs *  e)
		 {
			 Byte newval;

			 newval = Convert::ToByte(dbgText->Text);
			 do_debug_level(TRUE, newval);
		 }

private: System::Void timer1_Elapsed(System::Object *  sender, System::Timers::ElapsedEventArgs *  e)
		 {
			 Byte rval;
			 //update the LEDs
			 if (smemH == NULL)  return;
             grab_mutex();
             Byte __pin* pSharedMem;

			 pSharedMem = (BYTE *) MapViewOfFile(smemH,   // handle to map object
				 FILE_MAP_ALL_ACCESS, // read/write permission
				 0,                   
				 0,                   
				 16);      //last value is shared memory size   

			 if (pSharedMem == NULL) 
			 { 
				 statusBar->Text = S"Cannot read EVB shared memory!";
				 release_mutex();
			 }
              rval = *(pSharedMem);  //read the LEDs
			 UnmapViewOfFile(pSharedMem);

			 if (rval & LED1_MASK)  led1->Checked = TRUE;
			 else  led1->Checked = FALSE;				
		     if (rval & LED2_MASK)  led2->Checked = TRUE;
		     else led2->Checked = FALSE;
		     led1->Update();
		     led2->Update();


		     release_mutex();

		 }

private: System::Void rxEnable_CheckedChanged(System::Object *  sender, System::EventArgs *  e)
		 {
			 if (rxEnable->Checked){
				 rxEnable->Text=S"RX (blocked)";
			 }else {
				 rxEnable->Text=S"RX (enabled)";
			 }
			 rxEnable->Update();
			 update_switch(rxEnable->Checked, BLOCK_RX_MASK);		


		 }

};
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -