package frc.team5333.core.net;

import frc.team5333.NetIDs;
import frc.team5333.core.RobotImpl;
import frc.team5333.core.drive.RobotDriveTracker;
import frc.team5333.core.monitor.PDPMonitor;
import frc.team5333.lib.ThreadMonitor;

import java.io.DataInputStream;
import java.io.IOException;

/**
 * Parses data coming from clients and acts accordingly
 *
 * @author Jaci
 */
public class NetParser {

    public static void parse(NetIDs id, float data, NetworkedClient client) {
        switch (id) {
            case DRIVE_LEFT:
                RobotDriveTracker.setLeft(data);
                break;
            case DRIVE_RIGHT:
                RobotDriveTracker.setRight(data);
                break;
        }
    }

    public static void parse(NetIDs id, String data, NetworkedClient client) throws IOException {
        try {
            switch (id) {
                case COMMAND:
                    if (data.equalsIgnoreCase("ping"))
                        RobotImpl.log().info("pong");
                    if (data.equalsIgnoreCase("pig"))
                        RobotImpl.log().info("pog");

                    if (data.equalsIgnoreCase("stktce"))
                        RobotImpl.log().info(ThreadMonitor.getFormattedStackTrace(null));

                    if (data.startsWith("pdp"))
                        PDPMonitor.parse(data.split(" "));

                    break;
            }
        } catch (Exception e) {}
    }

}

@@ -883,16 +883,70 @@
 OMMAND:%0A
+                    String%5B%5D split = data.split(%22 %22);%0A
         
@@ -1187,36 +1187,207 @@
 ata.
-equalsIgnoreCase(%22stktce%22))%0A
+startsWith(%22stktce%22))%0A                        if (split.length %3E 1)%0A                            RobotImpl.log().info(ThreadMonitor.getFormattedStackTrace(split%5B1%5D));%0A                        else%0A    
     
@@ -1562,31 +1562,21 @@
 r.parse(
-data.split(%22 %22)
+split
 );%0A%0A    

parse stktce