Created
February 11, 2017 08:20
-
-
Save victoryforphil/6204fac07031b5f0a1718e63c922cc31 to your computer and use it in GitHub Desktop.
Working on GUI Logger #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Drawing; | |
using System.Linq; | |
using System.Text; | |
using System.Windows.Forms; | |
using System.Net.Sockets; | |
using System.Threading; | |
namespace TitanPlanner | |
{ | |
public partial class TitanLogger : Form | |
{ | |
delegate void SetTextCallback(string text); | |
TcpListener listener; | |
TcpClient client; | |
NetworkStream ns; | |
Thread t = null; | |
public TitanLogger() | |
{ | |
InitializeComponent(); | |
listener = new TcpListener(7777); | |
listener.Start(); | |
client = listener.AcceptTcpClient(); | |
ns = client.GetStream(); | |
t = new Thread(DoWork); | |
t.Start(); | |
} | |
public void DoWork() | |
{ | |
byte[] bytes = new byte[1024]; | |
while (true) | |
{ | |
int bytesRead = ns.Read(bytes, 0, bytes.Length); | |
this.SetText(Encoding.ASCII.GetString(bytes, 0, bytesRead)); | |
} | |
} | |
private void SetText(string text) | |
{ | |
// InvokeRequired required compares the thread ID of the | |
// calling thread to the thread ID of the creating thread. | |
// If these threads are different, it returns true. | |
if (this.listBox_logs.InvokeRequired) | |
{ | |
SetTextCallback d = new SetTextCallback(SetText); | |
this.Invoke(d, new object[] { text }); | |
} | |
else | |
{ | |
this.listBox_logs.Items.Add(text ); | |
} | |
} | |
private void label_phonestatus_Click(object sender, EventArgs e) | |
{ | |
} | |
private void label_serverstatus_Click(object sender, EventArgs e) | |
{ | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.firstinspires.ftc.teamcode; | |
import android.os.AsyncTask; | |
/** | |
* Created by VictoryForPhil on 2/10/2017. | |
*/ | |
public class TitanLogger { | |
TCPClient mTcpClient; | |
public void ConnectToServer(){ | |
new ConnectTask().execute(""); | |
if (mTcpClient != null) { | |
mTcpClient.sendMessage("{'type':'CONNECTED','message':'Robot Connected!'"); | |
}else{ | |
} | |
} | |
public void SendData(String type, String data){ | |
if (mTcpClient != null) { | |
mTcpClient.sendMessage("{'type':'"+type+"','message':'"+data+"'"); | |
}else{ | |
} | |
} | |
public class ConnectTask extends AsyncTask<String, String, TCPClient> { | |
@Override | |
protected TCPClient doInBackground(String... message) { | |
//we create a TCPClient object | |
mTcpClient = new TCPClient(new TCPClient.OnMessageReceived() { | |
@Override | |
//here the messageReceived method is implemented | |
public void messageReceived(String message) { | |
//this method calls the onProgressUpdate | |
publishProgress(message); | |
} | |
}); | |
mTcpClient.run(); | |
return null; | |
} | |
@Override | |
protected void onProgressUpdate(String... values) { | |
super.onProgressUpdate(values); | |
//response received from server | |
//process server response here.... | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.firstinspires.ftc.teamcode; | |
import android.os.AsyncTask; | |
import android.util.Log; | |
import com.qualcomm.robotcore.eventloop.opmode.Autonomous; | |
import com.qualcomm.robotcore.eventloop.opmode.Disabled; | |
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; | |
import com.qualcomm.robotcore.eventloop.opmode.TeleOp; | |
import com.qualcomm.robotcore.hardware.DcMotor; | |
import com.qualcomm.robotcore.util.ElapsedTime; | |
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; | |
import com.qualcomm.robotcore.eventloop.opmode.TeleOp; | |
import com.qualcomm.robotcore.eventloop.opmode.Disabled; | |
import com.qualcomm.robotcore.hardware.DcMotor; | |
import com.qualcomm.robotcore.hardware.DcMotorSimple; | |
import com.qualcomm.robotcore.util.ElapsedTime; | |
import org.firstinspires.ftc.robotcore.external.Telemetry; | |
@Autonomous(name="Titan Planner", group="Linear Opmode") // @Autonomous(...) is the other common choice | |
public class TitanOpTest extends LinearOpMode { | |
private ElapsedTime runtime = new ElapsedTime(); | |
private TitanLogger Logger = new TitanLogger(); | |
@Override | |
public void runOpMode() { | |
telemetry.addData("Status", "Initialized"); | |
telemetry.update(); | |
Logger.ConnectToServer(); | |
waitForStart(); | |
runtime.reset(); | |
while (opModeIsActive()) { | |
telemetry.addData("Status", "Run Time: " + runtime.toString()); | |
telemetry.update(); | |
Logger.SendData("RUNTIME", runtime.toString()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment