Beispiel #1
0
void IR::receive(){

   currReading = !(PINB & 1);                     // read input
   
  if(prevReading  ==0 && currReading == 1){       // rising edge ( beginning of signal )
    startPulse = micros();                        // start time
    if(endPulse!= 0){                             // if this is not the beginning of the signal, store the off time 
      offTime[offSize] = startPulse - endPulse;
      offSize++;
    }
    
  }else if(prevReading  ==1 && currReading == 0){ // falling edge ( end of signal )
     endPulse =  micros();                        // end time
     onTime[onSize] = endPulse - startPulse;
     onSize++;
  }
  
  if(endPulse!=0){                                // if MAX_DELAY ms passes with no signal, print the signal
    long timeDiff = millis() - (endPulse/1000) ; 
		if(timeDiff >= MAX_DELAY){
		   printSignal();
		   onSize = 0;  offSize = 0;  startPulse =0; endPulse =0;
		}
  }
  
  prevReading = currReading; 
}
Beispiel #2
0
void HammingCode::decodeSignal() {
  decodedSignal.assign(4, 0);

  if (this->crashedSignal[2]) decodedSignal[0] = 1;
  if (this->crashedSignal[4]) decodedSignal[1] = 1;
  if (this->crashedSignal[5]) decodedSignal[2] = 1;
  if (this->crashedSignal[6]) decodedSignal[3] = 1;

  printSignal(this->decodedSignal, "Decoded signal");
}
Beispiel #3
0
static MME_ERROR simpleMix(MME_TransformerHandle_t hdl)
{
    MME_ERROR err;
    MME_DataBuffer_t *bufs[3] = { 0, 0, 0 };
    MME_Command_t cmd = { sizeof(MME_Command_t) };

    /* allocate databuffers using MME_ALLOCATION_PHYSICAL to guarantee
     * a single scatter page per allocation */

    err = MME_AllocDataBuffer(hdl, sizeof(sample1), MME_ALLOCATION_PHYSICAL, bufs+0);
    if (MME_SUCCESS != err) goto error_recovery;
    memcpy(bufs[0]->ScatterPages_p->Page_p, sample1, sizeof(sample1));

    err = MME_AllocDataBuffer(hdl, sizeof(sample2), MME_ALLOCATION_PHYSICAL, bufs+1);
    if (MME_SUCCESS != err) goto error_recovery;
    memcpy(bufs[1]->ScatterPages_p->Page_p, sample2, sizeof(sample2));

    err = MME_AllocDataBuffer(hdl, sizeof(sample1), MME_ALLOCATION_PHYSICAL, bufs+2);
    if (MME_SUCCESS != err) goto error_recovery;

    /* fill in the non-zero parts of the command structure and issue the command.
     *
     * Note that setting constant due times will cause transforms to happen in
     * strict FIFO order within a transformer (and round-robin within multiple
     * transformers)
     */
    cmd.CmdCode = MME_TRANSFORM;
    cmd.CmdEnd = MME_COMMAND_END_RETURN_NOTIFY;
    cmd.DueTime = 0;
    cmd.NumberInputBuffers = 2;
    cmd.NumberOutputBuffers = 1;
    cmd.DataBuffers_p = bufs;
    err = MME_SendCommand(hdl, &cmd);
    if (MME_SUCCESS != err) goto error_recovery;
    OS_SIGNAL_WAIT(&callbackSignal);

    /* in normal use we would send many more commands before returning (at which
     * point the transformer will be terminated.
     */

    /* show the mixed waveform */
    printSignal(bufs[2]->ScatterPages_p->Page_p, sizeof(sample1));

    /*FALLTHRU*/
error_recovery:

    if (bufs[0]) (void) MME_FreeDataBuffer(bufs[0]);
    if (bufs[1]) (void) MME_FreeDataBuffer(bufs[1]);
    if (bufs[2]) (void) MME_FreeDataBuffer(bufs[2]);

    return err;
}
Beispiel #4
0
void HammingCode::crashSignal() {
  int whichOne = 0;

  std::srand(std::time(0));
  whichOne = std::rand() % 8;

  for (auto x : this->encodedSignal) {
    this->crashedSignal.push_back(x);
  }

  this->crashedSignal[whichOne] = (this->crashedSignal[whichOne] + 1) % 2;

  printSignal(this->crashedSignal, "Crashed Signal");
}
Beispiel #5
0
void HammingCode::encodeSignal(std::vector<int>& inputSignal) {
  int i = 0;

  for (auto x : inputSignal) {
    this->basicSignal.push_back(x);
  }

  printSignal(this->basicSignal, "Input signal");

  this->encodedSignal.push_back(
      (basicSignal[0] + basicSignal[1] + basicSignal[3]) % 2);
  this->encodedSignal.push_back(
      (basicSignal[0] + basicSignal[2] + basicSignal[3]) % 2);
  this->encodedSignal.push_back(basicSignal[0]);
  this->encodedSignal.push_back(
      (basicSignal[1] + basicSignal[2] + basicSignal[3]) % 2);
  
  this->encodedSignal.push_back(basicSignal[1]);
  this->encodedSignal.push_back(basicSignal[2]);
  this->encodedSignal.push_back(basicSignal[3]);

  printSignal(this->encodedSignal, "Encoded signal");
}
Beispiel #6
0
void printSignal(Tree sig, FILE* out, int prec)
{
	int 	i;
	double	r;
    Tree 	 x, y, z, u, le, id;
	    
		 if ( isSigInt(sig, &i) ) 			{ fprintf(out, "%d", i); 	}
	else if ( isSigReal(sig, &r) ) 			{ fprintf(out, "%f", r); 	}
	else if ( isSigInput(sig, &i) ) 		{ fprintf(out, "IN%d", i);	}
	else if ( isSigOutput(sig, &i, x) ) 	{ fprintf(out, "OUT%d := ", i); printSignal(x, out, 0); }
	
	else if ( isSigBinOp(sig, &i, x, y) )	{ 
		if (prec > binopprec[i]) fputs("(", out); 
		printSignal(x,out,binopprec[i]); fputs(binopname[i], out); printSignal(y, out, binopprec[i]); 
		if (prec > binopprec[i]) fputs(")", out); 	
	}
	else if ( isSigDelay1(sig, x) ) 		{ fputs("mem(", out); printSignal(x,out,0); fputs(")", out);		}
	else if ( isSigPrefix(sig, x, y) ) 		{ fputs("prefix(", out); printSignal(x,out,0); fputs(",", out);	 printSignal(y,out,0); fputs(")", out);		}
	else if ( isSigAttach(sig, x, y) ) 		{ fputs("attach(", out); printSignal(x,out,0); fputs(",", out);	 printSignal(y,out,0); fputs(")", out);		}
	else if ( isSigFixDelay(sig, x, y) ) 	{ 
		if (prec > 4) fputs("(", out); 
		printSignal(x,out,4); fputs("@", out); printSignal(y, out, 4); 
		if (prec > 4) fputs(")", out); 	
	}

	else if ( isProj(sig, &i, x) ) 			{ printSignal(x,out,prec); fprintf(out, "#%d", i); 		}
    else if ( isRef(sig, i) ) 				{ fprintf(out, "$%d", i);	}
	else if ( isRef(sig, x) ) 				{ print(x, out); 			}
	else if ( isRec(sig, le))				{ fputs("\\_.", out); printSignal(le, out, prec);	}
	else if ( isRec(sig, x, le))			{ fputs("\\", out); print(x,out); fputs(".", out); printSignal(le, out, prec);	}
	
	else if ( isSigTable(sig, id, x, y) ) 	{ fputs("table(", out); printSignal(x,out,0); fputc(',', out); printSignal(y,out,0); fputc(')', out);   }
	else if ( isSigWRTbl(sig, id, x, y, z) ){ printSignal(x,out,0); fputc('[',out); printSignal(y,out,0); fputs("] := (", out); printSignal(z,out,0); fputc(')', out);   }
	else if ( isSigRDTbl(sig, x, y) ) 		{ printSignal(x,out,0); fputc('[', out); printSignal(y,out,0); fputc(']', out);   }

    else if (isSigDocConstantTbl(sig,x,y)) 	{ fputs("sigDocConstantTbl(", out); printSignal(x,out,0); fputc(',', out);
                                                                                printSignal(y,out,0); fputc(')', out);   }

    else if (isSigDocWriteTbl(sig,x,y,z,u)) { fputs("sigDocWriteTbl(", out);    printSignal(x,out,0); fputc(',', out);
                                                                                printSignal(y,out,0); fputc(',', out);
                                                                                printSignal(z,out,0); fputc(',', out);
                                                                                printSignal(u,out,0); fputc(')', out);   }

    else if (isSigDocAccessTbl(sig,x,y)) 	{ fputs("sigDocAccessTbl(", out);   printSignal(x,out,0); fputc(',', out);
                                                                                printSignal(y,out,0); fputc(')', out);   }


	else if ( isSigGen(sig, x) ) 			{ printSignal(x,out,prec); 				}
 
	else if ( isSigIntCast(sig, x) ) 		{ fputs("int(", out); printSignal(x,out,0); fputs(")", out);		}
	else if ( isSigFloatCast(sig, x) ) 		{ fputs("float(", out); printSignal(x,out,0); fputs(")", out);		}

	else if (isList(sig)) {
		char sep = '{';
		do { 
			fputc(sep, out);
			printSignal(hd(sig), out, 0);
			sep=',';
			sig = tl(sig);
		} while (isList(sig));
		fputc('}', out);
	}
	else
		print(sig, out);
}
int main(int argc, char* argv[]) {
  Signal* signals = NULL;
  unsigned int nsignals = 0;

  const char* vcd_file = argv[1];
  char* name;
  char id;

  // Read VCD file
  FILE* fp;
  char* line = NULL;
  ssize_t len = 0;

  char* token = NULL;
  char* signalName = NULL;
  char signalId;

  if((fp = fopen(vcd_file, "r")) == NULL) {
    fprintf(stderr, "Failed to open VCD file: %s\n", vcd_file);
    exit(1);
  }

  unsigned char dumpVarsStarted = 0,
                dumpVarsEnded = 0;
  unsigned int timestamp = 0;
  while (getline(&line, &len, fp) != -1) {
    // Removing trailing line break
    if (line[strlen(line)-1] == '\n') {
      line[strlen(line)-1] = '\0';
    }

    // Signal declaration line
    if (startsWith("$var", line)) {
      // Ignore the first 3 parts of string.
      // Signal symbol is in the 4o part.
      // Signal name is in the 5o part.
      strtok(line, " ");
      strtok(NULL, " ");
      strtok(NULL, " ");
      token = strtok(NULL, " ");
      signalName = strtok(NULL, " ");
      signalId = token[0];
      createSignal(&signals, &nsignals, signalName, signalId);
    }
    else if (startsWith("$dumpvars", line)) {
      dumpVarsStarted = 1;
    }
    else if (startsWith("$end", line) && dumpVarsStarted) {
      dumpVarsEnded = 1;
    }
    else if (dumpVarsEnded) {
      if (line[0] == '#') {
        // Timestamp update
        char timestampStr[16];
        strcpy(timestampStr, line+1);
        timestamp = atoi(timestampStr);
      }
      else {
        // Signal value update
        unsigned char value  = line[0] - 0x30;
        char symbol = line[strlen(line)-1];
        Signal* signal = findSignalBySymbol(signals, nsignals, symbol);
        assignSignalUpdate(signal, value, timestamp);
      }
    }
  }

  // close all signals counters
  unsigned int i;
  for (i = 0; i < nsignals; i++) {
    closeSignalCounters(&signals[i], timestamp);
  }

  printf("--- REPORT ---\n");
  Signal *sigShortDelay = NULL,
         *sigLongDelay  = NULL;
  for(i = 0; i < nsignals; i++) {
    printSignal(&signals[i]);

    if (sigShortDelay == NULL || signals[i].shortestIdleDelay < sigShortDelay->shortestIdleDelay) {
      sigShortDelay = &signals[i];
    }

    if (sigLongDelay == NULL || signals[i].longestIdleDelay > sigLongDelay->longestIdleDelay) {
      sigLongDelay = &signals[i];
    }
  }

  printf("\nNumber of Signals: %d\n", nsignals);
  printf("Shortest delay: signal \"%s\" with delay of %d\n", sigShortDelay ? sigShortDelay->name : "", sigShortDelay ? sigShortDelay->shortestIdleDelay : -1);
  printf("Longest  delay: signal \"%s\" with delay of %d\n", sigLongDelay ? sigLongDelay->name : "", sigLongDelay ? sigLongDelay->longestIdleDelay : -1);

  return 0;
}
Beispiel #8
0
void HammingCode::correcError() {
  int p1 = 0, p2 = 0, p3 = 0;
  int p1Right = 0, p2Right = 0, p3Right = 0;

  p1 = this->crashedSignal[0];
  p2 = this->crashedSignal[1];
  p3 = this->crashedSignal[3];

  p1Right = (p1 == ((this->crashedSignal[2] + this->crashedSignal[4] +
                     this->crashedSignal[6]) %
                    2));
  p2Right = (p2 == ((this->crashedSignal[2] + this->crashedSignal[5] +
                     this->crashedSignal[6]) %
                    2));
  p3Right = (p3 == ((this->crashedSignal[4] + this->crashedSignal[5] +
                     this->crashedSignal[6]) %
                    2));

  if (!p1Right and p2Right and p3Right) {
    this->crashedSignal[0] = (this->crashedSignal[0] + 1) % 2;
  } else if (!p2Right and p1Right and p3Right) {
    this->crashedSignal[1] = (this->crashedSignal[1] + 1) % 2;
  } else if (!p3Right and p1Right and p2Right) {
    this->crashedSignal[3] = (this->crashedSignal[3] + 1) % 2;
  } else {
    std::cout << "None of bits was changed" << std::endl;
  }

  if (p1 != ((this->crashedSignal[2] + this->crashedSignal[4] +
              this->crashedSignal[6]) %
             2) and
      p2 != ((this->crashedSignal[2] + this->crashedSignal[5] +
              this->crashedSignal[6]) %
             2) and
      p3 == ((this->crashedSignal[4] + this->crashedSignal[5] +
              this->crashedSignal[6]) %
             2)) {
    this->crashedSignal[2] = (this->crashedSignal[2] + 1) % 2;
  }

  if (p1 == ((this->crashedSignal[2] + this->crashedSignal[4] +
              this->crashedSignal[6]) %
             2) and
      p2 != ((this->crashedSignal[2] + this->crashedSignal[5] +
              this->crashedSignal[6]) %
             2) and
      p3 != ((this->crashedSignal[4] + this->crashedSignal[5] +
              this->crashedSignal[6]) %
             2)) {
    this->crashedSignal[5] = (this->crashedSignal[5] + 1) % 2;
  }

  if (p1 != ((this->crashedSignal[2] + this->crashedSignal[4] +
              this->crashedSignal[6]) %
             2) and
      p2 == ((this->crashedSignal[2] + this->crashedSignal[5] +
              this->crashedSignal[6]) %
             2) and
      p3 != ((this->crashedSignal[4] + this->crashedSignal[5] +
              this->crashedSignal[6]) %
             2)) {
    this->crashedSignal[4] = (this->crashedSignal[4] + 1) % 2;
  }

  if (p1 != ((this->crashedSignal[2] + this->crashedSignal[4] +
              this->crashedSignal[6]) %
             2) and
      p2 != ((this->crashedSignal[2] + this->crashedSignal[5] +
              this->crashedSignal[6]) %
             2) and
      p3 != ((this->crashedSignal[4] + this->crashedSignal[5] +
              this->crashedSignal[6]) %
             2)) {
    this->crashedSignal[6] = (this->crashedSignal[6] + 1) % 2;
  }

  printSignal(this->crashedSignal, "Repaired signal");
}
/**
 * Opens a print dialog and prints the canvas widget.
 * @param printDialogTitle
 *      The print dialog title.
 */
void Context2D::print(QString printDialogTitle)
{
    emit printSignal(printDialogTitle);
}
Beispiel #10
0
void MasterServer::print(QString message)
{
    emit printSignal(message);
}