Exemplo n.º 1
0
bool CWidcommHandler::DoDiscoverWMouseXPThroughDeviceList()
{
			if(iCurDevice < iFoundDevices.GetSize())
			{
				iDiscoveringGUID.Data1 = 0x2bc2b92e;
				iDiscoveringGUID.Data2 = 0x3992;
				iDiscoveringGUID.Data3 = 0x11dc;
				iDiscoveringGUID.Data4[0] = 0x83;
				iDiscoveringGUID.Data4[1] = 0x14;
				iDiscoveringGUID.Data4[2] = 0x08;
				iDiscoveringGUID.Data4[3] = 0x00;
				iDiscoveringGUID.Data4[4] = 0x20;
				iDiscoveringGUID.Data4[5] = 0x0c;
				iDiscoveringGUID.Data4[6] = 0x9a;			
				iDiscoveringGUID.Data4[7] = 0x66;			


				CString dsp("Discovering services on ");

				CWidcommFoundDevice* dev = (CWidcommFoundDevice*) iFoundDevices.GetAt(iCurDevice);
				
				dsp += dev->iName;

				iLabel->SetWindowText(dsp);

				CopyBDADDR(dev->iAddr,iDiscoveringDevice);

				iDiscoverCommandSent = true;

				Sleep(3000);	// L2CAP needs at least 1 sec to clear previous discovery connection
				
				if(	StartDiscovery(dev->iAddr, &iDiscoveringGUID) )
					/*Sleep(2000)*/;
				else
				{
					if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))							
						MessageBox(iHwnd,"General discovery fault: Try again soon.","Discovey Fault",MB_OK | MB_ICONASTERISK);

					RevertToIdle(); //add hwnd, icon movement, icon animation rsc numbers, etc...
					return false;	
				}

				
				iCurDevice++;

				return true;
				

			}
			else
				return false;
}
Exemplo n.º 2
0
void EvilTree::Update()
{
	RevertToIdle();

	if (spawningAnimationOver)
	{
		if (health <= 0)
		{
			(facingLeft) ? Renderer.Initialize(70, 70, 153, 157, 135) : Renderer.Initialize(70, 70, 66, 70, 135);
		}
		else
		{
			/*
				Cache these locally to eliminate some function call overhead.

				The center points allow us to more easily/accurately track the player,
				so that we can make better decisions about what actions are the beneficial
				at a given point.
			*/
			RECT playerRect = gEnv->getPlayerRECT();
			Vector2 playerCenter(playerRect.right - (playerRect.right - playerRect.left) / 2, playerRect.bottom - (playerRect.bottom - playerRect.top) / 2);

			RECT myRect = hitBox.getBoundingBox();
			Vector2 myCenter(myRect.right - (myRect.right - myRect.left) / 2, myRect.bottom - (myRect.bottom - myRect.top) / 2);

			// Very simple move towards player to attack code
			// change later
			if (playerCenter.x > myCenter.x)
			{
				// Player to the right, move towards
				Renderer.modifyX(3.0f);
				hasMoved = true;
				facingLeft = false;
			}
			else if (playerCenter.x < myCenter.x)
			{
				// Player to the left, move towards
				Renderer.modifyX(-3.0f);
				hasMoved = true;
				facingLeft = true;
			}

			if (playerCenter.y > myCenter.y)
			{
				// Player below, move towards
				Renderer.modifyY(2.25f);
				hasMoved = true;
			}
			else if (playerCenter.y < myCenter.y)
			{
				//Player above, move towards
				Renderer.modifyY(-2.25f);
				hasMoved = true;
			}

			// If we've moved, we need to switch animations
			if (hasMoved)
			{
				if (facingLeft)
				{
					Renderer.Initialize(70, 70, 85, 98, 60);
				}
				else
				{
					Renderer.Initialize(70, 70, 3, 17, 60);
				}

				depth = hitBox.getBoundingBox().bottom - (hitBox.getBoundingBox().bottom - hitBox.getBoundingBox().top) / 2;
			}

			// 
			if (facingLeft)
			{
				idleAnimationStart = 85;
				idleAnimationEnd = 88;
			}
			else
			{
				idleAnimationStart = 0;
				idleAnimationEnd = 3;
			}

			// Occasionally play a menacing sound
			if (rand() % 1000 >= 995)
			{
				// Play a death sound
				std::ostringstream convert;
				convert << (1 + (rand() % 9));
				std::string num = convert.str();
				std::string prefix = "mnstr";
				std::string suffix = ".wav";
				std::string soundName = prefix + num + suffix;
				menacingSound->PlaySongMP3(soundName.c_str());
			}
		}
	}
	else
	{
		if (!soundPlayed)
		{
			// Play spawning sound
			std::ostringstream convert;
			convert << (1 + (rand() % 4));
			std::string num = convert.str();
			std::string prefix = "WoodCrack";
			std::string suffix = ".wav";
			std::string soundName = prefix + num + suffix;
			
			spawnSound->PlaySongMP3(soundName.c_str());

			soundPlayed = true;
		}
	}

	hitBox.UpdateCollider(Renderer.getPos().x, Renderer.getPos().y);
	Renderer.Update();

	hasMoved = false;
}
Exemplo n.º 3
0
void CToshHandler::HandleMsgDevSearchRes(UINT wParam, LONG lParam)
{

	PDEVINFO pDev = (PDEVINFO)lParam;
	//if (!pDev)	return;

	mydebug::log("w9211");
		
	if(	((USHORT*)&wParam)[1] ==  TOSBTAPI_EVENT_COMMPORT)			
	{
		mydebug::log("w9212");
			//AfxMessageBox("TOSBTAPI_EVENT_COMMPORT");

			USHORT hiword = ((USHORT*)&lParam)[1];
			USHORT loword = ((USHORT*)&lParam)[0];

			if(hiword == 0) //COMM port creaated - tosh doc page 12
			{
				//AfxMessageBox("commport created");
				//Sleep(5000);

				PBTDEVINFOLIST	ptr;			
					ptr = iDevInfo.pDevInfoList;

/*					BTAUTOCONNECTCOMMINFO aBTAUTOCONNECTCOMMINFO;
					
					aBTAUTOCONNECTCOMMINFO.dwSize = sizeof(BTAUTOCONNECTCOMMINFO);
					StringCbCopyA(aBTAUTOCONNECTCOMMINFO.szPortName,5,"COMwm");
					aBTAUTOCONNECTCOMMINFO.bSCN = iWmxpscn; //this is set before BtCreateCOMM
					aBTAUTOCONNECTCOMMINFO.wPSM = 0;
					aBTAUTOCONNECTCOMMINFO.wCID=0;
					CopyBDADDR(ptr->DevInfo[iSelectedDev].BdAddr,aBTAUTOCONNECTCOMMINFO.BdAddr);
					aBTAUTOCONNECTCOMMINFO.dwOption=0; // Not used.(name ‘0’)
					aBTAUTOCONNECTCOMMINFO.wAutoConnect=2;//auto-connect

					

					BtSetAutoConnectCOMMInfo(&aBTAUTOCONNECTCOMMINFO,&iStatus);*/

					CString porttoopen;
					porttoopen = "\\\\.\\"; //known issue for COM port above COM9 see http://support.microsoft.com/kb/115831
					porttoopen += rfcommport;					

					
					//AfxMessageBox(porttoopen);


/*						 iHFile = CreateFile (porttoopen,      // Open One.txt
                      GENERIC_READ|GENERIC_WRITE,           // Open for reading
                      FILE_SHARE_READ|FILE_SHARE_WRITE,    
                      NULL,                   // No security
                      OPEN_ALWAYS,        
                      FILE_ATTRIBUTE_NORMAL,  // Normal file
                      NULL);                  // No template file

					   if (iHFile == INVALID_HANDLE_VALUE)
					   {
						   //TODO: l2cap PSM
						   //TODO: cleanup notifycomm and BtCreateCOMM (BtDestroyCOMM)							
      						AfxMessageBox("Failed to open connection... Please try again.");		
							RevertToIdle(); //add hwnd, icon movement, icon animation rsc numbers, etc...		
							return;
					   }

    /////////////////prepare COMM port file
    DCB dcb;
	COMMTIMEOUTS commTimeouts;
	
	GetCommState((HANDLE)iHFile,&dcb);
	dcb.BaudRate = CBR_115200;
	dcb.Parity = NOPARITY;
	dcb.ByteSize = 8;
	dcb.StopBits = ONESTOPBIT;
	SetCommState((HANDLE)iHFile,&dcb);

	commTimeouts.ReadIntervalTimeout = MAXDWORD;
	commTimeouts.ReadTotalTimeoutConstant = 0;
	commTimeouts.ReadTotalTimeoutMultiplier = 0;
	commTimeouts.WriteTotalTimeoutConstant = 100;
	commTimeouts.WriteTotalTimeoutMultiplier = 10;
	SetCommTimeouts((HANDLE)iHFile,&commTimeouts);
	PurgeComm((HANDLE)iHFile, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR );
	SetupComm((HANDLE)iHFile, 1024, 1024);
	EscapeCommFunction((HANDLE)iHFile,SETRTS);
	EscapeCommFunction((HANDLE)iHFile,SETDTR);
	/////////////////////////////////////////
*/
					mydebug::log("w9213");

					DWORD	dwOpt = 0;

					iLabel->SetWindowText("Connecting to phone...");
					
					 if(BtConnectCOMM2(rfcommport, ptr->DevInfo[iSelectedDev].BdAddr, iWmxpscn,3, &iRFCOMMCID, dwOpt, &iStatus, iParams.iHWND, UM_TOSHMESSAGES, 0))
						 mydebug::log("BtConnectCOMM2 true");
					 else
					 {

						 mydebug::log("BtConnectCOMM2 false");

						 //TODO: cleanup notifycomm and BtCreateCOMM (BtDestroyCOMM)				
						 if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
      						AfxMessageBox("Failed to start connection... Please try again.");		
						 else
							 CWMouseXPDlg::curInstance->AddLog("Failed to start connection");

							RevertToIdle(); //add hwnd, icon movement, icon animation rsc numbers, etc...		
							return;
					 
					 }

					 mydebug::log("w9214");

			
			
			}
			else if(hiword == 1) //COMM port deleted
			{
				//AfxMessageBox("commport deleted");
			
			}
			else
			{			
			
			}


	}
	else
	{

	// Response message of asynchronous command (BtDiscoverRemoteDevice2)
	switch (wParam) {
		case TOSBTAPI_NM_DISCOVERDEVICE_START:
			mydebug::log("th522");
			iLabel->SetWindowText("Discovering services...");
			mydebug::log("th524");
			break;
		case TOSBTAPI_NM_DISCOVERDEVICE_FOUND:
		{	// Device exist
			mydebug::log("th528");
			iLabel->SetWindowText("found service...");
			mydebug::log("th529");
			//AfxMessageBox("found");

			/*PBTDEVINFOLIST	ptr;
			BDADDR	BdAddr;
			DWORD	i;
			char	szBuff[64] = {0};

			ptr = pDev->pDevInfoList;
			if (!ptr) {
				break;
			}
			if (ptr->dwDevListNum == 0) {
				break;
			}

			// Reset Combo Box for BD_Addr
			// Combo box (BD_ADDR list) Set and Show to list box
			for (i=0; i<ptr->dwDevListNum; i++) {
				DWORD dwMask = (BTDEVINFOSTS_BDADDR_DEV|BTDEVINFOSTS_BDADDR_DB);
				if (ptr->DevInfo[i].dwStatus & dwMask) {
					CopyMemory(BdAddr, ptr->DevInfo[i].BdAddr, sizeof(BDADDR));
					wsprintf(szBuff, "%02X:%02X:%02X:%02X:%02X:%02X", BdAddr[0], BdAddr[1], BdAddr[2], BdAddr[3], BdAddr[4], BdAddr[5]);
					m_cbBdAddr.AddString((LPCTSTR)szBuff);
				}
			}
			// Set cursel
			m_cbBdAddr.SetCurSel(0);*/
			break;
		}
		case TOSBTAPI_NM_DISCOVERDEVICE_END:
		{	
			mydebug::log("w9215");

			iLabel->SetWindowText("service discovery complete...");
			
			PBTDEVINFOLIST	ptr = NULL;
			BDADDR	BdAddr;
			DWORD	i;
			char	szBuff[64] = {0};

			mydebug::log("w9216");

			if(pDev==NULL)
			{
			if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
				AfxMessageBox("InternalError: invalid device set. Please try again.");

			RevertToIdle(); //add hwnd, icon movement, icon animation rsc numbers, etc...
			}

			ptr = pDev->pDevInfoList;

			
			if(pDev==NULL)
			{
				if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
					AfxMessageBox("InternalError: invalid device list. Please try again.");

			RevertToIdle(); //add hwnd, icon movement, icon animation rsc numbers, etc...
			}


			mydebug::log("w9217");

			if (!ptr) 
			{
				if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
					AfxMessageBox("Find device error (0), make sure your PC's Bluetooth is Enabled and try again.");

				RevertToIdle(); //add hwnd, icon movement, icon animation rsc numbers, etc...
				break;
			}
			if (ptr->dwDevListNum == 0) 
			{
				this->iLabel->SetWindowText("No nearby Bluetooth devices found");		
				if(iRequestedCommand == ESendFileSession)
				{
					if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
						MessageBox(iHwnd,"No nearby Bluetooth devices found.\r\n\r\n- Make sure your PC's Bluetooth is plugged-in/started and ready.\r\n- Make sure your phone's Bluetooth is ON and discoverable (\"show to all\",\"Find me!\",etc.).\r\n- Try Again.\r\n- See \"Help\" for other installation methods.","No nearby devices found",MB_OK | MB_ICONASTERISK);
				}
				else
				{
					if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
						MessageBox(iHwnd,"No nearby Bluetooth devices found.\r\n\r\n- Make sure your PC's Bluetooth is plugged-in/started and ready.\r\n- Make sure your phone's Bluetooth is ON and discoverable (\"show to all\",\"Find me!\",etc.).\r\n- Try Again.","No nearby devices found",MB_OK | MB_ICONASTERISK);				
				}
				RevertToIdle(); //add hwnd, icon movement, icon animation rsc numbers, etc...
				break;
			}
			
			mydebug::log("w9218");
			
			if(iRequestedCommand == ESendFileSession)				
			{

				mydebug::log("sendfilesession");

				int SelectedDev=-1;
				iIcon->Stop();
			
				mydebug::log("w622");
				
				//let user choose from listbox
				CSelectPhoneDialog dlg(EToshStack,NULL,SelectedDev,CWMouseXPDlg::curInstance,ptr);

				mydebug::log("w627");

				if(IDOK == dlg.DoModal() && SelectedDev>=0)
				{
					mydebug::log("w628");
					iLabel->SetWindowText("Preparing to send file...");
					mydebug::log("w629");
					if(!iOpenedObexApi)
					{
						mydebug::log("w630");
						long status;
						if(BtOBEXOpen(iParams.iHWND,&status))
						{
							mydebug::log("w631");
							iOpenedObexApi = true;						
						}
						else
						{
							MessageBox(iHwnd,"Failed to start the Toshiba Bluetooth file-send engine\r\n\r\nPlease install the Mobile-side program (WMouseXP.jar - at the installation folder of this program) manually.","Send Failed",MB_OK | MB_ICONASTERISK);
							RevertToIdle(); 
							break;
						}
					}

				
						///////////////////////////////////////////////////
					
						{
						
						
							mydebug::log("w636");
							DWORD dwAllocSize = sizeof( TOSBTOBEXAPI_SENDFILE_FILELIST );
							mydebug::log("w637");
							PTOSBTOBEXAPI_SENDFILE_FILELIST ptFileList = (PTOSBTOBEXAPI_SENDFILE_FILELIST) malloc(dwAllocSize);							
							mydebug::log("w638");
							ZeroMemory( ptFileList, dwAllocSize );
							mydebug::log("w639");
							ptFileList->dwCount = 1;
							ptFileList->tFile[0].pszName = iTmpObexFilePath;
							
							//send to phone
							//BtOBEXSendFile(hWndApp, uMessage, pb, ptFileList, dwProfile, dwMaskUI, plStatus);

							iLabel->SetWindowText("Sending file...");

							mydebug::log("w640");

							BtOBEXSendFile(NULL,0,ptr->DevInfo[SelectedDev].BdAddr,ptFileList,0,0,0);

							mydebug::log("w641");

							free(ptFileList);
							
							mydebug::log("w642");

							RevertToIdle();

							mydebug::log("w643");
						}

				}
				else
				{
				RevertToIdle(); 
				}
			}//end of if sendfilesession
			else
			{
				mydebug::log("th63");
				//start connect to phone session
				//discover through list and connect to it
				if(iWmxpToshSDPPattern)
				{
					mydebug::log("th64");
					//connect sdp to first device in list
					if(iSelectedDev == -1)
					{

						mydebug::log("th65");
						iLabel->SetWindowText("please select phone...");
						mydebug::log("th66");
						iIcon->Stop();
						mydebug::log("th67");
						CSelectPhoneDialog dlg(EToshStack,NULL,iSelectedDev,CWMouseXPDlg::curInstance,ptr);
						mydebug::log("th68");

						if(IDOK == dlg.DoModal() && iSelectedDev>=0)
						{
							mydebug::log("th69");
							iLabel->SetWindowText("Looking for WMouseXP on phone...");
							mydebug::log("th70");
							if(BtConnectSDP(ptr->DevInfo[iSelectedDev].BdAddr,&iCID,&iStatus,iParams.iHWND,UM_TOSHMESSAGES,iSelectedDev))							
							mydebug::log("th71");
							else
							{
								mydebug::log("th72");
								if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
									AfxMessageBox("Failed to connect to device...");

								RevertToIdle(); //add hwnd, icon movement, icon animation rsc numbers, etc...
							}
						}
						else
						{
							mydebug::log("th73");
							RevertToIdle();
						}
					}
					else
					{

										mydebug::log("w92183");
						iLabel->SetWindowText("Looking for WMouseXP on phone...");

						if(BtConnectSDP(ptr->DevInfo[iSelectedDev].BdAddr,&iCID,&iStatus,iParams.iHWND,UM_TOSHMESSAGES,iSelectedDev))							
						{
							mydebug::log("w92184");
						}
						else
						{
							if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
								AfxMessageBox("Failed to connect to device...");

							RevertToIdle(); //add hwnd, icon movement, icon animation rsc numbers, etc...
						}

						mydebug::log("w92185");

					}

				}
				else
				{
					mydebug::log("th771");
					if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
						AfxMessageBox("Invalid tosh sdp pattern.");

					RevertToIdle(); //add hwnd, icon movement, icon animation rsc numbers, etc...
				}
				
			}			
			break;
		}
		case TOSBTAPI_NM_DISCOVERDEVICE_ERROR:
		{	
			if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
				AfxMessageBox("Find device error (1), make sure your PC's Bluetooth is Enabled and try again.");

			RevertToIdle(); //add hwnd, icon movement, icon animation rsc numbers, etc...
			break;
		}
		
		////////////////SDP

		////////////sdp connect result
		case TOSBTAPI_NM_CONNECTSDP_CONNECTED:
		{
			
			mydebug::log("th795");
			//iSDPSSRESULT
			//Sleep(700);

			if(BtServiceSearchAttribute2(iCID,iWmxpToshSDPPatternSize ,iWmxpToshSDPPattern , iWmxpToshAttrIdListSize, iWmxpToshAttrIdList, &iMemSDP_SSA_Result, &iStatus, iParams.iHWND, UM_TOSHMESSAGES , iCID ))
				mydebug::log("th800");
			else
			{			
				mydebug::log("th803");
				if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
					AfxMessageBox("Failed to start search for WMouseXP on device...");

				RevertToIdle(); //add hwnd, icon movement, icon animation rsc numbers, etc...			
			}

			break;
		}

		case TOSBTAPI_NM_CONNECTSDP_ERROR:
		{
			mydebug::log("th804");
			if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
				AfxMessageBox("Failed to connect to search for WMouseXP on device...");

			mydebug::log("th805");
			RevertToIdle();
			break;
		}

		case TOSBTAPI_NM_CONNECTSDP_END:
		{
			mydebug::log("th822");
			break;		
		}
		/////////////////////////////


		////////////sdp search result
		case TOSBTAPI_NM_SSA_RESULT:
		{
			mydebug::log("th831");
			/*CString str;
			str.Format("%d status %d",iCID,iStatus);			
			AfxMessageBox(str);
			*/

			iLabel->SetWindowText("analyzing service search result...");

			mydebug::log("th832");
			PBTANALYZEDATTRLIST2 *pMemAnalyzedAttributeList;
			PBTANALYZEDATTRLIST2 pAnalyzeResult = NULL;	
			mydebug::log("th833");
			int wmxpscn = -1;
			
			BTUNIVATTRIBUTE mask = 0;
			mask |= TOSBTAPI_ATR_PROTOCOLDESCRIPTORLIST;
			mask |= TOSBTAPI_ATR_SERVICERECORDHANDLE;
mydebug::log("th834");
			if (BtAnalyzeServiceAttributeLists2(mask, iMemSDP_SSA_Result, &pAnalyzeResult, &iStatus) && pAnalyzeResult)
			{	
				mydebug::log("th835");

				/////disconnect now - no need to wait for reverttoidle - we prepare for rfcomm
				BtDisconnectSDP(iCID,&iStatus);
				mydebug::log("th836");
				iCID = 0;
				/////////////////
			mydebug::log("th837");
				BTUNIVATTRIBUTE		BtUnivAttr;
				for (int i=0; i<pAnalyzeResult->dwNum; i++) 
				{
					mydebug::log("th838");
					BtUnivAttr = pAnalyzeResult->BtAnalyzedAttr[i].BtAnalyzedAttribute;
					mydebug::log("th839");
					if (pAnalyzeResult->BtAnalyzedAttr[i].pMemProtocolDescriptorList) 
					{
						mydebug::log("th840");
					//	AfxMessageBox("0");

						PBTPROTOCOLLIST2 aPBTPROTOCOLLIST2 = pAnalyzeResult->BtAnalyzedAttr[i].pMemProtocolDescriptorList->pMemProtocolList[0];
						mydebug::log("th841");

						for(int j=0; j<aPBTPROTOCOLLIST2->dwProtocolNum; j++)			
						{
							mydebug::log("th842");
					//		AfxMessageBox("1");

							PBTPROTOCOL2 protocolinfo = &(aPBTPROTOCOLLIST2->BtProtocol[j]);							
							mydebug::log("th843");
							if(protocolinfo->wParameterType & 1)
							{
							//	AfxMessageBox("2")
								mydebug::log("th844");
								wmxpscn = protocolinfo->dwParameter;
								mydebug::log("th845");
							}
						}
					}
				}

				mydebug::log("th846");
				if(!BtFreePBTANALYZEDATTRLIST2(&pAnalyzeResult, &iStatus)) //let the tosh free their complex struct
				{
					mydebug::log("th847");
					free(pAnalyzeResult);//free as much as we can
					mydebug::log("th848");
				}

				if(wmxpscn == -1)
				{				
					mydebug::log("th849");
					if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
						AfxMessageBox("WMouseXP is not running on phone, please install/start WMouseXP on phone and try again.");

					mydebug::log("th850");
					RevertToIdle();	
					mydebug::log("th851");
					return;
				}

				iWmxpscn = wmxpscn;
				mydebug::log("th852");
				//prepare rfcomm connection to that wmxp rfcomm scn channel
				iLabel->SetWindowText("Preparing communication to phone...");
				mydebug::log("th853");
				BtDestroyCOMM(rfcommport,&iStatus);
				mydebug::log("th854");
				Sleep(2000);
				mydebug::log("th855");
				if(BtNotifyEvent(TOSBTAPI_EVENTMASK_COMMPORT, &iStatus, iParams.iHWND,UM_TOSHMESSAGES ) )
				{		
					mydebug::log("th856");
					BYTE	bSCN = 0;
					WORD	wPSM = 3;	// 3=RFCOMM

					
					mydebug::log("th857");
					if(BtCreateCOMM(rfcommport, bSCN, wPSM, &iStatus) )//we're using as a client so use scn 0, psm 0 as suggested by tosh doc on BtCreateCOMM
					{
						mydebug::log("th858");;//ok wait for comport created event

					}
					else
					{
						mydebug::log("th859");
						CString errstr;
						errstr.Format("Initial create connection failed: %x",iStatus);
						if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
							AfxMessageBox(errstr);

						RevertToIdle();	
						return;									
					}

					
				}
				else
				{
					mydebug::log("th860");
					CString errstr;
					errstr.Format("Initial connection start to phone failed: %x",iStatus);
					if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
						AfxMessageBox(errstr);

					RevertToIdle();	
					return;				
				}
				mydebug::log("th861");


			}			
			else
			{
				mydebug::log("th862");
				if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
					AfxMessageBox("Search for WMouseXP on device failed - failed to analyze, try again...");

				RevertToIdle();	
				return;
			}
			

			break;		
		}

		case TOSBTAPI_NM_SSA_ERROR:
		{			
			mydebug::log("TOSBTAPI_NM_SSA_ERROR");

			if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
				AfxMessageBox("Search for WMouseXP on device failed...");		

			RevertToIdle(); //add hwnd, icon movement, icon animation rsc numbers, etc...						
			break;
		}
		//////////////////////


		/////////////////////////////RFCOMM

		//////////create comm port
		case TOSBTAPI_NM_CREATECOMM_ERROR:
			{
				mydebug::log("TOSBTAPI_NM_CREATECOMM_ERROR");
				if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
					AfxMessageBox("Create comm-port failed...");		

				RevertToIdle();			
				break;
			}

		case TOSBTAPI_NM_CREATECOMM_CREATED:
			{
				mydebug::log("TOSBTAPI_NM_CREATECOMM_CREATED");
				//AfxMessageBox("TOSBTAPI_NM_CREATECOMM_CREATED");		
				break;
			}
		///////////////////////////


		//////////////////////////
		case TOSBTAPI_NM_CONNECTCOMM_ERROR:
			{
				mydebug::log("TOSBTAPI_NM_CONNECTCOMM_ERROR");
				if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
					AfxMessageBox("Failed to connect to phone... Please try again.");		

				RevertToIdle(); //add hwnd, icon movement, icon animation rsc numbers, etc...						
				break;
			}

		case TOSBTAPI_NM_CONNECTCOMM_CONNECTED:
			{
				mydebug::log("TOSBTAPI_NM_CONNECTCOMM_CONNECTED");

				iLabel->SetWindowText("Connected... preparing data reader");

				mydebug::log("0000000000000000");

				PBTDEVINFOLIST	ptr;
				ptr = iDevInfo.pDevInfoList;

				mydebug::log("connected");

				if(StartIoOnComport(iRFCOMMCID,rfcommport_int, true))
				{
					
					//ShowHex(ptr->DevInfo[iSelectedDev].BdAddr,6);
					
					mydebug::log("StartIoOnComport true");

					iCaller->OnConnected(ptr->DevInfo[iSelectedDev].BdAddr,6);    		

					mydebug::log("StartIoOnComport OnConnected");

					//if(FALSE == BtNotifyCOMM(gpInfo->szPortName, gpInfo->wEventMask, gpInfo->BD_ADDR, &(gpInfo->wCID), &(gpInfo->lSts)
					
					//0x0002 = monitor disconneciton 

					BtNotifyCOMM(rfcommport, 0x0002, ptr->DevInfo[iSelectedDev].BdAddr, &iRFCOMMCID, &iStatus, iParams.iHWND, UM_TOSHMESSAGES, iRFCOMMCID );					
					mydebug::log("BtNotifyCOMM");

					
				}
				else
				{
					if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
						AfxMessageBox("Failed to start COMM reader");		

					RevertToIdle(); //add hwnd, icon movement, icon animation rsc numbers, etc...						
				}

				break;
			};		

		case TOSBTAPI_NM_NOTIFYCOMM_ERROR:
			{
				mydebug::log("TOSBTAPI_NM_NOTIFYCOMM_ERROR");
		//	AfxMessageBox("TOSBTAPI_NM_NOTIFYCOMM_ERROR");
				break;
			};
		case TOSBTAPI_NM_NOTIFYCOMM_CONNECTED:
		{
			mydebug::log("TOSBTAPI_NM_NOTIFYCOMM_CONNECTED");
		//	AfxMessageBox("TOSBTAPI_NM_NOTIFYCOMM_CONNECTED");
			break;
		};
		case TOSBTAPI_NM_NOTIFYCOMM_DISCONNECTED:
		{
		//	AfxMessageBox("TOSBTAPI_NM_NOTIFYCOMM_DISCONNECTED");
			mydebug::log("TOSBTAPI_NM_NOTIFYCOMM_DISCONNECTED");

			RevertToIdle();
			
			mydebug::log("RevertToIdle");

			iCaller->OnDisconnected();
			
			mydebug::log("iCaller->OnDisconnected()");


			break;
		};		
		//////////////////////////


		default:
		{	// Unfixed status		
			//AfxMessageBox("toshbt handler state error");
			//RevertToIdle(); //add hwnd, icon movement, icon animation rsc numbers, etc...
			break;
		}
	}//end switch

	}//end else

}
Exemplo n.º 4
0
void CWidcommHandler::OnInquiryComplete (BOOL success, short num_responses)
{

	StopBTInteractionTimer();

	Sleep (100);
	

	if(iFoundDevices.GetSize() <=0 )
	{
		//CString str(((CWidcommFoundDevice*) iFoundDevices.GetAt(0))->iName);
		
		//TODO: get HWND so message box can be seen
		this->iLabel->SetWindowText("No nearby Bluetooth devices found");
		
		if(iRequestedCommand == ESendFileSession)
		{
			if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
				MessageBox(iHwnd,"No nearby Bluetooth devices found.\r\n\r\n- Make sure your PC's Bluetooth is plugged-in/started and ready.\r\n- Make sure your phone's Bluetooth is ON and discoverable (\"show to all\",\"Find me!\",etc.).\r\n- Try Again.\r\n- See \"Help\" for other installation methods.","No nearby devices found",MB_OK | MB_ICONASTERISK);
		}
		else
		{
			if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
				MessageBox(iHwnd,"No nearby Bluetooth devices found.\r\n\r\n- Make sure your PC's Bluetooth is plugged-in/started and ready.\r\n- Make sure your phone's Bluetooth is ON and discoverable (\"show to all\",\"Find me!\",etc.).\r\n- Try Again.","No nearby devices found",MB_OK | MB_ICONASTERISK);
		}

		RevertToIdle(); //add hwnd, icon movement, icon animation rsc numbers, etc...
		return;
	}

	

	if(iRequestedCommand == ESendFileSession)
	{	
		int SelectedDev=-1;
		iIcon->Stop();
		
		//let user choose from listbox
		CSelectPhoneDialog dlg(EWidcommStack,&iFoundDevices,SelectedDev,CWMouseXPDlg::curInstance);

		if(IDOK == dlg.DoModal() && SelectedDev>=0)
		{
			//do obexop to the selected device
			CString dsp("Discovering services on ");

			CWidcommFoundDevice* dev = (CWidcommFoundDevice*) iFoundDevices.GetAt(SelectedDev);
			
			dsp += dev->iName;

			iLabel->SetWindowText(dsp);

			CopyBDADDR(dev->iAddr,iDiscoveringDevice);

			iDiscoverCommandSent = true;

			iDiscoveringGUID = ObexObjectPush_guid;
			
			
			iIcon->UnLoad();
			iIcon->Load(MAKEINTRESOURCE(iSendAnim),iAnimRscType);
			iIcon->Draw();

			//Sleep(3000);	// L2CAP needs at least 1 sec to clear previous discovery connection

			if(	StartDiscovery(dev->iAddr, &ObexObjectPush_guid) )
				/*Sleep(2000)*/;
			else
			{
				if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))										
					MessageBox(iHwnd,"General discovery fault: Try again soon.","Discovey Fault",MB_OK | MB_ICONASTERISK);

				RevertToIdle(); //add hwnd, icon movement, icon animation rsc numbers, etc...
				return;	
			}




		}
		else
		{
			RevertToIdle(); //add hwnd, icon movement, icon animation rsc numbers, etc...
			return;	
		}
	}
	else
	{
		//start discovering for WMouseXP service on all devices.			

			iCurDevice = 0; //start going through all the devices

			DoDiscoverWMouseXPThroughDeviceList();	
	}


}
Exemplo n.º 5
0
void CWidcommHandler::OnDiscoveryComplete()
{

	if(!iDiscoverCommandSent)
		return;
	
	iDiscoverCommandSent = false;

	int services_found = 0;
	CSdpDiscoveryRec    SdpRecs[MAX_SERVICES_PER_DEVICE];
	
	UINT16 numrecs;
	
	
	if(DISCOVERY_RESULT_SUCCESS == GetLastDiscoveryResult(iDiscoveringDevice,&numrecs))
		;
	else
	{
		if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
			MessageBox(iHwnd,"Discovery Failed","Connect Failed",MB_OK | MB_ICONASTERISK);
	}


    services_found = ReadDiscoveryRecords(iDiscoveringDevice,MAX_SERVICES_PER_DEVICE,SdpRecs,&iDiscoveringGUID);


	
	if(iRequestedCommand == ESendFileSession)
	{
	
		if(services_found<=0)
		{
			this->iLabel->SetWindowText("OBEX Object Push not found on device.");
			MessageBox(iHwnd,"OBEX Object Push not found on selected device.\r\n\r\nWMouseXP can't send the mobile-side installer to it. \r\n\r\nPlease see \"Help\" for other installation methods:\r\n- Open \"wap.clearevo.com\" in your mobile's WAP browser and download WMouseXP directly.\r\n- Go to the installation path of this program and send the \"WMouseXP.jar\" via Bluetooth or phone's PC-Suite manually.","Send Failed",MB_OK | MB_ICONASTERISK);
			
			RevertToIdle(); //add hwnd, icon movement, icon animation rsc numbers, etc...
			return;		
		}
		else
		{
			for(int i=0;i<services_found;i++)
			{
				UINT8 rfcommscn;
				if(SdpRecs[i].FindRFCommScn(&rfcommscn))
				{
					
				
					//change icon to blue and start the icon
					//extract the jar to a temporary location...
					//do obex op to this device using this sdp record
					iLabel->SetWindowText("Sending File...");
				
					
					///////////////////////////////////////////////////
					


					
						{
						
							//AfxMessageBox(CString(iTmpObexFilePath));
							
							//send							
							if(OPP_CLIENT_SUCCESS == Push(iDiscoveringDevice,iTmpObexFilePath,SdpRecs[i]))
							{
							
							
							}
							else
							{
									if(OPP_CLIENT_SUCCESS == Push(iDiscoveringDevice,iTmpObexFilePath,SdpRecs[i]))
									{
									
									
									}
									else
									{
									
										MessageBox(iHwnd,"Temporary failure, Please try again.","Send Failed",MB_OK | MB_ICONASTERISK);
										RevertToIdle(); //add hwnd, icon movement, icon animation rsc numbers, etc...
										return;	

									}						

							}
							
							
													
						}


					

					
					
					return;
				}
			}
		
			this->iLabel->SetWindowText("No valid OBEX Object Push channels on device.");
			MessageBox(iHwnd,"No valid OBEX Object Push channels on device.\r\n\r\nWMouseXP can't send the mobile-side installer to it. \r\n\r\nPlease see \"Help\" for other installation methods:\r\n- Open \"wap.clearevo.com\" in your mobile's WAP browser and download WMouseXP directly.\r\n- Go to the installation path of this program and send the \"WMouseXP.jar\" via Bluetooth or phone's PC-Suite manually.","Send Failed",MB_OK | MB_ICONASTERISK);
			
			RevertToIdle(); //add hwnd, icon movement, icon animation rsc numbers, etc...
			return;	

		}
	}
	else
	{
		if(services_found<=0)
		{			
			iLabel->SetWindowText("WMouseXP not found on this device...");			
		}
		else
		{
			bool found = false;

			for(int i=0;i<services_found;i++)
			{
				UINT8 rfcommscn=0;
				if(SdpRecs[i].FindRFCommScn(&rfcommscn) && rfcommscn!=0)
				{					
					CWidcommFoundDevice* dev = (CWidcommFoundDevice*) iFoundDevices.GetAt(iCurDevice-1);										
					(dev->iWMouseXPscn) = rfcommscn;
					iWMouseXPDevicesIndex.Add(new int(iCurDevice-1));
					found = true;				
					break;
				}
			}
			
			if(!found)					
			{
				iLabel->SetWindowText("WMouseXP not found on this device...");				
			}
			
		}

		if(DoDiscoverWMouseXPThroughDeviceList())
		{
			;//wait until it finishes the list
		}
		else
		{
			//finished discovering all devices
			
			
			//see howmany devices remain in the list			
			if(iWMouseXPDevicesIndex.GetSize()==1)
			{
				//connect rfcomm to its scn
				int index = (*((int*)iWMouseXPDevicesIndex.GetAt(0)));

				CWidcommFoundDevice* dev = (CWidcommFoundDevice*) iFoundDevices.GetAt(index);					
				
				CString str = "Connecting to WMouseXP on ";
				str += dev->iName;									
				iLabel->SetWindowText(str);

				
				if (! m_RfCommIf.AssignScnValue(&iDiscoveringGUID,dev->iWMouseXPscn,m_serviceName))
				{
					iLabel->SetWindowText("Assign scn failed");
					RevertToIdle();				
					return;
				}

				 UINT8 sec_level = BTM_SEC_NONE;

				if (! m_RfCommIf.SetSecurityLevel(m_serviceName, sec_level , false))
				{
					/*dont give up - try continue - case from "Sébastien DOBLER" <*****@*****.**>
					iLabel->SetWindowText("Error setting security level");
					RevertToIdle();				
					return; */
				}


				CopyBDADDR(dev->iAddr,iDiscoveringDevice);

				if(PORT_RETURN_CODE::SUCCESS!= OpenClient(dev->iWMouseXPscn, dev->iAddr))
				{
					iLabel->SetWindowText("Error opening rfcomm connection");
					RevertToIdle();				
					return;					
				}
					

					


			}
			else
			if(iWMouseXPDevicesIndex.GetSize()<=0)
			{
				//show message
				if(!iUsingPrevDev)
				{
					iLabel->SetWindowText("Can't find any device with WMouseXP running");

					if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
						MessageBox(iHwnd,"Can't find any device with WMouseXP running:\r\n\r\n- Make sure your PC's Bluetooth is plugged-in/started and ready.\r\n- Make sure your phone's Bluetooth is ON and discoverable (\"show to all\").\r\n- Make sure your phone's WMouseXP (Mobile Side) is started and displaying \"Awaiting PC Side\".\r\n- Try Again.","Connect Failed",MB_OK | MB_ICONASTERISK);
				}
				else
				{
					iLabel->SetWindowText("Can't connect to WMouseXP on the Previous Phone");

					if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
						MessageBox(iHwnd,"Can't connect to WMouseXP on the Previous Phone:\r\n\r\n- Make sure your PC's Bluetooth is plugged-in/started and ready.\r\n- Make sure your phone's Bluetooth is ON and discoverable (\"show to all\").\r\n- Make sure your phone's WMouseXP (Mobile Side) is started and displaying \"Awaiting PC Side\".\r\n- If you don't want to use the previous phone, uncheck the \"Previous Phone\" box.\r\n- Try Again.","Connect Failed",MB_OK | MB_ICONASTERISK);
				}
				
				
				RevertToIdle();				
			}
			else// more than one device with WMouseXP found
			{				
				//let user choose the device like the msstack implementation
				int SelectedDev=-1;
				CSelectPhoneDialog dlg(EWidcommStack,&iFoundDevices,SelectedDev,CWMouseXPDlg::curInstance);

				if(IDOK == dlg.DoModal() && SelectedDev>=0)
				{
					//int index = (*((int*)iWMouseXPDevicesIndex.GetAt(SelectedDev))); That's for MS Stack style...
					int index = SelectedDev;

					CWidcommFoundDevice* dev = (CWidcommFoundDevice*) iFoundDevices.GetAt(index);					
					
					CString str = "Connecting to WMouseXP on ";
					str += dev->iName;									
					iLabel->SetWindowText(str);

					
					if (! m_RfCommIf.AssignScnValue(&iDiscoveringGUID,dev->iWMouseXPscn,m_serviceName))
					{
						iLabel->SetWindowText("Assign scn failed");
						RevertToIdle();				
						return;
					}

					 UINT8 sec_level = BTM_SEC_NONE;

					if (! m_RfCommIf.SetSecurityLevel(m_serviceName, sec_level , false))
					{
						iLabel->SetWindowText("Error setting security level");
						RevertToIdle();				
						return;					
					}


					CopyBDADDR(dev->iAddr,iDiscoveringDevice);

					if(PORT_RETURN_CODE::SUCCESS!= OpenClient(dev->iWMouseXPscn, dev->iAddr))
					{
						iLabel->SetWindowText("Error opening rfcomm connection");
						RevertToIdle();				
						return;					
					}
				}
				else
				{				
					RevertToIdle();				
				}



			}			
		
		}
		
	
	}
		
	
}