void LcdWriteInit(unsigned char data) { DATAPORT &= NOT_PIN_DC; //digitalWrite(PIN_DC, dc); DATAPORT &= NOT_PIN_SCE; //digitalWrite(PIN_SCE, LOW); shiftBits(data); DATAPORT |= PIN_SCE; //digitalWrite(PIN_SCE, HIGH); }
static void unpackBandwidthEfficientData(BufferedPacket* packet, Boolean isWideband) { #ifdef DEBUG fprintf(stderr, "Unpacking 'bandwidth-efficient' payload (%d bytes):\n", packet->dataSize()); for (unsigned j = 0; j < packet->dataSize(); ++j) { fprintf(stderr, "%02x:", (packet->data())[j]); } fprintf(stderr, "\n"); #endif BitVector fromBV(packet->data(), 0, 8*packet->dataSize()); unsigned const toBufferSize = 2*packet->dataSize(); // conservatively large unsigned char* toBuffer = new unsigned char[toBufferSize]; unsigned toCount = 0; // Begin with the payload header: unsigned CMR = fromBV.getBits(4); toBuffer[toCount++] = CMR << 4; // Then, run through and unpack the TOC entries: while (1) { unsigned toc = fromBV.getBits(6); toBuffer[toCount++] = toc << 2; if ((toc&0x20) == 0) break; // the F bit is 0 } // Then, using the TOC data, unpack each frame payload: unsigned const tocSize = toCount - 1; for (unsigned i = 1; i <= tocSize; ++i) { unsigned char tocByte = toBuffer[i]; unsigned char const FT = (tocByte&0x78) >> 3; unsigned short frameSizeBits = isWideband ? frameBitsFromFTWideband[FT] : frameBitsFromFT[FT]; unsigned short frameSizeBytes = (frameSizeBits+7)/8; shiftBits(&toBuffer[toCount], 0, // to packet->data(), fromBV.curBitIndex(), // from frameSizeBits // num bits ); #ifdef DEBUG if (frameSizeBits > fromBV.numBitsRemaining()) { fprintf(stderr, "\tWarning: Unpacking frame %d of %d: want %d bits, but only %d are available!\n", i, tocSize, frameSizeBits, fromBV.numBitsRemaining()); } #endif fromBV.skipBits(frameSizeBits); toCount += frameSizeBytes; } #ifdef DEBUG if (fromBV.numBitsRemaining() > 7) { fprintf(stderr, "\tWarning: %d bits remain unused!\n", fromBV.numBitsRemaining()); } #endif // Finally, replace the current packet data with the unpacked data: packet->removePadding(packet->dataSize()); // throws away current packet data packet->appendData(toBuffer, toCount); delete[] toBuffer; }
//send cmd void sendCMD(byte data) { CLK0 SDA0 //1 for cmd CLK1 shiftBits(data); }
//send data void sendData(byte data) { CLK0 SDA1 //1 for param CLK1 shiftBits(data); }
signed char hasBeenVisitedRelative(signed char direction) {//TODO: test, srsly test the f**k out of that stuff direction=shiftBits(direction,directionOffset);//seems to work so far :D switch (direction){ case 0x01: return (mazeStorage[currentPosition[0]][currentPosition[1]+1] >> 4); case 0x02: return (mazeStorage[currentPosition[0]+1][currentPosition[1]] >> 4); case 0x04: return (mazeStorage[currentPosition[0]][currentPosition[1]-1] >> 4); case 0x08: return (mazeStorage[currentPosition[0]-14][currentPosition[1]] >> 4); default: return(0);//stupid conventions. I know what I do -.- } }
/************************************************************* ************** LRU Page Replacement Algorithm **************** *************************************************************/ void LRURefPageReplacement(){ int numberOfPageFaults = 0,j; frame = malloc(sizeof(struct frames)); head = malloc(sizeof(struct frames)); tail = malloc(sizeof(struct frames)); head = frame; tail = frame; frame->next = NULL; frame->prev = head; frame->pageNum = inputSeq[0]; for (j=0;j<8;j++) frame->refBitArray[j] = 0; int i, isPageAlreadyExists = 0; frame->refBitDecimalValue = binToDecimal(frame->refBitArray); numberOfPageFaults += 1; for (i=0; i<strlen(inputSeq); i++){ if (isspace(inputSeq[i]) == 0){ isPageAlreadyExists = findPage(inputSeq[i]); if (isPageAlreadyExists == 1){ shiftBits(inputSeq[i]); }else if (isPageAlreadyExists == 0 && isFrameAvailable() == 1){ numberOfPageFaults += 1; framesLeft -= 1; addPageToTailOfFrame(inputSeq[i]); addShiftBits(inputSeq[i]); }else if (isPageAlreadyExists == 0 && isFrameAvailable() == 0){ numberOfPageFaults += 1; char victimPage = findVictimPage(); removeNodeFromFrame(victimPage); addPageToTailOfFrame(inputSeq[i]); addShiftBits(inputSeq[i]); } } } printf("\n# of page replacements with LRU-REF8 = %d\n",numberOfPageFaults-availableFrames); nbOfPageReplacementByAlgo = numberOfPageFaults-availableFrames; }
int main(int argc, char *argv[]) { if(argc == 2){ //argumente ueberpruefen //char mode; /*unsigned char divident[2]; //CRC16 = x 16 + x 15 + x 2 + 1 // 1100 0000 0000 0101 divident[0] = 192; divident[1] = 5;*/ char divisor[16]; byteToBits(divisor,(unsigned char)192,(unsigned char)5); //DEBUG dbgPrintBits(divisor); FILE *fp = fopen(argv[1],"r"); if(fp != NULL){ //.crc endung? --> letzte 4 Zeichen auf .crc ueberpruefen /*for(int i = 0; i<10;i++){printf("%c %d\n",argv[1][i],argv[1][i]); fflush(stdout); }*/ //string terminiert bei 0 - wer haette es gedacht.. int len = 0; while(argv[1][len] != 0){ len++; } if( argv[1][len-4] == '.' && argv[1][len-3] == 'c' && argv[1][len-2] == 'r' && argv[1][len-1] == 'c' ){ //check checksum MODE = DECODE; }else{ //create checksum //dateiinhalt um 2 leere (16x0) bytes erweitern //immer 2 bytes einlesen und durch divident teilen (mod 2) / bzw xor MODE = ENCODE; } printf("MODE: %d\n\n",MODE); //neuer dateiname char filename[128]; memset(filename,0,sizeof filename); //filename = argv[1]; int i = 0; while(argv[1][i] != 0 && i < 123){ filename[i] = argv[1][i]; i++; } if(MODE == 1){ //ENCODE filename[i] = '.'; filename[i+1] = 'c'; filename[i+2] = 'r'; filename[i+3] = 'c'; }else{ //DECODE filename[i] = 0; } //DEBUG printf("filename %s\n\n",filename); char remain[2]; //create file FILE *outputf = fopen(filename,"w+"); if(outputf != NULL){ //write file if(MODE){ //ENCODE : complete char buffer; while((buffer= fgetc(fp)) != EOF){ fputc(buffer,outputf); } }else{ //DECODE : all except the last 2 bytes char buffer; while ((buffer = fgetc(fp)) != EOF){ fputc(buffer,outputf); remain[0] = fgetc(fp); remain[1] = fgetc(fp); buffer = fgetc(fp); if(buffer == EOF){ break; }else{ fseek(fp,-3,SEEK_CUR); } } } //DEBUG printf("File copied\n"); //fseek if(fseek(outputf,0,SEEK_SET)!=0){ printf("error seeking in file\n"); } return 0; char bits[16], queue[16]; refillBits(bits,outputf); refillBits(queue,outputf); //DEBUG printf("Filled bits: \n"); dbgPrintBits(bits); dbgPrintBits(queue); shiftBits(bits,queue,outputf); //DEBUG printf("shifted bits: \n"); dbgPrintBits(bits); dbgPrintBits(queue); //return 0; //algorithm while(queue[0] != -1){ xor(bits,divisor); shiftBits(bits,queue,outputf); } if(MODE){ //ENCODE --> add remainder to file int remIndicator = 0; int c = 128; for(int i = 0;i<16;i++){ //DEBUG //printf("i = %d , byte: %d, c: %d\n",i,helpbyte,c); if(bits[i] == 1){ //DEBUG //printf("Byte: %d, C: %d\n",helpbyte,c); remain[remIndicator] += c; } if(c == 1){ if(remIndicator == 1){ break; } //DEBUG //printf("RESET c = %d byte = %d\n",c,helpbyte); c = 128; remIndicator = 1; }else{ //DEBUG //printf("c: %d :/ 2 = \n",c); c /= 2; //printf("%d\n",c); } } fputc(remain[0],outputf); fputc(remain[1],outputf); }else{ //DECODE check remainder char checksum[16]; byteToBits(checksum,remain[0],remain[1]); for(int z = 0; z<5;z++){ if(checksum[i] != bits[i]){ printf("CRC-Checksum stimmt nicht mit dem Inhalt ueberein!\n"); fclose(outputf); remove(filename); return 0; } } } //printf("EOF: %d %d\n",EOF,(unsigned char)EOF); //printf("asci 10: %c\n",10); fclose(fp); fclose(outputf); }else{ printf("Could not create File %s\n",filename); } }else{ printf("File not found\n"); } }else{ printf("usage: %s <filename>\n",argv[0]); } }