Ejemplo n.º 1
0
void main(void)
{
	/*
    * Get the compressed sizes of the files
    */
	xmem2root(&text_size, alice_html, 4);
	text_size &= ZIMPORT_MASK;
	xmem2root(&image_size, alice_jpg, 4);
	image_size &= ZIMPORT_MASK;

	/*
    * When compressed files are added via the sspec_addxmemfile() function,
    * they are automatically detected as such.  This is in distinction to
    * the static resource table setup (i.e. SSPEC_RESOURCE_* macros) which
    * require explicit specification at compile time.
    *
    * Note, that jpeg or gif files (as in the following) do not generally
    * compress well (or at all).  Hence, it is best to leave image files uncompressed.
    */
	sspec_addxmemfile("/alice.jpg", alice_jpg, SERVER_HTTP);
	sspec_addvariable("text_size", &text_size, INT32, "%ld", SERVER_HTTP);
   sspec_addvariable("image_size", &image_size, INT32, "%ld", SERVER_HTTP);

	// Start network and wait for interface to come up (or error exit).
	sock_init_or_exit(1);
   http_init();

   while (1) {
   	http_handler();
   }
}
Ejemplo n.º 2
0
/*
 * Write out an email message to the display buffer
 */
void DispEmail(void)
{
	int i;
	int j;
	char line[DISP_COLS + 1];
	int row;
	int col;
	int lineNum;

	lineNum = 0;
	emailDispLine = 0;

	if (emailList.ptr == -1)
	{
		DispNoEmail();
	}
	else
	{
		xmem2root(&email, emailBuffer + sizeof(Email)*emailList.ptr, sizeof(Email));
		DispPart(email.from, &lineNum, "FROM: ");
		DispPart(email.subject, &lineNum, "SUBJECT: ");
		strcpy(line, "BODY");
		root2xmem(dispBuffer + ((DISP_COLS+1) * lineNum), line, DISP_COLS+1);
		lineNum++;
		DispPart(email.body, &lineNum, "");

		line[0] = '\0';
		emailLastLine = lineNum;

		DispUpdateWindow();
	}
}
Ejemplo n.º 3
0
/**
 * 	Duplicate a string with a four-byte size in front of it.
 * 	Allocates xmem to store size and string.  The "xstring"
 * 	directive does NOT store the size.  To use sspec_addxmemfile(),
 * 	this is required.  Thus the copy which prepends a four-byte size
 * 	value (not including NUL char).  The final xmem2mem() copies the
 * 	string just after the size.
 *
 * 	RETURN: 	physical addr of 4 byte size (string follows, without
 * 			its NUl char termination).
 */
long
xmem_strdup( long xstr )
{
	auto long	xsrc, xnext;
	auto long 	siz;
	auto long 	xdest;

	xmem2root( & xsrc, xstr+0, 4 );
	xmem2root( & xnext, xstr+4, 4 );
	siz = xnext - xsrc - 1;   					// Don't store NUL char.

	xdest = xalloc( (int)siz + 4 );
	root2xmem( xdest, & siz, 4 );
	xmem2xmem( xdest+4, xsrc, (int)siz );

	return( xdest );
}   /* end xmem_strdup() */
Ejemplo n.º 4
0
void main()
{
    long x,length;
    char buffer[256];

    printf("physical address: %06lx\n",(long)tempfile);

    xmem2root(&length,tempfile,sizeof(long));

    if(length>256)  // only print first 256 characters of file
        length=256;

    xmem2root(buffer,tempfile+4,(int)length);

    for(x=0; x<length; x++) {
        printf("%c",buffer[(int)x]);
    }
}
Ejemplo n.º 5
0
int main()
{
	int count, err;
   unsigned int dma_div, flags;
   dma_chan_t handle;

	// The dma divisor determines how fast the data sent to TCR0LR changes.
	// The larger this number is, the slower the wav file will play.
	dma_div = 0x0F00;

	src = xmem_src + sizeof(long);
	xmem2root((void *)&wav_size, xmem_src, 4);
	timerc_setup();

   // Set the DMA to use 50% of the CPU resources.
	err = DMAsetParameters(0, 0, DMA_IDP_FIXED, 2, 50);
	if(err){
   	printf("Error: DMAsetParameters.\n");
		exit(err);
   }

   handle = DMAalloc(DMA_CHANNEL_ANY, 0);
   if(handle == DMA_CHANNEL_NONE){
      printf("Error: DMAalloc.\n");
      exit(EINVAL);
   }

   printf("Playing wav file...\n");
	for(count = 0; count < 5 && !kbhit(); count++){			// play the wav 5 times.
		printf(" Count = %d.\n", count + 1);

		// This function sets up the timer.  To use the timer, the flag values
      // must be set correctly as well.
      DMAtimerSetup(dma_div);

      // if the wav_size were larger than 32765 bytes, more than one transfer
      // would be necessary.
      flags = DMA_F_TIMER | DMA_F_TIMER_1BPR;
	   err = DMAmem2ioi(handle, TCR0LR, src, (int)wav_size, flags);
	   if(err){
			printf("Error: DMAmem2ioi.\n");
         exit(err);
	   }

	   while(!DMAcompleted(handle, NULL))
	      ;

   }

   WrPortI(TCCSR, NULL, 0x00);   // disable the main clock for timer c

   err = DMAunalloc(handle);
   if(err){
      printf("Error: DMAunalloc.\n");
      exit(err);
   }
}
Ejemplo n.º 6
0
/*
 * Display the current window within the display buffer
 */
void DispUpdateWindow(void)
{
	int i;
	char line[DISP_COLS + 1];

	glBlankScreen();
	for (i = 0; i < DISP_ROWS; i++) {
		if ((emailDispLine + i) < emailLastLine) {
			TextGotoXY(&wholewindow, 0, i);
			xmem2root(line, dispBuffer + ((DISP_COLS+1) * (emailDispLine+i)), DISP_COLS+1);
			TextPrintf(&wholewindow, "%s", line);
		} else {
			TextGotoXY(&wholewindow, 0, i);
			TextPrintf(&wholewindow, "");
		}
	}
}
Ejemplo n.º 7
0
int ViewLog(HttpState *state)
{
	if (state->length) {
		/* buffer to write out */
		if (state->offset < state->length) {
			state->offset += sock_fastwrite(&state->s,
					state->buffer + (int)state->offset,
					(int)state->length - (int)state->offset);
		} else {
			state->offset = 0;
			state->length = 0;
		}
	} else {
		switch (state->substate) {
			case 0:
				logPosition = 0;
				strcpy(state->buffer, "HTTP/1.0 200 OK\r\n\r\n");
				state->length = strlen(state->buffer);
				state->offset = 0;
				state->substate++;
				break;

			case 1:
				strcpy(state->buffer, "<html><head><title>Display Log</title></head><body>\r\n");
				state->length = strlen(state->buffer);
				state->substate++;
				break;

			case 2:
				strcpy(state->buffer, "<H1>Display Log</H1>\r\n<PRE>\r\n");
				state->length = strlen(state->buffer);
				state->substate++;
				break;

			case 3:
				xmem2root(state->buffer, logBuffer + logPosition, HTTP_MAXBUFFER);
				if (state->buffer[HTTP_MAXBUFFER - 1] != '\0') {
					state->buffer[HTTP_MAXBUFFER - 1] = '\0';
					if (strlen(state->buffer) == (HTTP_MAXBUFFER - 1)) {
						// More data to get
						logPosition += HTTP_MAXBUFFER - 1;
					} else {
						state->substate++;
					}
				} else {
					state->substate++;
				}
				state->length = strlen(state->buffer);
				break;

			case 4:
				strcpy(state->buffer, "\r\n</PRE>\r\n");
				state->length = strlen(state->buffer);
				state->substate++;
				break;

			case 5:
				strcpy(state->buffer, "<p><a href=\"/\">Back to main page</a></body></html>\r\n");
				state->length = strlen(state->buffer);
				state->substate++;
				break;

			default:
				state->substate = 0;
				return 1;
		}
	}
	return 0;
}
Ejemplo n.º 8
0
int Read(HttpState* state)
{
	int i;
	char line[10];

	if (state->length) {
		/* buffer to write out */
		if (state->offset < state->length) {
			state->offset += sock_fastwrite(&state->s,
					state->buffer + (int)state->offset,
					(int)state->length - (int)state->offset);
		} else {
			state->offset = 0;
			state->length = 0;
		}
	} else {
		switch (state->substate) {
		case 0:
			strcpy(state->buffer, "HTTP/1.0 200 OK\r\n\r\n");
			state->length = strlen(state->buffer);
			state->offset = 0;
			state->substate++;
			break;

		case 1:
			strcpy(state->buffer, "<html><head><title>Read Email</title></head><body>\r\n");
			state->length = strlen(state->buffer);
			state->substate++;
			break;

		case 2:
			emailCurr = emailList.head;
			emailNum = 1;
			strcpy(state->buffer, "<H1>Read Email</H1>\r\n");
			state->length = strlen(state->buffer);
			state->substate++;
			break;

		case 3:
			bodyPosition = 0;
			if (emailCurr != -1) {
				strcpy(state->buffer, "<B>Email #");
				itoa(emailNum, line);
				strcat(state->buffer, line);
				strcat(state->buffer, "</B><P><PRE>");
				state->length = strlen(state->buffer);
				state->substate++;
			} else if (emailNum == 1) {
				strcpy(state->buffer, "No email");
				state->length = strlen(state->buffer);
				state->substate = 9;
			} else {
				state->substate = 9;
			}
			break;

		case 4:
			xmem2root(&email, emailBuffer	+ sizeof(Email)*emailCurr, sizeof(Email));
			strcpy(state->buffer, "FROM: ");
			strcat(state->buffer, email.from);
			strcat(state->buffer, "\r\n");
			state->length = strlen(state->buffer);
			emailNum++;
			emailCurr = emailIndex[emailCurr].next;
			state->substate++;
			break;

		case 5:
			strcpy(state->buffer, "SUBJECT: ");
			strcat(state->buffer, email.subject);
			strcat(state->buffer, "\r\n");
			state->length = strlen(state->buffer);
			state->substate++;
			break;

		case 6:
			strcpy(state->buffer, "BODY\r\n");
			state->length = strlen(state->buffer);
			state->substate++;
			break;

		case 7:
			strncpy(state->buffer, email.body + bodyPosition, HTTP_MAXBUFFER);
			if (state->buffer[HTTP_MAXBUFFER - 1] != '\0') {
				state->buffer[HTTP_MAXBUFFER - 1] = '\0';
				if (strlen(state->buffer) == (HTTP_MAXBUFFER - 1)) {
					// More data to get
					bodyPosition += HTTP_MAXBUFFER - 1;
				} else {
					state->substate++;
				}
			} else {
				state->substate++;
			}
			state->length = strlen(state->buffer);
			break;

		case 8:
			strcpy(state->buffer, "\r\n</PRE>\r\n");
			state->length = strlen(state->buffer);
			state->substate = 3;
			break;

		case 9:
			strcpy(state->buffer, "<p><a href=\"/\">Back to main page</a></body></html>\r\n");
			state->length = strlen(state->buffer);
			state->substate++;
			break;

		default:
			state->substate = 0;
			return 1;
		}
	}

	return 0;
}
Ejemplo n.º 9
0
/////////////////////////////////////////////////////////////////////
// Locate the calibration data within the file using known
// identifier TAGS.
/////////////////////////////////////////////////////////////////////
unsigned long find_tag(unsigned long fileptr, long len)
{
    auto char data[2047];
    auto long index,i;
    auto char *begptr, *firstline, *secondline, *saveptr;
    auto int eofile, eoline, nextcase, dnstate, channel, gaincode;

    index = 0;
    xmem2root(data, fileptr, (int)len);
    begptr = strtok(data, "\n\r");		//begin data file
    while (strncmp(begptr, "::", 2))		//look for start
    {
        begptr = strtok(NULL, "\n\r");
    }
    begptr = strtok(NULL, "\n\r");
    serXputs(myport, "\n\rData file serial number is \x0");
    serXwrite(myport, begptr, strlen(begptr));

    eofile = FALSE;
    saveptr = begptr+strlen(begptr)+1;
    while (!eofile)
    {
        eoline = FALSE;
        nextcase = 0;
        begptr = strtok(saveptr, "\n\r");
        saveptr = begptr+strlen(begptr)+1;
        if (!strncmp(begptr, "ADSE", 4))
        {
            dnstate = 2;
        }
        else if (!strncmp(begptr, "ADDF", 4))
        {
            dnstate = 3;
        }
        else if (!strncmp(begptr, "ADMA", 4))
        {
            dnstate = 4;
        }
        else if (!strncmp(begptr, "END", 3))
        {
            eofile = TRUE;
            eoline = TRUE;
        }
        else
            nextcase = 1;

        while (!eoline)
        {
            switch (nextcase)
            {
            case 2:		//single ended
                firstline = strtok(NULL, "\n\r");
                secondline = strtok(NULL, "\n\r");
                for (gaincode = 0; gaincode <= 3; gaincode++)
                {
                    begptr = strtok(firstline, ",");
                    _adcCalibS[channel][gaincode].kconst = atof(begptr);
                    begptr = strtok(NULL, ",");
                    _adcCalibS[channel][gaincode].offset = atof(begptr);
                    firstline = begptr+strlen(begptr)+1;
                }

                for (gaincode = 4; gaincode <= 7; gaincode++)
                {
                    begptr = strtok(secondline, ",");
                    _adcCalibS[channel][gaincode].kconst = atof(begptr);
                    begptr = strtok(NULL, ",");
                    _adcCalibS[channel][gaincode].offset = atof(begptr);
                    secondline = begptr+strlen(begptr)+1;
                }
                saveptr = secondline+1;
                eoline = TRUE;
                break;
            case 3:		//differential
                firstline = strtok(NULL, "\n\r");
                secondline = strtok(NULL, "\n\r");
                for (gaincode = 0; gaincode <= 3; gaincode++)
                {
                    begptr = strtok(firstline, ",");
                    _adcCalibD[channel][gaincode].kconst = atof(begptr);
                    begptr = strtok(NULL, ",");
                    _adcCalibD[channel][gaincode].offset = atof(begptr);
                    firstline = begptr+strlen(begptr)+1;
                }
                for (gaincode = 4; gaincode <= 7; gaincode++)
                {
                    begptr = strtok(secondline, ",");
                    _adcCalibD[channel][gaincode].kconst = atof(begptr);
                    begptr = strtok(NULL, ",");
                    _adcCalibD[channel][gaincode].offset = atof(begptr);
                    secondline = begptr+strlen(begptr)+1;
                }
                saveptr = secondline+1;
                eoline = TRUE;
                break;
            case 4:		//milli-amp
                firstline = strtok(NULL, "\n\r");
                begptr = strtok(firstline, ",");
                _adcCalibM[channel].kconst = atof(begptr);
                begptr = strtok(NULL, ",");
                _adcCalibM[channel].offset = atof(begptr);
                saveptr = begptr+strlen(begptr)+2;
                eoline = TRUE;
                break;
            case 1:
                channel = atoi(begptr);
                nextcase = dnstate;
                eoline = FALSE;
                break;
            case 0:
                eoline = TRUE;
                break;
            } //switch

        } //while not eoline
    } //while not eofile

    anaInEEWr(ALLCHAN, SINGLE, gaincode);			//read all single-ended
    anaInEEWr(ALLCHAN, DIFF, gaincode);				//read all differential
    anaInEEWr(ALLCHAN, mAMP, gaincode);				//read all milli-amp

}