//! Process command line args //! //! @param argc - count of args //! @param argv - the actual arguments //! //! @return error code //! USBDM_ErrorCode doArgs(int argc, char **argv) { LOGGING; bool listDevices = false; const char *deviceName = NULL; while (argc-- > 1) { if (stricmp(argv[argc], "-D")==0) { // List targets listDevices = true; } else { // Assume device name deviceName = argv[argc]; } } if ((deviceName == NULL) && !listDevices) { fprintf(stderr, "No device specified\n"); Logging::print("No device specified\n"); return BDM_RC_ILLEGAL_PARAMS; } if (listDevices) { int count = 0; std::vector<DeviceDataPtr>::const_iterator it; DeviceDataBase *deviceDatabase = shared->getDeviceDataBase(); for (it = deviceDatabase->begin(); it != deviceDatabase->end(); it++) { fprintf(stderr, "%s,\t", (*it)->getTargetName().c_str()); if (++count == 3) { count = 0; fprintf(stderr, "\n"); } } if (count != 0) { fprintf(stderr, "\n"); } return BDM_RC_ERROR_HANDLED; } else { // Find device details from database USBDM_ErrorCode rc = shared->setCurrentDeviceByName(deviceName); if (rc != BDM_RC_OK) { return rc; } Logging::print( "Loaded device description\n"); } return BDM_RC_OK; }
// // Device name e.g. MCF51CN128 // -noload - don't load (program) flash // USBDM_ErrorCode doArgs(int argc, char **argv) { bool noLoad = false; bool listDevices = false; const char *deviceName = NULL; while (argc-- > 1) { // fprintf(stderr, "doArgs() - arg = \'%s\'\n", argv[argc]); if (stricmp(argv[argc], "-noload")==0) { noLoad = true; } else if (stricmp(argv[argc], "-D")==0) { // List targets listDevices = true; } else { // Assume device name deviceName = argv[argc]; } } if ((deviceName == NULL) && !listDevices) { fprintf(stderr, "No device specified\n"); print("doArgs() - No device specified\n"); return BDM_RC_ILLEGAL_PARAMS; } // fprintf(stderr, "doArgs() - opening device database\n"); // Find device details from database DeviceDataBase *deviceDatabase = new DeviceDataBase; fprintf(stderr, "Loading device database...\n"); print( "doArgs() - Loading device database\n"); try { deviceDatabase->loadDeviceData(); } catch (MyException &exception) { fprintf(stderr, "Loading device database...Failed\n"); print("doArgs() - Failed to load device database\n"); return BDM_RC_DEVICE_DATABASE_ERROR; } print( "doArgs() - Loaded device database\n"); if (listDevices) { int count = 0; std::vector<DeviceData *>::iterator it; try { for (it = deviceDatabase->begin(); it != deviceDatabase->end(); it++) { fprintf(stderr, "%s,\t", (*it)->getTargetName().c_str()); if (++count == 3) { count = 0; fprintf(stderr, "\n"); } } if (count != 0) { fprintf(stderr, "\n"); } } catch (...) { } delete deviceDatabase; return BDM_RC_ERROR_HANDLED; } else { const DeviceData *devicePtr = deviceDatabase->findDeviceFromName(deviceName); if (devicePtr == NULL) { fprintf(stderr, "Failed to find device '%s' in database\n", deviceName); print("doArgs() - Failed to find device '%s' in database\n", deviceName); return BDM_RC_UNKNOWN_DEVICE; } // if (!devicePtr->valid) { // fprintf(stderr, "OPPS #1!\n"); // print("doArgs() - OPPS #1!\n"); // return E_FATAL; // } deviceData = *devicePtr; // if (!deviceData.valid) { // fprintf(stderr, "OPPS #2!\n"); // print("doArgs() - OPPS #2!\n"); // return E_FATAL; // } delete deviceDatabase; // if (!deviceData.valid) { // fprintf(stderr, "OPPS #3!\n"); // print("doArgs() - OPPS #3!\n"); // return E_FATAL; // } } return BDM_RC_OK; }