Пример #1
0
void handle_telnet(const unsigned char *bytes, uint16_t frame_len) {
    print1("TELNET  ");
    print_ips_from_last_header_v1();
    printf1("%u bytes\n", frame_len);

    const unsigned char *end = bytes + frame_len;

    while(bytes < end) {
        if(*bytes & 0xFF) {
            bytes++;
            uint8_t command = *bytes++;
            printf3("        cmd %s (%u): ", TELCMD_OK(command) ? TELCMD(command) : "CMD?", command);
            switch(command) {
                case DO:
                case DONT:
                case WONT:
                case WILL: {
                    uint8_t option = *bytes++;
                    printf3("%s (%u)", TELOPT(option), option);
                    break;
                }
                case SB: {
                    uint8_t suboption = *bytes++;
                    printf3("%s (%u)", TELOPT(suboption), suboption);
                    switch(suboption) {
                        case TELOPT_TSPEED:
                            printf3(" = %u", *bytes++);
                            break;
                        case TELOPT_NAWS:
                            printf3(" = %u x %u", ntohs(*(uint16_t*)&bytes[0]), ntohs(*(uint16_t*)&bytes[2]));
                            bytes += 4;
                            break;
                        default:
                            break;
                    }
                    break;
                }
                case SE:
                    print3("end of suboptions");
                    break;
                default:
                    print3("unknown command");
                    break;
            }
            putchar3('\n');
            if(command == SE)
                break; // end of options
        }
        else {
            bytes++;
        }
    }
}
Пример #2
0
void handle_tcp(const unsigned char *bytes, uint16_t segment_len) {
    struct tcphdr *tcp_hdr = (struct tcphdr *) bytes;
    tcp_hdr->th_sport = ntohs(tcp_hdr->th_sport);
    tcp_hdr->th_dport = ntohs(tcp_hdr->th_dport);
    printf2("TCP     %u -> %u, [", tcp_hdr->th_sport, tcp_hdr->th_dport);
    print_flags(tcp_hdr->th_flags);
    print2("], ");
    printf2("seq %u, ack %u, win %u\n", ntohl(tcp_hdr->seq), ntohl(tcp_hdr->ack_seq), ntohs(tcp_hdr->window));

    int data_offset = 4 * tcp_hdr->th_off;
    const unsigned char *end = bytes + data_offset;
    bytes += sizeof(struct tcphdr);

    while(bytes < end) {
        uint8_t kind = *bytes++;

        uint8_t len = 0;
        if(kind != 0 && kind != 1)
            len = *bytes++;

        printf3("        option %u: ", kind);
        switch(kind) {
            case 0: print3("end of options"); break;
            case 1: print3("no operation (NOP)"); break;
            case 2: printf3("MSS %u", (*(uint32_t*) bytes)); break;
            case 3: print3("window scale"); break;
            case 4: print3("SACK permited"); break;
            case 5: print3("SACK"); break;
            case 8: print3("timestamps"); break;
            default: print3("unknown"); break;
        }
        print3("\n");

        // advance by the size of the option read
        if(kind != 0 && kind != 1)
            bytes += len - 2;
    }

    if(tcp_hdr->th_sport == 80 || tcp_hdr->th_dport == 80) {
        handle_http((const char *) bytes);
    }
    else if(tcp_hdr->th_sport == 23 || tcp_hdr->th_dport == 23) {
        handle_telnet(bytes, segment_len - data_offset);
    }
    else {
        printf1("???     Unknown TCP application with ports %u -> %u\n", tcp_hdr->th_sport, tcp_hdr->th_dport);
    }
}
Пример #3
0
void loadTest(int number) {
	byte* test1 = tests[number];
	byte* test2 = tests[number+1];
	
	word memaddr = test1[0] + (test1[1]<<8); // first 2 bytes are load address
	printf1("Test #%d",number);
	word progaddr;	
	unsigned int programlength = test2-test1;
	memWriteByte(memaddr++, 0x10);
	memWriteByte(memaddr++, 0x8);
	for(progaddr=4; progaddr<programlength; progaddr++) {
		memWriteByte(memaddr, test1[progaddr]);
		//printf2("%x:%x",memaddr,test1[progaddr]);
		memaddr++;
	}
}
Пример #4
0
void handle_arp(const unsigned char *bytes) {
    struct arphdr *arp_hdr = (struct arphdr *)bytes;
    arp_hdr->ar_op = ntohs(arp_hdr->ar_op);
    print1("ARP     ");

    switch(arp_hdr->ar_op) {
    case ARPOP_REQUEST:
        print1("request");
        break;
    case ARPOP_REPLY:
        print1("reply");
        break;
    case ARPOP_RREQUEST:
        print1("r-request");
        break;
    case ARPOP_RREPLY:
        print1("r-reply");
        break;
    default:
        printf1("opcode %u", arp_hdr->ar_op);
        break;
    }

    bytes += sizeof(struct arphdr);

    // Check if we really have Ethernet and IPv4
    if(arp_hdr->ar_hln == 6 && arp_hdr->ar_pln == 4) {
        print1(", ");
        print_ether_address1((u_int8_t *) bytes);
        bytes += 6;
        print1(" (");
        print_ip_addr1(*(int32_t *) bytes);
        bytes += 4;
        print1(") -> ");
        print_ether_address1((u_int8_t *) bytes);
        bytes += 6;
        print1(" (");
        print_ip_addr1(*(int32_t *) bytes);
        bytes += 4;
        print1(")");
    }
    print1("\n");
}
Пример #5
0
int main (int argc, char **argv)
{
	volatile int opt, i,j;
	char *device = "/dev/pccl";
	char option_chars [BUFSIZ];
	char *filename = NULL;

	int rc, fd;

#if ENABLE_NLS
#if HAVE_SETLOCALE
   setlocale (LC_ALL, "");
#endif
   bindtextdomain (PACKAGE, LOCALEDIR);
   bindtextdomain (program_invocation_short_name, LOCALEDIR);
   textdomain (PACKAGE);
#endif

	/*
	**	build the option-char string from the option struct.
	*/

	for (i=j=0; long_options[i].name; i++)
	{
		switch (long_options[i].has_arg)
		{
			case no_argument:
				option_chars[j++] = (char) long_options[i].val;
				break;
			case required_argument:
				option_chars[j++] = (char) long_options[i].val;
				option_chars[j++] = ':';
				break;
		}
	}
	option_chars[j] = 0;

	while ((opt = getopt_long(argc,argv,option_chars,long_options,NULL)) != EOF)
	{
		switch (opt)
		{
			case OPTION_HELP:
				printf1 (copyright_text,program_invocation_short_name);
				printf1 (_("Usage: %s [options] <filename>\n"),program_invocation_short_name);
				for (i=0; long_options[i].name; i++)
				{
					switch (long_options[i].has_arg)
					{
						case no_argument:
							printf1 ("--%s,-%c \t%s\n",long_options[i].name,long_options[i].val,_(option_help[i]));
							break;
						case required_argument:
							printf1 ("--%s=x,-%c\t%s\n",long_options[i].name,long_options[i].val,_(option_help[i]));
							break;
					}
				}
				exit (EXIT_SUCCESS);

			case OPTION_VERSION:
				printf1 (copyright_text,program_invocation_short_name);
				printf1 ("%s version %s\n",program_invocation_short_name,version_text);
				exit (EXIT_SUCCESS);

			case OPTION_QUIET:
				verbose_level = 0;
				break;

			case OPTION_VERBOSE:
				verbose_level = 2;
				break;

			case OPTION_DEVICE:
				device = optarg;
				break;

			default:
				exit(1);
		}
	}

	if (optind < argc) filename = argv[optind];

	if (getenv("PSXDEV_QUIET") && (verbose_level==1)) verbose_level = 0;

	if (filename == NULL) errorf (_("input filename missing"));

	psxdev_init();

	errno = 0;
	fd = open (filename,O_RDONLY);
	if (fd != -1)
	{
		int status;
		struct stat st;
	
		errno = 0;
		status = fstat (fd,&st);
		if (status != -1)
		{
			void *bytes;
			
			if (st.st_size == 0) errorf(_("input file has zero length"));

			errno = 0;
			bytes = mmap (NULL,st.st_size,PROT_READ,MAP_PRIVATE,fd,0);
			if (((int)bytes) != -1)
			{
				int pccl = open(device,O_RDWR);
				if (pccl != -1)
				{
					u_char byte;
				
					on_exit (on_exit_handler,(void*)pccl);

					rc = ioctl (pccl,CAEIOC_WRITE_XALIST);
					if (rc == -1) ioerrorf("ioctl(CAEIOC_WRITE_XALIST)");
					
					rc = write (pccl,bytes,st.st_size);
					if (rc < 0) ioerrorf("write()");
					
					rc = ioctl (pccl,CAEIOC_SWAP_8,&byte);
					if (rc == -1) ioerrorf("ioctl(CAEIOC_SWAP_8)");

					switch (byte)
					{
						case 0x00: printf2 (_("O.K.\n")); break;
						case 0xFF: errorf (_("invalid header")); break;
						case 0xFE: errorf (_("unsupported version")); break;
						case 0xFD: errorf (_("over size")); break;
						case 0xFC: errorf (_("inconsistency checksum")); break;
						default  : errorf (_("unknown error code")); break;
					}

					rc = ioctl (pccl,CAEIOC_RESUME);
					if (rc == -1) ioerrorf("ioctl(CAEIOC_RESUME)");

					close (pccl);
				}
				else ioerrorf ("open(%s)",device);

				munmap (bytes,st.st_size);
			}
				else ioerrorf ("mmap()");
		}
		else ioerrorf ("fstat()");
		close (fd);
	}
	else ioerrorf ("open(%s)",filename);

	return EXIT_SUCCESS;
}
Пример #6
0
int main (int argc, char **argv)
{
	volatile int opt, i,j;
	char *device = "/dev/pccl";
	char option_chars [BUFSIZ];

	int pccl;
	int x,y,w,h,m;
	
	x = y = 0;
	w = 256;
	h = 240;
	m = 0;

#if ENABLE_NLS
#if HAVE_SETLOCALE
   setlocale (LC_ALL, "");
#endif
   bindtextdomain (PACKAGE, LOCALEDIR);
   bindtextdomain (program_invocation_short_name, LOCALEDIR);
   textdomain (PACKAGE);
#endif

	/*
	**	build the option-char string from the option struct.
	*/

	for (i=j=0; long_options[i].name; i++)
	{
		switch (long_options[i].has_arg)
		{
			case no_argument:
				option_chars[j++] = (char) long_options[i].val;
				break;
			case required_argument:
				option_chars[j++] = (char) long_options[i].val;
				option_chars[j++] = ':';
				break;
		}
	}
	option_chars[j] = 0;

	while ((opt = getopt_long(argc,argv,option_chars,long_options,NULL)) != EOF)
	{
		switch (opt)
		{
			case OPTION_HELP:
				printf1 (copyright_text,program_invocation_short_name);
				printf1 (_("Usage: %s [options] <filename>\n"),program_invocation_short_name);
				for (i=0; long_options[i].name; i++)
				{
					switch (long_options[i].has_arg)
					{
						case no_argument:
							printf1 ("--%s,-%c \t%s\n",long_options[i].name,long_options[i].val,_(option_help[i]));
							break;
						case required_argument:
							printf1 ("--%s=x,-%c\t%s\n",long_options[i].name,long_options[i].val,_(option_help[i]));
							break;
					}
				}
				exit (EXIT_SUCCESS);

			case OPTION_VERSION:
				printf1 (copyright_text,program_invocation_short_name);
				printf1 ("%s version %s\n",program_invocation_short_name,version_text);
				exit (EXIT_SUCCESS);

			case OPTION_QUIET:
				verbose_level = 0;
				break;

			case OPTION_VERBOSE:
				verbose_level = 2;
				break;

			case OPTION_DEVICE:
				device = optarg;
				break;

			case OPTION_LEFT:
				x = strtoul (optarg,NULL,0);
				break;

			case OPTION_TOP:
				y = strtoul (optarg,NULL,0);
				break;

			case OPTION_WIDTH:
				w = strtoul (optarg,NULL,0);
				break;

			case OPTION_HEIGHT:
				h = strtoul (optarg,NULL,0);
				break;

			case OPTION_MODE:
				m = strtoul (optarg,NULL,0);
				break;

			default:
				exit(1);
		}
	}

	if (getenv("PSXDEV_QUIET") && (verbose_level==1)) verbose_level = 0;


	psxdev_init();

	pccl = open(device,O_RDWR);
	if (pccl != -1)
	{
		caetla_fb_mode_t fbm;
		int rc;
		
		fbm.x = x;
		fbm.y = y;
		fbm.width = w;
		fbm.height = h;
		fbm.mode = m;

		on_exit (on_exit_handler,(void*)pccl);

		rc = ioctl (pccl,CAEIOC_FB_SET_MODE,&fbm);
		if (rc == -1) ioerrorf("ioctl(CAEIOC_FB_SET_MODE)");

		rc = ioctl (pccl,CAEIOC_RESUME);
		if (rc == -1) ioerrorf("ioctl(CAEIOC_RESUME)");

		close (pccl);
	}
	else ioerrorf ("open(%s)",device);

	return EXIT_SUCCESS;
}
Пример #7
0
// reservation server protocol:
// send a MSG_RESERVE_REQUEST with the list of nodes you want to reserve
// if blocking, you'll block until the nodes are all available, at which point you'll get an ok
// if non-blocking, you'll immediately either get an ok or a fail, depending on whether the request is satisfiable
// when you want to unreserve, send a MSG_RESERVE_RELEASE with the nodes you want to release; you'll get NOTHING BACK
void reservation_server(void) {

	// allocate a list of blocked tasks and the requests they made
	BlockList bl[MAX_ENGINEERS];
	// initialize all of the bl elements to invalid
	int blIndex;
	for (blIndex=0; blIndex<MAX_ENGINEERS; blIndex++) {
		bl[blIndex].tid = -1; // tid == -1 means invalid
	}


	// deadlock detection algorithm:
	// * maintain hold list (hl) in addition to bl.
	// * accomodateRequest also returns a list of engineers I'm waiting on
	// * if I do need to block, this list is necessarily non-empty
	// * then check the block lists for these same engineers and see if they're blocked on anything I hold
	// * if so, that's a deadlock.
	// but there's no way I can implement this tonight.


	RegisterAs("reservationserver");

	FOREVER {

		// receive buffers
		int tid;
		MsgReservation request;
		MsgReservation reply;

		Receive(&tid, (char *)&request, sizeof(MsgReservation));

		switch(request.type) {

			case MSG_RESERVE_REQUEST_BLOCKING: ;
				Node *rcNode = resConflict(request.numNodes, request.nodes, tid);
				if (rcNode == NULL) { // if the request can be accomodated, log it
					logReservation(request.numNodes, request.nodes, tid, request.iAmPacman, request.trainNum, request.curDir);
				} else { // else if the request cannot be accomodated
					// deadlock detection

					printf0("Res Serv.: Checking for deadlock...\n\r");

					// the tid of the task that currently has this reservation
					int otherTid = (rcNode->type == NODE_SWITCH) ? ((Switch *)(rcNode))->reserverTid : ((Sensor *)(rcNode))->reserverTid;
					int blIndex = findTidInBlockList(otherTid, bl);

					printf2("Res Serv.: otherTid: %d, otherIsblocked? %d!\n\r", otherTid, blIndex != -1);

					// if this other tid is blocked and wants a node we own, that's a deadlock
					if (blIndex != -1 && blWantsNodeHeldBy(bl[blIndex], tid)) {

						// we now know we have a deadlock, so it's time to resolve it
						printf2("Res Serv.: DEADLOCK between tr. %d and tr. %d!\n\r", request.trainNum, bl[blIndex].trainNum);

						// if we're the pacman or
						// the other one isn't a pacman and we have the lower train number
						if (request.iAmPacman ||
							(!((rcNode->type == NODE_SWITCH) ? ((Switch *)rcNode)->reserverIAmPacman : ((Sensor *)rcNode)->reserverIAmPacman)
								&& (request.trainNum <= ((rcNode->type == NODE_SWITCH) ? ((Switch *)rcNode)->reserverTrainNum : ((Sensor *)rcNode)->reserverTrainNum) ))) {

							// find a node to move to
							Node *nodeToMoveTo = moveAway(request.trainLoc, request.curDir == 'F' ? 'B' : 'F');

							printf1("Res Serv.: GTFO self (train %d) to ", request.trainNum);
							if (nodeToMoveTo == NULL) {
								printf0("NULL");
							} else {
								printNode2(nodeToMoveTo);
							}
							printf1(", curDir %c!\n\r", (int)request.curDir);

							if (nodeToMoveTo == NULL) { // if we can't move away, it's the game over case
								printf0("res. serv.: case 1.\n\r");

								int pacmanServerTid = WhoIs("pacmanserver");
								char c = MSG_PACMAN_GAMEOVER;
								int retVal = Send(pacmanServerTid, &c, 1, NULL, 0);
								printf1("res. serv.: retVal from Reply to PMS: %d\n\r", retVal);

								reply.type = MSG_RESERVE_GAMEOVER;
								retVal = Reply(tid, (char *)&reply, sizeof(MsgReservation));
								printf1("res. serv.: retVal from Reply to train: %d\n\r", retVal);

								int i;
								for (i=0; i<MAX_ENGINEERS; i++) {
									if (bl[i].tid != -1) {
										reply.type = MSG_RESERVE_GAMEOVER;
										retVal = Reply(bl[blIndex].tid, (char *)&reply, sizeof(MsgReservation));
										printf1("res. serv.: retVal from Reply to train: %d\n\r", retVal);
									}
								}
							} else { // else if we can move away, send the move reply
								reply.type = MSG_RESERVE_MOVE;
								reply.numNodes = 1;
								reply.nodes[0] = nodeToMoveTo;
								printf0("res. serv.: about to reply case 2.\n\r");
								int retVal = Reply(tid, (char *)&reply, sizeof(MsgReservation));
								printf1("res. serv.: retVal from Reply to train: %d\n\r", retVal);
							}

						} else { // else the other train needs to move out of the way

							// find a node to move to
							Node *nodeToMoveTo = moveAway(bl[blIndex].trainLoc, bl[blIndex].curDir == 'F' ? 'B' : 'F');

							printf1("Res Serv.: GTFO other (train %d) to ", bl[blIndex].trainNum);
							if (nodeToMoveTo == NULL) {
								printf0("NULL");
							} else {
								printNode2(nodeToMoveTo);
							}
							printf1(", curDir %c!\n\r", (int)bl[blIndex].curDir);

							if (nodeToMoveTo == NULL) { // if we can't move away, it's the game over case
								printf0("res. serv.: case 1.\n\r");

								int pacmanServerTid = WhoIs("pacmanserver");

								char c = MSG_PACMAN_GAMEOVER;
								int retVal = Send(pacmanServerTid, &c, 1, NULL, 0);
								printf1("res. serv.: retVal from Reply to PMS: %d\n\r", retVal);

								reply.type = MSG_RESERVE_GAMEOVER;
								retVal = Reply(tid, (char *)&reply, sizeof(MsgReservation));
								printf1("res. serv.: retVal from Reply to train: %d\n\r", retVal);

								int i;
								for (i=0; i<MAX_ENGINEERS; i++) {
									if (bl[i].tid != -1) {
										reply.type = MSG_RESERVE_GAMEOVER;
										retVal = Reply(bl[blIndex].tid, (char *)&reply, sizeof(MsgReservation));
										printf1("res. serv.: retVal from Reply to train: %d\n\r", retVal);
									}
								}

							} else { // else if we can move away, send the move reply

								reply.type = MSG_RESERVE_MOVE;
								reply.numNodes = 1;
								reply.nodes[0] = nodeToMoveTo;
								printf0("res. serv.: about to reply case 2.\n\r");
								int retVal = Reply(bl[blIndex].tid, (char *)&reply, sizeof(MsgReservation));
								printf1("res. serv.: retVal from Reply to train: %d\n\r", retVal);

								// remove the other train from the block list, since he's no longer going to be blocked
								bl[blIndex].tid = -1;

								// now, block the current train, waiting for the other one to get ouf of the way
								blockTask(tid, request.iAmPacman, request.trainNum, request.trainLoc, request.curDir, request.numNodes, request.nodes, bl);
							}
						}

					} else { // else if it's not a deadlock, just a reservation conflict, handle it normally by blocking
						blockTask(tid, request.iAmPacman, request.trainNum, request.trainLoc, request.curDir, request.numNodes, request.nodes, bl);
					}
				}
				break;
			case MSG_RESERVE_REQUEST_NONBLOCKING:
				if (resConflict(request.numNodes, request.nodes, tid) == NULL) { // if the request can be accomodated, log it and reply
					logReservation(request.numNodes, request.nodes, tid, request.iAmPacman, request.trainNum, request.curDir);
					reply.type = MSG_RESERVE_OK;
					Reply(tid, (char *)&reply, sizeof(MsgReservation));
				} else { // else if the request cannot be accomodated, send a fail message back
					reply.type = MSG_RESERVE_FAIL;
					Reply(tid, (char *)&reply, sizeof(MsgReservation));
				}
				break;
			case MSG_RESERVE_RELEASE:
				logRelease(request.numNodes, request.nodes, request.trainNum); // log the release
				Reply(tid, NULL, 0); // reply with a NULL buffer
				// now, check if any waiting task can now be awoken due to the release
				for (blIndex = 0; blIndex<MAX_ENGINEERS; blIndex++) {
					// if the bl entry is valid and we can now accomodate it, do so
					if (bl[blIndex].tid != -1 && resConflict(bl[blIndex].numNodes, bl[blIndex].nodes, bl[blIndex].tid) == NULL) {
						// log the reservation
						logReservation(bl[blIndex].numNodes, bl[blIndex].nodes, bl[blIndex].tid, bl[blIndex].iAmPacman, bl[blIndex].trainNum, bl[blIndex].curDir);
						// reply to the task, telling it the reserve has finally been processed
						reply.type = MSG_RESERVE_OK;
						Reply(bl[blIndex].tid, (char *)&reply, sizeof(MsgReservation));
						// ...and invalidate its entry in the block list
						bl[blIndex].tid = -1;
					}
				}
				break;
			default:
				bwprintf(COM2, "ERROR: illegal reservation request type %d! Halt!!!", request.type);
				Halt();
				break;
		} // switch
	} // FOREVER

	return; // can't happen due to above FOREVER loop
}
Пример #8
0
void AutoLaunch()
{
    u8 len=0;
    u8 temp[100];
    u8 flag=0;
    u8 t=0;
    char command='0';
    u8 flagOfX86=0;
    u8 tempOfX86[100];
    u8 lenOfX86=0;
    u8 tOfX86=0;

    while(1)
    {
        if(USART_RX1_STA&0x8000)
        {
            len=USART_RX1_STA&0x3fff;//得到此次接收到的数据长度
            for(t=0; t<len; t++)
            {
                temp[t]=Rx1Buf[t];
                while((USART1->SR&0X40)==0);//等待发送结束
            }
            flag=1;
            USART_RX1_STA=0;
        }

        if(USART_RX2_STA&0x8000)
        {
            lenOfX86=USART_RX2_STA&0x3fff;//得到此次接收到的数据长度
            for(tOfX86=0; tOfX86<lenOfX86; tOfX86++)
            {
                tempOfX86[tOfX86]=Rx2Buf[tOfX86];
                while((USART2->SR&0X40)==0);//等待发送结束
            }
            flagOfX86=1;
            USART_RX2_STA=0;
        }

        if(flag==1)
        {
            command=TempOrPressure(temp);
            if(command=='S')
            {
                if(ValueOfMea(temp)==9)//当G大于300cm时就匀速起飞了。
                {
                    break;
                }
            }
            memset(temp,0,sizeof(u8)*100);
            flag=0;
        }

#ifdef __TRANSPARENT_MODE
        printf1("\"G\":\"%ld\"\r\n",GROUND_GetDistance_Filter());
#endif

#ifdef __COMMAND_MODE
        E17_SendMsg(CMD_G_PARAM,GROUND_GetDistance_Filter());
#endif
        //输出高度


    }
}
Пример #9
0
int main (int argc, char **argv)
{
	volatile int opt, i,j;
	char *filename = NULL;
	char *outname = NULL;
	char option_chars [BUFSIZ];
	
	int qscale = 1;
	int type = 2;
	int width = -1;
	int height = -1;
	int limit = 65536;

#if ENABLE_NLS
#if HAVE_SETLOCALE
   setlocale (LC_ALL, "");
#endif
   bindtextdomain (PACKAGE, LOCALEDIR);
   bindtextdomain (program_invocation_short_name, LOCALEDIR);
   textdomain (PACKAGE);
#endif

	/*
	**	build the option-char string from the option struct.
	*/

	for (i=j=0; long_options[i].name; i++)
	{
		switch (long_options[i].has_arg)
		{
			case no_argument:
				option_chars[j++] = (char) long_options[i].val;
				break;
			case required_argument:
				option_chars[j++] = (char) long_options[i].val;
				option_chars[j++] = ':';
				break;
		}
	}
	option_chars[j] = 0;

	while ((opt = getopt_long(argc,argv,option_chars,long_options,NULL)) != EOF)
	{
		switch (opt)
		{
			case OPTION_HELP:
				printf1 (copyright_text,program_invocation_short_name);
				printf1 (_("Usage: %s [options] <filename>\n"),program_invocation_short_name);
				for (i=0; long_options[i].name; i++)
				{
					switch (long_options[i].has_arg)
					{
						case no_argument:
							printf1 ("--%s,-%c \t%s\n",long_options[i].name,long_options[i].val,_(option_help[i]));
							break;
						case required_argument:
							printf1 ("--%s=x,-%c\t%s\n",long_options[i].name,long_options[i].val,_(option_help[i]));
							break;
					}
				}
				exit (EXIT_SUCCESS);

			case OPTION_VERSION:
				printf1 (copyright_text,program_invocation_short_name);
				printf1 ("%s version %s\n",program_invocation_short_name,version_text);
				exit (EXIT_SUCCESS);

			case OPTION_QUIET:
				verbose_level = 0;
				break;

			case OPTION_VERBOSE:
				verbose_level = 2;
				break;

			case OPTION_OUTPUT:
				outname = optarg;
				break;

			case OPTION_QSCALE:
				qscale = strtoul(optarg,0,0);
				break;

			case OPTION_TYPE:
				type = strtoul(optarg,0,0);
				break;

			case OPTION_WIDTH:
				width = strtoul(optarg,0,0);
				break;

			case OPTION_HEIGHT:
				height = strtoul(optarg,0,0);
				break;

			case OPTION_LIMIT:
				limit = strtoul(optarg,0,0);
				break;

			default:
				exit(1);
		}
	}

	if (optind < argc) filename = argv[optind];

	if (getenv("PSXDEV_QUIET") && (verbose_level==1)) verbose_level = 0;

	bs_init();

	if (filename)
	{
		FILE *fp = stdout;
		int size = 99999999;
		unsigned short buf[0x80000];

		while (limit < size)
		{
			ImlibData id;
			ImlibImage *im, *im2;
			bs_input_image_t img;

			// this is kind of a hack,
			// I do not initialize imlib!
			// so this utilitiy may not always work
			// correctly.

			im = Imlib_load_image (&id,filename);

			if (im)
			{
				printf2 (_("%s: input dimension: %dx%d\n"),program_invocation_short_name,im->rgb_width,im->rgb_height);

				if (width!=-1 || height!=-1)
				{
					im2 = Imlib_clone_scaled_image(&id,im,
						(width==-1) ? im->rgb_width : width,
						(height==-1) ? im->rgb_height : height);
					Imlib_kill_image (&id,im);
					im = im2;

					printf2 (_("%s: scaled to: %dx%d\n"),program_invocation_short_name,im->rgb_width,im->rgb_height);
				}

				img.width		= im->rgb_width;
				img.height		= im->rgb_height;
				img.lpbits		= im->rgb_data;
				img.top			= img.lpbits;
				img.nextline	= img.width*3;
				img.bit			= 24;					// depth
				size = bs_encode ((bs_header_t*)buf,&img,type,qscale,0);

				printf2 (_("%s: output size: %d bytes\n"),program_invocation_short_name,size);
				printf2 (_("%s: Q scale factor: %d\n"),program_invocation_short_name,qscale);

				qscale++;
				if (qscale>255)
				{
					errorf("can't compress!\n");
				}

				Imlib_kill_image (&id,im);
			}
		}

		if (outname) freopen(outname,"wb",fp);
		fwrite(buf,1,size,fp);
		fflush (fp);
		if (outname) fclose (fp);
	}

	return EXIT_SUCCESS;
}
Пример #10
0
int main(void)
{
	u8 len=0;
	u8 temp[100];
	u8 t=0;
	u8 flag=0;
	char mode='O';
	long value=0;
	u8 counter=0;
	//char val2str[]="50";
	char SelfCheck='O';
	int D_val=0;
	u8 SelfCheckCounter=0;
	/////////////////////以上变量定义///////////////////////////
	
	delay_init(72);
	USART1_Init(19200);//与地面站传递命令
	USART2_Init(115200);//与X86板子传递命令
	USART3_Init(115200);//调试用
	HCSR04_Init();
	ResetOLED();
	OLED_Init();
	Key_Init();
	///////////////以上初始化///////////////////////
	OLED_ShowString(35,20,"READY",24);
	OLED_Refresh_Gram();
	delay_ms(1000);
	OLED_Clear();
	/////////////////////////////欢迎界面,提示准备工作/////////////////////////////////
	while(KEY==1)
	{
		OLED_ShowString(0,0,"Self checking now...",12);
		OLED_Refresh_Gram();
		if(USART_RX2_STA&0x8000)
		{					   
			len=USART_RX2_STA&0x3fff;//得到此次接收到的数据长度
			for(t=0;t<len;t++)
			{
				temp[t]=Rx2Buf[t];
				while((USART2->SR&0X40)==0);//等待发送结束
			}
			flag=1;
			USART_RX2_STA=0;
		}//接受来自X86的命令,用于自检。
		
		if(flag==1)
		{
			SelfCheck=TempOrPressure(temp);
				{
					if(SelfCheck=='C')
					{
						value=ValueOfMea(temp);
						if(value==1)
						{
							OLED_ShowString(0,15,"Environment ok",12);
							SelfCheckCounter++;
						}
						if(value==2)
						{
							OLED_ShowString(0,30,"The data chain ok",12);
						}
						if(value==0)
						{
							OLED_ShowString(0,42,"Checking fail...",12);
						}
					}
				}
			memset(temp,0,sizeof(u8)*100);
			flag=0;
		}//先对开发环境进行自检,在VS下下发ok标志即可。
		OLED_Refresh_Gram();
		
		if(SelfCheckCounter==1)//如果已经通过了开发环境自检
		{
			while(KEY==1)//不按强制退出就一直自检,直到成功
			{
				if(DataChain_SelfTest()==1)//数据链自检完成
					break;
				else
					continue;
			}
			SelfCheckCounter=0;
			break;//在不按按键强制退出的情况下,只有自检成功了才能退出。
		}
	}
	OLED_Clear();
	/////////////////////////以上对上位机的自检,按键强制结束//////////////////
	
	OLED_ShowString(0,0,"Parameters",16);
	OLED_ShowString(0,16,"X=",12);
	OLED_ShowString(0,28,"Y=",12);
  OLED_ShowString(0,40,"S=",12);
  OLED_ShowString(0,52,"D=",12);
	OLED_Refresh_Gram();
	flag=0;//复位flag
	///////////显示参数////////////////////////////////
	//AutoLaunch();
	////////////////////////以上开始起飞/////////////////////////////////

	while(1)
	{
		if(USART_RX2_STA&0x8000)
		{					   
			len=USART_RX2_STA&0x3fff;//得到此次接收到的数据长度
			for(t=0;t<len;t++)
			{
				temp[t]=Rx2Buf[t];
				while((USART2->SR&0X40)==0);//等待发送结束
			}
			flag=1;
			USART_RX2_STA=0;
			//printf3("%s\r\n",temp);
		}//接受来自X86的命令
		
		
		if(flag==1)
		{
			mode=TempOrPressure(temp);
			if(mode=='S')
			{
				value=ValueOfMea(temp);
					{
						#ifdef __TRANSPARENT_MODE
							printf1("\"S\":\"%ld\"\r\n",value);
						#endif
						
						#ifdef __COMMAND_MODE
							E17_SendMsg(CMD_S_PARAM,value);
						#endif						
					}
				OLED_ShowNum(20,40,value,6,12);
//				counter++;
			}  
			
			if(mode=='X')
			{
				value=ValueOfMea(temp);
					{
						#ifdef __TRANSPARENT_MODE
							printf1("\"X\":\"%ld\"\r\n",value);
						#endif
						#ifdef __COMMAND_MODE
							E17_SendMsg(CMD_X_PARAM,value);
						#endif	
					}
				OLED_ShowNum(20,16,value,6,12);
//				counter++;
			}
			else if(mode=='Y')
			{
				value=ValueOfMea(temp);
					{
						#ifdef __TRANSPARENT_MODE
							printf1("\"Y\":\"%ld\"\r\n",value);
						#endif
						#ifdef __COMMAND_MODE
							E17_SendMsg(CMD_Y_PARAM,value);
						#endif	
					}
				OLED_ShowNum(20,28,value,6,12);
//				counter++;
			}
			{
				  delay_ms(10);//太小在透传情况下可能出问题?
					{
						D_val=HCSR04_GetDistance_Filter();
						#ifdef __TRANSPARENT_MODE
							printf1("\"D\":\"%ld\"\r\n",D_val);
						#endif
						
						#ifdef __COMMAND_MODE
							E17_SendMsg(CMD_D_PARAM,value);			
						#endif	
					}
				OLED_ShowNum(20,52,D_val,6,12);
//				counter=0;
			}//去掉了判断,每个周期都要做判断,同时进行距离的pid调控。
			OLED_Refresh_Gram();
			memset(temp,0,sizeof(u8)*100);
			flag=0;
		}
	}
}
Пример #11
0
int main (int argc, char **argv)
{
	volatile int opt, i,j;
	char option_chars [BUFSIZ];
	char *filename = NULL;

	int fd;

#if ENABLE_NLS
#if HAVE_SETLOCALE
   setlocale (LC_ALL, "");
#endif
   bindtextdomain (PACKAGE, LOCALEDIR);
   bindtextdomain (program_invocation_short_name, LOCALEDIR);
   textdomain (PACKAGE);
#endif

	/*
	**	build the option-char string from the option struct.
	*/

	for (i=j=0; long_options[i].name; i++)
	{
		switch (long_options[i].has_arg)
		{
			case no_argument:
				option_chars[j++] = (char) long_options[i].val;
				break;
			case required_argument:
				option_chars[j++] = (char) long_options[i].val;
				option_chars[j++] = ':';
				break;
		}
	}
	option_chars[j] = 0;

	while ((opt = getopt_long(argc,argv,option_chars,long_options,NULL)) != EOF)
	{
		switch (opt)
		{
			case OPTION_HELP:
				printf1 (copyright_text,program_invocation_short_name);
				printf1 (_("Usage: %s [options] <filename>\n"),program_invocation_short_name);
				for (i=0; long_options[i].name; i++)
				{
					switch (long_options[i].has_arg)
					{
						case no_argument:
							printf1 ("--%s,-%c \t%s\n",long_options[i].name,long_options[i].val,_(option_help[i]));
							break;
						case required_argument:
							printf1 ("--%s=x,-%c\t%s\n",long_options[i].name,long_options[i].val,_(option_help[i]));
							break;
					}
				}
				exit (EXIT_SUCCESS);

			case OPTION_VERSION:
				printf1 (copyright_text,program_invocation_short_name);
				printf1 ("%s version %s\n",program_invocation_short_name,version_text);
				exit (EXIT_SUCCESS);

			case OPTION_QUIET:
				verbose_level = 0;
				break;

			case OPTION_VERBOSE:
				verbose_level = 2;
				break;

			default:
				exit(1);
		}
	}

	if (optind < argc) filename = argv[optind];

	if (getenv("PSXDEV_QUIET") && (verbose_level==1)) verbose_level = 0;

	if (filename == NULL) errorf (_("input filename missing"));

	errno = 0;
	fd = open (filename,O_RDONLY);
	if (fd != -1)
	{
		int status;
		struct stat st;
	
		errno = 0;
		status = fstat (fd,&st);
		if (status != -1)
		{
			void *bytes;
			
			if (st.st_size == 0) errorf(_("input file has zero length"));

			errno = 0;
			bytes = mmap (NULL,st.st_size,PROT_READ,MAP_PRIVATE,fd,0);
			if (((int)bytes) != -1)
			{
				u_char *p = (u_char*) bytes;
				
				/*
					a quick and dirty parser for the XALISTs
				*/
				
				if (strcmp(p,"caetla XA-List")) errorf(_("file is not a XA-LIST"));

				p += 0x18;

				do
				{
					printf(_("Volume: %s\n"),p);
					while (*p) p++;
					p+=5;
				
					do
					{
						printf(_("Filename: %s\n"),p);
						while (*p) p++;
						p+=5;

						do
						{						
							switch (*p)
							{
								case 0x00:
									printf(_("Audio: %02x:%02x:%02x - %02x:%02x:%02x (Speed:%dX, Interleave:%d)\n")
									,p[4],p[4],p[3],p[8],p[7],p[6],p[9]+1,p[10]); p+=11;
									break;
								case 0x01:
									printf(_("Movie: %02x:%02x:%02x - %02x:%02x:%02x\n")
									,p[4],p[4],p[3],p[8],p[7],p[6]); p+=13;
									break;
							}
						}
						while (*p!=0xFF);
						p++;
					}
					while (*p);
					p++;
				}
				while (*p);

				munmap (bytes,st.st_size);
			}
			else ioerrorf ("mmap()");
		}
		else ioerrorf ("fstat()");
		close (fd);
	}
	else ioerrorf ("open(%s)",filename);

	return EXIT_SUCCESS;
}
Пример #12
0
int main (int argc, char **argv)
{
	volatile int opt, i,j;
	char *device = "/dev/pccl";
	char option_chars [BUFSIZ];
	char *filename = NULL;
	int emergency = 0;

	int fd;

#if ENABLE_NLS
#if HAVE_SETLOCALE
   setlocale (LC_ALL, "");
#endif
   bindtextdomain (PACKAGE, LOCALEDIR);
   bindtextdomain (program_invocation_short_name, LOCALEDIR);
   textdomain (PACKAGE);
#endif

	/*
	**	build the option-char string from the option struct.
	*/

	for (i=j=0; long_options[i].name; i++)
	{
		switch (long_options[i].has_arg)
		{
			case no_argument:
				option_chars[j++] = (char) long_options[i].val;
				break;
			case required_argument:
				option_chars[j++] = (char) long_options[i].val;
				option_chars[j++] = ':';
				break;
		}
	}
	option_chars[j] = 0;

	while ((opt = getopt_long(argc,argv,option_chars,long_options,NULL)) != EOF)
	{
		switch (opt)
		{
			case OPTION_HELP:
				printf1 (copyright_text,program_invocation_short_name);
				printf1 (_("Usage: %s [options] <filename>\n"),program_invocation_short_name);
				for (i=0; long_options[i].name; i++)
				{
					switch (long_options[i].has_arg)
					{
						case no_argument:
							printf1 ("--%s,-%c \t%s\n",long_options[i].name,long_options[i].val,_(option_help[i]));
							break;
						case required_argument:
							printf1 ("--%s=x,-%c\t%s\n",long_options[i].name,long_options[i].val,_(option_help[i]));
							break;
					}
				}
				exit (EXIT_SUCCESS);

			case OPTION_VERSION:
				printf1 (copyright_text,program_invocation_short_name);
				printf1 ("%s version %s\n",program_invocation_short_name,version_text);
				exit (EXIT_SUCCESS);

			case OPTION_QUIET:
				verbose_level = 0;
				break;

			case OPTION_VERBOSE:
				verbose_level = 2;
				break;

			case OPTION_EMERGENCY:
				emergency = 1;
				break;

			case OPTION_DEVICE:
				device = optarg;
				break;

			default:
				exit(1);
		}
	}

	if (optind < argc) filename = argv[optind];

	if (getenv("PSXDEV_QUIET") && (verbose_level==1)) verbose_level = 0;


	if (filename == NULL) errorf (_("input filename missing"));

	psxdev_init();

	errno = 0;
	fd = open (filename,O_RDONLY);
	if (fd != -1)
	{
		int status;
		struct stat st;
	
		errno = 0;
		status = fstat (fd,&st);
		if (status != -1)
		{
			int bytes;
			
			if (st.st_size == 0) errorf(_("input file has zero length"));

			errno = 0;
			bytes = (int) mmap (NULL,st.st_size,PROT_READ,MAP_PRIVATE,fd,0);
			if (bytes != -1)
			{
				int pccl = open(device,O_RDWR);
				if (pccl != -1)
				{
					unsigned char arg,x;
					unsigned int tmp;
					unsigned char *p;
					unsigned short chk,stmp;
					int i;

// emergency mode:
// we have booted with a CD-ROM, which already started the update program
			if (emergency==0)
			{ 
					printf(_("WARNING: FLASH UPDATE - Turn PSX off and hit CTRL-C to abort!\n"));
					printf(_("Press RESET on PSX to continue!\n"));

				  arg = 'W';
				  while (arg != 'R')
					{
					  arg = 'W';
					  ioctl(pccl,CAEIOC_SWAP_8, &arg);
					}
				  printf1(_("Sending update program.\n"));
				  arg = 'B';
				  while (arg != 'W')
					{
					  arg = 'B';
					  ioctl(pccl,CAEIOC_SWAP_8, &arg);
					}
				  arg = 'X';
				  ioctl(pccl,CAEIOC_SWAP_8, &arg);
				  while (arg != 'X')
					{
					  arg = 'X';
					  ioctl(pccl,CAEIOC_SWAP_8, &arg);
					}
				  
				  tmp = 0x80020000;
				  ioctl(pccl,CAEIOC_SWAP_32, &tmp);
				  tmp = sizeof(flasher_rom);
				  ioctl(pccl,CAEIOC_SWAP_32, &tmp);
				  
				  p = (unsigned char *)flasher_rom;
				  chk = 0;
				  for (i=0;i<sizeof(flasher_rom);i++)
					{
					  x = *p++;
					  arg = x;
					  ioctl(pccl,CAEIOC_SWAP_8, &arg);
					  if (arg != x) printf(_("Transfer error!\n"));
					  chk += x;
					}
				  stmp = chk & 0xfff;
				  ioctl(pccl,CAEIOC_SWAP_16, &stmp);
				  
				  arg = 0;
				  while (arg != 'O')
					{
					  arg = 0;
					  ioctl(pccl,CAEIOC_SWAP_8,&arg);
					}
				  arg = 'W';
				  while (arg != 'K')
					{
					  arg = 'K';
					  ioctl(pccl,CAEIOC_SWAP_8,&arg);
					}
			}
				  printf1(_("Sending ROM image.\n")); 
				  arg = 'W';
				  while (arg != 'R')
					{
					  arg = 'W';
					  ioctl(pccl,CAEIOC_SWAP_8,&arg);
					}
				  arg = 'B';
				  while (arg != 'W')
					{
					  arg = 'B';
					  ioctl(pccl,CAEIOC_SWAP_8,&arg);
					}
				  arg = 'U';
				  ioctl(pccl,CAEIOC_SWAP_8,&arg);
				  while (arg != 'U')
					{
					  arg = 'U';
					  ioctl(pccl,CAEIOC_SWAP_8,&arg);
					}
				  
				  tmp=0x80040000;
				  ioctl(pccl,CAEIOC_SWAP_32, &tmp);
				  ioctl(pccl,CAEIOC_SWAP_32, &st.st_size);
				  
				  p = (unsigned char *) bytes;
				  chk = 0;
				  for (i=0;i<st.st_size;i++)
					{
					  x = *p++;
					  arg = x;
					  ioctl(pccl,CAEIOC_SWAP_8, &arg);
					  if (arg != x) printf(_("Transfer error!\n"));
					  chk += x;
					}
				  stmp = chk & 0xfff;
				  ioctl(pccl,CAEIOC_SWAP_16, &stmp);
				  
				  arg = 0;
				  while (arg != 'O')
					{
					  arg = 0;
					  ioctl(pccl,CAEIOC_SWAP_8,&arg);
					}
				  arg = 'W';
				  while (arg != 'K')
					{
					  arg = 'K';
					  ioctl(pccl,CAEIOC_SWAP_8,&arg);
					}

				  printf1(_("Update complete.\n"));
				  

					close (pccl);
				}
				else ioerrorf ("open(%s)",device);

				munmap ((void*)bytes,st.st_size);
			}
				else ioerrorf ("mmap()");
		}
		else ioerrorf ("fstat()");
		close (fd);
	}
	else ioerrorf ("open(%s)",filename);

	return EXIT_SUCCESS;
}