static void resetBus() { //cleanup primitive resources. required if the last user abruptly //terminated. this method isn't ideal since it just resets the first bus, //even though there might be more (there aren't on our robot, though). raw1394handle_t handle = raw1394_new_handle(); if(!handle) { CV_Error(CV_StsError, "unable to open raw1394 handle (is there a bus available on this computer?)"); } const int numPorts = raw1394_get_port_info(handle, NULL, 0); if(numPorts < 1) { raw1394_destroy_handle(handle); CV_Error(CV_StsError, "no raw1394 ports"); } raw1394_set_port(handle, 0); raw1394_reset_bus(handle); raw1394_destroy_handle(handle); }
int main(int argc, char **argv) { raw1394handle_t handle; int retval; quadlet_t rom[0x100]; size_t rom_size; unsigned char rom_version; rom1394_directory dir; char *(leaf[2]); handle = raw1394_new_handle(); if (!handle) { if (!errno) { printf(not_compatible); } else { perror("couldn't get handle"); printf(not_loaded); } exit(EXIT_FAILURE); } if (raw1394_set_port(handle, 0) < 0) { perror("couldn't set port"); exit(EXIT_FAILURE); } /* get the current rom image */ retval=raw1394_get_config_rom(handle, rom, 0x100, &rom_size, &rom_version); rom_size = rom1394_get_size(rom); printf("get_config_rom returned %d, romsize %d, rom_version %d:",retval,rom_size,rom_version); /* get the local directory */ rom1394_get_directory( handle, raw1394_get_local_id(handle) & 0x3f, &dir); /* free the allocated mem for the textual leaves */ rom1394_free_directory( &dir); /* add an RFC 2734 unit directory */ dir.unit_spec_id = 0x0000005e; dir.unit_sw_version = 0x00000001; leaf[0] = "IANA"; leaf[1] = "IPv4"; dir.nr_textual_leafs = 2; dir.textual_leafs = leaf; /* manipulate the rom */ retval = rom1394_add_unit( rom, &dir); /* get the computed size of the rom image */ rom_size = rom1394_get_size(rom); printf("rom1394_add_unit_directory returned %d, romsize %d:",retval,rom_size); /* convert computed rom size from quadlets to bytes before update */ rom_size *= sizeof(quadlet_t); retval = raw1394_update_config_rom(handle, rom, rom_size, rom_version); printf("update_config_rom returned %d\n",retval); printf("You need to reload your ieee1394 modules to reset the rom.\n"); raw1394_reset_bus(handle); exit(EXIT_SUCCESS); }
int CameraDcam::findCameraByGuid(void) { /*----------------------------------------------------------------------- * get the camera nodes and describe them as we find them * Number of available ports is known globally. *-----------------------------------------------------------------------*/ //as the root node is not determined statically we may reset the bus in order to make a camera become //NOT a root node. //Uses generally the first camera found on bus. int portNum,resetNum, numNodes, foundCamerasOnBus; int resetBus = 1; nodeid_t * camera_nodes = NULL; for (resetNum=0; resetNum < MAX_RESETS && resetBus == 1; resetNum++) { resetBus = 0; foundCamerasOnBus = 0; for (portNum=0; portNum < firewireNumPorts; portNum++) { porthandle[portNum] = dc1394_create_handle(portNum);//handle for portNum if (porthandle[portNum]==NULL) { GDOS_WARNING("error: Unable to aquire handle for port %i.\n", portNum); } //each port can have multiple cameras attached. numNodes = 0; camera_nodes = dc1394_get_camera_nodes(porthandle[portNum], &numNodes, 0); //last parameter defines if output is given. //if any camera is found on this port... if (numNodes > 0) { GDOS_DBG_INFO("found %i cameras to port %i.\n",numNodes, portNum); //try to put them all at their position. int k; for (k = 0; k < numNodes; k++) { //try to get camera guid dc1394_camerainfo info; if (dc1394_get_camera_info(porthandle[portNum], camera_nodes[k], &info) == DC1394_SUCCESS) { //test if camera node is root, if so reset bus... if (camera_nodes[k] == raw1394_get_nodecount(porthandle[portNum])-1) { //reset and retry if root GDOS_WARNING("error: camera found as root node - resetting.\n"); raw1394_reset_bus(porthandle[portNum]); int node_pos = 0; for (node_pos=0; node_pos < 10; node_pos++) resetBus = 1; foundCamerasOnBus = foundCamerasOnBus - k; //no -1 as the array stqarts with 0 } GDOS_DBG_INFO("found camera with guid:%x \n", info.euid_64); //put camera in the global variable if ((cameraGuid == 0) || (cameraGuid == (int) info.euid_64)) { GDOS_DBG_INFO("using camera node:%i with guid:%x \n",camera_nodes[k], info.euid_64); camera_node = camera_nodes[k]; dc1394CameraPortNo = portNum; } foundCamerasOnBus = foundCamerasOnBus + 1; }//if camera_info }//for numCameras }//if numCamera > 0 else { GDOS_ERROR("No cameras found! (%d nodes on the bus)\n" " - could be you need to try a different 1394 device (modify code to fix)\n", numNodes ); } }//for firewireNumPorts }//for MAXRESETS GDOS_DBG_INFO("bus init complete found %i cameras.\n",foundCamerasOnBus); if (resetNum == MAX_RESETS-1) return FW_ERROR; return DC1394_SUCCESS; }