<commit_before>// <NAME> Feb. 12, 2017
#include "stm32l476xx.h" //board
#include "SysClock.h"    //Sysclock
#include "LED.h"         //LED
#include "UART.h"        //UART
#include "TIMER.h"       //TIMER
#include "input_pa0_test.h"
#include "binSearch.h"
#include "sort.h"

#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#define SAMPLES 1000				//Number of samples to be taken
#define POST_REQ_TIME 100000		//100000 microseconds = 100ms
uint8_t buffer[BufferSize]; 

char str[] = "POST failed! Pulse not seen in 100ms. Rerun? (Y or N):\r\n";
char defaultBounds[] = "Using default bounds! (950 micro & 1050 micro) Change? (Y or N):\r\n";
char rerun[] = "Rerun? (Y or N):\r\n";
int measurements[SAMPLES];	// initialize array of 1000 elements
int defaultLow = 950;		//Default Low boundary micro
int defaultHigh = 1050;		//Default High boundry micro

int FAIL( void ){
	char rxByte;
	USART_Write(USART2, (uint8_t *)str, strlen(str));
	rxByte = USART_Read(USART2);
	if (rxByte == 'N' || rxByte == 'n'){
		USART_Write(USART2, (uint8_t *)"Exitting\r\n\r\n", 14);
		//FAIL and exit program
		return 0;
	}
	else if (rxByte == 'Y' || rxByte == 'y'){
		USART_Write(USART2, (uint8_t *)"Rerunning POST\r\n\r\n", 20);
		return POST();
	}
	else {
		USART_Write(USART2, (uint8_t *)"Invalid Response\r\n\r\n", 22);
		return FAIL();
	}
}

int POST( void ) {
	int beginPostTime=0;
    start_timer();			// start capture
	beginPostTime = timer_now();
	while( 1 ){
		if ( is_event() ) {	// received edge TIM2->CCR1
			if ( ( timer_now() - beginPostTime ) <= POST_REQ_TIME ){ // test received an edge before 100000micro (100ms)
				//DISPLAY success on UART/Time seen
                USART_Write(USART2, (uint8_t *)"POST passed!\r\n\r\n", 18);
				return 1;
				break;
			}
			else{ // test received edge but too long
				//TEST FAILED!
				//OPTION TO RUN AGAIN
                USART_Write(USART2, (uint8_t *)"POST failed!\r\n\r\n", 17);
				return FAIL();
				break;
			}
		}
		else { // nothing seen yet TIM2->CNT
			if ( ( timer_now() - beginPostTime ) > POST_REQ_TIME ){ // exceeded 100ms 
				//TEST FAILED!
				//OPTION TO RUN AGAIN
                USART_Write(USART2, (uint8_t *)"POST failed!\r\n\r\n", 17);
				return FAIL();
				break;
			}
		}
	}
	stop_timer();
}

void run( void ){
	char rvByte;
    int numOfSample=0;
    int beginSampleTime=0;
	USART_Write(USART2, (uint8_t *)defaultBounds, strlen(defaultBounds));
	rvByte = USART_Read(USART2);
	if (rvByte == 'N' || rvByte == 'n'){
		USART_Write(USART2, (uint8_t *)"Running with defaults\r\n\r\n", 27);
	}
	else if (rvByte == 'Y' || rvByte == 'y'){
		USART_Write(USART2, (uint8_t *)"Changing Bounds\r\n\r\n", 21);
		//Change bounds handle user input 
	}
	else {
		USART_Write(USART2, (uint8_t *)"Invalid Response\r\n\r\n", 22);
		run();
	}

	//capture 1000 pulses
	//Return time it took - store in array in main
	for ( numOfSample = 0; numOfSample < SAMPLES; numOfSample++ ){//detect pulse and duration (multiply by 2 for total period?)
		start_timer();
		beginSampleTime = timer_now();
		while( 1 ){
			if ( is_event() ){
				measurements[numOfSample] = (timer_now() - beginSampleTime); //(possibly multiplied by 2)
				stop_timer(); // might need to reset
				break;
			}
			else{//edge not detected
				;
			}
		}
	}

}

void UART_graph( void ){
    int size = sizeof(measurements)/sizeof(measurements[0]);
	int x; //individual element of the array for a pass
	int c; //count of the individual element
    int p;//counter for the measurements loop
    int n;
    int sorted[SAMPLES];
    char rxByte;
    int zack=0;
    sort_array(measurements);

    /*
    for (zack=0;zack<size;zack++){
        n = sprintf((char *)buffer, "%d \r\n", measurements[zack]);
        USART_Write(USART2, buffer, n);
    }*/
    
	USART_Write(USART2, (uint8_t *)"Number || Tally\r\n\r\n", 21);
	USART_Write(USART2, (uint8_t *)"===============\r\n\r\n", 21);
    
	for (p=0; p<size; p++)
	{
        c=0;
		x = measurements[p]; // Element to be counted in measurements[]
		if (p==0){//first element
			c = count(measurements, x, size);
			n = sprintf((char *)buffer, "%d || %d\r\n", x, c);
			USART_Write(USART2, buffer, n);	
            //c=0;
		}
		else{//not first element
			if (x==measurements[p-1]){//current element is the same as the last element //make sure there is no other occurence of the element in the entire array noit just the previous element
				;
			}
			else{
				c = count(measurements, x, size);
				n = sprintf((char *)buffer, "%d || %d\r\n", x, c);
				USART_Write(USART2, buffer, n);
                //c=0;
			}
	  	}
	}
}


int rerunFunc( void ){
	char rxByte;
	USART_Write(USART2, (uint8_t *)rerun, strlen(rerun));
	rxByte = USART_Read(USART2);
	if (rxByte == 'N' || rxByte == 'n'){
		USART_Write(USART2, (uint8_t *)"Exitting\r\n\r\n", 14);
		return 0;
	}
	else if (rxByte == 'Y' || rxByte == 'y'){
		USART_Write(USART2, (uint8_t *)"Rerunning Program\r\n\r\n", 23);
		return 1;
	}
	else {
		USART_Write(USART2, (uint8_t *)"Invalid Response\r\n\r\n", 22);
		return rerunFunc();
	}
}

int main( void )
{
	int pass;
    int rerunProgram;
	System_Clock_Init();	// System Clock = 80 MHz
	LED_Init();
	UART2_Init();
	init_pa0();<commit_msg>Comment for no sig on pin hang, print only within bounds, prompts need bounds shown - update report accordingly<commit_after>// <NAME> Feb. 12, 2017
#include "stm32l476xx.h" //board
#include "SysClock.h"    //Sysclock
#include "LED.h"         //LED
#include "UART.h"        //UART
#include "TIMER.h"       //TIMER
#include "input_pa0_test.h"
#include "binSearch.h"
#include "sort.h"

#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#define SAMPLES 1000				//Number of samples to be taken
#define POST_REQ_TIME 100000		//100000 microseconds = 100ms
uint8_t buffer[BufferSize]; 

char str[] = "POST failed! Pulse not seen in 100ms. Rerun? (Y or N):\r\n";
char defaultBounds[] = "Using default bounds! (950 micro & 1050 micro) Change? (Y or N):\r\n";
char rerun[] = "Rerun? (Y or N):\r\n";
int measurements[SAMPLES];	// initialize array of 1000 elements
int defaultLow = 950;		//Default Low boundary micro
int defaultHigh = 1050;		//Default High boundry micro

int FAIL( void ){
	char rxByte;
	USART_Write(USART2, (uint8_t *)str, strlen(str));
	rxByte = USART_Read(USART2);
	if (rxByte == 'N' || rxByte == 'n'){
		USART_Write(USART2, (uint8_t *)"Exitting\r\n\r\n", 14);
		//FAIL and exit program
		return 0;
	}
	else if (rxByte == 'Y' || rxByte == 'y'){
		USART_Write(USART2, (uint8_t *)"Rerunning POST\r\n\r\n", 20);
		return POST();
	}
	else {
		USART_Write(USART2, (uint8_t *)"Invalid Response\r\n\r\n", 22);
		return FAIL();
	}
}

int POST( void ) {
	int beginPostTime=0;
    start_timer();			// start capture
	beginPostTime = timer_now();
	while( 1 ){
		if ( is_event() ) {	// received edge TIM2->CCR1
			if ( ( timer_now() - beginPostTime ) <= POST_REQ_TIME ){ // test received an edge before 100000micro (100ms)
				//DISPLAY success on UART/Time seen
                USART_Write(USART2, (uint8_t *)"POST passed!\r\n\r\n", 18);
				return 1;
				break;
			}
			else{ // test received edge but too long
				//TEST FAILED!
				//OPTION TO RUN AGAIN
                USART_Write(USART2, (uint8_t *)"POST failed!\r\n\r\n", 17);
				return FAIL();
				break;
			}
		}
		//else { // nothing seen yet TIM2->CNT - ADJUST for no sig on pin
		if ( ( timer_now() - beginPostTime ) > POST_REQ_TIME ){ // exceeded 100ms 
			//TEST FAILED!
			//OPTION TO RUN AGAIN
            USART_Write(USART2, (uint8_t *)"POST failed!\r\n\r\n", 17);
			return FAIL();
			break;
		//	}
		}
	}
	stop_timer();
}

void run( void ){
	char rvByte;
    int numOfSample=0;
    int beginSampleTime=0;
	USART_Write(USART2, (uint8_t *)defaultBounds, strlen(defaultBounds));
	rvByte = USART_Read(USART2);
	if (rvByte == 'N' || rvByte == 'n'){//print with bounds, use var in write method
		USART_Write(USART2, (uint8_t *)"Running with defaults\r\n\r\n", 27);
	}
	else if (rvByte == 'Y' || rvByte == 'y'){
		USART_Write(USART2, (uint8_t *)"Changing Bounds\r\n\r\n", 21);
		//Change bounds handle user input 
		//get input
		//defaultLow = 
		//defaultHigh = 
	}
	else {
		USART_Write(USART2, (uint8_t *)"Invalid Response\r\n\r\n", 22);
		run();
	}

	//capture 1000 pulses
	//Return time it took - store in array in main
	for ( numOfSample = 0; numOfSample < SAMPLES; numOfSample++ ){//detect pulse and duration (multiply by 2 for total period?)
		start_timer();
		beginSampleTime = timer_now();
		while( 1 ){
			if ( is_event() ){
				measurements[numOfSample] = (timer_now() - beginSampleTime); //(possibly multiplied by 2)
				stop_timer(); // might need to reset
				break;
			}
			else{//edge not detected
				;
			}
		}
	}

}

void UART_graph( void ){
    int size = sizeof(measurements)/sizeof(measurements[0]);
	int x; //individual element of the array for a pass
	int c; //count of the individual element
    int p;//counter for the measurements loop
    int n;
    int sorted[SAMPLES];
    char rxByte;
    sort_array(measurements);

    //int zack=0;
    /*
    for (zack=0;zack<size;zack++){
        n = sprintf((char *)buffer, "%d \r\n", measurements[zack]);
        USART_Write(USART2, buffer, n);
    }*/
    
	USART_Write(USART2, (uint8_t *)"Number || Tally\r\n\r\n", 21);
	USART_Write(USART2, (uint8_t *)"===============\r\n\r\n", 21);
    
	for (p=0; p<size; p++)
	{
        c=0;
		x = measurements[p]; // Element to be counted in measurements[]
		if (x>=defaultLow && x<=defaultHigh){//within defined bounds
			if (p==0){//first element
				c = count(measurements, x, size);
				n = sprintf((char *)buffer, "%d || %d\r\n", x, c);
				USART_Write(USART2, buffer, n);	
	            //c=0;
			}
			else{//not first element
				if (x==measurements[p-1]){//current element is the same as the last element //make sure there is no other occurence of the element in the entire array noit just the previous element
					;
				}
				else{
					c = count(measurements, x, size);
					n = sprintf((char *)buffer, "%d || %d\r\n", x, c);
					USART_Write(USART2, buffer, n);
	                //c=0;
				}
		  	}
		}
		else{//measure time out of bounds, do not show
			;
		}
	}
}


int rerunFunc( void ){
	char rxByte;
	USART_Write(USART2, (uint8_t *)rerun, strlen(rerun));
	rxByte = USART_Read(USART2);
	if (rxByte == 'N' || rxByte == 'n'){
		USART_Write(USART2, (uint8_t *)"Exitting\r\n\r\n", 14);
		return 0;
	}
	else if (rxByte == 'Y' || rxByte == 'y'){
		USART_Write(USART2, (uint8_t *)"Rerunning Program\r\n\r\n", 23);
		return 1;
	}
	else {
		USART_Write(USART2, (uint8_t *)"Invalid Response\r\n\r\n", 22);
		return rerunFunc();
	}
}

int main( void )
{
	int pass;
    int rerunProgram;
	System_Clock_Init();	// System Clock = 80 MHz
	LED_Init();
	UART2_Init();
	init_pa0();
{'fraction_non_alphanumeric': 0.1650088314585851, 'fraction_numerical': 0.030677698243004554, 'mean_word_length': 3.0367729831144463, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '742291', 'n_tokens_mistral': 4651, 'n_tokens_neox': 4102, 'n_words': 1110}