Exemplo n.º 1
0
// Generate pulses for speedometer and odometers.
void
gen_pulse_mod::gen_pulse_proc()
{
  wait();
 
  speed_pulse = false;
  dist_pulse = false;

  // Wait until the car is started.
  // do { wait(); } while (start == true);
  do {
    wait();
  } while (start == false);

  while (true) {

    speed_pulse = true;
    dist_pulse = true;
    AWAIT(find_period(speed));

    speed_pulse = false;
    dist_pulse = false;
    AWAIT(find_period(speed));
  }
}
Exemplo n.º 2
0
int _tmain(int argc, _TCHAR* argv[])
{
int signal1 [] = {1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1};  //User defined signal1
int signal2 [] = {1, 0, -1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1};    //User defined signal2
int signal3 [] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};       //Temporary empty signal array

//Adds signal 1 and signal 2.
add_signals(signal1, signal2, signal3, LEN);

//Finds the periods of all 3 signals.
int p1 = find_period(signal1, LEN);
int p2 = find_period(signal2, LEN);
int p3 = find_period(signal3, LEN);

printf("\nChris Whiting\n");
printf("\nSignal 1: ");
print_vector(signal1, LEN);
printf("\nSingal 1's period: %d samples", p1);
printf("\nSignal 2: ");
print_vector(signal2, LEN);
printf("\nSingal 2's period: %d samples", p2);
printf("\nSignal 1 + Signal 2: ");
print_vector(signal3, LEN);
printf("\nSingal 1+2's period: %d samples", p3);
_getche();
return 0;
}
Exemplo n.º 3
0
int solve()
{
    int x, y, s = 0, t, pc = 0;
    init_pos(&x, &y);

    memset(idx, -1, sizeof(idx));
    pos[0] = x*MAXN+y;
    idx[x][y][0] = 0;
    for(;;)
    {
        t = next_dir(pc++);
        if(pc == prog_len)
            pc = 0;
        int x1 = x+dx[t], y1 = y+dy[t];
        if(grid[x1][y1] != '#')
        {
            x = x1, y = y1;
            pos[++s] = x*MAXN+y;
        }
        //printf("haha %d %d %d %d\n", x, y, pc, s);
        if(idx[x][y][pc] >= 0)
            break;
        idx[x][y][pc] = s;
    }

    if(s == idx[x][y][pc])
        return 1;
    return find_period(s-idx[x][y][pc], idx[x][y][pc], s-1);
}
Exemplo n.º 4
0
int main(int argc, char** argv){
	char* text, *output;
	size_t fsize=read_file(&text, argv[1]);	
	output=malloc(fsize+1);
	int p=find_period(text,fsize),s,m=4,fudge;
	
	for(fudge=-2; fudge<=2; ++fudge){
		for(s=0; s<p+fudge; ++s){
			char k=decrypt_caesar(text, &output, fsize, p+fudge,s,4);
			printf("%c",k);
		}
		printf("\n");
		printf(output);
		printf ("\n");
	}
	free(output);
	free(text);
	return 0;
}