Exemplo n.º 1
0
static void setup_ivl_environment()
{
	if (*gstr.pIVL) {
		checkIvlDir(gstr.pIVL);
		SetRegistryKey(IVL_REGKEY_IVL,gstr.pIVL);
	} else if (!GetRegistryKey(IVL_REGKEY_IVL,&gstr.pIVL)) {
			fprintf(stderr,"error: can not locate the Icarus Verilog root directory, use the -ivl option\n");
			fprintf(stderr,"       of iverilog-vpi" IVERILOG_SUFFIX " to point to the Icarus Verilog root directory.\n");
			fprintf(stderr,"       For a Windows command shell the option would be something like\n");
			fprintf(stderr,"       -ivl=c:\\iverilog  For a Cygwin shell the option would be something\n");
			fprintf(stderr,"       like -ivl=c:\\\\iverilog\n");
			myExit(6);
		}

	  /* Build up the CFLAGS option string */
	assign(&gstr.pCFLAGS,IVERILOG_VPI_CFLAGS " -I\"");
	append(&gstr.pCFLAGS,gstr.pIVL);
	appendBackSlash(&gstr.pCFLAGS);
	append(&gstr.pCFLAGS,"\\include\\\\iverilog\"" IVERILOG_SUFFIX);

	  /* Build up the LDFLAGS option string */
	assign(&gstr.pLDLIBS,"-L\"");
	append(&gstr.pLDLIBS,gstr.pIVL);
	appendBackSlash(&gstr.pLDLIBS);
	append(&gstr.pLDLIBS,"\\lib\" " IVERILOG_VPI_LDLIBS);
}
Exemplo n.º 2
0
static void usage()
{
	fprintf(stderr,"usage: iverilog-vpi" IVERILOG_SUFFIX " [src and obj files]...\n");
	fprintf(stderr,"   or  iverilog-vpi" IVERILOG_SUFFIX " -mingw=dir\n");
	fprintf(stderr,"   or  iverilog-vpi" IVERILOG_SUFFIX " -ivl=dir\n");
	myExit(1);
}
Exemplo n.º 3
0
static void setup_mingw_environment()
{
	char *pOldPATH = getenv("PATH");		/* get current path */

	if (*gstr.pMINGW) {
		checkMingwDir(gstr.pMINGW);
		SetRegistryKey(IVL_REGKEY_MINGW,gstr.pMINGW);
	} else if (!GetRegistryKey(IVL_REGKEY_MINGW,&gstr.pMINGW)) {
			fprintf(stderr,"error: can not locate the MinGW root directory, use the -mingw option of\n");
			fprintf(stderr,"       iverilog-vpi.exe to point to the MinGW root directory.  For\n");
			fprintf(stderr,"       a Windows command shell the option would be something like\n");
			fprintf(stderr,"       -mingw=c:\\mingw  For a Cygwin shell the option would be\n");
			fprintf(stderr,"       something like -mingw=c:\\\\mingw\n");
			myExit(5);
		}

	  /* Create new path with MinGW in it */
	assign(&gstr.pNewPath,"PATH=");
	append(&gstr.pNewPath,gstr.pMINGW);
	appendBackSlash(&gstr.pNewPath);
	append(&gstr.pNewPath, "\\");
	append(&gstr.pNewPath,"bin;");
	append(&gstr.pNewPath,pOldPATH);

	  /* Place new path in environment */
	_putenv(gstr.pNewPath);
}
Exemplo n.º 4
0
static void checkMingwDir(char *root)
{
	int irv;
	struct _stat stat_buf;

	char *path, *comp, *cp;
	initDynString(&path);
	assign(&path,gstr.pMINGW);
	appendBackSlash(&path);
	append(&path,"bin\\");
	/* Get just the compiler name (the first word) */
	comp = strdup(IVERILOG_VPI_CC);
	cp = strchr(comp, ' ');
	if (cp != NULL) *cp = '\0';
        append(&path, comp);
	append(&path,".exe");
        free(comp);

	irv = _stat(path,&stat_buf);
	deInitDynString(path);

	if (irv) {
		fprintf(stderr,"error: %s does not appear to be the valid root directory\n",root);
		fprintf(stderr,"       of MinGW.  Use the -mingw option of iverilog-vpi.exe to\n");
		fprintf(stderr,"       point to the MinGW root directory.  For a Windows command\n");
		fprintf(stderr,"       shell the option would be something like -mingw=c:\\mingw\n");
		fprintf(stderr,"       For a Cygwin shell the option would be something like\n");
		fprintf(stderr,"       -mingw=c:\\\\mingw\n");
		myExit(5);
	}
}
Exemplo n.º 5
0
char *loadWordList() {
  FILE *fp;
  char *line = NULL, *nl;
  size_t len = 0, size = 10240;
  ssize_t read;

  size = 10240;
  
  words = malloc(size);
  *words = 0;
  strcat(words, ":");

  fp = fopen("WordList.dat", "r");
  if (!fp)
    myExit(-60);
  while ((read = getline(&line, &len, fp)) != -1) {
    if (strlen(words) + read + 2 >= size) {
      size += 10240;
      words = realloc(words, size);
    } /* if */
    if(nl = strstr(line, "\n"))
      *nl = 0;
    strcat(words, line);
    strcat(words, ":"); /* why yes this IS remarkably lazy */
  } /* while */
  if (line)
    free(line);
  return EXIT_SUCCESS;
} /* loadWordList */
Exemplo n.º 6
0
static void testSOPClasses(DUL_NETWORKKEY* network, const char* classFile,
	const char* callingTitle, const char* sourceHost,
	const char* calledTitle, const char* targetHost, int port) {

    FILE* f = NULL;
    char line[512] = "";
    CONDITION cond = 0;
   DUL_ASSOCIATIONKEY		/* Describes the Association with the Acceptor */
	* association = NULL;
    f = fopen(classFile, "r");
    if (f == NULL) {
	printf("Could not open %s\n", classFile);
	return;
    }
    
    while (fgets(line, sizeof(line), f) != NULL) {
	char sopClassUID[512] = "";
	DUL_ASSOCIATESERVICEPARAMETERS	/* The items which describe this
					 * Association */
	  params = {
	  DICOM_STDAPPLICATIONCONTEXT, "DICOM_TEST", "DICOM_VERIFY",
	    "", 16384, 0, 0, 0,
	    "calling presentation addr", "called presentation addr",
	    NULL, NULL, 0, 0,
	    MIR_IMPLEMENTATIONCLASSUID, MIR_IMPLEMENTATIONVERSIONNAME,
	    "", ""
	};
	sscanf(line, "%s", sopClassUID);

	sprintf(params.calledPresentationAddress, "%s:%d", targetHost, port);
	strcpy(params.callingPresentationAddress, sourceHost);
	strcpy(params.calledAPTitle,  calledTitle);
	strcpy(params.callingAPTitle, callingTitle);
	cond = SRV_RequestServiceClass(sopClassUID, DUL_SC_ROLE_DEFAULT, &params);
	if (cond != SRV_NORMAL) {
	    COND_DumpConditions();
	    THR_Shutdown();
	    exit(1);
	}
	cond = DUL_RequestAssociation(&network, &params, &association);
	if (cond != DUL_NORMAL) {
	    if (cond == DUL_ASSOCIATIONREJECTED) {
		fprintf(stderr, "Association Rejected\n");
		fprintf(stderr, " Result: %2x Source %2x Reason %2x\n",
			params.result, params.resultSource,
			params.diagnostic);
	    }
	    myExit(&association);
	}
	printf(" Success: %s\n", sopClassUID);
	cond = DUL_ReleaseAssociation(&association);
	(void) DUL_ClearServiceParameters(&params);
	COND_PopCondition(TRUE);

    }
    fclose(f);

}
Exemplo n.º 7
0
static void compile_and_link()
{
	char *buf=0;
	int iRet, compile_errors = 0;

	  /* To make the output match iverilog-vpi.sh do not print out the
	   * root directories */

//	printf("MinGW root directory:  %s.\n", gstr.pMINGW);
	checkMingwDir(gstr.pMINGW);

//	printf("Icarus Verilog root directory:  %s.\n", gstr.pIVL);
	checkIvlDir(gstr.pIVL);

	  /* compile the C source files (*.c) */
	compile(gstr.pCCSRC, &gstr.pOBJ, &compile_errors, IVERILOG_VPI_CC );
	  /* compile the C++ source files (*.cc, *.cpp) */
	compile(gstr.pCXSRC, &gstr.pOBJ, &compile_errors, IVERILOG_VPI_CXX);

	if (compile_errors) {
		fprintf(stderr,"iverilog-vpi: %d file(s) failed to compile.\n",
		        compile_errors);
		myExit(2);
	}

	  /* link */
	assign(&buf, gstr.pLD);
	append(&buf, " -o ");
	append(&buf, gstr.pOUT);
	append(&buf, " ");
	append(&buf, IVERILOG_VPI_LDFLAGS);
	append(&buf, " ");
	append(&buf, gstr.pOBJ);
	append(&buf, " ");
	append(&buf, gstr.pLIB);
	append(&buf, " ");
	append(&buf, gstr.pLDLIBS);

	printf("Making %s from %s...\n", gstr.pOUT,gstr.pOBJ);

	iRet = system(buf);
	free(buf);
	if (iRet) myExit(3);
}
Exemplo n.º 8
0
static void initDynString(char **str)
{
	*str = (char *) malloc(1);

	if (!*str) {
		fprintf(stderr,"error: out of memory\n");
		myExit(4);
	}

	*str[0] = 0;
}
Exemplo n.º 9
0
int       main(int argc, char const *argv[])
{
  Parser  p;
  params  pr;

try
{
  if (p.start(argc, argv, pr) != 1) // U
    myExit(0);
  Plazza  plazza(pr.m, pr.n, pr.t);

  plazza.reception(); // lvl down
}
catch (const cerrExcept &error)
{
  std::cerr << "Error: " << error.what() << std::endl;
  myExit(1);
}
  myExit(0);
}
Exemplo n.º 10
0
int main(int argc, char *argv[])
{
	init();

	if (!parse(argc,argv)) usage();

	setup_mingw_environment();
	setup_ivl_environment();

	  /* are there any source or object files specified */
	if (*gstr.pOUT) compile_and_link();

	myExit(0);
	return 0; // eliminate warnings.
}
Exemplo n.º 11
0
void MainWindow::newGraphicsScene() {

    delete gameEngine;
    gameEngine = nullptr;

    qDebug() << "trying to create new scene";

    gameEngine = new GameEngine();
    gameEngine->setSceneRect(0, 0, 1275, 643);
    gameEngine->displayInitialMenu();//displayLoadMenu
    connect(gameEngine, SIGNAL(myExit()), this, SLOT(newGraphicsScene()));

    ui->graphicsView->setScene(gameEngine);
    ui->graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    ui->graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
Exemplo n.º 12
0
static void appendn (char **ptr, char *app, int count)
{
	char *nptr = (char *) realloc(*ptr, strlen(*ptr) +
                                            (count?count:strlen(app)) + 1);

	if (nptr == NULL) {
		fprintf(stderr,"error: out of memory\n");
		free(*ptr);
		myExit(4);
	}
	*ptr = nptr;

	if (count)
		strncat(*ptr,app,count);
	else
		strcat(*ptr,app);
}
Exemplo n.º 13
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow) {

    ui->setupUi(this);

    gameEngine = new GameEngine();
    gameEngine->setSceneRect(0, 0, 1275, 643);
    gameEngine->displayInitialMenu();//displayLoadMenu

    ui->graphicsView->setScene(gameEngine);
    ui->graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    ui->graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    //ui->graphicsView->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing);

    connect(gameEngine, SIGNAL(myExit()), this, SLOT(newGraphicsScene()));
}
Exemplo n.º 14
0
static void assignn (char **ptr, char *str, int count)
{
	char *nptr = (char *) realloc(*ptr, (count?count:strlen(str)) + 1);

	if (nptr == NULL) {
		fprintf(stderr,"error: out of memory\n");
		free(*ptr);
		myExit(4);
	}
	*ptr = nptr;

	if (count) {
		strncpy(*ptr,str,count);
		(*ptr)[count] = 0;
	}
	else
		strcpy(*ptr,str);
}
Exemplo n.º 15
0
static void
reqReleaseAssociation(DUL_NETWORKKEY ** network,
		      DUL_ASSOCIATESERVICEPARAMETERS * params)
{
    DUL_ASSOCIATIONKEY		/* Describes the Association with the
				 * Acceptor */
    * association = NULL;
    char
       *SOPClasses[] = {DICOM_SOPCLASSMR
    };

    if (requestAssociation(network, &association, params, SOPClasses, 1) == 0) {
	myExit(NULL);
    }
    (void) DUL_ReleaseAssociation(&association);
    (void) DUL_ClearServiceParameters(params);
    (void) DUL_DropNetwork(network);
}
Exemplo n.º 16
0
static int GetRegistryKey(char *key, char **value)
{
	long lrv;
	HKEY hkKey;
	char *regKeyBuffer;
	DWORD regKeyType, regKeySize;

	lrv = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Icarus Verilog",0,KEY_QUERY_VALUE,&hkKey);
	if (lrv != ERROR_SUCCESS)
		return 0;

	lrv = RegQueryValueEx(hkKey,key,NULL,&regKeyType,NULL,&regKeySize);
	if ((lrv != ERROR_SUCCESS) || (regKeyType != REG_SZ) || (!regKeySize)) {
		lrv = RegCloseKey(hkKey);
		return 0;
	}

	regKeyBuffer = (char *) malloc(regKeySize+1);
	if (!regKeyBuffer) {
		lrv = RegCloseKey(hkKey);
		fprintf(stderr,"error: out of memory\n");
		myExit(4);
	}
	regKeyBuffer[regKeySize] = 0;		/* makes sure there is a trailing NULL */

	/* This needs an unsigned char *, but for MinGW the char is signed. */
	lrv = RegQueryValueEx(hkKey, key, NULL, &regKeyType,
	                      (unsigned char *) regKeyBuffer, &regKeySize);
	if ((lrv != ERROR_SUCCESS) || (regKeyType != REG_SZ) || (!regKeySize)) {
		lrv = RegCloseKey(hkKey);
		free(regKeyBuffer);
		return 0;
	}

	RegCloseKey(hkKey);

	assign(value,regKeyBuffer);
	free(regKeyBuffer);

	return 1;
}
Exemplo n.º 17
0
static void checkIvlDir(char *root)
{
	int irv;
	struct _stat stat_buf;

	char *path;
	initDynString(&path);
	assign(&path,gstr.pIVL);
	appendBackSlash(&path);
	append(&path,"bin\\vvp" IVERILOG_SUFFIX ".exe");

	irv = _stat(path,&stat_buf);
	deInitDynString(path);

	if (irv) {
		fprintf(stderr,"error: %s does not appear to be the valid root directory of\n",root);
		fprintf(stderr,"       Icarus Verilog.  Use the -ivl option of iverilog-vpi" IVERILOG_SUFFIX " to\n");
		fprintf(stderr,"       point to the Icarus Verilog root directory.  For a Windows\n");
		fprintf(stderr,"       command shell the option would be something like -ivl=c:\\iverilog\n");
		fprintf(stderr,"       For a Cygwin shell the option would be something like\n");
		fprintf(stderr,"       -ivl=c:\\\\iverilog\n");
		myExit(6);
	}
}
Exemplo n.º 18
0
main(int argc, char **argv)
{

  CONDITION cond;

  DUL_NETWORKKEY* network = NULL;
  DUL_ASSOCIATIONKEY* association = NULL;
  DUL_ASSOCIATESERVICEPARAMETERS params;
  char
    *calledAPTitle = "QUERY_SCP",
    *callingAPTitle = "QUERY_SCU";

  char localHost[40];

  int port;			/* TCP port used to establish Association */
  char* node;			/* The node we are calling */

  CTNBOOLEAN
    verbose = FALSE,
    abortFlag = FALSE,
    paramsFlag = FALSE;
  char *fileName = NULL;
  DUL_SC_ROLE role = DUL_SC_ROLE_DEFAULT;
  MSG_C_FIND_RESP response;
  MSG_C_FIND_REQ findRequest = {MSG_K_C_FIND_REQ, 0, 0,
				DCM_CMDDATAIDENTIFIER,
				0, NULL, DICOM_SOPPATIENTQUERY_FIND};
  char* queryLevel = "patient";
  LST_HEAD* patientList = 0;
  LST_HEAD* studyList = 0;

  while (--argc > 0 && (*++argv)[0] == '-') {
    switch (*(argv[0] + 1)) {
    case 'a':
      argc--;
      argv++;
      if (argc <= 0)
	usageerror();
      callingAPTitle = *argv;
      break;
    case 'c':
      argc--;
      argv++;
      if (argc <= 0)
	usageerror();
      calledAPTitle = *argv;
      break;
    case 'f':
      argc--;
      argv++;
      if (argc <= 0)
	usageerror();
      fileName = *argv;
      break;
    case 'l':
      argc--;
      argv++;
      if (argc <= 0)
	usageerror();
      queryLevel = *argv;
      break;
    case 'p':
      paramsFlag = TRUE;
      break;
    case 'v':
      verbose = TRUE;
      break;
    default:
      break;
    }
  }

  if (argc < 2)
    usageerror();

  THR_Init();
  DUL_Debug(verbose);
  SRV_Debug(verbose);
  
  node = *argv;
  if (sscanf(*++argv, "%d", &port) != 1)
    usageerror();
  (void) gethostname(localHost, sizeof(localHost));

  cond = DUL_InitializeNetwork(DUL_NETWORK_TCP, DUL_AEREQUESTOR,
			       NULL, 10, DUL_ORDERBIGENDIAN, &network);
  if (cond != DUL_NORMAL)
    myExit(&association);

  DUL_DefaultServiceParameters(&params);
  sprintf(params.calledPresentationAddress, "%s:%s", node, *argv);
  strcpy(params.callingPresentationAddress, localHost);
  strcpy(params.calledAPTitle, calledAPTitle);
  strcpy(params.callingAPTitle, callingAPTitle);
  cond = SRV_RequestServiceClass(DICOM_SOPPATIENTQUERY_FIND, role, &params);
  if (cond != SRV_NORMAL) {
    COND_DumpConditions();
    THR_Shutdown();
    exit(1);
  }
  cond = DUL_RequestAssociation(&network, &params, &association);
  if (cond != DUL_NORMAL) {
    if (cond == DUL_ASSOCIATIONREJECTED) {
      fprintf(stderr, "Association Rejected\n");
      fprintf(stderr, " Result: %2x Source %2x Reason %2x\n",
	      params.result, params.resultSource,
	      params.diagnostic);
    }
    myExit(&association);
  }
  if (verbose || paramsFlag) {
    (void) printf("Association accepted, parameters:\n");
    DUL_DumpParams(&params);
  }
  findRequest.messageID = SRV_MessageIDOut();
  findRequest.identifier = createQueryObject(fileName);


  patientList = LST_Create();
  studyList = LST_Create();

  cond = SRV_CFindRequest(&association, &params,
			  &findRequest, &response,
			  queryCallback, patientList, "");
  if (!(CTN_SUCCESS(cond))) {
    (void) printf("Verification Request unsuccessful\n");
    COND_DumpConditions();
  } else {
    MSG_DumpMessage(&response, stdout);
  }
  SRV_MessageIDIn(findRequest.messageID);

  if (strcmp(queryLevel, "patient") != 0) {
    handleStudyQueries(&association, &params, &findRequest,
		       patientList, queryLevel);
  }

  if (strcmp(queryLevel, "series") == 0) {
    handleSeriesQueries(&association, &params, &findRequest,
			patientList, queryLevel);
  }

  cond = DUL_ReleaseAssociation(&association);
  if (cond != DUL_RELEASECONFIRMED) {
    (void) fprintf(stderr, "%x\n", cond);
    COND_DumpConditions();
  }
  (void) DUL_ClearServiceParameters(&params);

  printResults(patientList);

  (void) DUL_DropNetwork(&network);
  THR_Shutdown();
  return 0;
}
Exemplo n.º 19
0
main(int argc, char **argv)
{

    CONDITION			/* Return values from DUL and ACR routines */
	cond;
    DUL_NETWORKKEY		/* Used to initialize our network */
	* network = NULL;
    DUL_ASSOCIATIONKEY		/* Describes the Association with the
				 * Acceptor */
	* association = NULL;
    DUL_ASSOCIATESERVICEPARAMETERS	/* The items which describe this
					 * Association */
	params = {
	DICOM_STDAPPLICATIONCONTEXT, "DICOM_TEST", "DICOM_VERIFY",
	    "", 16384, 0, 0, 0,
	    "calling presentation addr", "called presentation addr",
	    NULL, NULL, 0, 0,
	    MIR_IMPLEMENTATIONCLASSUID, MIR_IMPLEMENTATIONVERSIONNAME,
	    "", ""
    };
    char
       *calledAPTitle = "DICOM_STORAGE",
       *callingAPTitle = "DICOM_ECHO";

    char
        localHost[256];

    int
        port;			/* TCP port used to establish Association */
    char
       *node;			/* The node we are calling */

    CTNBOOLEAN
	verbose = FALSE,
	abortFlag = FALSE,
	paramsFlag = FALSE,
	drop = FALSE,
	noRelease = FALSE;
    int
        repeat = 1,
        connections = 1,
        repeatCopy,
        sleepTime = 0;
    DUL_SC_ROLE
	role = DUL_SC_ROLE_DEFAULT;
    MSG_C_ECHO_RESP
	response;
    char *classFile = NULL;

    while (--argc > 0 && (*++argv)[0] == '-') {
	switch (*(argv[0] + 1)) {
	case 'a':
	    argc--;
	    argv++;
	    if (argc <= 0)
		usageerror();
	    callingAPTitle = *argv;
	    break;
	case 'c':
	    argc--;
	    argv++;
	    if (argc <= 0)
		usageerror();
	    calledAPTitle = *argv;
	    break;
	case 'd':
	    drop = TRUE;
	    break;
	case 'f':
	    argc--;
	    argv++;
	    if (argc <= 0) {
		usageerror();
	    }
	    classFile = *argv;
	    break;
	case 'm':
	    argc--;
	    argv++;
	    if (argc <= 0)
		usageerror();
	    if (strcmp(*argv, "SCU") == 0)
		role = DUL_SC_ROLE_SCU;
	    else if (strcmp(*argv, "SCP") == 0)
		role = DUL_SC_ROLE_SCP;
	    else if (strcmp(*argv, "SCUSCP") == 0)
		role = DUL_SC_ROLE_SCUSCP;
	    else
		usageerror();
	    break;
	case 'n':
	    argc--;
	    argv++;
	    if (argc <= 0)
		usageerror();
	    if (sscanf(*argv, "%d", &connections) != 1)
		usageerror();
	    break;
	case 'p':
	    paramsFlag = TRUE;
	    break;
	case 'r':
	    argc--;
	    argv++;
	    if (argc <= 0)
		usageerror();
	    if (sscanf(*argv, "%d", &repeat) != 1)
		usageerror();
	    if (repeat <= 0)	/* A special case */
		repeat = 32 * 1024 * 1024;
	    break;
	case 's':
	    argc--;
	    argv++;
	    if (argc <= 0)
		usageerror();
	    if (sscanf(*argv, "%d", &sleepTime) != 1)
		usageerror();
	    break;
	case 'v':
	    verbose = TRUE;
	    break;
	case 'x':
	    noRelease = TRUE;
	    break;
	default:
	    break;
	}
    }
    if (argc < 2)
	usageerror();

    THR_Init();
    DUL_Debug(verbose);
    SRV_Debug(verbose);

    node = *argv;
    if (sscanf(*++argv, "%d", &port) != 1)
	usageerror();
    (void) gethostname(localHost, sizeof(localHost));

    cond = DUL_InitializeNetwork(DUL_NETWORK_TCP, DUL_AEREQUESTOR,
				 NULL, 10, DUL_ORDERBIGENDIAN, &network);
    if (cond != DUL_NORMAL)
	myExit(&association);
	
    if (classFile != NULL) {
	testSOPClasses(network, classFile, callingAPTitle, localHost,
	  calledAPTitle, node, port);
	connections = 0;			/* This will force us to skip the next section of echo code */
    }

    while (connections-- > 0) {
	sprintf(params.calledPresentationAddress, "%s:%s", node, *argv);
	strcpy(params.callingPresentationAddress, localHost);
	strcpy(params.calledAPTitle, calledAPTitle);
	strcpy(params.callingAPTitle, callingAPTitle);
	cond = SRV_RequestServiceClass(DICOM_SOPCLASSVERIFICATION, role,
				       &params);
	if (cond != SRV_NORMAL) {
	    COND_DumpConditions();
	    THR_Shutdown();
	    exit(1);
	}
	cond = DUL_RequestAssociation(&network, &params, &association);
	if (cond != DUL_NORMAL) {
	    if (cond == DUL_ASSOCIATIONREJECTED) {
		fprintf(stderr, "Association Rejected\n");
		fprintf(stderr, " Result: %2x Source %2x Reason %2x\n",
			params.result, params.resultSource,
			params.diagnostic);
	    }
	    myExit(&association);
	}
	if (verbose || paramsFlag) {
	    (void) printf("Association accepted, parameters:\n");
	    DUL_DumpParams(&params);
	}
	repeatCopy = repeat;
	while (repeatCopy-- > 0) {
	    MSG_C_ECHO_REQ echoRequest = {MSG_K_C_ECHO_REQ, 0, 0, DCM_CMDDATANULL,
	    DICOM_SOPCLASSVERIFICATION};

	    echoRequest.messageID = SRV_MessageIDOut();

	    cond = SRV_CEchoRequest(&association, &params,
				    &echoRequest, &response,
				    echoCallback, "Context", "");
	    if (!(CTN_SUCCESS(cond))) {
		(void) printf("Verification Request unsuccessful\n");
		COND_DumpConditions();
	    } else {
		MSG_DumpMessage(&response, stdout);
	    }
	    SRV_MessageIDIn(echoRequest.messageID);
#ifdef _MSC_VER
	    if (sleepTime > 0)
		Sleep(sleepTime * 1000);
#else
	    if (sleepTime > 0)
		sleep(sleepTime);
#endif
	}

	if (abortFlag) {
	    cond = DUL_AbortAssociation(&association);
	} else if (drop) {
	    cond = DUL_DropAssociation(&association);
	} else if (noRelease == FALSE) {
	    cond = DUL_ReleaseAssociation(&association);
	    if (cond != DUL_RELEASECONFIRMED) {
		(void) COND_PopCondition(TRUE);
#if 0
		(void) fprintf(stderr, "%x\n", cond);
		COND_DumpConditions();
#endif
	    }
	}
	(void) DUL_ClearServiceParameters(&params);
    }
    (void) DUL_DropNetwork(&network);
    THR_Shutdown();
    return 0;
}
Exemplo n.º 20
0
/* makeDBEntry
**
** Purpose:
**	Adds an image file to the database.
**      The patient, study, series are created in the database if they don't
**      already exist.  If the image UID matches an existing one, the
**      existing one is deleted before the new one is added.
**
** Parameter Dictionary:
**	dbid		DB database id
**	imgfile		Image file name
**	prefmtImgfile	Preformatted image file name
**
** Return Values:
**	NONE
**
** Notes:
**
** Algorithm:
**	Description of the algorithm (optional) and any other notes.
*/
void
makeDBEntry(short dbid, char *imgfile, char *prefmtImgfile)
{
    CONDITION
    cond;			/* return condition status */
    Query
	query;			/* The Query structure */
    DCM_OBJECT
	* object;		/* Pointer to a DICOM object */
    int
        parseCount;		/* keeps track of the number of elements
				 * parsed while converting from DCM object to
				 * Query */

    /* Initialize the query structure to all null characters */
    (void) memset((void *) &query, '\0', sizeof(query));

    /* Read the image file and convert it into an object representation */
    cond = DCM_OpenFile(imgfile, (long) DCM_ORDERLITTLEENDIAN, &object);
    if (cond != DCM_NORMAL)
	myExit(DCMOPENFILEERROR);

    if (verbose)
	DCM_DumpElements(&object);

    /* Convert the object into the query structure */
    cond = IAP_ObjectToQuery(&object, "", &query, &parseCount);
    if (verbose) {
	printf("Number of elements parsed = %d\n", parseCount);
	COND_DumpConditions();
	printf("Query Structure created :- \n");
	dump_query(&query);
    }
    if (ERROR(cond))
	myExit(IAPOBJTOQUERYERROR);


    /* free the memory ocupied by the object */
    cond = DCM_CloseObject(&object);
    if (cond != DCM_NORMAL)
	myExit(DCMCLOSEOBJERROR);

    /*
     * So far everything is fine. Now store the name of the preformatted
     * image file in the FileName field in the ImageLevel structure
     */
    (void) sprintf(query.Image.FileName,
		   "%.*s", sizeof(query.Image.FileName) - 2, prefmtImgfile);

    /* now create the PATIENT, STUDY and SERIES, if they don't already exist */
    cond = DB_AddPatient(dbid, &query.Patient);
    if (cond != DB_NORMAL && cond != DB_DUPATIENT)
	myExit(DBADDPATERROR);

    cond = DB_AddStudy(dbid, query.Patient.PatID, &query.Study);
    if (cond != DB_NORMAL && cond != DB_DUPSTUDY)
	myExit(DBADDSTUDYERROR);

    cond = DB_AddSeries(dbid, query.Patient.PatID, query.Study.StudyUID,
			&query.Series);
    if (cond != DB_NORMAL && cond != DB_DUPSERIES)
	myExit(DBADDSERIESERROR);

    cond = DB_AddImage(dbid, query.Patient.PatID, query.Study.StudyUID,
		       query.Series.SeriesUID, &query.Image);
    if (cond == DB_DUPIMAGE) {
	/* we just delete previous image and replace it by new one */
	cond = DB_DelImage(dbid, query.Patient.PatID, query.Study.StudyUID,
			   query.Series.SeriesUID, query.Image.ImageUID);
	if (cond != DB_NORMAL)
	    myExit(DBDELIMGERROR);

	/* Now add this new image */
	cond = DB_AddImage(dbid, query.Patient.PatID, query.Study.StudyUID,
			   query.Series.SeriesUID, &query.Image);
	if (cond != DB_NORMAL)
	    myExit(DBADDIMGERROR);
    }
    if (verbose) {
	dump_query(&query);
	DB_DumpDB(dbid);
    }
    /* As a last step, we close the data base */
    cond = DB_Close(dbid);
    if (cond != DB_NORMAL)
	myExit(DBCLOSEERROR);
}
Exemplo n.º 21
0
main(int argc, char **argv)
{
    CONDITION			/* Return values from facilities */
	cond;
    DUL_NETWORKKEY		/* Used to initialize our network */
	* network = NULL;
    DUL_ASSOCIATESERVICEPARAMETERS	/* The items which describe this
					 * Association */
	params = {
	DICOM_STDAPPLICATIONCONTEXT, "DEMO_SENDER_93", "RSNA_STORAGE_93",
	    "", 16384, 0, 0, 0,
	    "calling addr", "called addr", NULL, NULL, 0, 0,
	    MIR_IMPLEMENTATIONCLASSUID, MIR_IMPLEMENTATIONVERSIONNAME,
	    "", ""
    };
    char
       *calledAPTitle = "RSNA_STORAGE_93",
       *callingAPTitle = "DEMO_SENDER_93",
        localHost[40],
       *node,			/* The node we are calling */
       *port;			/* ASCIIZ representation of TCP port */
    int
        scratch;		/* Used to check syntax of port number */
    unsigned long
        maxPDU = 16384;

    CTNBOOLEAN
	verboseDCM = FALSE,
	verboseDUL = FALSE,
	verboseSRV = FALSE;

    while (--argc > 0 && (*++argv)[0] == '-') {
	switch (*(argv[0] + 1)) {
	case 'c':
	    argc--;
	    argv++;
	    if (argc <= 0)
		usageerror();
	    callingAPTitle = *argv;
	    break;
	case 'd':
	    argc--;
	    argv++;
	    if (argc <= 0)
		usageerror();
	    if (strcmp(*argv, "DCM") == 0)
		verboseDCM = TRUE;
	    else if (strcmp(*argv, "DUL") == 0)
		verboseDUL = TRUE;
	    else if (strcmp(*argv, "SRV") == 0)
		verboseSRV = TRUE;
	    else
		usageerror();
	    break;
	case 'm':
	    argc--;
	    argv++;
	    if (argc <= 0)
		usageerror();
	    if (sscanf(*argv, "%lu", &maxPDU) != 1)
		usageerror();
	    break;
	case 't':
	    argc--;
	    argv++;
	    if (argc <= 0)
		usageerror();
	    calledAPTitle = *argv;
	    break;
	case 'v':
	    verboseDUL = TRUE;
	    verboseSRV = TRUE;
	    break;
	default:
	    break;
	}
    }
    if (argc < 2)
	usageerror();

    THR_Init();
    DCM_Debug(verboseDCM);
    DUL_Debug(verboseDUL);
    SRV_Debug(verboseSRV);
    node = *argv++;
    argc--;
    port = *argv++;
    argc--;
    if (sscanf(port, "%d", &scratch) != 1)
	usageerror();

    cond = DUL_InitializeNetwork(DUL_NETWORK_TCP, DUL_AEREQUESTOR,
			   NULL, DUL_TIMEOUT, DUL_ORDERBIGENDIAN, &network);
    if (cond != DUL_NORMAL)
	myExit(NULL);

    (void) gethostname(localHost, sizeof(localHost));
    sprintf(params.calledPresentationAddress, "%s:%s", node, port);
    strcpy(params.callingPresentationAddress, localHost);
    strcpy(params.calledAPTitle, calledAPTitle);
    strcpy(params.callingAPTitle, callingAPTitle);
    params.maxPDU = maxPDU;

    reqReleaseAssociation(&network, &params);
    THR_Shutdown();
    exit(0);
}
Exemplo n.º 22
0
int InputThreadEntryPoint(void *data) {
  SDL_Event event;
  SDL_Joystick *js;
  int num_js, i;

  char *threadname;

  threadname = (char *) data;


  /* by default keyboard repeat is disabled in SDL 
     use SDL_EnableKeyrepeat(delay, rate) to enable it */
  /* SDL_EnableKeyRepeat(350, 30); */
  
  num_js = SDL_NumJoysticks();
  if (num_js == 0) {
    fprintf(stderr, "No joysticks were detected.\n");
    myExit (-20);
  } /* if */

  js = SDL_JoystickOpen(0);
  if (js == NULL) {
    fprintf(stderr, "Unable to open joystick: %s\n.", SDL_GetError());
    myExit (-20);
  } /* if */

  while((!exit_flag) && (SDL_WaitEvent(&event) != 0)) {
    SDL_keysym keysym;
    
    /* SDL_WaitEvent has filled in our event structure with the next event.
       We check its type field to find out what has happened */
    
    switch(event.type) {
    case SDL_JOYAXISMOTION:
      if ((event.jaxis.which == 0) && (event.jaxis.axis <2))
	movePlayer(event.jaxis.axis, event.jaxis.value);
      break;
      
    case SDL_JOYBUTTONUP:
      break;

    case SDL_JOYBUTTONDOWN:
      if (event.jbutton.which == 0)
	switch(event.jbutton.button) {
	case 0:
	  delLetter();
	  break;
	case 2:
	  fireShot();
	  break;
	case 3:
	  scoreWord();
	  break;
	} /* switch */
      break;

    case SDL_KEYDOWN:
      keysym = event.key.keysym;

      /* toggle full screen mode */
      if (keysym.sym == SDLK_f) {
	fprintf(stderr, "'F' pressed, toggling fullscreen.\n");
	toggleFullScreen();
      } /* if */

      /* would you like a zombie? */
      if (keysym.sym == SDLK_z) {
	fprintf(stderr, "'Z' pressed, sending in a zombie.\n");
	newZombie();
      } /* if */
      
      /* did the user press the Q key? */
      if (keysym.sym == SDLK_q) {
	fprintf(stderr, "'Q' pressed, exiting.\n");
	myExit(0);
      } /* if */
      break;
      
    case SDL_KEYUP:
      break;
      
    case SDL_QUIT:
      fprintf(stderr, "Quit event. Bye.\n");
      exit_flag = 1;
      break;
    } /* switch */
  } /* while */
  SDL_JoystickClose(js);
  fprintf(stderr, "%s is now exiting.\n", threadname);
  
  myExit(1);
} /* InputThreadEntryPoint */
Exemplo n.º 23
0
/* Main program.*/
main(int argc, char **argv)
{
    CONDITION
	cond;			/* condition return code */
    short
        dbid;			/* DB database id */
    BOOLEAN
	prepend = FALSE;	/* for prepending current working directory */

    (void) strcpy(cwd, "\0");	/* initialize current working directory */

    /* get the current working directory */
    if (!getwd(cwd))
	myExit(GETWDERROR);

    /* parse the command line arguments */
    while (--argc > 0 && (*++argv)[0] == '-') {
	switch (*(argv[0] + 1)) {
	case 'v':
	    verbose = TRUE;
	    break;
	case 'p':
	    prepend = TRUE;
	    break;
	default:
	    myExit(UNKNOWNCMDLINEARG);
	}
    }
    if (argc < 3)
	usageError();

    if (sscanf(*argv++, "%s", dbfile) != 1)
	usageError();

    /* prepend the current working directory before the filenames */
    if (prepend) {
	(void) sprintf(imgfile, "%s/%s", cwd, *argv++);
	(void) sprintf(prefmtImgfile, "%s/%s", cwd, *argv++);
    } else {
	(void) sprintf(imgfile, "%s", *argv++);
	(void) sprintf(prefmtImgfile, "%s", *argv++);
    }

    if (verbose)
	printf("DB file : %s, imgfile : %s, prefmtfile : %s\n", dbfile,
	       imgfile, prefmtImgfile);

    /*
     * The first step is to open the DB database file, if it exists, else
     * newly create it.
     */

    cond = DB_Open(dbfile, &dbid);
    if (cond != DB_NORMAL) {	/* DB database file doesnot exist */
	/* create the DB data base file */
	cond = DB_CreateDB(dbfile);
	if (cond != DB_NORMAL)
	    myExit(DBCREATEERROR);
	/* now open the file */
	cond = DB_Open(dbfile, &dbid);
	if (cond != DB_NORMAL)
	    myExit(DBOPENERROR);
    }
    /* now add the image and make an entry into the data base */
    if (!access(imgfile, R_OK))
	makeDBEntry(dbid, imgfile, prefmtImgfile);
    else
	myExit(NOREADACCESSERROR);

    exit(0);			/* success */
}
Exemplo n.º 24
0
int main(int argc, char **argv)
{

  CONDITION cond;
  DUL_NETWORKKEY* network = NULL;
  DUL_ASSOCIATIONKEY* association = NULL;
  DUL_ASSOCIATESERVICEPARAMETERS params;
  char
    *calledAPTitle = "CFIND_SCP",
    *callingAPTitle = "CFIND_SCU";

  char localHost[40] = "";

  int port;
  char *node;

  CTNBOOLEAN
    verbose = FALSE,
    abortFlag = FALSE,
    paramsFlag = FALSE;
  char *fileName = NULL;
  DUL_SC_ROLE
    role = DUL_SC_ROLE_DEFAULT;

  char* sopClass = DICOM_SOPSTUDYQUERY_FIND;
  char* outputPath = "";

  while (--argc > 0 && (*++argv)[0] == '-') {
    switch (*(argv[0] + 1)) {
    case 'a':
      argc--;
      argv++;
      if (argc <= 0)
	usageerror();
      callingAPTitle = *argv;
      break;
    case 'c':
      argc--;
      argv++;
      if (argc <= 0)
	usageerror();
      calledAPTitle = *argv;
      break;
    case 'o':
      argc--;
      argv++;
      if (argc <= 0)
	usageerror();
      outputPath = *argv;
      break;
    case 'v':
      verbose = TRUE;
      break;
    default:
      break;
    }
  }

  if (argc < 5)
    usageerror();

  ::THR_Init();
  ::DUL_Debug(verbose);
  ::SRV_Debug(verbose);

  node = *argv;
  if (sscanf(*++argv, "%d", &port) != 1)
    usageerror();

  if( gethostname(localHost, sizeof(localHost)) != 0) {
	  // gethostname is failing under Win32
	  //fprintf(stderr, "gethostname() failed.\n");
  }

  cond = DUL_InitializeNetwork(DUL_NETWORK_TCP, DUL_AEREQUESTOR,
				 NULL, 10, DUL_ORDERBIGENDIAN, &network);
  if (cond != DUL_NORMAL)
    myExit(&association);

  ::DUL_DefaultServiceParameters(&params);
  ::sprintf(params.calledPresentationAddress, "%s:%s", node, *argv);
  ::strcpy(params.callingPresentationAddress, localHost);
  ::strcpy(params.calledAPTitle, calledAPTitle);
  ::strcpy(params.callingAPTitle, callingAPTitle);
  cond = ::SRV_RequestServiceClass(sopClass, role, &params);
  if (cond != SRV_NORMAL) {
    ::COND_DumpConditions();
    ::THR_Shutdown();
    ::exit(1);
  }

  cond = ::DUL_RequestAssociation(&network, &params, &association);
  if (cond != DUL_NORMAL) {
    if (cond == DUL_ASSOCIATIONREJECTED) {
      ::fprintf(stderr, "Association Rejected\n");
      ::fprintf(stderr, " Result: %2x Source %2x Reason %2x\n",
		params.result, params.resultSource,
		params.diagnostic);
    }
    myExit(&association);
  }
  if (verbose || paramsFlag) {
    (void) ::printf("Association accepted, parameters:\n");
    ::DUL_DumpParams(&params);
  }

  MString patientID(*++argv);
  MDICOMWrapper qStudy(*++argv);
  qStudy.setString(0x00100020, patientID);
  MDICOMWrapper qSeries(*++argv);
  MDICOMWrapper qSOPInstance(*++argv);

  DCM_OBJECT* queryObj = qStudy.getNativeObject();

  MLQuery qHandlerStudy(outputPath);
  MLQuery qHandlerSeries(outputPath);
  MLQuery qHandlerInstance(outputPath);

  MDICOMReactor reactor;

  reactor.registerHandler(&qHandlerStudy, sopClass);
  qHandlerStudy.sendCFindRequest(&association, &params,
			    sopClass, &queryObj);
  reactor.processRequests(&association, &params, 1);

  WRAPPERVector studyVector = qHandlerStudy.wrapperVector();


  WRAPPERVector::iterator studyIterator = studyVector.begin();
  for (; studyIterator != studyVector.end(); studyIterator++) {
    MDICOMWrapper* w = *studyIterator;

    DCM_OBJECT* obj = w->getNativeObject();
    ::DCM_FormatElements(&obj, 1, "");
    reactor.registerHandler(&qHandlerSeries, sopClass);

    MString studyUID = w->getString(0x0020000D);
    qSeries.setString(0x0020000D, studyUID);

    DCM_OBJECT* seriesQueryObj = qSeries.getNativeObject();
    qHandlerSeries.sendCFindRequest(&association, &params,
				    sopClass, &seriesQueryObj);

    qHandlerSeries.clearVector();
    reactor.processRequests(&association, &params, 1);

    WRAPPERVector seriesVector = qHandlerSeries.wrapperVector();

    WRAPPERVector::iterator seriesIterator = seriesVector.begin();
    for (; seriesIterator != seriesVector.end(); seriesIterator++) {
      MDICOMWrapper* w2 = *seriesIterator;
      DCM_OBJECT* objSeries = w2->getNativeObject();
      ::DCM_FormatElements(&objSeries, 1, "  ");

      reactor.registerHandler(&qHandlerInstance, sopClass);
      MString seriesUID = w2->getString(0x0020000E);
      qSOPInstance.setString(0x0020000D, studyUID);
      qSOPInstance.setString(0x0020000E, seriesUID);
      DCM_OBJECT* instanceQueryObj = qSOPInstance.getNativeObject();
      qHandlerInstance.sendCFindRequest(&association, &params,
					sopClass, &instanceQueryObj);
      qHandlerInstance.clearVector();
      reactor.processRequests(&association, &params, 1);

      WRAPPERVector instanceVector = qHandlerInstance.wrapperVector();

      WRAPPERVector::iterator instanceIterator = instanceVector.begin();
      for (; instanceIterator != instanceVector.end(); instanceIterator++) {
	MDICOMWrapper* w3 = *instanceIterator;
	DCM_OBJECT* objInstance = w3->getNativeObject();
	::DCM_FormatElements(&objInstance, 1, "    ");
      }
    }
  }


  cond = ::DUL_ReleaseAssociation(&association);
  if (cond != DUL_RELEASECONFIRMED) {
    (void) ::fprintf(stderr, "%x\n", cond);
    ::COND_DumpConditions();
  }
  (void) ::DUL_ClearServiceParameters(&params);

  (void) ::DUL_DropNetwork(&network);
  ::THR_Shutdown();
  return 0;
}
Exemplo n.º 25
0
void
//brcm begin
tftpd_receive (int peer, struct tftphdr *first_pkt, int pkt_len, int buffersize)
{
// brcm	FILE *file=NULL;
	char buffer[TFTP_BLOCKSIZE_DEFAULT+4];
	struct tftphdr *pkt;
	int block, inbytes;
	char *list[64];
	int listcount;

    //brcm begin
    PARSE_RESULT imageType = NO_IMAGE_FORMAT;
    int byteRd = 0;
    char tag[TAG_LEN];
    int tagSize = 0;
    int size = 0;
    char *curPtr = NULL;
    unsigned int totalAllocatedSize = 0;
    int socketPid = 0;
    int fNeedReset = FALSE;
	 char *imagePtr = NULL;
    int uploadSize = 0;
    int i = 0;   

//printf("tftpd_receive, peer = %d, pkt_len = %d, buffersize=%d\n", peer, pkt_len, buffersize);

	pkt=(struct tftphdr *)buffer;
	listcount = tftpd_options (first_pkt->th_stuff, pkt_len, list ,64);

	/* get the size of the file (remember, chroot() supposed to point us in the right directory) */

//printf ("mode= %s, file= %s\n", list[1], list[0]);	
    if (strcasecmp(list[1],"octet")!=0)
	{
        printf("Only support 'bin' mode. Type 'bin' at tftp client\n");
		tftpd_nak(peer,EBADOP);
		close(peer);
		exit(0);
	}

#if 0//brcm
    file = fopen (list[0], "w");
	if (file == NULL)
	{
	  tftpd_nak (peer, EACCESS);
	  close(peer);
	  exit(0);
	}
#endif //brcm

    block=0;

    socketPid = bcmSocketIfPid();   
    // kill the app first so that when there are heavy traffic, the UDP packet will not be lost.
    killAllApps(socketPid, SKIP_HTTPD_APP, 0, 0);     // skip kill httpd for xml config. update
    printf("Done removing processes\n");
    fNeedReset = TRUE;

	do
	{
		tftpd_ack(peer,block);
		block++;

      // if duplicate pkt, (for slow ack on 38R board) discard it.
      for (i = 0; i < DUP_PKT_CHECK_COUNT; i++)
      {
         inbytes=tftpd_getdata(peer,block,buffer,TFTP_BLOCKSIZE_DEFAULT+4, fNeedReset);
         if (block == (int) (*(short*)(buffer+2)))
            break;
      }
		// brcm fwrite(pkt->th_msg,1,inbytes-4,file);
        byteRd=inbytes-4;
        // brcm begin
        if (curPtr == NULL) 
        {
            if (byteRd < TFTP_BLOCKSIZE_DEFAULT)   // not enough data for a valid first packet and exit
            {
                uploadSize = byteRd;
                break;
            }
            // The first data that is downloaded is the FILE_TAG structure.
            // After the entire FILE_TAG structure has been downloaded, use
            // the totalImageSize field to determine the size of pkt->th_msg to
            // allocate.
            if( tagSize + byteRd > TAG_LEN)
                size = TAG_LEN - tagSize;
            else 
                size = byteRd;

            memcpy(tag + tagSize, pkt->th_msg, size);
            tagSize += size;
            byteRd -= size;
            if( tagSize == TAG_LEN ) 
            {
                PFILE_TAG pTag = (PFILE_TAG) tag;

                if (verifyTag(pTag, 1) == UPLOAD_OK) 
                {
                    // if chip id mismatched.
                    if (checkChipId(pTag->chipId, pTag->signiture_2) != 0)
                        myExit(fNeedReset, peer);
                    int totalImageSize = atoi(pTag->totalImageLen);
                    // add tag len plus some pkt->th_msg for over flow during the sending...
                    totalAllocatedSize = totalImageSize + TAG_LEN + 8;
                    printf( "Allocating %d bytes for broadcom image.\n", totalAllocatedSize );
                    curPtr = (char *) malloc(totalImageSize + TAG_LEN + 8);
                    if (curPtr == NULL) 
                    {
                        printf("Not enough memory error.");       
                        myExit(fNeedReset, peer);
                    }
                    else 
                    {
                        printf("Memory allocated\n");
                        imagePtr = curPtr;
                        memcpy(curPtr, tag, TAG_LEN);
                        curPtr += TAG_LEN;
                        uploadSize += TAG_LEN;
                        memcpy(curPtr, pkt->th_msg + size, byteRd);
                        curPtr += byteRd;
                    }
                }
                // try to allocate the memory for .w image, same as flash size + some overhead
                else 
                {   
                    totalAllocatedSize = sysFlashSizeGet() + TOKEN_LEN;
                    printf("Allocating %d bytes for flash image.\n", totalAllocatedSize);
                    curPtr = (char *) malloc(totalAllocatedSize);
                    if(curPtr == NULL) 
                    {
                        printf("Not enough memory error.");       
                        myExit(fNeedReset, peer);
                    }
                    else 
                    {
                        printf("Memory allocated\n");
                        imagePtr = curPtr;
                        byteRd += TAG_LEN;          // add back the tag size
                        memcpy(curPtr, pkt->th_msg, byteRd);
                        curPtr += byteRd;
                    }
                }  // else alloc memory for .w image
            } //tagSize == TAG_LEN
        } // if curPtr == NULL
        else 
        { // not first block of data
            memcpy(curPtr, pkt->th_msg, byteRd);
            curPtr += byteRd;
        }
        
        uploadSize += byteRd;
//printf("Current uploadSize= %d\n", uploadSize);
        if (uploadSize > totalAllocatedSize) // try not to over flow the pkt->th_msg
        {       
            printf("Failed on data corruption during file transfer or over sized image.\n");
			printf("Upload size = %d, size allowed = %d\n", uploadSize, totalAllocatedSize);
            myExit(fNeedReset, peer);
        }
        // brcm end
	}
	while (inbytes==(TFTP_BLOCKSIZE_DEFAULT+4));

    tftpd_ack(peer,block); /* final acknowledge */

// brcm	fclose(file);

    printf("Total size: %d\n", uploadSize);

    if ((imagePtr != NULL) && 
        ((imageType = parseImageData(imagePtr, uploadSize, BUF_ALL_TYPES)) != NO_IMAGE_FORMAT)) 
    {
        printf("Tftp image done.\n");
        flashImage(imagePtr, imageType, uploadSize);
        if (imagePtr)
	        free(imagePtr);
    }
    else 
        printf("Tftp Image failed: Illegal image.\n");

    // no reset if psi update (need httpd to process xml file)
    if (imageType == PSI_IMAGE_FORMAT)
        fNeedReset=FALSE;
    myExit(fNeedReset, peer);
}
Exemplo n.º 26
0
static int parse(int argc, char *argv[])
{
	int idx, srcFileCnt=0;

	char dot_c_ext[]    = ".c";
	char dot_cc_ext[]   = ".cc";
	char dot_cpp_ext[]  = ".cpp";
	char dot_o_ext[]    = ".o";
	char name_option[]  = "--name=";
	char lib_option[]   = "-l";
	char inc_option[]   = "-I";
	char mingw_option[] = "-mingw=";
	char ivl_option[]   = "-ivl=";
	char def_option[]   = "-D";

	if (argc == 1) return 0;

	for (idx=1; idx<argc; ++idx) {
		  /* Check for C source files (*.c) */
		if (endsIn(dot_c_ext, argv[idx])) {
			++srcFileCnt;
			append(&gstr.pCCSRC, argv[idx]);
			append(&gstr.pCCSRC, " ");
			if (!*gstr.pOUT)
			   assignn(&gstr.pOUT, argv[idx],
			           strlen(argv[idx])-strlen(dot_c_ext));
		}
		  /* Check for C++ source files (*.cc) */
		else if (endsIn(dot_cc_ext, argv[idx])) {
			  /* We need to link with the C++ compiler. */
			assign(&gstr.pLD, IVERILOG_VPI_CXX);
			++srcFileCnt;
			append(&gstr.pCXSRC, argv[idx]);
			append(&gstr.pCXSRC, " ");
			if (!*gstr.pOUT)
			   assignn(&gstr.pOUT, argv[idx],
			           strlen(argv[idx])-strlen(dot_cc_ext));
		}
		  /* Check for C++ source files (*.cpp) */
		else if (endsIn(dot_cpp_ext, argv[idx])) {
			  /* We need to link with the C++ compiler. */
			assign(&gstr.pLD, IVERILOG_VPI_CXX);
			++srcFileCnt;
			append(&gstr.pCXSRC, argv[idx]);
			append(&gstr.pCXSRC, " ");
			if (!*gstr.pOUT)
			   assignn(&gstr.pOUT, argv[idx],
			           strlen(argv[idx])-strlen(dot_cpp_ext));
		}
		  /* Check for compiled object files */
		else if (endsIn(dot_o_ext, argv[idx])) {
			++srcFileCnt;
			append(&gstr.pOBJ," ");
			append(&gstr.pOBJ, argv[idx]);
			if (!*gstr.pOUT)
			   assignn(&gstr.pOUT, argv[idx],
			           strlen(argv[idx])-strlen(dot_o_ext));
		}
		  /* Check for the -mingw option */
		else if (startsWith(mingw_option, argv[idx]))
			assignn(&gstr.pMINGW, argv[idx]+sizeof(mingw_option)-1,
			        strlen(argv[idx])-(sizeof(mingw_option)-1));
		  /* Check for the -ivl   option */
		else if (startsWith(ivl_option, argv[idx]))
			assignn(&gstr.pIVL, argv[idx]+sizeof(ivl_option)-1,
			        strlen(argv[idx])-(sizeof(ivl_option)-1));
		  /* Check for the --name option */
		else if (startsWith(name_option, argv[idx])) {
			assignn(&gstr.pOUT, argv[idx]+sizeof(name_option)-1,
			        strlen(argv[idx])-(sizeof(name_option)-1));
		}
		  /* Check for the -l option */
		else if (startsWith(lib_option, argv[idx])) {
			append(&gstr.pLIB, " ");
			append(&gstr.pLIB, argv[idx]);
		}
		  /* Check for the -I option */
		else if (startsWith(inc_option, argv[idx])) {
			append(&gstr.pINCS, " ");
			append(&gstr.pINCS, argv[idx]);
		}
		  /* Check for the -D option */
		else if (startsWith(def_option, argv[idx])) {
			append(&gstr.pDEFS, " ");
			append(&gstr.pDEFS, argv[idx]);
		}
		  /* Check for the --cflags option */
		else if (stricmp("--cflags", argv[idx]) == 0) {
			setup_ivl_environment();
			printf("%s\n", gstr.pCFLAGS);
			myExit(0);
		}
		  /* Check for the --ldflags option */
		else if (stricmp("--ldflags", argv[idx]) == 0) {
			printf("%s\n", IVERILOG_VPI_LDFLAGS);
			myExit(0);
		}
		  /* Check for the --ldlibs option */
		else if (stricmp("--ldlibs", argv[idx]) == 0) {
			setup_ivl_environment();
			printf("%s\n", gstr.pLDLIBS);
			myExit(0);
		}
		  /* Check for the --install-dir option */
		else if (stricmp("--install-dir", argv[idx]) == 0) {
			setup_ivl_environment();
			printf("%s\\\\lib\\\\ivl" IVERILOG_SUFFIX "\\\\.\n", gstr.pIVL);
			myExit(0);
		}
		  /* This is different than iverilog-vpi.sh, we don't
		   * ignore unknown arguments */
		else return 0;
	}

	  /* In case there is a --name without source/object files */
	if (0 == srcFileCnt) assign(&gstr.pOUT,"");

	  /* Normally it's an error if there are no source or object files */
	  /* Unless we are setting the IVL or MinGW registry entries */
	if (!*gstr.pOUT) {
		if (!*gstr.pMINGW && !*gstr.pIVL) return 0;
	} else
		  /* We have a valid result file so add the .vpi extension */
		append(&gstr.pOUT, ".vpi");

	return 1;
}