Class: FW::FWDevice

Inherits:
Object
  • Object
show all
Defined in:
lib/fw.rb,
ext/macosx/fwext.c

Instance Method Summary collapse

Instance Method Details

#guidObject



71
72
73
74
75
76
77
# File 'ext/macosx/fwext.c', line 71

static VALUE FWDevice_getGUID(VALUE Self)
{
  FWDevice *obj;
  Data_Get_Struct(Self, FWDevice, obj);
  
  return rb_ll2inum(obj->GUID);
}

#nodeIDObject



95
96
97
98
99
100
101
# File 'ext/macosx/fwext.c', line 95

static VALUE FWDevice_getNodeID(VALUE Self)
{
  FWDevice *obj;
  Data_Get_Struct(Self, FWDevice, obj);
  
  return INT2FIX(obj->NodeID);
}

#read(StartAddr, Size) ⇒ Object

Read more values…



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'ext/macosx/fwext.c', line 224

static VALUE FWDevice_read(VALUE Self, VALUE StartAddr, VALUE Size)
{
  FWDevice *device;
  Data_Get_Struct(Self, FWDevice, device);
  
  IOCFPlugInInterface **cfPlugInInterface = NULL;
  SInt32 theScore;
  IOFireWireLibDeviceRef fwIntf;  

  IOReturn result = IOCreatePlugInInterfaceForService(device->Device, 
                      kIOFireWireLibTypeID, kIOCFPlugInInterfaceID, 
                      &cfPlugInInterface, &theScore);
  (*cfPlugInInterface)->QueryInterface(cfPlugInInterface,
                          CFUUIDGetUUIDBytes(kIOFireWireDeviceInterfaceID), 
                          (void **) &fwIntf);
  assert((*fwIntf)->InterfaceIsInited(fwIntf));

  VALUE ret;

  if((*fwIntf)->Open(fwIntf) == 0)
  {
    // Set destination adress. Note that the upper 48 bits identify 
    // the device on the bus and the address set by the operating system.
    uint64_t startaddr = rb_num2ull(StartAddr);
    FWAddress fwaddr;

    fwaddr.nodeID = 0;
    fwaddr.addressHi =  startaddr >> 32;
    fwaddr.addressLo = startaddr & 0xffffffffL;

    // do the actual read and store the result code in an object attribute
    UInt32 bufsize = NUM2UINT(Size);
    void *buffer = malloc(bufsize);
    memset(buffer, 0, bufsize);
    result = (*fwIntf)->Read(fwIntf, device->Device, &fwaddr, buffer, &bufsize, false, 0);
    ret = rb_hash_new();
    rb_hash_aset(ret, ID2SYM(rb_intern("buffer")), rb_str_new(buffer, bufsize));
    rb_hash_aset(ret, ID2SYM(rb_intern("resultcode")), INT2FIX(result));
    free(buffer);
  }
  else
  {
    rb_fatal("Device->Open() failed");
    return Qnil;
  }
  
  if (fwIntf != NULL)
    (*fwIntf)->Close(fwIntf);

  if (cfPlugInInterface != NULL)
    IODestroyPlugInInterface(cfPlugInInterface);

  return ret;
}

#readQuadlet(StartAddr) ⇒ Object

Read a 32bit value



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'ext/macosx/fwext.c', line 171

static VALUE FWDevice_readQuadlet(VALUE Self, VALUE StartAddr)
{
  FWDevice *device;
  Data_Get_Struct(Self, FWDevice, device);
  
  IOCFPlugInInterface **cfPlugInInterface = NULL;
  SInt32 theScore;
  IOFireWireLibDeviceRef fwIntf;  

  IOReturn result = IOCreatePlugInInterfaceForService(device->Device, 
                      kIOFireWireLibTypeID, kIOCFPlugInInterfaceID, 
                      &cfPlugInInterface, &theScore);
  (*cfPlugInInterface)->QueryInterface(cfPlugInInterface,
                          CFUUIDGetUUIDBytes(kIOFireWireDeviceInterfaceID), 
                          (void **) &fwIntf);
  assert((*fwIntf)->InterfaceIsInited(fwIntf));

  VALUE ret;

  if((*fwIntf)->Open(fwIntf) == 0)
  {
    // Set destination adress. Note that the upper 48 bits identify 
    // the device on the bus and the address set by the operating system.
    uint64_t startaddr = rb_num2ull(StartAddr);
    FWAddress fwaddr;

    fwaddr.nodeID = 0;
    fwaddr.addressHi =  startaddr >> 32;
    fwaddr.addressLo = startaddr & 0xffffffffL;

    // do the actual read
    UInt32 val = 0;
    result = (*fwIntf)->ReadQuadlet(fwIntf, device->Device, &fwaddr, &val, false, 0);
    ret = rb_hash_new();
    rb_hash_aset(ret, ID2SYM(rb_intern("value")), INT2FIX(val));
    rb_hash_aset(ret, ID2SYM(rb_intern("resultcode")), INT2FIX(result));
  }
  else
  {
    rb_fatal("Device->Open() failed");
    return Qnil;
  }
  
  if (fwIntf != NULL)
    (*fwIntf)->Close(fwIntf);

  if (cfPlugInInterface != NULL)
    IODestroyPlugInInterface(cfPlugInInterface);

  return ret;
}

#speedObject



103
104
105
106
107
108
109
# File 'ext/macosx/fwext.c', line 103

static VALUE FWDevice_getSpeed(VALUE Self)
{
  FWDevice *obj;
  Data_Get_Struct(Self, FWDevice, obj);
  
  return INT2FIX(obj->Speed);
}

#to_sObject



29
30
31
# File 'lib/fw.rb', line 29

def to_s
  "#{guid.to_ui64} - #{vendorName}"
end

#vendorIDObject



87
88
89
90
91
92
93
# File 'ext/macosx/fwext.c', line 87

static VALUE FWDevice_getVendorID(VALUE Self)
{
  FWDevice *obj;
  Data_Get_Struct(Self, FWDevice, obj);
  
  return INT2FIX(obj->VendorID);
}

#vendorNameObject



79
80
81
82
83
84
85
# File 'ext/macosx/fwext.c', line 79

static VALUE FWDevice_getVendorName(VALUE Self)
{
  FWDevice *obj;
  Data_Get_Struct(Self, FWDevice, obj);
  
  return rb_str_new2(obj->VendorName);
}

#write(StartAddr, Size) ⇒ Object

Read more values…



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'ext/macosx/fwext.c', line 224

static VALUE FWDevice_read(VALUE Self, VALUE StartAddr, VALUE Size)
{
  FWDevice *device;
  Data_Get_Struct(Self, FWDevice, device);
  
  IOCFPlugInInterface **cfPlugInInterface = NULL;
  SInt32 theScore;
  IOFireWireLibDeviceRef fwIntf;  

  IOReturn result = IOCreatePlugInInterfaceForService(device->Device, 
                      kIOFireWireLibTypeID, kIOCFPlugInInterfaceID, 
                      &cfPlugInInterface, &theScore);
  (*cfPlugInInterface)->QueryInterface(cfPlugInInterface,
                          CFUUIDGetUUIDBytes(kIOFireWireDeviceInterfaceID), 
                          (void **) &fwIntf);
  assert((*fwIntf)->InterfaceIsInited(fwIntf));

  VALUE ret;

  if((*fwIntf)->Open(fwIntf) == 0)
  {
    // Set destination adress. Note that the upper 48 bits identify 
    // the device on the bus and the address set by the operating system.
    uint64_t startaddr = rb_num2ull(StartAddr);
    FWAddress fwaddr;

    fwaddr.nodeID = 0;
    fwaddr.addressHi =  startaddr >> 32;
    fwaddr.addressLo = startaddr & 0xffffffffL;

    // do the actual read and store the result code in an object attribute
    UInt32 bufsize = NUM2UINT(Size);
    void *buffer = malloc(bufsize);
    memset(buffer, 0, bufsize);
    result = (*fwIntf)->Read(fwIntf, device->Device, &fwaddr, buffer, &bufsize, false, 0);
    ret = rb_hash_new();
    rb_hash_aset(ret, ID2SYM(rb_intern("buffer")), rb_str_new(buffer, bufsize));
    rb_hash_aset(ret, ID2SYM(rb_intern("resultcode")), INT2FIX(result));
    free(buffer);
  }
  else
  {
    rb_fatal("Device->Open() failed");
    return Qnil;
  }
  
  if (fwIntf != NULL)
    (*fwIntf)->Close(fwIntf);

  if (cfPlugInInterface != NULL)
    IODestroyPlugInInterface(cfPlugInInterface);

  return ret;
}

#writeQuadlet(StartAddr) ⇒ Object

Read a 32bit value



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'ext/macosx/fwext.c', line 171

static VALUE FWDevice_readQuadlet(VALUE Self, VALUE StartAddr)
{
  FWDevice *device;
  Data_Get_Struct(Self, FWDevice, device);
  
  IOCFPlugInInterface **cfPlugInInterface = NULL;
  SInt32 theScore;
  IOFireWireLibDeviceRef fwIntf;  

  IOReturn result = IOCreatePlugInInterfaceForService(device->Device, 
                      kIOFireWireLibTypeID, kIOCFPlugInInterfaceID, 
                      &cfPlugInInterface, &theScore);
  (*cfPlugInInterface)->QueryInterface(cfPlugInInterface,
                          CFUUIDGetUUIDBytes(kIOFireWireDeviceInterfaceID), 
                          (void **) &fwIntf);
  assert((*fwIntf)->InterfaceIsInited(fwIntf));

  VALUE ret;

  if((*fwIntf)->Open(fwIntf) == 0)
  {
    // Set destination adress. Note that the upper 48 bits identify 
    // the device on the bus and the address set by the operating system.
    uint64_t startaddr = rb_num2ull(StartAddr);
    FWAddress fwaddr;

    fwaddr.nodeID = 0;
    fwaddr.addressHi =  startaddr >> 32;
    fwaddr.addressLo = startaddr & 0xffffffffL;

    // do the actual read
    UInt32 val = 0;
    result = (*fwIntf)->ReadQuadlet(fwIntf, device->Device, &fwaddr, &val, false, 0);
    ret = rb_hash_new();
    rb_hash_aset(ret, ID2SYM(rb_intern("value")), INT2FIX(val));
    rb_hash_aset(ret, ID2SYM(rb_intern("resultcode")), INT2FIX(result));
  }
  else
  {
    rb_fatal("Device->Open() failed");
    return Qnil;
  }
  
  if (fwIntf != NULL)
    (*fwIntf)->Close(fwIntf);

  if (cfPlugInInterface != NULL)
    IODestroyPlugInInterface(cfPlugInInterface);

  return ret;
}