Example #1
0
int main (int argc, char *argv[]) {
	int serial_d;
	speed_t speed;
	struct termios soptions, soptions_org;
	char command;
	unsigned char send_buf[BUFLEN];
	unsigned char recv_buf[BUFLEN];
	int sent_c, recv_c;

	char move;

	//no port specified
	if (argc == 1) {
		printf("Parameter: /dev/ttyUSB0 [command]\n");
		printf("\"/dev/ttyUSB0\" is a USB serial device to support serial control.\n");
		return 1;
	}

	serial_d = openserial(argv[1]);
	if (serial_d == -1) return 1;

	// ----- Begin of setup serial ports
	tcgetattr(serial_d, &soptions_org);
	tcgetattr(serial_d, &soptions);

	speed = B9600; // Speed options: B19200, B38400, B57600, B115200
	cfsetispeed(&soptions, speed);
	cfsetospeed(&soptions, speed);

	// Enable the reciver and set local mode...
	soptions.c_cflag |= ( CLOCAL | CREAD );
	// Setting Parity Checking (8N1)
	soptions.c_cflag &= ~PARENB;
	soptions.c_cflag &= ~CSTOPB;
	soptions.c_cflag &= ~CSIZE;
	soptions.c_cflag |= CS8;

	// Local setting
	//soptions.c_lflag = (ICANON | ECHO | ECHOE); //canonical
	soptions.c_lflag =  ~(ICANON | ECHO | ECHOE | ISIG); //noncanonical

	// Input setting
	//soptions.c_iflag |= (IXON | IXOFF | IXANY); //software flow control
	soptions.c_iflag |= (INPCK | ISTRIP);
	soptions.c_iflag = IGNPAR;

	// Output setting
	soptions.c_oflag = 0;
	soptions.c_oflag &= ~OPOST;

	// Read options
	soptions.c_cc[VTIME] = 0;
	soptions.c_cc[VMIN] = 1; //transfer at least 1 character or block

	// Apply setting
	tcsetattr(serial_d, TCSANOW, &soptions);
	// ----- End of setup serial ports
	map[mapsize-1][0]=wall; // left down corner =wall
	map[mapsize-2][0]=wall;
    map[mapsize-1][1]=wall;
    map[mapsize-2][1]=visit;
    state =0;
    x=1;
    y=8;
    int i,j,k;
	int* package;
	char p[10];
	int start =0;
	//system("./plotmap.pyc &");
	
	
		while (1) {
        	printf("Receiving Data\n");
       	 	/*
			printf("Enter command ('q' to exit): ");
			command = getchar();
			clean_buffer();
			if (command == 'q') {
				printf ("Bye!\n");
				break;
			}
			printf("Sending command '%c'...\n", command);
			sent_c = write(serial_d, &command, 1); // Send command
			tcdrain(serial_d);
        	*/
			
			usleep(1000000); // Wait for response
			if(start ==0)
			{
				memset(recv_buf, '\0', BUFLEN);
				recv_c = read(serial_d, recv_buf, BUFLEN); // Get response message
				tcdrain(serial_d);
				if(recv_buf[0] == 'g')
					start =1;
				else
					start=0;
			}
			else{
			for(k=0; k<5;k++){
				memset(recv_buf, '\0', BUFLEN);
				recv_c = read(serial_d, recv_buf, BUFLEN); // Get response message
				tcdrain(serial_d);
				printf("%c\n", recv_buf[0]);
				p[k] = recv_buf[0];	
			}
			}
			package =Decode(p);
			move = p[1];
			state = package[0];
			lb = package[1];
			fb = package[2];
			rb = package[3];
			printf("parameter %d %c %d %d %d\n",p[0],p[1],p[2],p[3],p[4]);
			printf("parameter %d %c %d %d %d\n",state,move,lb,fb,rb);
			//Draw
			Record(state);
			state = walk(state,move);
    		map[y][x]=visit;
    		//printf("%c %d %d %d\n",move,x,y,state);
			FILE *f = fopen("map.txt","w");
    		for(i=0;i<mapsize;i++){
       			for(j=0;j<mapsize;j++){
           			printf("%d ",map[i][j]);
					fprintf(f,"%d ",map[i][j]);
				}
       			printf("\n");
				fprintf(f,"\n");
    		}
			fclose(f);
			//system("./plotmap.pyc &");
		
	}
		// restore setting and close
		tcsetattr(serial_d, TCSANOW, &soptions_org);
		close(serial_d);
		return 0;
}
/**
 * MD5 basic transformation. Transforms state based on block.
 */
static void MD5Transform(uint32_t state[4], const uint8_t block[64])
{
    uint32_t a = state[0], b = state[1], c = state[2], d = state[3];

    Decode(t_x, block, 64);

    /* Round 1 */
    FF (a, b, c, d, t_x[ 0], S11, 0xd76aa478); /* 1 */
    FF (d, a, b, c, t_x[ 1], S12, 0xe8c7b756); /* 2 */
    FF (c, d, a, b, t_x[ 2], S13, 0x242070db); /* 3 */
    FF (b, c, d, a, t_x[ 3], S14, 0xc1bdceee); /* 4 */
    FF (a, b, c, d, t_x[ 4], S11, 0xf57c0faf); /* 5 */
    FF (d, a, b, c, t_x[ 5], S12, 0x4787c62a); /* 6 */
    FF (c, d, a, b, t_x[ 6], S13, 0xa8304613); /* 7 */
    FF (b, c, d, a, t_x[ 7], S14, 0xfd469501); /* 8 */
    FF (a, b, c, d, t_x[ 8], S11, 0x698098d8); /* 9 */
    FF (d, a, b, c, t_x[ 9], S12, 0x8b44f7af); /* 10 */
    FF (c, d, a, b, t_x[10], S13, 0xffff5bb1); /* 11 */
    FF (b, c, d, a, t_x[11], S14, 0x895cd7be); /* 12 */
    FF (a, b, c, d, t_x[12], S11, 0x6b901122); /* 13 */
    FF (d, a, b, c, t_x[13], S12, 0xfd987193); /* 14 */
    FF (c, d, a, b, t_x[14], S13, 0xa679438e); /* 15 */
    FF (b, c, d, a, t_x[15], S14, 0x49b40821); /* 16 */

    /* Round 2 */
    GG (a, b, c, d, t_x[ 1], S21, 0xf61e2562); /* 17 */
    GG (d, a, b, c, t_x[ 6], S22, 0xc040b340); /* 18 */
    GG (c, d, a, b, t_x[11], S23, 0x265e5a51); /* 19 */
    GG (b, c, d, a, t_x[ 0], S24, 0xe9b6c7aa); /* 20 */
    GG (a, b, c, d, t_x[ 5], S21, 0xd62f105d); /* 21 */
    GG (d, a, b, c, t_x[10], S22,  0x2441453); /* 22 */
    GG (c, d, a, b, t_x[15], S23, 0xd8a1e681); /* 23 */
    GG (b, c, d, a, t_x[ 4], S24, 0xe7d3fbc8); /* 24 */
    GG (a, b, c, d, t_x[ 9], S21, 0x21e1cde6); /* 25 */
    GG (d, a, b, c, t_x[14], S22, 0xc33707d6); /* 26 */
    GG (c, d, a, b, t_x[ 3], S23, 0xf4d50d87); /* 27 */
    GG (b, c, d, a, t_x[ 8], S24, 0x455a14ed); /* 28 */
    GG (a, b, c, d, t_x[13], S21, 0xa9e3e905); /* 29 */
    GG (d, a, b, c, t_x[ 2], S22, 0xfcefa3f8); /* 30 */
    GG (c, d, a, b, t_x[ 7], S23, 0x676f02d9); /* 31 */
    GG (b, c, d, a, t_x[12], S24, 0x8d2a4c8a); /* 32 */

    /* Round 3 */
    HH (a, b, c, d, t_x[ 5], S31, 0xfffa3942); /* 33 */
    HH (d, a, b, c, t_x[ 8], S32, 0x8771f681); /* 34 */
    HH (c, d, a, b, t_x[11], S33, 0x6d9d6122); /* 35 */
    HH (b, c, d, a, t_x[14], S34, 0xfde5380c); /* 36 */
    HH (a, b, c, d, t_x[ 1], S31, 0xa4beea44); /* 37 */
    HH (d, a, b, c, t_x[ 4], S32, 0x4bdecfa9); /* 38 */
    HH (c, d, a, b, t_x[ 7], S33, 0xf6bb4b60); /* 39 */
    HH (b, c, d, a, t_x[10], S34, 0xbebfbc70); /* 40 */
    HH (a, b, c, d, t_x[13], S31, 0x289b7ec6); /* 41 */
    HH (d, a, b, c, t_x[ 0], S32, 0xeaa127fa); /* 42 */
    HH (c, d, a, b, t_x[ 3], S33, 0xd4ef3085); /* 43 */
    HH (b, c, d, a, t_x[ 6], S34,  0x4881d05); /* 44 */
    HH (a, b, c, d, t_x[ 9], S31, 0xd9d4d039); /* 45 */
    HH (d, a, b, c, t_x[12], S32, 0xe6db99e5); /* 46 */
    HH (c, d, a, b, t_x[15], S33, 0x1fa27cf8); /* 47 */
    HH (b, c, d, a, t_x[ 2], S34, 0xc4ac5665); /* 48 */

    /* Round 4 */
    II (a, b, c, d, t_x[ 0], S41, 0xf4292244); /* 49 */
    II (d, a, b, c, t_x[ 7], S42, 0x432aff97); /* 50 */
    II (c, d, a, b, t_x[14], S43, 0xab9423a7); /* 51 */
    II (b, c, d, a, t_x[ 5], S44, 0xfc93a039); /* 52 */
    II (a, b, c, d, t_x[12], S41, 0x655b59c3); /* 53 */
    II (d, a, b, c, t_x[ 3], S42, 0x8f0ccc92); /* 54 */
    II (c, d, a, b, t_x[10], S43, 0xffeff47d); /* 55 */
    II (b, c, d, a, t_x[ 1], S44, 0x85845dd1); /* 56 */
    II (a, b, c, d, t_x[ 8], S41, 0x6fa87e4f); /* 57 */
    II (d, a, b, c, t_x[15], S42, 0xfe2ce6e0); /* 58 */
    II (c, d, a, b, t_x[ 6], S43, 0xa3014314); /* 59 */
    II (b, c, d, a, t_x[13], S44, 0x4e0811a1); /* 60 */
    II (a, b, c, d, t_x[ 4], S41, 0xf7537e82); /* 61 */
    II (d, a, b, c, t_x[11], S42, 0xbd3af235); /* 62 */
    II (c, d, a, b, t_x[ 2], S43, 0x2ad7d2bb); /* 63 */
    II (b, c, d, a, t_x[ 9], S44, 0xeb86d391); /* 64 */

    state[0] += a;
    state[1] += b;
    state[2] += c;
    state[3] += d;
}
Example #3
0
// compiler is expected to optimized this function to avoid return value copy
inline Unicode Decode(const string& str) {
  Unicode unicode;
  unicode.reserve(str.size());
  Decode(str, unicode);
  return unicode;
}
int main2(int numArgs, const char *args[], char *rs)
{
  CFileSeqInStream inStream;
  CFileOutStream outStream;
  int res;
  int encodeMode = 0;
  Bool modeWasSet = False;
  const char *inputFile = NULL;
  const char *outputFile = "file.tmp";
  int param;
  UInt64 fileSize;

  FileSeqInStream_CreateVTable(&inStream);
  File_Construct(&inStream.file);

  FileOutStream_CreateVTable(&outStream);
  File_Construct(&outStream.file);

  if (numArgs == 1)
  {
    PrintHelp(rs);
    return 0;
  }

  for (param = 1; param < numArgs; param++) {
    if (strcmp(args[param], "-e") == 0 || strcmp(args[param], "-d") == 0) {
      encodeMode = (args[param][1] == 'e');
      modeWasSet = True;
    } else if (strcmp(args[param], "--f86") == 0) {
      mConType = X86Converter;
    } else if (strcmp(args[param], "-o") == 0 ||
               strcmp(args[param], "--output") == 0) {
      if (numArgs < (param + 2)) {
        return PrintUserError(rs);
      }
      outputFile = args[++param];
    } else if (strcmp(args[param], "--debug") == 0) {
      if (numArgs < (param + 2)) {
        return PrintUserError(rs);
      }
      //
      // For now we silently ignore this parameter to achieve command line
      // parameter compatibility with other build tools.
      //
      param++;
    } else if (
                strcmp(args[param], "-h") == 0 ||
                strcmp(args[param], "--help") == 0
              ) {
      PrintHelp(rs);
      return 0;
    } else if (
                strcmp(args[param], "-v") == 0 ||
                strcmp(args[param], "--verbose") == 0
              ) {
      //
      // For now we silently ignore this parameter to achieve command line
      // parameter compatibility with other build tools.
      //
    } else if (
                strcmp(args[param], "-q") == 0 ||
                strcmp(args[param], "--quiet") == 0
              ) {
      mQuietMode = True;
    } else if (strcmp(args[param], "--version") == 0) {
      PrintVersion(rs);
      return 0;
    } else if (inputFile == NULL) {
      inputFile = args[param];
    } else {
      return PrintUserError(rs);
    }
  }

  if ((inputFile == NULL) || !modeWasSet) {
    return PrintUserError(rs);
  }

  {
    size_t t4 = sizeof(UInt32);
    size_t t8 = sizeof(UInt64);
    if (t4 != 4 || t8 != 8)
      return PrintError(rs, "Incorrect UInt32 or UInt64");
  }

  if (InFile_Open(&inStream.file, inputFile) != 0)
    return PrintError(rs, "Can not open input file");

  if (OutFile_Open(&outStream.file, outputFile) != 0)
    return PrintError(rs, "Can not open output file");

  File_GetLength(&inStream.file, &fileSize);

  if (encodeMode)
  {
    if (!mQuietMode) {
      printf("Encoding\n");
    }
    res = Encode(&outStream.s, &inStream.s, fileSize);
  }
  else
  {
    if (!mQuietMode) {
      printf("Decoding\n");
    }
    res = Decode(&outStream.s, &inStream.s, fileSize);
  }

  File_Close(&outStream.file);
  File_Close(&inStream.file);

  if (res != SZ_OK)
  {
    if (res == SZ_ERROR_MEM)
      return PrintError(rs, kCantAllocateMessage);
    else if (res == SZ_ERROR_DATA)
      return PrintError(rs, kDataErrorMessage);
    else if (res == SZ_ERROR_WRITE)
      return PrintError(rs, kCantWriteMessage);
    else if (res == SZ_ERROR_READ)
      return PrintError(rs, kCantReadMessage);
    return PrintErrorNumber(rs, res);
  }
  return 0;
}
void Stopwatch() {
// dit is een methode dat een stopwatch op de harddrive doet verschijnen
//in het totaal moeten 6 getallen worden weergegeven
// ieder getal is gelinkt aan een counter, deze zijn hieronder gedeclareerd
	char secondenE = 0; //counter dat de eenheden van de seconden bijhoudt
	char secondenT = 0; //counter dat de tientallen van de seconden bijhoudt
//de volgende counters zijn analoog opgebouwd als deze voor de seconden
	char minutenE = 0;
	char minutenT = 0;
	char urenE = 0;
	char urenT = 0;
	char AsecondenE[16];
	char AsecondenT[16];
	char AminutenE[16];
	char AminutenT[16];
	char AurenE[16];
	char AurenT[16];
	while (1) {
		char* pSecondenE = Decode(secondenE);
		char* pSecondenT = Decode(secondenT);
		char* pMinutenE = Decode(minutenE);
		char* pMinutenT = Decode(minutenT);
		char* pUrenE = Decode(urenE);
		char* pUrenT = Decode(urenT);
		for (int i = 0; i < segments; i++) {
			AsecondenE[i] = *(pSecondenE + i);
		}
		for (int i = 0; i < segments; i++) {
			AsecondenT[i] = *(pSecondenT + i);
		}
		for (int i = 0; i < segments; i++) {
			AminutenE[i] = *(pMinutenE + i);
		}
		for (int i = 0; i < segments; i++) {
			AminutenT[i] = *(pMinutenT + i);
		}
		for (int i = 0; i < segments; i++) {
			AurenE[i] = *(pUrenE + i);
		}
		for (int i = 0; i < segments; i++) {
			AurenT[i] = *(pUrenT + i);
		}
		MakeCircle(AminutenT, AminutenE, DubbleDot, AsecondenT, AsecondenE,
				Dflt, Dflt, Dflt, Dflt, Dflt, Dflt, Dflt, Dflt, AurenT, AurenE,
				DubbleDot);

	}
//when timer ticks
	secondenE++;
	if (secondenE == 10) {
		secondenE = 0;
		secondenT++;
		if (secondenT == 6) {
			secondenT = 0;
			minutenE++;
			if (minutenE == 10) {
				minutenE = 0;
				minutenT++;
				if (minutenT == 6) {
					minutenT = 0;
					urenE++;
					if (urenE == 10) {
						urenE = 0;
						urenT++;
					}
				}
			}
		}
	}

}
Example #6
0
DrawableSurface
RasterImage::LookupFrame(const IntSize& aSize,
                         uint32_t aFlags,
                         PlaybackType aPlaybackType)
{
  MOZ_ASSERT(NS_IsMainThread());

  // If we're opaque, we don't need to care about premultiplied alpha, because
  // that can only matter for frames with transparency.
  if (IsOpaque()) {
    aFlags &= ~FLAG_DECODE_NO_PREMULTIPLY_ALPHA;
  }

  IntSize requestedSize = CanDownscaleDuringDecode(aSize, aFlags)
                        ? aSize : mSize;
  if (requestedSize.IsEmpty()) {
    return DrawableSurface();  // Can't decode to a surface of zero size.
  }

  LookupResult result =
    LookupFrameInternal(requestedSize, aFlags, aPlaybackType);

  if (!result && !mHasSize) {
    // We can't request a decode without knowing our intrinsic size. Give up.
    return DrawableSurface();
  }

  if (result.Type() == MatchType::NOT_FOUND ||
      result.Type() == MatchType::SUBSTITUTE_BECAUSE_NOT_FOUND ||
      ((aFlags & FLAG_SYNC_DECODE) && !result)) {
    // We don't have a copy of this frame, and there's no decoder working on
    // one. (Or we're sync decoding and the existing decoder hasn't even started
    // yet.) Trigger decoding so it'll be available next time.
    MOZ_ASSERT(aPlaybackType != PlaybackType::eAnimated ||
               !mAnimationState || mAnimationState->KnownFrameCount() < 1,
               "Animated frames should be locked");

    bool ranSync = Decode(requestedSize, aFlags, aPlaybackType);

    // If we can or did sync decode, we should already have the frame.
    if (ranSync || (aFlags & FLAG_SYNC_DECODE)) {
      result = LookupFrameInternal(requestedSize, aFlags, aPlaybackType);
    }
  }

  if (!result) {
    // We still weren't able to get a frame. Give up.
    return DrawableSurface();
  }

  if (result.Surface()->GetCompositingFailed()) {
    return DrawableSurface();
  }

  MOZ_ASSERT(!result.Surface()->GetIsPaletted(),
             "Should not have a paletted frame");

  // Sync decoding guarantees that we got the frame, but if it's owned by an
  // async decoder that's currently running, the contents of the frame may not
  // be available yet. Make sure we get everything.
  if (mHasSourceData && (aFlags & FLAG_SYNC_DECODE)) {
    result.Surface()->WaitUntilFinished();
  }

  // If we could have done some decoding in this function we need to check if
  // that decoding encountered an error and hence aborted the surface. We want
  // to avoid calling IsAborted if we weren't passed any sync decode flag because
  // IsAborted acquires the monitor for the imgFrame.
  if (aFlags & (FLAG_SYNC_DECODE | FLAG_SYNC_DECODE_IF_FAST) &&
    result.Surface()->IsAborted()) {
    return DrawableSurface();
  }

  return Move(result.Surface());
}
Example #7
0
// main entry for decompiling from a memory buffer
bool KEmfDC::DeCompileBuffer(const TCHAR * outfilename, const void * buffer, KTreeView * pTree, HENHMETAFILE & hEmf)
{
	const EMR * emr = (const EMR *) buffer;
	
	// if not normal EMF file
	while ( ! IsEMFHeader(emr) )
	{
		if ( IsEMFHeader(emr+1) )
		{
			emr ++;

			if ( hEmf==NULL )
				hEmf = SetEnhMetaFileBits(emr[-1].nSize, (const BYTE *) emr);
			
			break;
		}
		else
			emr = (const EMR *) ( ( const char * ) emr + emr->nSize );
	}

	const ENHMETAHEADER * pHeader = (const ENHMETAHEADER *) emr;
	
	if ( pTree==NULL )
	{
		fmt.Open(outfilename);

		HRSRC hRsc = FindResource(hModule, MAKEINTRESOURCE(IDR_PRE), RT_RCDATA);
		
		if ( hRsc )
		{
			HGLOBAL hResData  = LoadResource(hModule, hRsc);
			const char * pPgm = (const char *) LockResource(hResData);

			fmt.Write(pPgm);
		}

		fmt.Indent(1);
		fmt.Newline(); fmt.Write("HGDIOBJ hObj["); fmt.WriteDec((long) pHeader->nHandles); fmt.Write("] = { NULL };");
		fmt.Newline();
	}
	m_nSeq = 1;

	bool bOptimize = false;

	// enumuerate all EMF records
	while ( (emr->iType>=EMR_MIN) && (emr->iType<=EMR_MAX) )
	{
		bool rslt = true;

		if ( bOptimize )
		{
			const EMR * next = (const EMR *) ( ( const char * ) emr + emr->nSize );

			if ( next->iType == emr->iType )
				switch ( emr->iType )
				{
					case EMR_SETWINDOWORGEX:
					case EMR_SETWINDOWEXTEX:
					case EMR_SETVIEWPORTORGEX:
					case EMR_SETVIEWPORTEXTEX:
					case EMR_SETTEXTCOLOR:
					case EMR_SETBKCOLOR:
					case EMR_SETBRUSHORGEX:
					case EMR_SELECTCLIPPATH:
					case EMR_SETTEXTALIGN:
	    
					case EMR_SETBKMODE:
					case EMR_SETARCDIRECTION:
					case EMR_SETPOLYFILLMODE:
					case EMR_SETMAPMODE:
					case EMR_SETSTRETCHBLTMODE:
					case EMR_SETMAPPERFLAGS:
					case EMR_SETICMMODE:
					case EMR_SETROP2:

					case EMR_SETMITERLIMIT:
					case EMR_SETWORLDTRANSFORM:
					case EMR_MOVETOEX:
						fmt.Write("/* */");
						break;
				
					default:
						rslt = Decode(emr, pTree);
				}
			else 
				rslt = Decode(emr, pTree);
		}
		else
			rslt = Decode(emr, pTree);
		
		if (! rslt ) 
			break;

		if ( emr->iType== EMR_EOF )
			break;

		emr = (const EMR *) ( ( const char * ) emr + emr->nSize );
	}
	
	if ( pTree==NULL )
	{
		fmt.Indent(-1);

		HRSRC hRsc = FindResource(hModule, MAKEINTRESOURCE(IDR_POST), RT_RCDATA);
		
		if ( hRsc )
		{
			HGLOBAL hResData  = LoadResource(hModule, hRsc);
			const char * pPgm = (const char *) LockResource(hResData);

			fmt.Write(pPgm);
		}

		fmt.Close();
	}
	
	return true;
}