serial_monitor/src/serialApplication/SerialPanel.java
/* Adds new information to data, stores locations marked for error,
	 * runs ML model on error
	 */
Adds new information to data, stores locations marked for error,
runs ML model on error
Adds new information to data stores locations marked for error runs ML model on error
public void addData(String data) {
		if (data.length() > 19 && data.substring(0, 20).equals("Locations of Error: ")) {
			String test = data.substring(20);
			int a = 0, b = 1; 
			if (e > 0) {
				e = 0;
				error = new int[8];
				errorSub = new int[8];
			}
			if (test.charAt(a) == '{') { 
				while (b < test.length() - 1) {
					char bChar = test.charAt(b);
					if (bChar != ',' && bChar != ';') {
						b++;
					}
					else {
						String str = test.substring(a + 1, b);
						System.out.println("str: " + str);
						int set = Integer.parseInt(str);
						if (set >= 0) {
							if (bChar == ',') error[e] = set;
							if (bChar == ';') errorSub[e++] = set;
						}
						a = b;
						b++;
					}
				}
				for (int i = 0; i < error.length; i++) {
				System.out.println("error[" + i + "]: " + error[i]);
				System.out.println("errorSub[" + i + "]: " + errorSub[i]);
				}
			}
		}
		if (data.length() >= 19 && data.substring(0, 19).equals("ML-Corrected Data: ")) {
			String sentence; 
			String result = null;
			for (int i = 0; i < error.length; i++) {
				sentence = data.substring(19);
				if (error[i] >= 0 && error[i] < sentence.length() && errorSub[i] > 0) {
					byte alternative = 0;
					alternative = (byte) (((byte) sentence.charAt(error[i])) + Math.pow(2, 7 - errorSub[i])); 
					String test = GenerateData.sentenceToWord(sentence, error[i]);
					if (corrector.addToArff(test, (char) alternative)) {
						int bit = (int) corrector.test();
						System.out.println(bit);
						if (bit == 1) {
							System.out.println("Got into 1");
							result = data.substring(0, 19 + error[i]) + (char) alternative;
							if (result.length() < data.length()) result = result.concat(data.substring(19 + error[i] + 1, data.length()));
							System.out.println(result);
							data = result;
						}
						else if (bit == 0){
							System.out.println("Got into 0");
							result = data;
						}
					}
					if (result == null) {
						serialMonitor.append("\nSomething wrong happened.");
						break;
					}
				}
			}
			serialMonitor.append("\n" + data);
			e = 0;
			error = new int[8];
			errorSub = new int[8];
		}
		else serialMonitor.append("\n" + data);
	}
public void addData ( String data ) { if ( data . length ( ) > 19 && data . substring ( 0 , 20 ) . equals ( "Locations of Error: " ) ) { String test = data . substring ( 20 ) ; int a = 0 , b = 1 ; if ( e > 0 ) { e = 0 ; error = new int [ 8 ] ; errorSub = new int [ 8 ] ; } if ( test . charAt ( a ) == '{' ) { while ( b < test . length ( ) - 1 ) { char bChar = test . charAt ( b ) ; if ( bChar != ',' && bChar != ';' ) { b ++ ; } else { String str = test . substring ( a + 1 , b ) ; System . out . println ( "str: " + str ) ; int set = Integer . parseInt ( str ) ; if ( set >= 0 ) { if ( bChar == ',' ) error [ e ] = set ; if ( bChar == ';' ) errorSub [ e ++ ] = set ; } a = b ; b ++ ; } } for ( int i = 0 ; i < error . length ; i ++ ) { System . out . println ( "error[" + i + "]: " + error [ i ] ) ; System . out . println ( "errorSub[" + i + "]: " + errorSub [ i ] ) ; } } } if ( data . length ( ) >= 19 && data . substring ( 0 , 19 ) . equals ( "ML-Corrected Data: " ) ) { String sentence ; String result = null ; for ( int i = 0 ; i < error . length ; i ++ ) { sentence = data . substring ( 19 ) ; if ( error [ i ] >= 0 && error [ i ] < sentence . length ( ) && errorSub [ i ] > 0 ) { byte alternative = 0 ; alternative = ( byte ) ( ( ( byte ) sentence . charAt ( error [ i ] ) ) + Math . pow ( 2 , 7 - errorSub [ i ] ) ) ; String test = GenerateData . sentenceToWord ( sentence , error [ i ] ) ; if ( corrector . addToArff ( test , ( char ) alternative ) ) { int bit = ( int ) corrector . test ( ) ; System . out . println ( bit ) ; if ( bit == 1 ) { System . out . println ( "Got into 1" ) ; result = data . substring ( 0 , 19 + error [ i ] ) + ( char ) alternative ; if ( result . length ( ) < data . length ( ) ) result = result . concat ( data . substring ( 19 + error [ i ] + 1 , data . length ( ) ) ) ; System . out . println ( result ) ; data = result ; } else if ( bit == 0 ) { System . out . println ( "Got into 0" ) ; result = data ; } } if ( result == null ) { serialMonitor . append ( "\nSomething wrong happened." ) ; break ; } } } serialMonitor . append ( "\n" + data ) ; e = 0 ; error = new int [ 8 ] ; errorSub = new int [ 8 ] ; } else serialMonitor . append ( "\n" + data ) ; }
Adds new information to data, stores locations marked for error,
 runs ML model on error
Adds new information to data stores locations marked for error runs ML model on error
// Stores locations marked for error.
 // Used to parse locations from string
 // resets marked error locations if not already reset
 // parses and adds all non-trivial numbers (!= -1)
 // runs ML-Model on data
 // resets marked error locations
