Commits

Nzen committed 8e25097

Encoding finished

The prior problem with 2 encoding as 3 stemmed from not changing that
portion of the fsm to test against char 0 instead of int 0. Changed the
testPhysical sample input to use every byte value. Success with hand
checked validation, so feel free to use encode() naively.

I may switch to Luis' preferred method, hashmap, on a different branch to
preserve current functionality. That will clean a bunch of the code down
to string accesses. Also, I will see if reverting to append() affects the
output on that branch.

The other aspects of this project were duly meted out today between Luis, Jonathan, & Timothy.

  • Participants
  • Parent commits fc36b87

Comments (0)

Files changed (3)

 
 public enum Comm {
-idle, startAsk, startAck, end, NULL
+quiet, idle, startAsk, startAck, end, NULL
 }

File PhysicalLayer.java

 import java.lang.StringBuilder;
 import java.lang.Math;
-import java.util.regex.*;
 
 public class PhysicalLayer
 {
 	{
 		switch( exe )
 		{
+			case quiet:
+				return "00000";
 			case idle:
 				return "11111";
 			case startAsk:
 				return "10001";
 			case end:
 				return "10011";
+			case NULL: // fall through
 			default:
 				return "";
 		}
 						else
 							codedBuff.replace( cbInd, cbInd+4, "01001" ); // 0001
 					else
-						if ( bitBuff.charAt( ind + 3 )== 0 )
+						if ( bitBuff.charAt( ind + 3 )== '0' )
 							codedBuff.replace( cbInd, cbInd+4, "10100" ); // 0010
 						else
 							codedBuff.replace( cbInd, cbInd+4, "10101" ); // 0011
 	// assuming command is the whole message, rather than appended
 	Comm whichSpecialInput( String bitString )
 	{
-		if ( bitString.equals( "11111" ) )
-			return Comm.idle;
-		else
-		{
-			if ( bitString.equals( "11000" ) )
-				return Comm.startAsk;
-			else
-			{
-				if ( bitString.equals( "10001" ) )
-					return Comm.startAck;
-				else
-				{
-					if ( bitString.equals( "10011" ) )
-						return Comm.end;
-					else
-						return Comm.NULL; // This wasn't a command, move to decode
-				}
-			}
-		}
-		
+		if ( bitString.equals( "00000" ) )
+			return Comm.quiet;
+		else if ( bitString.equals( "11111" ) )
+				return Comm.idle;
+			else if ( bitString.equals( "11000" ) )
+					return Comm.startAsk;
+				else if ( bitString.equals( "10001" ) )
+						return Comm.startAck;
+					else if ( bitString.equals( "10011" ) )
+							return Comm.end;
+						else
+							return Comm.NULL; // This wasn't a command, move to decode
 	}
 	
 	// assuming that client got Comm.Null, decode normally

File TestPhysical.java

 	static void testOutput( PhysicalLayer link )
 	{
 		String output;
-		String[ ] words = { "hi", "hi u", "OAF!" };
-		System.out.println( " originals, in hex:\n68 69 ; 68 69 20 75 ; 4F 41 46 21");
-		for ( String message : words )
-		{
-			System.out.println( message );
-			output = link.encode( message );
-			System.out.printf( "Encoded bits: %s\n", output );
-		}
-		System.out.println( " encoded, in hex:\n78 9E 3 ; 78 9E 3A 79 ED ; 57 54 95 3A 89");
-		// should be correct but I hand calculated these
-		/*	produces
-		 * 74 9D 3	/thest differ from my calculations. hmm
-		 * 74 9D 3A F9 EB	/ encoding reflects 68 69 30 75, off at 2/3
-		 * 57 54 95 3A A9	/ encoding reflects 4F 42 46 31, off at 1/2 & 2/3
-		*/
+		String message = "/>M\\kz!0HY";
+		System.out.println( "Testing />M\\kz!0HY" );
+		System.out.println( "in hex: 2F 3E 4D 5C 6B 7A 21 30 48 59" );
+		output = link.encode( message );
+		System.out.printf( "Encoded bits: %s\n", output );
+		// Actually produces codes matching 3F 3E 4D 5C 6B 7A 31 30 48 59 // circa 12 4 23
 	}
 	
 	static void pretestInput( PhysicalLayer link )
 	{
-		System.out.println( "Should print ack, end, idle, null, ask" );
-		String[ ] inputs = { "10001", "10011", "11111", "11010", "11000" };
+		System.out.println( "Should print quiet, ack, end, idle, null, ask" );
+		String[ ] inputs = { "00000", "10001", "10011", "11111", "11010", "11000" };
 		for ( String received : inputs )
-			reportCommInterpreted( link, received );
+			System.out.print( reportCommInterpreted( link, received ) );
 	}
 	
-	public static void reportCommInterpreted( PhysicalLayer link, String toTest )
+	static String reportCommInterpreted( PhysicalLayer link, String toTest )
 	{
 		switch( link.whichSpecialInput( toTest ) )
 		{
+		case quiet:
+			return "\tquiet";
 		case idle:
-			{
-			System.out.print( "\tidle" );
-			break;
-			}
+			return "\tidle";
 		case startAsk:
-			{
-			System.out.print( "\task" );
-			break;
-			}
+			return "\task";
 		case startAck:
-			{
-			System.out.print( "\tack" );
-			break;
-			}
+			return "\tack";
 		case end:
-			{
-			System.out.print( "\tend" );
-			break;
-			}
+			return "\tend";
 		case NULL:
-			{
-			System.out.print( "\tnull" ); // or test decode
-			break;
-			}
+			return "\tnull";
 		default:
-			System.out.print( "reached the unreachable" );
-			break;
+			return "\tnull";
 		}
 	}
 	
 	static void testInput( PhysicalLayer link )
 	{
-		String message = link.decode( "01110" );
+		String message = link.decode( "01110" ); // replace
 	}
+	/*0	( "11110" ) 	1	( "01001" ) 	2	( "10100" ) 	3	( "10101" )
+	4	( "01010" ) 	5	( "01011" ) 	6	( "01110" ) 	7	( "01111" )
+	8	( "10010" ) 	9	( "10011" ) 	A	( "10110" ) 	B	( "10111" )
+	C	( "11010" ) 	D	( "11011" ) 	E	( "11100" ) 	F	( "11101" )*/
 }