Ejemplo n.º 1
0
static void readDat(){
	unsigned short accumulatedData = 0;
	int i;
	copyController(&prev_controller_state, controller_state);

	IOWR_8DIRECT(controller_out, 0, 0x01);
	IOWR_8DIRECT(controller_out, 0, 0x03);
	alt_busy_sleep(12);
	IOWR_8DIRECT(controller_out, 0, 0x01);
	alt_busy_sleep(6);

	accumulatedData = IORD_8DIRECT(controller_in, 0);

	for (i = 0; i < 16; i++)
	{
		IOWR_8DIRECT(controller_out, 0, 0x00);
		alt_busy_sleep(6);
		accumulatedData <<= 1;
		accumulatedData += IORD_8DIRECT(controller_in, 0);
		IOWR_8DIRECT(controller_out, 0, 0x01); // Pulse clock
		alt_busy_sleep(6);
	}

	IOWR_8DIRECT(leds, 0, accumulatedData);

	copyController(&controller_state, getControllerButtons(accumulatedData));
}
Ejemplo n.º 2
0
	void BaseRpcChannel::processResponse( const string& responseMsg ) {
		try {
			istringstream in( responseMsg );
			int msgType = Util::readInt( in );

			switch( msgType ) {
			case RpcMessage::RESPONSE_MSG: 
				{                            
					string callId;
					RpcController controller;
					shared_ptr<Message> response;
					//parse the response
					RpcMessage::parseResponseFrom( in, callId, controller, response );
					GOOGLE_LOG( INFO ) << "received a response message, callId:" << callId;
					//if the response is still not timeout
					shared_ptr<ResponseParam> respParam = waitingResponses_->erase( callId );
					if( respParam ) {                            
						timer_->cancel( callId );
						RpcController* pController = dynamic_cast<RpcController*>( respParam->controller );
						if( pController ) {
							copyController( *pController, controller );
						}
						if( respParam->response && response ) {
							copyMessage( *(respParam->response), *response );
						}

						if( respParam->completed ) {
							
							{
								boost::lock_guard<boost::mutex> lock(mMutex);
								*(respParam->completed) = true;
							}
							mCondVariable.notify_all();
						}

						if( respParam->done ) {
							respParam->done->Run();
						}

						if( pController ) {
							pController->complete();
						}

					}
				}
				break;
			}

		}catch( const std::exception& ex) {
			GOOGLE_LOG( ERROR ) << "catch exception:" << ex.what() ;
		} catch( ... ) {
			GOOGLE_LOG( ERROR ) << "catch unknown exception";
		}
	}