//------------------------------------------------------------------------ void CWeaponSystem::OnLoadingStart(ILevelInfo *pLevel) { if (gEnv->bMultiplayer) SetConfiguration("mp"); else SetConfiguration(""); }
void evaluateGradientFromPotential(struct configuration *p) { struct functionDefinition *fd; struct configuration *pPlusDelta = NULL; struct configuration *pMinusDelta = NULL; int i; int j; NULLPTR(p); fd = p->functionDefinition; NULLPTR(fd); if (fd->gradient_delta == 0.0) { fd->gradient_delta = 1e-8; } for (i=0; i<fd->dimension; i++) { pPlusDelta = makeConfiguration(fd); for (j=0; j<fd->dimension; j++) { pPlusDelta->coordinate[j] = p->coordinate[j]; } pPlusDelta->coordinate[i] += fd->gradient_delta / 2.0; pMinusDelta = makeConfiguration(fd); for (j=0; j<fd->dimension; j++) { pMinusDelta->coordinate[j] = p->coordinate[j]; } pMinusDelta->coordinate[i] -= fd->gradient_delta / 2.0; p->gradient[i] = (evaluate(pMinusDelta) - evaluate(pPlusDelta)) / fd->gradient_delta; BAIL(); SetConfiguration(&pPlusDelta, NULL); SetConfiguration(&pMinusDelta, NULL); } }
/************************************************************************* * SEQ-STUDIO-WINDOW *************************************************************************/ SeqStudioWindow::SeqStudioWindow( BRect frame, const BMessage* config = NULL) : inherited(frame, "Studio", B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS), mBg(NULL), mPortMenu(NULL), mLabelCtrl(NULL), mDeviceCtrl(NULL) { BRect b(Bounds() ); BRect r(b); r.bottom = Prefs().Size(MAINMENU_Y); AddMainMenu(r); r.top = r.bottom + 1; /* This accounts for the document window tab. That tab does * not play nicely with a background that goes completely behind * it -- it leaves trails -- so we have to chunk the background * into two parts. */ r.bottom = b.bottom - B_H_SCROLL_BAR_HEIGHT; AddViews(r); r.top = r.bottom + 1; r.bottom = b.bottom; r.right = b.right - B_V_SCROLL_BAR_WIDTH; BView* v = new BView(r, "filler", B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM, 0); if (v) { v->SetViewColor( Prefs().Color(AM_AUX_WINDOW_BG_C) ); AddChild(v); } if (config) SetConfiguration(config); }
/***************************************************************************** 初期化 *****************************************************************************/ bool CGainer::Init(int portNum, int mode) { if ( m_inited ) { return true; } m_led = false; m_config = mode; m_port = portNum; m_endFlag = false; m_hwnd_sstp = NULL; m_analog_period = 0; m_analog_last = 0; m_digital_period = 0; m_digital_last = 0; ZeroMemory(m_LEDMatrixOutputs,sizeof(m_LEDMatrixOutputs)); m_receive_buffer.assign(RECV_BUFFER,0); InitializeCriticalSection(&m_receive_queue_lock); m_receive_queue_semaphore = ::CreateSemaphore(NULL,0,9999,NULL); // COM port open if ( ! m_serial.Open(m_port, RECV_BUFFER, SEND_BUFFER) ) { return false; } // setting of COM port if ( ! m_serial.SetConfig(COMLIBFLAG_38400|COMLIBFLAG_NO|COMLIBFLAG_1|COMLIBFLAG_8|COMLIBFLAG_NO_FLOW_CONTROL) ) { m_serial.Close(); return false; } // setting receiving timeout m_serial.SetTimeout(RECV_TIMEOUT_COMM, RECV_TIMEOUT_INTERVAL, SEND_TIMEOUT_COMM); // software reset Reboot(true); m_thread_handle = (HANDLE)_beginthreadex(NULL, 0, receiver, this, 0, NULL); wait_recv(); // ver. m_version_string = command_send("?*"); m_version_string.erase(0,1); m_version_string.erase(m_version_string.size()-1,1); // set configulation mode if ( m_config ) { SetConfiguration(m_config); } m_inited = true; g_gainer_open_ports.push_back(m_port); return true; }
int main(int argc, char* argv[]) { PrintHello(); if (ProcessCmdLine(argc, argv) != 0) return -1; OpenUsbDevice(); if (dwRC == USBIO_ERR_SUCCESS) { GetDeviceDescriptor(); } if (dwRC == USBIO_ERR_SUCCESS) { GetConfigurationDescriptor(); } if (dwRC == USBIO_ERR_SUCCESS) { GetStringDescriptor(); } if (dwRC == USBIO_ERR_SUCCESS) { SetConfiguration(); } if (dwRC == USBIO_ERR_SUCCESS) { // In order to give the USB device-side program (t_usb) // enough time after getting configured to carry out // some device tests, we wait here for a short while // before proceeding: Delay(2000); GetConfigurationInfo(); } if (dwRC == USBIO_ERR_SUCCESS) { OpenPipes(); } if (dwRC == USBIO_ERR_SUCCESS) { ExchangeVersions(); } if (dwRC == USBIO_ERR_SUCCESS) { DoTransfers(); } if (dwRC == USBIO_ERR_SUCCESS) { ClosePipes(); } CloseUsbDevice(); return 0; }
/************************************************************************* * SEQ-PREF-WIN *************************************************************************/ SeqPrefWin::SeqPrefWin(BRect frame, const BMessage* config) : inherited(frame, "Preferences", B_TITLED_WINDOW, B_NOT_ZOOMABLE), mOwqTable(0), mFilePanel(0), mUndoLevelCtrl(NULL), mTrackWinFollowCtrl(NULL), mTrackWinPlayToEndCtrl(NULL), mTrackHeightCtrl(NULL), mLabelHeightCtrl(NULL), mRefreshWindows(0), mFactoryView(0), mFactoryList(0), mFactoryInspector(0) { seq_app->GetPreferences(&mPreferences); if (config) SetConfiguration(config); AddViews(mPreferences); }
static GOOD_OR_BAD DS2482_channel_select(struct connection_in * in) { struct connection_in *head = in->master.i2c.head; int chan = in->master.i2c.index; FILE_DESCRIPTOR_OR_ERROR file_descriptor = in->pown->file_descriptor; /* Write and verify codes for the CHANNEL_SELECT command (DS2482-800 only). To set the channel, write the value at the index of the channel. Read and compare against the corresponding value to verify the change. */ static const BYTE W_chan[8] = { 0xF0, 0xE1, 0xD2, 0xC3, 0xB4, 0xA5, 0x96, 0x87 }; static const BYTE R_chan[8] = { 0xB8, 0xB1, 0xAA, 0xA3, 0x9C, 0x95, 0x8E, 0x87 }; if ( FILE_DESCRIPTOR_NOT_VALID(file_descriptor) ) { LEVEL_CONNECT("Calling a closed i2c channel (%d) "I2Cformat" ", chan,I2Cvar(in)); return gbBAD; } /* Already properly selected? */ /* All `100 (1 channel) will be caught here */ if (chan != head->master.i2c.current) { int read_back; /* Select command */ if (i2c_smbus_write_byte_data(file_descriptor, DS2482_CMD_CHANNEL_SELECT, W_chan[chan]) < 0) { LEVEL_DEBUG("Channel select set error"); return gbBAD; } /* Read back and confirm */ read_back = i2c_smbus_read_byte(file_descriptor); if (read_back < 0) { LEVEL_DEBUG("Channel select get error"); return gbBAD; // flag for DS2482-100 vs -800 detection } if (((BYTE) read_back) != R_chan[chan]) { LEVEL_DEBUG("Channel selected doesn't match"); return gbBAD; // flag for DS2482-100 vs -800 detection } /* Set the channel in head */ head->master.i2c.current = in->master.i2c.index; } /* Now check the configuration register */ /* This is since configuration is per chip, not just channel */ if (in->master.i2c.configreg != head->master.i2c.configchip) { return SetConfiguration(in->master.i2c.configreg, in); } return gbGOOD; }
/************************************************************************* * AM-CONTROL-CHANGE-INFO-VIEW *************************************************************************/ AmControlChangeInfoView::AmControlChangeInfoView( BRect frame, AmSongRef songRef, AmTrackWinPropertiesI& trackWinProps, const AmViewPropertyI* property, TrackViewType viewType) : inherited(frame, STR_CONTROL_CHANGE_INFO, songRef, trackWinProps, viewType), mCc(INITIAL_CC), mCachedControlMenu(0) { mFactorySignature = property->Signature(); mViewName = property->Name(); if( property->Configuration() ) SetConfiguration( property->Configuration() ); }
void touchmind::view::node::NodeViewManager::DrawPath(touchmind::Context *pContext, ID2D1RenderTarget *pRenderTarget, std::shared_ptr<model::node::NodeModel> node) { if (m_nodeIdToPathView.count(node->GetId()) == 0) { auto pathView = touchmind::view::path::PathViewFactory::Create(node); m_nodeIdToPathView.insert({node->GetId(), pathView}); pathView->SetConfiguration(m_pConfiguration); pathView->SetNodeViewManager(this); pathView->SetNodeModel(node); } auto pathView = m_nodeIdToPathView[node->GetId()]; pathView->Draw(pContext, pRenderTarget); pathView->SetHandled(); }
//------------------------------------------------------------------------ void CWeaponSystem::OnLoadingStart(ILevelInfo *pLevel) { if(gEnv->bMultiplayer) SetConfiguration("mp"); else SetConfiguration(""); //Reset cache geometry flags, since cache geometry is reset on loading start in ItemSytem for(TAmmoTypeParams::iterator it = m_ammoparams.begin(); it != m_ammoparams.end(); ++it) { SAmmoTypeDesc &desc=it->second; desc.params->ResetCacheGeometry(); if(!desc.configurations.empty()) { for(std::map<string, const SAmmoParams *>::iterator ait=desc.configurations.begin(); ait!=desc.configurations.end(); ait++) { ait->second->ResetCacheGeometry(); } } } }
// Perform a one dimensional minimization starting at configuration p. // The gradient of the function at p is calculated, and the // minimization is along the line of that gradient. The resulting // minimum configuration point is returned. static struct configuration * linearMinimize(struct configuration *p, double tolerance, enum linearAlgorithm algorithm) { struct configuration *a = NULL; struct configuration *b = NULL; struct configuration *c = NULL; struct configuration *min = NULL; Enter(p); bracketMinimum(&a, &b, &c, p); BAILR(NULL); if (Interrupted) return b; NULLPTRR(a, p); NULLPTRR(b, p); NULLPTRR(c, p); if (DEBUG(D_MINIMIZE)) { message(p->functionDefinition, "bmin: a %e[%e] b %e[%e] c %e[%e]", evaluate(a), a->parameter, evaluate(b), b->parameter, evaluate(c), c->parameter); } if (algorithm == LinearBracket && b != p) { SetConfiguration(&min, b); } else { min = brent(p, a, b, c, tolerance); } //printf("minimum at parameter value: %e, function value: %e\n", min->parameter, evaluate(min)); SetConfiguration(&a, NULL); SetConfiguration(&b, NULL); SetConfiguration(&c, NULL); if (DEBUG(D_MINIMIZE) && min == p) { message(p->functionDefinition, "linearMinimize returning argument"); } Leave(linearMinimize, p, (min == p) ? 0 : 1); return min; }
/** * Local function to handle a standard interface request * * @param [in] pSetup The setup packet * @param [in,out] *piLen Pointer to data length * @param [in] ppbData Data buffer. * * @return TRUE if the request was handled successfully */ uint8_t USBCTRL::HandleStdInterfaceReq(TSetupPacket *pSetup, int *piLen, uint8_t **ppbData) { uint8_t *pbData = *ppbData; switch (pSetup->bRequest) { case REQ_GET_STATUS: // no bits specified pbData[0] = 0; pbData[1] = 0; *piLen = 2; break; case REQ_CLEAR_FEATURE: case REQ_SET_FEATURE: // not defined for interface return FALSE; case REQ_GET_INTERFACE: // TODO use bNumInterfaces // there is only one interface, return n-1 (= 0) pbData[0] = bAlternate; *piLen = 1; break; case REQ_SET_INTERFACE: // TODO use bNumInterfaces // there is only one interface (= 0) if (pSetup->wValue > conf->bNumInterfaces) { return FALSE; } iprintf("Set alternate %d", pSetup->wValue); if (SetConfiguration(conf->bConfigurationValue, pSetup->wValue)) { // DBG(" OK\n"); bAlternate = pSetup->wValue; } else { // DBG(" failed!\n"); return FALSE; } *piLen = 0; break; default: // DBG("Illegal interface req %d\n", pSetup->bRequest); return FALSE; } return TRUE; }
MediaServer::MediaServer(void) : m_pUPnpCDS(NULL), m_pUPnpCMGR(NULL), m_sSharePath(GetShareDir()) { VERBOSE(VB_UPNP, "MediaServer:ctor:Begin"); // ---------------------------------------------------------------------- // Initialize Configuration class (Database for Servers) // ---------------------------------------------------------------------- SetConfiguration( new DBConfiguration() ); // ---------------------------------------------------------------------- // Create mini HTTP Server // ---------------------------------------------------------------------- VERBOSE(VB_UPNP, "MediaServer:ctor:End"); }
bool EHCIDevice::CheckConfiguration(char& bConfigValue, char bNumConfigs) { if(bNumConfigs <= 0) { printf("\n Invalid NumConfigs: %d", bNumConfigs) ; return false; } if(bConfigValue <= 0 || bConfigValue > bNumConfigs) { bool bStatus ; printf("\n Current Configuration %d -> Invalid. Setting to Configuration 1", bConfigValue) ; RETURN_MSG_IF_NOT(bStatus, SetConfiguration(1), true, "SetConfiguration Failed") ; bConfigValue = 1 ; } return true; }
static GOOD_OR_BAD DS2482_PowerByte(const BYTE byte, BYTE * resp, const UINT delay, const struct parsedname *pn) { struct connection_in * in = pn->selected_connection ; /* Make sure we're using the correct channel */ RETURN_BAD_IF_BAD(DS2482_channel_select(in)) ; /* Set the power (bit is automatically cleared by reset) */ TrafficOut("power write", &byte, 1, in ) ; RETURN_BAD_IF_BAD(SetConfiguration( in->master.i2c.configreg | DS2482_REG_CFG_SPU, in)) ; /* send and get byte (and trigger strong pull-up */ RETURN_BAD_IF_BAD(DS2482_send_and_get( in->pown->file_descriptor, byte, resp)) ; TrafficOut("power response", resp, 1, in ) ; UT_delay(delay); return gbGOOD; }
bool Flea3Camera::Connect() { PGRGuid guid; PgrError(bus_manager_.GetCameraFromSerialNumber(serial_id(), &guid), serial_ + " not found. " + AvailableDevice()); const auto error = camera_.Connect(&guid); if (error == PGRERROR_OK) { // This is a total hack, it exists because one of my camera doesn't enable // auto white balance by default. You have to write to its presence register // to bring it online. // EnableAutoWhiteBalance(); // For now this only set the grab timeout SetConfiguration(); return true; } else { ROS_INFO("Failed to connect to camera: %s. Try again. | %s", serial().c_str(), error.GetDescription()); return false; } }
void AmControlChangeInfoView::MessageReceived(BMessage *msg) { switch (msg->what) { case I_ARP_CC_CHANGE_MSG: int32 tmp; if (msg->FindInt32(STR_CONTROL_CHANGE, &tmp) == B_OK) { mCc = (uchar)tmp; mTrackWinProps.PostMessageToDataView(*msg, this); Invalidate(); } break; case ARPMSG_CONFIGDATA: SetConfiguration(msg); break; default: inherited::MessageReceived(msg); break; } }
// Initialize usb device. NTSTATUS UsbDev::InitializeUsbDevice(PVOID pDevExt) // shawn 2011/05/06 modify { NTSTATUS ntStatus = STATUS_SUCCESS; m_pDevExtTmp = pDevExt; // shawn 2011/05/06 add DBGU_TRACE(">>>UsbDev::InitializeUsbDevice !\n"); ntStatus = GetDeviceDescriptor(); if(NT_SUCCESS(ntStatus)) { ntStatus = GetConfigurationDescriptor(); if(NT_SUCCESS(ntStatus)) { ntStatus = SetConfiguration(); } } DBGU_TRACE("UsbDev::InitializeUsbDevice return %X\n", ntStatus); return ntStatus; }
/************************************************************************* * SEQ-EDIT-TOOL-WINDOW *************************************************************************/ SeqEditMultiFilterWindow::SeqEditMultiFilterWindow( BRect frame, const BMessage* config, const BMessage* multiMsg) : inherited(frame, "Edit Multi Filter"), mMultiFilterAddOn(NULL), mMultiFilter(NULL), mNameCtrl(NULL), mKeyCtrl(NULL), mLongDescriptionCtrl(NULL), mPipelineView(NULL), mIconCtrl(NULL), mIconEditor(NULL) { BRect targetF(CurrentPageFrame() ); BView* view = NULL; if ((view = NewGeneralView(targetF))) AddPage(view); if ((view = NewPipelineView(targetF))) AddPage(view); if ((view = NewDescriptionView(targetF))) AddPage(view); if ((view = NewIconView(targetF))) AddPage(view); if (config) SetConfiguration(config); else SetFirstPage(); if (multiMsg) SetMultiFilter(multiMsg); }
MediaServer::MediaServer(void) : #ifdef USING_LIBDNS_SD m_bonjour(NULL), #endif m_pUPnpCDS(NULL), m_pUPnpCMGR(NULL), m_sSharePath(GetShareDir()) { LOG(VB_UPNP, LOG_INFO, "MediaServer:ctor:Begin"); // ---------------------------------------------------------------------- // Initialize Configuration class (Database for Servers) // ---------------------------------------------------------------------- SetConfiguration( new DBConfiguration() ); // ---------------------------------------------------------------------- // Create mini HTTP Server // ---------------------------------------------------------------------- LOG(VB_UPNP, LOG_INFO, "MediaServer:ctor:End"); }
/************************************************************************* * SEQ-PHRASE-PROPERTY-WINDOW *************************************************************************/ SeqPhrasePropertyWindow::SeqPhrasePropertyWindow( AmSongRef songRef, AmPhraseEvent* event, const BMessage* config) : inherited(BRect(0, 0, 0, 0), "Phrase Properties", B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS), mSongRef(songRef), mEvent(NULL), mBg(NULL), mNameCtrl(NULL), mTimeLabel(NULL), mTimeCtrl(NULL), mColorField(NULL), mColorCtrl(NULL) { AddViews(BRect(0, 0, 50, 50)); float w = 0, h = 0; /* Set my dimensions. */ if (mBg) { for (BView* view = mBg->ChildAt(0); view; view = view->NextSibling() ) { BRect f = view->Frame(); if (f.right > w) w = f.right; if (f.bottom > h) h = f.bottom; } ResizeTo(w + Prefs().Size(BORDER_X), h + Prefs().Size(BORDER_Y)); } /* Set my location. */ BScreen s(this); if (s.IsValid() ) { BRect sf = s.Frame(); float newX = 10, newY = 10; if (w < sf.Width() ) newX = (sf.Width() - w) / 2; if (h < sf.Height() ) newY = (sf.Height() - h) / 2; MoveTo(newX, newY); } if (config) SetConfiguration(config); if (event) SetPhraseEvent(event); }
U8 Host_Initial(void) { data U8 i; data U8 EP_flag=0; data U8 states; data U8 tc_StrProductName; data U8 tc_StrSerialNum; data U16 Stg_idx; USB_HOST_Init: DeviceAddress = 1; gb_HostConnect = 1; gb_HostInitial=1; EA=0; XBYTE[0xB530]=0xFF; XBYTE[0xB01F]=0x01; Host_register_INIT(); XBYTE[0xB01C]&=0xDF; //Auto Ack in delay(5000); // USB SUSPEND XBYTE[0xB610]=0x04; //force full-speed delay(60000); XBYTE[0xB610]=0x04; delay(200); // USB RESET XBYTE[0xB610]=0x03; //force full-speed delay(20000); XBYTE[0xB610]=0x03; delay(200); XBYTE[0xB630]=0x01; //SOF ON XBYTE[0xB632]=0xB8; //EOF point XBYTE[0xB633]=0x0B; delay(10000); gdw_pollingtime=320000; i=0; EA=1; while(1) { delay(2000); states = GetDescriptor(0,0x100,0,0x40); if(states == 0x00) { Max_Trans_Length = XBYTE[HOST_BUF_SA+7]; break; } else { i++; if(i==3) { gb_HostConnect=0; return HOST_GETDESCRIPTOR_FAIL; } if(gb_HostConnect == 0) { return HOST_PHYCOUNECT_FAIL; } } } EA=0; gb_HostInitial=0; XBYTE[0xB002] |= 0x02; //bit 2 turn on USB_host_SW_RESET XBYTE[0xB002] &=~0x02; //bit 2 turn off USB_host_SW_RESET // USB RESET XBYTE[0xB610]=0x03; //force full-speed delay(1200); XBYTE[0xB610]=0x03; delay(200); XBYTE[0xB630]=0x01; //SOF ON XBYTE[0xB632]=0xB8; //EOF point XBYTE[0xB633]=0x0B; delay(5000); XBYTE[0xB01C]|=0x10; //clear RX error flags XBYTE[0xB01C]&=0xEF; EA=1; // Set address--00 05 01 00 00 00 00 00 states = SetAddress(); if(states) { return HOST_SETADDRESS_FAIL; } delay(50000); gb_dtg_in=0; gb_dtg_out=0; //---- 80 06 00 01 00 00 12 00---- if(gb_HostConnect == 0) { return HOST_PHYCOUNECT_FAIL; } states = GetDescriptor(DeviceAddress,0x0100,0x00,0x12); if(states) { return HOST_GETDESCRIPTOR_FAIL; } tc_StrProductName=XBYTE[HOST_BUF_SA+15]; tc_StrSerialNum=XBYTE[HOST_BUF_SA+16]; gw_VID=XBYTE[HOST_BUF_SA+8]+(XBYTE[HOST_BUF_SA+9]<<8); //---- 80 06 00 02 00 00 09 00 ---- if(gb_HostConnect == 0) { return HOST_PHYCOUNECT_FAIL; } delay(1000); states = GetDescriptor(DeviceAddress,0x200,0,0x09); if(states) { return HOST_GETDESCRIPTOR_FAIL; } Syn_Reset(); ConfigurationDescriptorLength=XBYTE[HOST_BUF_SA+2]; //---- 80 06 00 03 00 00 FF 00 ---- //---- 80 06 3r 03 09 04 FF 00 ---- if(tc_StrSerialNum!=0) { if(gb_HostConnect == 0) { return HOST_PHYCOUNECT_FAIL; } delay(1000); states = GetDescriptor(DeviceAddress,0x300,0,0xFF); if(states) { return HOST_GETDESCRIPTOR_FAIL; } Stg_idx=(U16)(XBYTE[HOST_BUF_SA+3]<<8)+XBYTE[HOST_BUF_SA+2]; if(gb_HostConnect == 0) { return HOST_PHYCOUNECT_FAIL; } delay(1000); states = GetDescriptor(DeviceAddress,tc_StrSerialNum+0x0300,Stg_idx,0xFF); if(states) { return HOST_GETDESCRIPTOR_FAIL; } Syn_Reset(); } //---- 80 06 00 02 00 00 FF 00 ---- if(gb_HostConnect == 0) { return HOST_PHYCOUNECT_FAIL; } delay(1000); states = GetDescriptor(DeviceAddress,0x200,0,0xFF); if(states) { return HOST_GETDESCRIPTOR_FAIL; } //---- 80 06 00 06 00 00 0A 00 ---- // delay(1000); // GetDescriptor(DeviceAddress,0x0600,0,0x0A); //---- 80 06 00 03 00 00 FF 00 ---- //---- 80 06 PP 03 09 04 FF 00 ---- //---- 80 06 00 03 00 00 FF 00 ---- //---- 80 06 PP 03 09 04 FF 00 ---- if(tc_StrProductName!=0) { U8 i; for(i=0;i<2;i++) { if(gb_HostConnect == 0) { return HOST_PHYCOUNECT_FAIL; } delay(1000); states = GetDescriptor(DeviceAddress,0x300,0,0xFF); if(states) { return HOST_GETDESCRIPTOR_FAIL; } Stg_idx=(U16)(XBYTE[HOST_BUF_SA+3]<<8)+XBYTE[HOST_BUF_SA+2]; if(gb_HostConnect == 0) { return HOST_PHYCOUNECT_FAIL; } delay(1000); states = GetDescriptor(DeviceAddress,tc_StrProductName+0x0300,Stg_idx,0xFF); if(states) { return HOST_GETDESCRIPTOR_FAIL; } } } //---- 80 06 00 01 00 00 12 00 ---- if(gb_HostConnect == 0) { return HOST_PHYCOUNECT_FAIL; } delay(1000); states = GetDescriptor(DeviceAddress,0x0100,0x00,0x12); if(states) { return HOST_GETDESCRIPTOR_FAIL; } //---- 80 06 00 02 00 00 09 00 ---- delay(1000); GetDescriptor(DeviceAddress,0x0200,0x00,0x09); //---- 80 06 00 02 00 00 xx 00 ---- delay(1000); GetDescriptor(DeviceAddress,0x0200,0x00,ConfigurationDescriptorLength); CFGValue=XBYTE[HOST_BUF_SA+0x05]; //---- Set Endpoint Value ---- for(i=0;i<ConfigurationDescriptorLength;) { if(XBYTE[HOST_BUF_SA+i]== 0x09) { i += 0x09; } else if(XBYTE[HOST_BUF_SA+i]== 0x07) { if((XBYTE[HOST_BUF_SA+i+1]==0x05)&&(XBYTE[HOST_BUF_SA+i+3]==0x02)) { if(XBYTE[HOST_BUF_SA+i+2]&0x80) { EP_IN = XBYTE[HOST_BUF_SA+i+2]&0x0F; EP_flag = EP_flag + 0x01; } else { EP_OUT = XBYTE[HOST_BUF_SA+i+2]&0x0F; EP_flag = EP_flag + 0x10; } } if(EP_flag == 0x11) { break; } i += 0x07; } else { i++; } } //---- 80 06 00 03 00 00 02 00 ---- delay(1000); GetDescriptor(DeviceAddress,0x0300,0x00,0x02); //---- 80 06 00 03 00 00 04 00 ---- delay(1000); GetDescriptor(DeviceAddress,0x0300,0x00,0x04); //---- 80 06 SS 03 09 04 02 00 ---- if(tc_StrSerialNum!=0) { U8 tc_leng; if(gb_HostConnect == 0) { return HOST_PHYCOUNECT_FAIL; } delay(1000); states = GetDescriptor(DeviceAddress,0x300+tc_StrSerialNum,Stg_idx,0x02); if(states) { return HOST_GETDESCRIPTOR_FAIL; } tc_leng=XBYTE[HOST_BUF_SA]; if(gb_HostConnect == 0) { return HOST_PHYCOUNECT_FAIL; } delay(1000); states = GetDescriptor(DeviceAddress,0x0300+tc_StrSerialNum,Stg_idx,tc_leng); if(states) { return HOST_GETDESCRIPTOR_FAIL; } } //---- 00 09 xx 00 00 00 00 00 ---- if(gb_HostConnect == 0) { return HOST_PHYCOUNECT_FAIL; } delay(1000); states = SetConfiguration(DeviceAddress,CFGValue,0,0); //---- Get MaxLun ---- if(gb_HostConnect == 0) { return HOST_PHYCOUNECT_FAIL; } gb_stall_flag=0; delay(1000); GetMAXLUN(); if(gb_stall_flag == 1) { MaxLUN=0; gb_stall_flag=0; } XBYTE[0xB01C]&=0xdf; //Auto Ack in delay(30000); SCSICMD_12_INQUIRY(); delay(1000); states = SCSICMD_23_READFORMATCAPACITY(); if(states!=0) { return HOST_PHYCOUNECT_FAIL; } if(gb_HostConnect == 0) { return HOST_PHYCOUNECT_FAIL; } Host_StallCmd_Timeout=0; while(1) { states = SCSICMD_25_READCAPACITY(); if(gb_HostConnect == 0) { return HOST_PHYCOUNECT_FAIL; } if(Host_StallCmd_Timeout>60) { return 0x77; // Initial fail } if(states!=HOST_STALL) { break; } } gc_CurrentCard = CURRENT_MEDIA_HOST; gdw_pollingtime=3000; gdw_HOSTStartSectorRead=0xFFFFFFF0; states=HOST_Read_Logicsector(0); if(states==3) { goto USB_HOST_Init; } return 0; }
MediaRenderer::MediaRenderer() { LOG(VB_UPNP, LOG_INFO, "MediaRenderer::Begin"); // ---------------------------------------------------------------------- // Initialize Configuration class (XML file for frontend) // ---------------------------------------------------------------------- SetConfiguration( new XmlConfiguration( "config.xml" )); // ---------------------------------------------------------------------- // Create mini HTTP Server // ---------------------------------------------------------------------- int nPort = g_pConfig->GetValue( "UPnP/MythFrontend/ServicePort", 6547 ); m_pHttpServer = new HttpServer(); if (!m_pHttpServer) return; if (!m_pHttpServer->listen(QHostAddress(gCoreContext->MythHostAddressAny()), nPort)) { LOG(VB_GENERAL, LOG_ERR, "MediaRenderer::HttpServer Create Error"); delete m_pHttpServer; m_pHttpServer = NULL; return; } // ---------------------------------------------------------------------- // Initialize UPnp Stack // ---------------------------------------------------------------------- if (Initialize( nPort, m_pHttpServer )) { // ------------------------------------------------------------------ // Create device Description // ------------------------------------------------------------------ LOG(VB_UPNP, LOG_INFO, "MediaRenderer::Creating UPnp Description"); UPnpDevice &device = g_UPnpDeviceDesc.m_rootDevice; device.m_sDeviceType = "urn:schemas-upnp-org:device:MediaRenderer:1"; device.m_sFriendlyName = "MythTv AV Renderer"; device.m_sManufacturer = "MythTV"; device.m_sManufacturerURL = "http://www.mythtv.org"; device.m_sModelDescription = "MythTV AV Media Renderer"; device.m_sModelName = "MythTV AV Media Renderer"; device.m_sModelURL = "http://www.mythtv.org"; device.m_sUPC = ""; device.m_sPresentationURL = "/"; // ------------------------------------------------------------------ // Register any HttpServerExtensions... // ------------------------------------------------------------------ LOG(VB_UPNP, LOG_INFO, "MediaRenderer::Registering MythFrontendStatus service."); m_pHttpServer->RegisterExtension( new MythFrontendStatus(m_pHttpServer->m_sSharePath)); QString sSinkProtocols = "http-get:*:image/gif:*," "http-get:*:image/jpeg:*," "http-get:*:image/png:*," "http-get:*:video/avi:*," "http-get:*:audio/mpeg:*," "http-get:*:audio/wav:*," "http-get:*:video/mpeg:*," "http-get:*:video/nupplevideo:*," "http-get:*:video/x-ms-wmv:*"; // ------------------------------------------------------------------ // Register the MythFEXML protocol... // ------------------------------------------------------------------ LOG(VB_UPNP, LOG_INFO, "MediaRenderer::Registering MythFEXML Service."); m_pHttpServer->RegisterExtension( new MythFEXML( RootDevice(), m_pHttpServer->m_sSharePath)); #if 0 LOG(VB_UPNP, LOG_INFO, "MediaRenderer::Registering AVTransport Service."); m_pUPnpAVT = new UPnpAVTransport( RootDevice() ); m_pHttpServer->RegisterExtension( m_pUPnpAVT ); #endif LOG(VB_UPNP, LOG_INFO, "MediaRenderer::Registering CMGR Service."); // HttpServer will be responsible for deleting UPnpCMGR m_pUPnpCMGR = new UPnpCMGR(RootDevice(), m_pHttpServer->m_sSharePath, "", sSinkProtocols ); m_pHttpServer->RegisterExtension( m_pUPnpCMGR ); #if 0 LOG(VB_UPNP, LOG_INFO, "MediaRenderer::Registering RenderingControl Service."); m_pUPnpRCTL= new UPnpRCTL( RootDevice() ); m_pHttpServer->RegisterExtension( m_pUPnpRCTL ); #endif UPNPSubscription *subscription = NULL; if (getenv("MYTHTV_UPNPSCANNER")) { LOG(VB_UPNP, LOG_INFO, "MediaRenderer: Registering subscription service."); subscription = new UPNPSubscription(m_pHttpServer->m_sSharePath, nPort); m_pHttpServer->RegisterExtension(subscription); } Start(); // Start scanning for UPnP media servers if (subscription) UPNPScanner::Enable(true, subscription); // ensure the frontend is aware of all backends (slave and master) and // other frontends SSDP::Instance()->PerformSearch("ssdp:all"); } else { LOG(VB_GENERAL, LOG_ERR, "MediaRenderer::Unable to Initialize UPnp Stack"); } LOG(VB_UPNP, LOG_INFO, "MediaRenderer::End"); }
void AndroidAccessory::init(int device, int configuration, int interfaceNumber) { log("AndroidAccessory::init \r\n"); // _initok=false; _device = device; _configuration = configuration; _interfaceNumber = interfaceNumber; printf("device = %d configuration = %d interfaceNumber = %d\r\n", device, configuration, interfaceNumber); int err; u8* buffer=_strbuff; err = GetDescriptor(_device,DESCRIPTOR_TYPE_CONFIGURATION,0,buffer,4); if (err < 0) { log("Failed to get descriptor\r\n"); return; } int len = buffer[2] | (buffer[3] << 8); if (len > 255) { log("config descriptor too large\n"); /* might want to truncate here */ return; } err = GetDescriptor(_device,DESCRIPTOR_TYPE_CONFIGURATION,0,buffer,len); u8* p = buffer; input_ep=0; output_ep=0; EndpointDescriptor *epDesc; while (p<(buffer+len)) { u8 descLen = p[0]; u8 descType = p[1]; log("descLen=%d,descType=%d\r\n",descLen,descType); switch (descType) { case DESCRIPTOR_TYPE_CONFIGURATION: log("config desc\r\n"); break; case DESCRIPTOR_TYPE_INTERFACE: log("interface desc\r\n"); break; case DESCRIPTOR_TYPE_ENDPOINT: epDesc=(EndpointDescriptor*)p; if (!input_ep && (epDesc->bEndpointAddress& 0x80)) { input_ep=epDesc->bEndpointAddress& 0x7f; //PacketSize drop log("input Endpoint address=%d,wMaxPacketSize=%d,bmAttributes=%d\r\n",input_ep,epDesc->wMaxPacketSize,epDesc->bmAttributes); } else if (!output_ep) { output_ep=epDesc->bEndpointAddress& 0x7f; //PacketSize drop log("output Endpoint address=%d,wMaxPacketSize=%d,bmAttributes=%d\r\n",input_ep,epDesc->wMaxPacketSize,epDesc->bmAttributes); } else { //other log("non input,output Endpoint address=%d,wMaxPacketSize=%d,bmAttributes=%d\r\n",input_ep,epDesc->wMaxPacketSize,epDesc->bmAttributes); } break; default: log("unkown desc type(%d) \r\n",descType); } p+=descLen; } if (!(input_ep && output_ep)) { log("can't find accessory endpoints\r\n"); return; } log("SetConfiguration\r\n"); err = SetConfiguration(device,configuration); if (err < 0) { log("SetConfiguration error\r\n"); return; } log("interrupt setup\r\n"); //interrupt setup if (_readbuff==NULL || _readbuffsize<=0) { error("_readbuffer error please setup buffer call setReadBuffer function\r\n"); } if (IO_PENDING!=USBBulkTransfer(_device,input_ep|0x80,_readbuff,_readbuffsize,AdkreadCallback,this)) return; log("setupDevice\r\n"); this->setupDevice(); // _initok=true; }
bool USBDriver_Impl_Libusb::Open( int iVendorID, int iProductID ) { Close(); if( usb_find_busses() < 0 ) { LOG->Warn( "Libusb: usb_find_busses: %s", usb_strerror() ); return false; } if( usb_find_devices() < 0 ) { LOG->Warn( "Libusb: usb_find_devices: %s", usb_strerror() ); return false; } struct usb_device *dev = FindDevice( iVendorID, iProductID ); if( dev == NULL ) { LOG->Warn( "Libusb: no match for %04x, %04x.", iVendorID, iProductID ); return false; } m_pHandle = usb_open( dev ); if( m_pHandle == NULL ) { LOG->Warn( "Libusb: usb_open: %s", usb_strerror() ); return false; } #ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP // The device may be claimed by a kernel driver. Attempt to reclaim it. for( unsigned i = 0; i < dev->config->bNumInterfaces; i++ ) { int iResult = usb_detach_kernel_driver_np( m_pHandle, i ); switch( iResult ) { case -61: // "No data available" (no driver attached) - continue case 0: // no error continue; break; default: // unhandled error LOG->Warn( "Libusb: usb_detach_kernel_driver_np: %s", usb_strerror() ); Close(); return false; break; } } #endif if ( !SetConfiguration(dev->config->bConfigurationValue) ) { LOG->Warn( "Libusb: usb_set_configuration: %s", usb_strerror() ); Close(); return false; } // attempt to claim all interfaces for this device for( unsigned i = 0; i < dev->config->bNumInterfaces; i++ ) { if ( !ClaimInterface(i) ) { LOG->Warn( "Libusb: usb_claim_interface(%i): %s", i, usb_strerror() ); Close(); return false; } } return true; }
//------------------------------------------------------------------------------ /// Handles the given request if it is standard, otherwise STALLs it. /// \param pDriver Pointer to a USBDDriver instance. /// \param pRequest Pointer to a USBGenericRequest instance. //------------------------------------------------------------------------------ void USBDDriver_RequestHandler( USBDDriver *pDriver, const USBGenericRequest *pRequest) { unsigned char cfgnum; unsigned char infnum; unsigned char eptnum; unsigned char setting; unsigned char type; unsigned char indexDesc; unsigned int length; unsigned int address; TRACE_INFO_WP("Std "); // Check request code switch (USBGenericRequest_GetRequest(pRequest)) { case USBGenericRequest_GETDESCRIPTOR: TRACE_INFO_WP("gDesc "); // Send the requested descriptor type = USBGetDescriptorRequest_GetDescriptorType(pRequest); indexDesc = USBGetDescriptorRequest_GetDescriptorIndex(pRequest); length = USBGenericRequest_GetLength(pRequest); GetDescriptor(pDriver, type, indexDesc, length); break; case USBGenericRequest_SETADDRESS: TRACE_INFO_WP("sAddr "); // Sends a zero-length packet and then set the device address address = USBSetAddressRequest_GetAddress(pRequest); USBD_Write(0, 0, 0, (TransferCallback) USBD_SetAddress, (void *) address); break; case USBGenericRequest_SETCONFIGURATION: TRACE_INFO_WP("sCfg "); // Set the requested configuration cfgnum = USBSetConfigurationRequest_GetConfiguration(pRequest); SetConfiguration(pDriver, cfgnum); break; case USBGenericRequest_GETCONFIGURATION: TRACE_INFO_WP("gCfg "); // Send the current configuration number GetConfiguration(pDriver); break; case USBGenericRequest_GETSTATUS: TRACE_INFO_WP("gSta "); // Check who is the recipient switch (USBGenericRequest_GetRecipient(pRequest)) { case USBGenericRequest_DEVICE: TRACE_INFO_WP("Dev "); // Send the device status GetDeviceStatus(pDriver); break; case USBGenericRequest_ENDPOINT: TRACE_INFO_WP("Ept "); // Send the endpoint status eptnum = USBGenericRequest_GetEndpointNumber(pRequest); GetEndpointStatus(eptnum); break; default: TRACE_WARNING( "USBDDriver_RequestHandler: Unknown recipient (%d)\n\r", USBGenericRequest_GetRecipient(pRequest)); USBD_Stall(0); } break; case USBGenericRequest_CLEARFEATURE: TRACE_INFO_WP("cFeat "); // Check which is the requested feature switch (USBFeatureRequest_GetFeatureSelector(pRequest)) { case USBFeatureRequest_ENDPOINTHALT: TRACE_INFO_WP("Hlt "); // Unhalt endpoint and send a zero-length packet USBD_Unhalt(USBGenericRequest_GetEndpointNumber(pRequest)); USBD_Write(0, 0, 0, 0, 0); break; case USBFeatureRequest_DEVICEREMOTEWAKEUP: TRACE_INFO_WP("RmWU "); // Disable remote wake-up and send a zero-length packet pDriver->isRemoteWakeUpEnabled = 0; USBD_Write(0, 0, 0, 0, 0); break; default: TRACE_WARNING( "USBDDriver_RequestHandler: Unknown feature selector (%d)\n\r", USBFeatureRequest_GetFeatureSelector(pRequest)); USBD_Stall(0); } break; case USBGenericRequest_SETFEATURE: TRACE_INFO_WP("sFeat "); // Check which is the selected feature switch (USBFeatureRequest_GetFeatureSelector(pRequest)) { case USBFeatureRequest_DEVICEREMOTEWAKEUP: TRACE_INFO_WP("RmWU "); // Enable remote wake-up and send a ZLP pDriver->isRemoteWakeUpEnabled = 1; USBD_Write(0, 0, 0, 0, 0); break; case USBFeatureRequest_ENDPOINTHALT: TRACE_INFO_WP("Halt "); // Halt endpoint USBD_Halt(USBGenericRequest_GetEndpointNumber(pRequest)); USBD_Write(0, 0, 0, 0, 0); break; #if defined(CHIP_USB_UDPHS) || defined(CHIP_USB_OTGHS) case USBFeatureRequest_TESTMODE: // 7.1.20 Test Mode Support if ((USBGenericRequest_GetType(pRequest) == USBGenericRequest_DEVICE) && ((USBGenericRequest_GetIndex(pRequest) & 0x000F) == 0)) { // Handle test request USBDDriver_Test(USBFeatureRequest_GetTestSelector(pRequest)); } else { USBD_Stall(0); } break; #endif #if defined(CHIP_USB_OTGHS) case USBFeatureRequest_OTG_B_HNP_ENABLE: TRACE_INFO_WP("OTG_B_HNP_ENABLE "); otg_features_supported |= 1<<USBFeatureRequest_OTG_B_HNP_ENABLE; USBD_Write(0, 0, 0, 0, 0); break; case USBFeatureRequest_OTG_A_HNP_SUPPORT: TRACE_INFO_WP("OTG_A_HNP_SUPPORT "); otg_features_supported |= 1<<USBFeatureRequest_OTG_A_HNP_SUPPORT; USBD_Write(0, 0, 0, 0, 0); break; case USBFeatureRequest_OTG_A_ALT_HNP_SUPPORT: TRACE_INFO_WP("OTG_A_ALT_HNP_SUPPORT "); otg_features_supported |= 1<<USBFeatureRequest_OTG_A_ALT_HNP_SUPPORT; USBD_Write(0, 0, 0, 0, 0); break; #endif default: TRACE_WARNING( "USBDDriver_RequestHandler: Unknown feature selector (%d)\n\r", USBFeatureRequest_GetFeatureSelector(pRequest)); USBD_Stall(0); } break; case USBGenericRequest_SETINTERFACE: TRACE_INFO_WP("sInterface "); infnum = USBInterfaceRequest_GetInterface(pRequest); setting = USBInterfaceRequest_GetAlternateSetting(pRequest); SetInterface(pDriver, infnum, setting); break; case USBGenericRequest_GETINTERFACE: TRACE_INFO_WP("gInterface "); infnum = USBInterfaceRequest_GetInterface(pRequest); GetInterface(pDriver, infnum); break; default: TRACE_WARNING( "USBDDriver_RequestHandler: Unknown request code (%d)\n\r", USBGenericRequest_GetRequest(pRequest)); USBD_Stall(0); } }
/** * Handles the given request if it is standard, otherwise STALLs it. * \param pDriver Pointer to a USBDDriver instance. * \param pRequest Pointer to a USBGenericRequest instance. */ void USBDDriver_RequestHandler( USBDDriver *pDriver, const USBGenericRequest *pRequest) { uint8_t cfgnum; uint8_t infnum; uint8_t eptnum; uint8_t setting; uint8_t type; uint8_t indexDesc; uint32_t length; uint32_t address; TRACE_INFO_WP("Std "); /* Check request code */ switch (USBGenericRequest_GetRequest(pRequest)) { case USBGenericRequest_GETDESCRIPTOR: TRACE_INFO_WP("gDesc "); /* Send the requested descriptor */ type = USBGetDescriptorRequest_GetDescriptorType(pRequest); indexDesc = USBGetDescriptorRequest_GetDescriptorIndex(pRequest); length = USBGenericRequest_GetLength(pRequest); GetDescriptor(pDriver, type, indexDesc, length); break; case USBGenericRequest_SETADDRESS: TRACE_INFO_WP("sAddr "); /* Sends a zero-length packet and then set the device address */ address = USBSetAddressRequest_GetAddress(pRequest); USBD_Write(0, 0, 0, (TransferCallback) USBD_SetAddress, (void *) address); break; case USBGenericRequest_SETCONFIGURATION: TRACE_INFO_WP("sCfg "); /* Set the requested configuration */ cfgnum = USBSetConfigurationRequest_GetConfiguration(pRequest); SetConfiguration(pDriver, cfgnum); break; case USBGenericRequest_GETCONFIGURATION: TRACE_INFO_WP("gCfg "); /* Send the current configuration number */ GetConfiguration(pDriver); break; case USBGenericRequest_GETSTATUS: TRACE_INFO_WP("gSta "); /* Check who is the recipient */ switch (USBGenericRequest_GetRecipient(pRequest)) { case USBGenericRequest_DEVICE: TRACE_INFO_WP("Dev "); /* Send the device status */ GetDeviceStatus(pDriver); break; case USBGenericRequest_ENDPOINT: TRACE_INFO_WP("Ept "); /* Send the endpoint status */ eptnum = USBGenericRequest_GetEndpointNumber(pRequest); GetEndpointStatus(eptnum); break; default: TRACE_WARNING( "USBDDriver_RequestHandler: Unknown recipient (%d)\n\r", USBGenericRequest_GetRecipient(pRequest)); USBD_Stall(0); } break; case USBGenericRequest_CLEARFEATURE: TRACE_INFO_WP("cFeat "); /* Check which is the requested feature */ switch (USBFeatureRequest_GetFeatureSelector(pRequest)) { case USBFeatureRequest_ENDPOINTHALT: TRACE_INFO_WP("Hlt "); /* Unhalt endpoint and send a zero-length packet */ USBD_Unhalt(USBGenericRequest_GetEndpointNumber(pRequest)); USBD_Write(0, 0, 0, 0, 0); break; case USBFeatureRequest_DEVICEREMOTEWAKEUP: TRACE_INFO_WP("RmWU "); /* Disable remote wake-up and send a zero-length packet */ pDriver->isRemoteWakeUpEnabled = 0; USBD_Write(0, 0, 0, 0, 0); break; default: TRACE_WARNING( "USBDDriver_RequestHandler: Unknown feature selector (%d)\n\r", USBFeatureRequest_GetFeatureSelector(pRequest)); USBD_Stall(0); } break; case USBGenericRequest_SETFEATURE: TRACE_INFO_WP("sFeat "); /* Check which is the selected feature */ switch (USBFeatureRequest_GetFeatureSelector(pRequest)) { case USBFeatureRequest_DEVICEREMOTEWAKEUP: TRACE_INFO_WP("RmWU "); /* Enable remote wake-up and send a ZLP */ pDriver->isRemoteWakeUpEnabled = 1; USBD_Write(0, 0, 0, 0, 0); break; case USBFeatureRequest_ENDPOINTHALT: TRACE_INFO_WP("Halt "); /* Halt endpoint */ USBD_Halt(USBGenericRequest_GetEndpointNumber(pRequest)); USBD_Write(0, 0, 0, 0, 0); break; case USBFeatureRequest_OTG_B_HNP_ENABLE: TRACE_INFO_WP("OTG_B_HNP_ENABLE "); pDriver->otg_features_supported |= 1<<USBFeatureRequest_OTG_B_HNP_ENABLE; USBD_Write(0, 0, 0, 0, 0); break; case USBFeatureRequest_OTG_A_HNP_SUPPORT: TRACE_INFO_WP("OTG_A_HNP_SUPPORT "); pDriver->otg_features_supported |= 1<<USBFeatureRequest_OTG_A_HNP_SUPPORT; USBD_Write(0, 0, 0, 0, 0); break; case USBFeatureRequest_OTG_A_ALT_HNP_SUPPORT: TRACE_INFO_WP("OTG_A_ALT_HNP_SUPPORT "); pDriver->otg_features_supported |= 1<<USBFeatureRequest_OTG_A_ALT_HNP_SUPPORT; USBD_Write(0, 0, 0, 0, 0); break; default: TRACE_WARNING( "USBDDriver_RequestHandler: Unknown feature selector (%d)\n\r", USBFeatureRequest_GetFeatureSelector(pRequest)); USBD_Stall(0); } break; case USBGenericRequest_SETINTERFACE: TRACE_INFO_WP("sInterface "); infnum = USBInterfaceRequest_GetInterface(pRequest); setting = USBInterfaceRequest_GetAlternateSetting(pRequest); SetInterface(pDriver, infnum, setting); break; case USBGenericRequest_GETINTERFACE: TRACE_INFO_WP("gInterface "); infnum = USBInterfaceRequest_GetInterface(pRequest); GetInterface(pDriver, infnum); break; default: TRACE_WARNING( "USBDDriver_RequestHandler: Unknown request code (%d)\n\r", USBGenericRequest_GetRequest(pRequest)); USBD_Stall(0); } }
/** * Local function to handle a standard device request * * @param [in] pSetup The setup packet * @param [in,out] *piLen Pointer to data length * @param [in,out] ppbData Data buffer. * * @return TRUE if the request was handled successfully */ uint8_t USBCTRL::HandleStdDeviceReq(TSetupPacket *pSetup, int *piLen, uint8_t **ppbData) { uint8_t *pbData = *ppbData; iResidue = 0; switch (pSetup->bRequest) { case REQ_GET_STATUS: iprintf("GET_STATUS\n"); // bit 0: self-powered // bit 1: remote wakeup = not supported pbData[0] = 0; pbData[1] = 0; *piLen = 2; break; case REQ_SET_ADDRESS: iprintf("USBADDR %d!\n", pSetup->wValue); HwSetAddress(pSetup->wValue); *piLen = 0; break; case REQ_GET_DESCRIPTOR: iprintf("GET DESCRIPTOR 0x%02X/0x%02X\n", GET_DESC_TYPE(pSetup->wValue), GET_DESC_INDEX(pSetup->wValue)); // DBG("D%x", pSetup->wValue); return GetDescriptor(pSetup->wValue, pSetup->wIndex, piLen, ppbData); case REQ_GET_CONFIGURATION: iprintf("GET CONFIGURATION\n"); // indicate if we are configured pbData[0] = conf->bConfigurationValue; *piLen = 1; break; case REQ_SET_CONFIGURATION: iprintf("SET CONFIGURATION\n"); *piLen = 0; if (!SetConfiguration(pSetup->wValue & 0xFF, bAlternate)) { // DBG("USBSetConfiguration failed!\n"); return FALSE; } // configuration successful, update current configuration // bConfiguration = pSetup->wValue & 0xFF; break; case REQ_CLEAR_FEATURE: case REQ_SET_FEATURE: *piLen = 0; iprintf("CLEAR/SET FEATURE\n"); if (pSetup->wValue == FEA_REMOTE_WAKEUP) { // put DEVICE_REMOTE_WAKEUP code here } if (pSetup->wValue == FEA_TEST_MODE) { // put TEST_MODE code here } return FALSE; case REQ_SET_DESCRIPTOR: *piLen = 0; iprintf("SET DESCRIPTOR\n"); // DBG("Device req %d not implemented\n", pSetup->bRequest); return FALSE; default: *piLen = 0; iprintf("UNKNOWN: 0x%02X\n", pSetup->bRequest); // DBG("Illegal device req %d\n", pSetup->bRequest); return FALSE; } return TRUE; }
/***************************************************************************** 実行前初期化チェック *****************************************************************************/ void CGainer::check_config() { if ( m_config == 0 ) { SetConfiguration(1); } }
int main (int argc, const char * argv[]) { UInt32 addr = 0; UInt8 config = 0; USBDevice device; USBInterface iface; dload_action action = kDLoadNone; printf("Starting DLOADTool\n"); if(argc >= 1) { if(strcmp(argv[1], "-c") == 0) { // Send custom packets action = kDLoadSend; } else if(strcmp(argv[1], "-f") == 0) { // Upload firmware file action = kDLoadUpload; } else { // Upload dbl action = kDLoadNone; } } else { printf("Usage: %s [-f firmware] [-c command1 command2 ... commandN]\n", argv[0]); return -1; } //Vendor ID: 0x5c6 //Product ID: 0x9008 device = OpenDevice(0x5c6, 0x9008); if(device) { printf("Device Opened\n"); config = SetConfiguration(device, 1); if(config == 1) { printf("Configuration %hhx set\n", config); iface = OpenInterface(device, 0, 0); if(iface) { printf("Interface Opened\n"); if(action == kDLoadSend && argc >= 3) { int i = 0; int v = 0; unsigned char input[0x200]; unsigned char output[0x200]; for(v = 2; v < argc; v++) { const char* arg = (const char*) argv[v]; unsigned int size = strlen(arg) / 2; memset(output,'\0', sizeof(output)); memset(input, '\0', sizeof(input)); for(i = 0; i < size; i++) { unsigned int byte = 0; sscanf(arg, "%02x", &byte); output[i] = byte; arg += 2; } dload_write(iface, output, size); dload_read(iface, input, sizeof(input)); } } if(action == kDLoadUpload && argc == 3) { addr = 0x20012000; dload_get_params(iface); dload_get_sw_version(iface); dload_upload_firmware(iface, addr, argv[2]); dload_send_execute(iface, addr); } if(action == kDLoadNone && argc == 1) { addr = 0x20012000; dload_get_params(iface); dload_get_sw_version(iface); dload_upload_firmware(iface, addr, "/usr/local/standalone/firmware/Trek/dbl.mbn"); dload_send_execute(iface, addr); } printf("Closing Interface\n"); CloseInterface(iface); } else { fprintf(stderr, "Couldn't open device interface\n"); } } CloseDevice(device); } return 0; }