25.12.2013 Aufrufe

Gecko3 - CCC Event Weblog

Gecko3 - CCC Event Weblog

Gecko3 - CCC Event Weblog

MEHR ANZEIGEN
WENIGER ANZEIGEN

Sie wollen auch ein ePaper? Erhöhen Sie die Reichweite Ihrer Titel.

YUMPU macht aus Druck-PDFs automatisch weboptimierte ePaper, die Google liebt.

E.3. Hostsoftware<br />

#include <br />

31<br />

QGecko : : QGecko ( QObject ∗ parent )<br />

: QObject ( parent )<br />

{<br />

u s b i n i t ( ) ; // i n i t i a l i s i z e t h e l i b u s b<br />

36 geckoAdm = 0 ;<br />

geckoCom = 0 ;<br />

}<br />

41 QGecko : : ˜ QGecko ( )<br />

{<br />

}<br />

//−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

46 // f u n c t i o n s f o r normal communication with t h e gecko board<br />

bool QGecko : : open ( ) {<br />

struct usb bus ∗ b u s s e s ;<br />

u s b f i n d b u s s e s ( ) ;<br />

51 u s b f i n d d e v i c e s ( ) ; // rescan a l l usb t h i n g s<br />

b u s s e s = u s b g e t b u s s e s ( ) ; // r e t u r n s t h e l i s t o f a l l usb b u s s e s<br />

56<br />

struct usb bus ∗ bus ;<br />

for ( bus = b u s s e s ; bus ; bus = bus−>next ) {<br />

struct u s b d e v i c e ∗ dev ;<br />

for ( dev = bus−>d e v i c e s ; dev ; dev = dev−>next ) { // go through a l l b u s s e s and<br />

a l l d e v i c e s and check i f i t i s a gecko<br />

61 i f ( dev−>d e s c r i p t o r . idVendor == ID VENDOR GECKO3) {<br />

i f ( dev−>d e s c r i p t o r . idProduct == ID PRODUCT GECKO3) {<br />

geckoCom = usb open ( dev ) ; //we found a gecko , now we open t h e d e v i c e<br />

char dr name [ 1 0 0 ] ;<br />

int np = u s b g e t d r i v e r n p ( geckoCom , 0 , dr name , 100) ; // checks i f t h e r e<br />

i s a k e r n e l d r i v e r loaded f o r t h i s d e v i c e<br />

66 i f ( np==0) {<br />

u s b d e t a c h k e r n e l d r i v e r n p ( geckoCom , 0) ; // unloads t h e k e r n e l d r i v e r<br />

i f t h e r e i s one . e l s e t h e d e v i c e i s not a v i a b l e f o r us<br />

}<br />

int t = u s b c l a i m i n t e r f a c e ( geckoCom , GECKO COM INTERFACE) ; // bound t h e<br />

i n t e r f a c e from t h e os . now we can use t h i s i n t e r f a c e<br />

i f ( t == 0) {<br />

71 return true ; //end o f s e a r c h i n g f o r d e v i c e s . t h e f i r s t found<br />

d e v i c e i s used<br />

}<br />

else {<br />

return f a l s e ;<br />

}<br />

76 }<br />

}<br />

}<br />

}<br />

return f a l s e ;<br />

81 }<br />

bool QGecko : : c l o s e ( )<br />

{<br />

i f ( geckoCom != 0) {<br />

86 u s b r e l e a s e i n t e r f a c e ( geckoCom , GECKO COM INTERFACE) ; // u n r e g i s t e r t h e i n t e r f a c e<br />

from t h e os<br />

u s b c l o s e ( geckoCom ) ; // c l o s e t h e usb connection<br />

geckoCom = 0 ; // r e s e t s t h e d e v i c e handler so we can d e t e c t t h a t i t i s c l o s e d<br />

Project Report 105

Hurra! Ihre Datei wurde hochgeladen und ist bereit für die Veröffentlichung.

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!