Browse Source

Merge remote-tracking branch 'origin/yigit' into efe

efe
Efe Aydın 6 years ago
parent
commit
3a94b830db
43 changed files with 507522 additions and 355609 deletions
  1. +43
    -0
      Ev3/main.py
  2. +21
    -28
      MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java
  3. +11
    -5
      MyCity/app/src/main/java/gq/yigit/mycity/MainFragment.java
  4. +487
    -30
      master_app/src/main/java/me/yigitcolakoglu/master_app/cameraForm.form
  5. +602
    -125
      master_app/src/main/java/me/yigitcolakoglu/master_app/cameraForm.java
  6. +1
    -1
      master_app/src/main/java/me/yigitcolakoglu/master_app/ips.json
  7. +0
    -0
      master_app/target/classes/.netbeans_automatic_build
  8. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/Main.class
  9. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm$1.class
  10. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm$2.class
  11. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm$3.class
  12. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm$4.class
  13. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm.class
  14. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$1.class
  15. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$2.class
  16. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$3.class
  17. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$4.class
  18. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$5.class
  19. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$6.class
  20. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$7.class
  21. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$8.class
  22. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$9.class
  23. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/managementForm.class
  24. BIN
      master_app/target/master_app-1.0-SNAPSHOT.jar
  25. +1
    -1
      master_app/target/maven-archiver/pom.properties
  26. +2
    -3
      master_app/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
  27. +3
    -3
      master_app/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
  28. +0
    -0
      master_app/target/test-classes/.netbeans_automatic_build
  29. +3
    -2
      server_side/api/app.py
  30. +3
    -3
      server_side/api/modules/SpotSelector.py
  31. +36
    -36
      server_side/api/modules/car_crash.py
  32. +114669
    -111650
      server_side/api/modules/databases/bus.json
  33. +42
    -0
      server_side/api/modules/databases/complaints.json
  34. +21
    -7
      server_side/api/modules/databases/locations.json
  35. +391375
    -243479
      server_side/api/modules/databases/park_data.json
  36. +3
    -4
      server_side/api/modules/smart_park.py
  37. +12
    -1
      server_side/api/modules/user_info.py
  38. +6
    -0
      telnet/.vscode/arduino.json
  39. +19
    -0
      telnet/.vscode/c_cpp_properties.json
  40. +5
    -0
      telnet/.vscode/settings.json
  41. +89
    -0
      telnet/main.ino
  42. +68
    -0
      telnet/main/main.ino
  43. +0
    -231
      telnet/telnet.ino

+ 43
- 0
Ev3/main.py View File

@ -0,0 +1,43 @@
#!/usr/bin/env python3
print("[INFO]: Interpreter started")
from ev3dev.core import *
print("[INFO]: Imported ev3dev.ev3")
import socket
print("[INFO]: Imported socket")
import os
print("[INFO]: Imported os")
import json
print("[INFO]: Imported json")
HOST = '0.0.0.0'
PORT = 3131
mjpeg_loc = "/home/robot/mjpeg-streamer/mjpeg-streamer-experimantal/mjpeg-streamer"
os.spawnl(os.P_DETACH, ' -i "./input_uvc.so -f 15 -r 640x480" -o "./output_http.so -w ./www"')
power = PowerSupply()
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
try:
s.bind((HOST, PORT))
while True:
s.listen()
print("[INFO]: Listening...")
conn, addr = s.accept()
with conn:
print('[INFO]: Connected by', addr)
while True:
try:
data = {
"battery_voltage":power.measured_volts,
"current_drawn":power.measured_amps,
"lat":31,
"lng":39
}
conn.send((json.dumps(data, ensure_ascii=False)+"\n").encode('gbk'))
except BrokenPipeError:
print("[INFO]: Client disconnected")
break
except KeyboardInterrupt:
s.close()

+ 21
- 28
MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java View File

@ -7,6 +7,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
@ -19,6 +20,7 @@ import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.util.Base64;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.*;
@ -70,12 +72,10 @@ public class MainActivity extends AppCompatActivity
ComplaintViewFragment.OnFragmentInteractionListener,
CrashFragment.OnFragmentInteractionListener,
CrashMapFragment.OnFragmentInteractionListener,
responseListener,
imageListener {
responseListener{
public static Context cntxt;
public static JSONObject userData;
public static Bitmap userAvatar;
private String url;
private ImageView avatarView;
private TextView userName;
@ -323,36 +323,29 @@ public class MainActivity extends AppCompatActivity
public void receivedResponse(boolean success,String response,int reqid){
if(success) {
try {
JSONArray receivedData = new JSONArray(response);
if(!(boolean)receivedData.get(0)){
Toast.makeText(cntxt,"Please login again!",Toast.LENGTH_LONG).show();
}else{
if (reqid == 0) {
try {
JSONArray receivedData = new JSONArray(response);
if (!(boolean) receivedData.get(0)) {
Toast.makeText(cntxt, "Please login again!", Toast.LENGTH_LONG).show();
} else {
userData = new JSONObject(receivedData.get(1).toString());
Log.i("[INFO]", userData.toString());
byte[] decodedString = Base64.decode(userData.getString("image"), Base64.DEFAULT);
Bitmap img = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
avatarView.setImageBitmap(img);
userName.setText(userData.getString("realname"));
}
} catch (Exception e) {
Log.e("[ERROR]", "Cannot receive userdata");
userData = new JSONObject(receivedData.get(1).toString());
Log.i("[INFO]",userData.toString());
ImageDownload avatar_downloader = new ImageDownload();
avatar_downloader.addListener(this);
avatar_downloader.execute(url +"/img/"+ userData.get("id")+".png");
userName.setText(userData.getString("realname"));
}
}catch (Exception e){
Log.e("[ERROR]","Cannot receive userdata");
}
}
}
public void imageDownloaded(Bitmap img){
try {
userAvatar = img;
if(userAvatar != null) {
avatarView.setImageBitmap(img);
}
}catch(Exception e){
Log.e("[ERROR]","Cannot set avatar!");
}
}
@Override
public void onListFragmentInteraction(ComplaintsContent.ComplaintItem item){


+ 11
- 5
MyCity/app/src/main/java/gq/yigit/mycity/MainFragment.java View File

@ -71,17 +71,23 @@ public class MainFragment extends Fragment implements WebRequest.responseListene
swipeRefreshLayout = rootView.findViewById(R.id.simpleSwipeRefreshLayout);
HashMap<String,String> params = new HashMap<>();
Location curloc = null;
try {
while(true) {
for(int i = 0;i<10;i++) {
try {
Location curloc = MainActivity.locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
curloc = MainActivity.locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
params.put("lat", String.valueOf(curloc.getLatitude()));
params.put("lon", String.valueOf(curloc.getLongitude()));
}catch (NullPointerException e){
break;
continue;
}
break;
}
try {
params.put("lat", String.valueOf(curloc.getLatitude()));
params.put("lon", String.valueOf(curloc.getLongitude()));
}catch (NullPointerException e){
params.put("lat", "39.9123762");
params.put("lon", "32.8097898");
}
}catch (SecurityException e){
Log.e("[ERROR]", "An error occured with location permissions");


+ 487
- 30
master_app/src/main/java/me/yigitcolakoglu/master_app/cameraForm.form View File

@ -82,15 +82,19 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="30" max="-2" attributes="0"/>
<Component id="intersection_label" min="-2" pref="1024" max="-2" attributes="0"/>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace min="-2" pref="185" max="-2" attributes="0"/>
<Component id="ambulance_label" min="-2" pref="250" max="-2" attributes="0"/>
<EmptySpace pref="204" max="32767" attributes="0"/>
<Component id="camera_full_label" min="-2" pref="1280" max="-2" attributes="0"/>
<EmptySpace pref="31" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
<Component id="ambulance_button" min="-2" pref="247" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="475" max="-2" attributes="0"/>
</Group>
</Group>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="32767" attributes="0"/>
<Component id="fps_label" min="-2" max="-2" attributes="0"/>
@ -105,10 +109,13 @@
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace min="-2" pref="52" max="-2" attributes="0"/>
<Component id="fps_label" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="88" max="-2" attributes="0"/>
<Component id="ambulance_label" min="-2" pref="280" max="-2" attributes="0"/>
<Component id="camera_full_label" min="-2" pref="720" max="-2" attributes="0"/>
<EmptySpace pref="27" max="32767" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="ambulance_button" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="manage_button" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="29" max="-2" attributes="0"/>
@ -121,31 +128,25 @@
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="intersection_label">
<Component class="javax.swing.JLabel" name="camera_full_label">
<Properties>
<Property name="alignmentY" type="float" value="0.0"/>
<Property name="name" type="java.lang.String" value="" noResource="true"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="ambulance_label">
<Component class="javax.swing.JButton" name="ambulance_button">
<Properties>
<Property name="name" type="java.lang.String" value="" noResource="true"/>
<Property name="text" type="java.lang.String" value="Start"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="ambulance_buttonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="fps_label">
<Component class="javax.swing.JLabel" name="camera_cut_label">
<Properties>
<Property name="text" type="java.lang.String" value="0 FPS"/>
<Property name="text" type="java.lang.String" value="camera_cut"/>
</Properties>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel6">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription">
<JTabbedPaneConstraints tabName="Traffic Lights">
<Property name="tabTitle" type="java.lang.String" value="Traffic Lights"/>
</JTabbedPaneConstraints>
</Constraint>
</Constraints>
<Container class="javax.swing.JPanel" name="jPanel3">
<Layout>
<DimensionLayout dim="0">
@ -185,11 +186,455 @@
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel4">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription">
<JTabbedPaneConstraints tabName="Lights">
<Property name="tabTitle" type="java.lang.String" value="Lights"/>
</JTabbedPaneConstraints>
</Constraint>
</Constraints>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="276" max="-2" attributes="0"/>
<Component id="jLabel8" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="jLabel9" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="241" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<EmptySpace min="-2" pref="125" max="-2" attributes="0"/>
<Component id="jPanel5" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="526" max="32767" attributes="0"/>
<Component id="jPanel6" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="33" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel9" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel8" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="4" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jPanel6" alignment="0" max="32767" attributes="0"/>
<Component id="jPanel5" alignment="0" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JPanel" name="jPanel5">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.BevelBorderInfo">
<BevelBorder/>
</Border>
</Property>
</Properties>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace pref="109" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="intersect_1_G" min="-2" pref="196" max="-2" attributes="0"/>
<Component id="intersect_1_R" min="-2" pref="196" max="-2" attributes="0"/>
<Component id="intersect_1_Y" min="-2" pref="196" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="107" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace min="-2" pref="54" max="-2" attributes="0"/>
<Component id="intersect_1_R" min="-2" pref="196" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="45" max="-2" attributes="0"/>
<Component id="intersect_1_Y" min="-2" pref="196" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="45" max="-2" attributes="0"/>
<Component id="intersect_1_G" min="-2" pref="196" max="-2" attributes="0"/>
<EmptySpace pref="49" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="intersect_1_Y">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="cc" green="cc" red="cc" type="rgb"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="cc" green="cc" red="cc" type="rgb"/>
</Property>
<Property name="opaque" type="boolean" value="true"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="intersect_1_G">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="cc" green="cc" red="cc" type="rgb"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="cc" green="cc" red="cc" type="rgb"/>
</Property>
<Property name="opaque" type="boolean" value="true"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="intersect_1_R">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="cc" green="cc" red="cc" type="rgb"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="cc" green="cc" red="cc" type="rgb"/>
</Property>
<Property name="opaque" type="boolean" value="true"/>
</Properties>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel6">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.BevelBorderInfo">
<BevelBorder/>
</Border>
</Property>
</Properties>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace pref="159" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="intersect_2_G" min="-2" pref="196" max="-2" attributes="0"/>
<Component id="intersect_2_R" min="-2" pref="196" max="-2" attributes="0"/>
<Component id="intersect_2_Y" min="-2" pref="196" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="163" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace min="-2" pref="36" max="-2" attributes="0"/>
<Component id="intersect_2_R" min="-2" pref="196" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="53" max="-2" attributes="0"/>
<Component id="intersect_2_Y" min="-2" pref="196" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="intersect_2_G" min="-2" pref="196" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="38" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="intersect_2_Y">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="cc" green="cc" red="cc" type="rgb"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="cc" green="cc" red="cc" type="rgb"/>
</Property>
<Property name="opaque" type="boolean" value="true"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="intersect_2_G">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="cc" green="cc" red="cc" type="rgb"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="cc" green="cc" red="cc" type="rgb"/>
</Property>
<Property name="opaque" type="boolean" value="true"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="intersect_2_R">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="cc" green="cc" red="cc" type="rgb"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="99" green="99" red="ff" type="rgb"/>
</Property>
<Property name="opaque" type="boolean" value="true"/>
</Properties>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JLabel" name="jLabel8">
<Properties>
<Property name="text" type="java.lang.String" value="Intersection 1"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel9">
<Properties>
<Property name="text" type="java.lang.String" value="Intersection 2"/>
</Properties>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel7">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription">
<JTabbedPaneConstraints tabName="Robot Cam">
<Property name="tabTitle" type="java.lang.String" value="Robot Cam"/>
</JTabbedPaneConstraints>
</Constraint>
</Constraints>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="449" max="-2" attributes="0"/>
<Component id="robot_cam_label" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="1173" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="243" max="-2" attributes="0"/>
<Component id="robot_cam_label" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="573" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="robot_cam_label">
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel4">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription">
<JTabbedPaneConstraints tabName="Lights">
<Property name="tabTitle" type="java.lang.String" value="Lights"/>
</JTabbedPaneConstraints>
</Constraint>
</Constraints>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="276" max="-2" attributes="0"/>
<Component id="jLabel8" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="jLabel9" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="241" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<EmptySpace min="-2" pref="125" max="-2" attributes="0"/>
<Component id="jPanel5" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="526" max="32767" attributes="0"/>
<Component id="jPanel6" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="33" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel9" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel8" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="4" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jPanel6" alignment="0" max="32767" attributes="0"/>
<Component id="jPanel5" alignment="0" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JPanel" name="jPanel5">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.BevelBorderInfo">
<BevelBorder/>
</Border>
</Property>
</Properties>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace pref="109" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="intersect_1_G" min="-2" pref="196" max="-2" attributes="0"/>
<Component id="intersect_1_R" min="-2" pref="196" max="-2" attributes="0"/>
<Component id="intersect_1_Y" min="-2" pref="196" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="107" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace min="-2" pref="54" max="-2" attributes="0"/>
<Component id="intersect_1_R" min="-2" pref="196" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="45" max="-2" attributes="0"/>
<Component id="intersect_1_Y" min="-2" pref="196" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="45" max="-2" attributes="0"/>
<Component id="intersect_1_G" min="-2" pref="196" max="-2" attributes="0"/>
<EmptySpace pref="49" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="intersect_1_Y">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="cc" green="cc" red="cc" type="rgb"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="cc" green="cc" red="cc" type="rgb"/>
</Property>
<Property name="opaque" type="boolean" value="true"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="intersect_1_G">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="cc" green="cc" red="cc" type="rgb"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="cc" green="cc" red="cc" type="rgb"/>
</Property>
<Property name="opaque" type="boolean" value="true"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="intersect_1_R">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="cc" green="cc" red="cc" type="rgb"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="cc" green="cc" red="cc" type="rgb"/>
</Property>
<Property name="opaque" type="boolean" value="true"/>
</Properties>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel6">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.BevelBorderInfo">
<BevelBorder/>
</Border>
</Property>
</Properties>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace pref="159" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="intersect_2_G" min="-2" pref="196" max="-2" attributes="0"/>
<Component id="intersect_2_R" min="-2" pref="196" max="-2" attributes="0"/>
<Component id="intersect_2_Y" min="-2" pref="196" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="163" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace min="-2" pref="36" max="-2" attributes="0"/>
<Component id="intersect_2_R" min="-2" pref="196" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="53" max="-2" attributes="0"/>
<Component id="intersect_2_Y" min="-2" pref="196" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="intersect_2_G" min="-2" pref="196" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="38" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="intersect_2_Y">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="cc" green="cc" red="cc" type="rgb"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="cc" green="cc" red="cc" type="rgb"/>
</Property>
<Property name="opaque" type="boolean" value="true"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="intersect_2_G">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="cc" green="cc" red="cc" type="rgb"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="cc" green="cc" red="cc" type="rgb"/>
</Property>
<Property name="opaque" type="boolean" value="true"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="intersect_2_R">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="cc" green="cc" red="cc" type="rgb"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="99" green="99" red="ff" type="rgb"/>
</Property>
<Property name="opaque" type="boolean" value="true"/>
</Properties>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JLabel" name="jLabel8">
<Properties>
<Property name="text" type="java.lang.String" value="Intersection 1"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel9">
<Properties>
<Property name="text" type="java.lang.String" value="Intersection 2"/>
</Properties>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel7">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription">
<JTabbedPaneConstraints tabName="Loads">
<Property name="tabTitle" type="java.lang.String" value="Loads"/>
<JTabbedPaneConstraints tabName="Robot Cam">
<Property name="tabTitle" type="java.lang.String" value="Robot Cam"/>
</JTabbedPaneConstraints>
</Constraint>
</Constraints>
@ -197,15 +642,27 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="1693" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="449" max="-2" attributes="0"/>
<Component id="robot_cam_label" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="1173" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="978" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="243" max="-2" attributes="0"/>
<Component id="robot_cam_label" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="573" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="robot_cam_label">
</Component>
</SubComponents>
</Container>
</SubComponents>
</Container>


+ 602
- 125
master_app/src/main/java/me/yigitcolakoglu/master_app/cameraForm.java View File

@ -13,11 +13,13 @@ import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.util.Base64;
import javax.imageio.ImageIO;
import javax.net.ssl.HttpsURLConnection;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import net.schmizz.sshj.common.IOUtils;
import org.json.JSONObject;
/**
@ -36,6 +38,7 @@ public class cameraForm extends javax.swing.JFrame implements ChangeListener{
private ServerSocket server;
private Socket client;
private Thread running = null;
private boolean listening = false;
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
@ -47,14 +50,40 @@ public class cameraForm extends javax.swing.JFrame implements ChangeListener{
jPanel1 = new javax.swing.JPanel();
jTabbedPane1 = new javax.swing.JTabbedPane();
jPanel5 = new javax.swing.JPanel();
intersection_label = new javax.swing.JLabel();
ambulance_label = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
camera_full_label = new javax.swing.JLabel();
ambulance_button = new javax.swing.JButton();
camera_cut_label = new javax.swing.JLabel();
jPanel3 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
gpu_usage = new javax.swing.JLabel();
gpu_temp = new javax.swing.JLabel();
cpu_usage = new javax.swing.JLabel();
cpu_temp = new javax.swing.JLabel();
ram_usage = new javax.swing.JLabel();
ram_temp = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
fan_rpm = new javax.swing.JLabel();
fps_label = new javax.swing.JLabel();
manage_button = new javax.swing.JButton();
jPanel4 = new javax.swing.JPanel();
jPanel5 = new javax.swing.JPanel();
intersect_1_Y = new javax.swing.JLabel();
intersect_1_G = new javax.swing.JLabel();
intersect_1_R = new javax.swing.JLabel();
jPanel6 = new javax.swing.JPanel();
light_1_label = new javax.swing.JLabel();
light_2_label = new javax.swing.JLabel();
intersect_2_Y = new javax.swing.JLabel();
intersect_2_G = new javax.swing.JLabel();
intersect_2_R = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jPanel7 = new javax.swing.JPanel();
robot_cam_label = new javax.swing.JLabel();
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
@ -80,43 +109,14 @@ public class cameraForm extends javax.swing.JFrame implements ChangeListener{
}
});
intersection_label.setAlignmentY(0.0F);
ambulance_label.setName(""); // NOI18N
camera_full_label.setText(" ");
fps_label.setText("0 FPS");
javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
jPanel5.setLayout(jPanel5Layout);
jPanel5Layout.setHorizontalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createSequentialGroup()
.addGap(30, 30, 30)
.addComponent(intersection_label, javax.swing.GroupLayout.PREFERRED_SIZE, 1024, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createSequentialGroup()
.addGap(185, 185, 185)
.addComponent(ambulance_label, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(204, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(fps_label)
.addGap(168, 168, 168))))
);
jPanel5Layout.setVerticalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createSequentialGroup()
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createSequentialGroup()
.addGap(52, 52, 52)
.addComponent(fps_label)
.addGap(88, 88, 88)
.addComponent(ambulance_label, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel5Layout.createSequentialGroup()
.addGap(29, 29, 29)
.addComponent(intersection_label, javax.swing.GroupLayout.PREFERRED_SIZE, 768, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(181, Short.MAX_VALUE))
);
ambulance_button.setText("Start");
ambulance_button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ambulance_buttonActionPerformed(evt);
}
});
jTabbedPane1.addTab("Intersection & Ambulance", jPanel5);
@ -147,18 +147,346 @@ public class cameraForm extends javax.swing.JFrame implements ChangeListener{
jTabbedPane1.addTab("Traffic Lights", jPanel6);
fan_rpm.setFont(new java.awt.Font("Dialog", 1, 24)); // NOI18N
fan_rpm.setText("2500 RPM");
fps_label.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N
fps_label.setText("60 FPS");
manage_button.setText("Management");
manage_button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
manage_buttonActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(camera_full_label, javax.swing.GroupLayout.PREFERRED_SIZE, 1280, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(ambulance_button, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(475, 475, 475)))
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(fan_rpm, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addComponent(fps_label, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(86, 86, 86)))
.addGap(18, 18, 18))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(camera_cut_label, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addComponent(manage_button, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(95, 95, 95))))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(32, 32, 32)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(camera_full_label, javax.swing.GroupLayout.PREFERRED_SIZE, 720, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(ambulance_button)
.addComponent(manage_button))
.addContainerGap())
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(camera_cut_label, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(180, 180, 180)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel7)
.addComponent(fan_rpm, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(fps_label, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(110, 110, 110))))
);
jTabbedPane1.addTab("Loads", jPanel7);
jPanel5.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
intersect_1_Y.setBackground(new java.awt.Color(204, 204, 204));
intersect_1_Y.setForeground(new java.awt.Color(204, 204, 204));
intersect_1_Y.setOpaque(true);
intersect_1_G.setBackground(new java.awt.Color(204, 204, 204));
intersect_1_G.setForeground(new java.awt.Color(204, 204, 204));
intersect_1_G.setOpaque(true);
intersect_1_R.setBackground(new java.awt.Color(204, 204, 204));
intersect_1_R.setForeground(new java.awt.Color(204, 204, 204));
intersect_1_R.setOpaque(true);
javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
jPanel5.setLayout(jPanel5Layout);
jPanel5Layout.setHorizontalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
.addContainerGap(109, Short.MAX_VALUE)
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(intersect_1_G, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(intersect_1_R, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(intersect_1_Y, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(107, 107, 107))
);
jPanel5Layout.setVerticalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
.addGap(54, 54, 54)
.addComponent(intersect_1_R, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(45, 45, 45)
.addComponent(intersect_1_Y, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(45, 45, 45)
.addComponent(intersect_1_G, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(49, Short.MAX_VALUE))
);
jPanel6.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
intersect_2_Y.setBackground(new java.awt.Color(204, 204, 204));
intersect_2_Y.setForeground(new java.awt.Color(204, 204, 204));
intersect_2_Y.setOpaque(true);
intersect_2_G.setBackground(new java.awt.Color(204, 204, 204));
intersect_2_G.setForeground(new java.awt.Color(204, 204, 204));
intersect_2_G.setOpaque(true);
intersect_2_R.setBackground(new java.awt.Color(204, 204, 204));
intersect_2_R.setForeground(new java.awt.Color(255, 153, 153));
intersect_2_R.setOpaque(true);
javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
jPanel6.setLayout(jPanel6Layout);
jPanel6Layout.setHorizontalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
.addContainerGap(159, Short.MAX_VALUE)
.addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(intersect_2_G, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(intersect_2_R, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(intersect_2_Y, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(163, 163, 163))
);
jPanel6Layout.setVerticalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
.addGap(36, 36, 36)
.addComponent(intersect_2_R, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(53, 53, 53)
.addComponent(intersect_2_Y, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(intersect_2_G, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(38, 38, 38))
);
jLabel8.setText("Intersection 1");
jLabel9.setText("Intersection 2");
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addGap(276, 276, 276)
.addComponent(jLabel8)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel9)
.addGap(241, 241, 241))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
.addGap(125, 125, 125)
.addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 526, Short.MAX_VALUE)
.addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(33, 33, 33))
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel9)
.addComponent(jLabel8))
.addGap(4, 4, 4)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
jTabbedPane1.addTab("Lights", jPanel4);
javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
jPanel7.setLayout(jPanel7Layout);
jPanel7Layout.setHorizontalGroup(
jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 1693, Short.MAX_VALUE)
.addGroup(jPanel7Layout.createSequentialGroup()
.addGap(449, 449, 449)
.addComponent(robot_cam_label)
.addContainerGap(1173, Short.MAX_VALUE))
);
jPanel7Layout.setVerticalGroup(
jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 978, Short.MAX_VALUE)
.addGroup(jPanel7Layout.createSequentialGroup()
.addGap(243, 243, 243)
.addComponent(robot_cam_label)
.addContainerGap(573, Short.MAX_VALUE))
);
jTabbedPane1.addTab("Loads", jPanel7);
jTabbedPane1.addTab("Robot Cam", jPanel7);
jPanel5.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
intersect_1_Y.setBackground(new java.awt.Color(204, 204, 204));
intersect_1_Y.setForeground(new java.awt.Color(204, 204, 204));
intersect_1_Y.setOpaque(true);
intersect_1_G.setBackground(new java.awt.Color(204, 204, 204));
intersect_1_G.setForeground(new java.awt.Color(204, 204, 204));
intersect_1_G.setOpaque(true);
intersect_1_R.setBackground(new java.awt.Color(204, 204, 204));
intersect_1_R.setForeground(new java.awt.Color(204, 204, 204));
intersect_1_R.setOpaque(true);
javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
jPanel5.setLayout(jPanel5Layout);
jPanel5Layout.setHorizontalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
.addContainerGap(109, Short.MAX_VALUE)
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(intersect_1_G, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(intersect_1_R, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(intersect_1_Y, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(107, 107, 107))
);
jPanel5Layout.setVerticalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
.addGap(54, 54, 54)
.addComponent(intersect_1_R, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(45, 45, 45)
.addComponent(intersect_1_Y, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(45, 45, 45)
.addComponent(intersect_1_G, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(49, Short.MAX_VALUE))
);
jPanel6.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
intersect_2_Y.setBackground(new java.awt.Color(204, 204, 204));
intersect_2_Y.setForeground(new java.awt.Color(204, 204, 204));
intersect_2_Y.setOpaque(true);
intersect_2_G.setBackground(new java.awt.Color(204, 204, 204));
intersect_2_G.setForeground(new java.awt.Color(204, 204, 204));
intersect_2_G.setOpaque(true);
intersect_2_R.setBackground(new java.awt.Color(204, 204, 204));
intersect_2_R.setForeground(new java.awt.Color(255, 153, 153));
intersect_2_R.setOpaque(true);
javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
jPanel6.setLayout(jPanel6Layout);
jPanel6Layout.setHorizontalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
.addContainerGap(159, Short.MAX_VALUE)
.addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(intersect_2_G, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(intersect_2_R, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(intersect_2_Y, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(163, 163, 163))
);
jPanel6Layout.setVerticalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
.addGap(36, 36, 36)
.addComponent(intersect_2_R, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(53, 53, 53)
.addComponent(intersect_2_Y, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(intersect_2_G, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(38, 38, 38))
);
jLabel8.setText("Intersection 1");
jLabel9.setText("Intersection 2");
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addGap(276, 276, 276)
.addComponent(jLabel8)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel9)
.addGap(241, 241, 241))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
.addGap(125, 125, 125)
.addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 526, Short.MAX_VALUE)
.addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(33, 33, 33))
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel9)
.addComponent(jLabel8))
.addGap(4, 4, 4)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
jTabbedPane1.addTab("Lights", jPanel4);
javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
jPanel7.setLayout(jPanel7Layout);
jPanel7Layout.setHorizontalGroup(
jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel7Layout.createSequentialGroup()
.addGap(449, 449, 449)
.addComponent(robot_cam_label)
.addContainerGap(1173, Short.MAX_VALUE))
);
jPanel7Layout.setVerticalGroup(
jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel7Layout.createSequentialGroup()
.addGap(243, 243, 243)
.addComponent(robot_cam_label)
.addContainerGap(573, Short.MAX_VALUE))
);
jTabbedPane1.addTab("Robot Cam", jPanel7);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
@ -235,9 +563,42 @@ public class cameraForm extends javax.swing.JFrame implements ChangeListener{
}//GEN-LAST:event_jTabbedPane1MouseExited
private void jTabbedPane1MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTabbedPane1MouseEntered
if(!listening){
jTabbedPane1.addChangeListener(this);
System.out.println("Added listener");
listening = true;
}
}//GEN-LAST:event_jTabbedPane1MouseEntered
private void manage_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_manage_buttonActionPerformed
managementForm settings = new managementForm();
settings.setVisible(true);
settings.initIp();
}//GEN-LAST:event_manage_buttonActionPerformed
private void ambulance_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ambulance_buttonActionPerformed
if(running!=null){
try{
server.close();
client.close();
running.stop();
}catch(IOException e){
System.out.println("IO Exception occured");
}catch(Exception e){
System.out.println(e.toString());
}
}else{
running = new Thread(() -> {
try{
onCreate(8485,"Ambulance");
}catch(Exception e){
System.out.println(e.toString());
}
});
running.start();
}
}//GEN-LAST:event_ambulance_buttonActionPerformed
/**
* @param args the command line arguments
*/
@ -263,6 +624,7 @@ public class cameraForm extends javax.swing.JFrame implements ChangeListener{
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new cameraForm().setVisible(true);
}});
@ -270,31 +632,50 @@ public class cameraForm extends javax.swing.JFrame implements ChangeListener{
public void onCreate(int port, String name) throws Exception{
boolean run = true;
if ("lights".equals(name)) {
Socket clientSocket = new Socket("192.168.2.174",69);
int c;
InputStream in = clientSocket.getInputStream();
String message = "";
while((c=in.read()) != -1){
if (c == 10 || c == 13) {
break;
}
message += (char) c;
if (name == "robot") {
while (run) {
BufferedImage image = null;
URL img_url = new URL("http://10.10.26.141:8080/?action=snapshot");
image = ImageIO.read(img_url);
robot_cam_label.setIcon(new ImageIcon(image));
URL obj = new URL("http://10.10.26.164:5001/ai");
HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
con.setRequestMethod("POST");
byte[] imageBytes = IOUtils.toByteArray(img_url);
String base64 = Base64.getEncoder().encodeToString(imageBytes);
String params = "type=coco&img=" + base64;
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(params);
wr.flush();
wr.close();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
JSONObject json = new JSONObject(response.toString());
Graphics2D g2d = image.createGraphics();
}
this.light_1_label.setText("Light 1: " + message.charAt(0));
this.light_2_label.setText("Light 2: " + message.charAt(2));
System.out.println(message);
return;
}
this.intersection_label.setIcon(new ImageIcon());
this.ambulance_label.setIcon(new ImageIcon());
this.camera_cut_label.setIcon(new ImageIcon());
this.camera_full_label.setIcon(new ImageIcon());
String fromClient = "";
String toClient;
server = new ServerSocket(port);
System.out.println("wait for connection on port " + port);
jTabbedPane1.addChangeListener(this);
client = server.accept();
System.out.println("got connection on port " + port);
BufferedImage image = null;
@ -302,70 +683,99 @@ public class cameraForm extends javax.swing.JFrame implements ChangeListener{
int null_reps = 0;
int fps_sum = 0;
int reps = 0;
while(run) {
try{
long start = System.currentTimeMillis();
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
fromClient = in.readLine();
if(fromClient != null) {
if(fromClient.trim().equals("Bye")) {
run = false;
System.out.println("socket closed");
}else{
System.out.println("received data in size: " + fromClient.length());
JSONObject json = new JSONObject(fromClient);
byte[] decodedBytes = Base64.getDecoder().decode(json.getString("image_full"));
ByteArrayInputStream bis = new ByteArrayInputStream(decodedBytes);
image = ImageIO.read(bis);
bis.close();
if ("cams".equals(name)) {
this.intersection_label.setIcon(new ImageIcon(resizeImage(image,1024, 768)));
if(name.equals("cams")){
while(run) {
try{
long start = System.currentTimeMillis();
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
fromClient = in.readLine();
if(fromClient != null) {
if(fromClient.trim().equals("Bye")) {
run = false;
System.out.println("socket closed");
}else{
System.out.println("received data in size: " + fromClient.length());
JSONObject json = new JSONObject(fromClient);
byte[] decodedBytes = Base64.getDecoder().decode(json.getString("image_full"));
ByteArrayInputStream bis = new ByteArrayInputStream(decodedBytes);
image = ImageIO.read(bis);
bis.close();
JSONObject dims = json.getJSONObject("image_sizes");
this.ambulance_label.setIcon(new ImageIcon(resizeImage(image.getSubimage(dims.getInt("x"), dims.getInt("y"), dims.getInt("width"), dims.getInt("height")),250,280)));
} else if ("Loads".equals(name)) {
this.camera_full_label.setIcon(new ImageIcon(resizeImage(image,1280,720)));
this.camera_cut_label.setIcon(new ImageIcon(resizeImage(image.getSubimage(dims.getInt("x"), dims.getInt("y"), dims.getInt("width"), dims.getInt("height")),300,300)));
JSONObject data = json.optJSONObject("load");
/*this.gpu_temp.setText(data.getString("gpu_temp"));
this.gpu_usage.setText(daqqta.getString("gpu_load"));
this.gpu_temp.setText(data.getString("gpu_temp"));
this.gpu_usage.setText(data.getString("gpu_load"));
this.cpu_temp.setText(data.getString("cpu_temp"));
this.cpu_usage.setText(data.getString("cpu_load"));
this.ram_temp.setText(data.getString("mem_temp"));
this.ram_usage.setText(data.getString("mem_load"));
this.fan_rpm.setText(data.getString("fan_speed"));*/
}
null_reps=0;
long end = System.currentTimeMillis();
float sec = (end - start) / 1000F;
fps_sum += Math.round(1/sec);
reps+=1;
if(reps%10==0){
this.fps_label.setText(fps_sum/10 + " FPS");
fps_sum=0;
this.fan_rpm.setText(data.getString("fan_speed"));
null_reps=0;
long end = System.currentTimeMillis();
float sec = (end - start) / 1000F;
fps_sum += Math.round(1/sec);
reps+=1;
if(reps%10==0){
this.fps_label.setText(fps_sum/10 + " FPS");
fps_sum=0;
}
}
}else{
null_reps +=1;
}
}else{
null_reps +=1;
}
catch(Exception e){
System.out.println(fromClient);
System.out.println(e.toString());
null_reps+=1;
}
if (null_reps >= 1000000000){
run = false;
System.out.println("socket closed");
}
}
catch(Exception e){
System.out.println(fromClient);
System.out.println(e.toString());
null_reps+=1;
}
if (null_reps >= 100){
run = false;
System.out.println("socket closed");
}
server.close();
client.close();
this.camera_cut_label.setIcon(new ImageIcon());
this.camera_full_label.setIcon(new ImageIcon());
JOptionPane.showMessageDialog(this, name +" socket server down!");
running.stop();
}else if(name.equals("lights")){
int[][] colors = {{204,0,0},{204,204,0},{0,204,0}};
javax.swing.JLabel[][] labels = {{intersect_1_R,intersect_1_Y,intersect_1_G},{intersect_2_R,intersect_2_Y,intersect_2_G}};
int[] lights = {0,0};
while(run) {
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
fromClient = in.readLine();
if(fromClient != null) {
if(fromClient.trim().equals("Bye")) {
run = false;
System.out.println("socket closed");
}else{
System.out.println("received data in size: " + fromClient.length());
System.out.println(fromClient);
lights[0] = Character.getNumericValue(fromClient.charAt(0));
lights[1] = Character.getNumericValue(fromClient.charAt(2));
for(int i = 0;i < 2;i++){
for(int j = 0;j<3;j++){
if(lights[i] == j){
labels[i][j].setBackground(new java.awt.Color(colors[j][0], colors[j][1], colors[j][2]));
continue;
}
labels[i][j].setBackground(new java.awt.Color(204,204,204));
}
}
}
}
}
}
server.close();
client.close();
this.ambulance_label.setIcon(new ImageIcon());
this.intersection_label.setIcon(new ImageIcon());
JOptionPane.showMessageDialog(this, name +" socket server down!");
running.stop();
}
public static BufferedImage resizeImage(final Image image, int width, int height) {
@ -381,23 +791,90 @@ public class cameraForm extends javax.swing.JFrame implements ChangeListener{
return bufferedImage;
}
@Override
public void stateChanged(ChangeEvent changeEvent){
System.out.println("TEST");
JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent.getSource();
int index = sourceTabbedPane.getSelectedIndex();
System.out.println("Tab changed to: " + sourceTabbedPane.getTitleAt(index));
public void stateChanged(ChangeEvent e){
System.out.println("Tab: " + jTabbedPane1.getSelectedIndex());
if(running!=null){
try{
server.close();
client.close();
running.stop();
}catch(IOException ex){
System.out.println("IO Exception occured");
}catch(Exception ex){
System.out.println(ex.toString());
}
}
switch (jTabbedPane1.getSelectedIndex()) {
case 0:
running = new Thread(() -> {
try{
onCreate(8485,"cams");
}catch(Exception ex){
System.out.println(e.toString());
}
});
running.start();
break;
case 1:
running = new Thread(() -> {
try{
onCreate(69,"lights");
}catch(Exception ex){
System.out.println(e.toString());
}
});
running.start();
break;
case 2:
running = new Thread(() -> {
try{
onCreate(0,"robot");
}catch(Exception ex){
System.out.println(e.toString());
}
});
running.start();
break;
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel ambulance_label;
private javax.swing.JButton ambulance_button;
private javax.swing.JLabel camera_cut_label;
private javax.swing.JLabel camera_full_label;
private javax.swing.JLabel cpu_temp;
private javax.swing.JLabel cpu_usage;
private javax.swing.JLabel fan_rpm;
private javax.swing.JLabel fps_label;
private javax.swing.JLabel intersection_label;
private javax.swing.JLabel gpu_temp;
private javax.swing.JLabel gpu_usage;
private javax.swing.JLabel intersect_1_G;
private javax.swing.JLabel intersect_1_R;
private javax.swing.JLabel intersect_1_Y;
private javax.swing.JLabel intersect_2_G;
private javax.swing.JLabel intersect_2_R;
private javax.swing.JLabel intersect_2_Y;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JPanel jPanel6;
private javax.swing.JPanel jPanel7;
private javax.swing.JTabbedPane jTabbedPane1;
private javax.swing.JLabel light_1_label;
private javax.swing.JLabel light_2_label;
private javax.swing.JButton manage_button;
private javax.swing.JLabel ram_temp;
private javax.swing.JLabel ram_usage;
private javax.swing.JLabel robot_cam_label;
// End of variables declaration//GEN-END:variables


+ 1
- 1
master_app/src/main/java/me/yigitcolakoglu/master_app/ips.json View File

@ -1,5 +1,5 @@
{
"qr": "127.0.0.3",
"intersection": "127.0.0.1",
"ambulance": "192.168.1.35"
"ambulance": "192.168.2.75"
}

+ 0
- 0
master_app/target/classes/.netbeans_automatic_build View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/Main.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm$1.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm$2.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm$3.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm$4.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$1.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$2.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$3.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$4.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$5.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$6.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$7.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$8.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$9.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/managementForm.class View File


BIN
master_app/target/master_app-1.0-SNAPSHOT.jar View File


+ 1
- 1
master_app/target/maven-archiver/pom.properties View File

@ -1,5 +1,5 @@
#Generated by Maven
#Fri May 24 18:58:10 EET 2019
#Mon Jul 08 11:26:41 EET 2019
groupId=me.yigitcolakoglu
artifactId=master_app
version=1.0-SNAPSHOT

+ 2
- 3
master_app/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst View File

@ -2,14 +2,13 @@ me/yigitcolakoglu/master_app/managementForm$4.class
me/yigitcolakoglu/master_app/cameraForm$3.class
me/yigitcolakoglu/master_app/cameraForm$2.class
me/yigitcolakoglu/master_app/managementForm$3.class
me/yigitcolakoglu/master_app/cameraForm$5.class
me/yigitcolakoglu/master_app/Main.class
me/yigitcolakoglu/master_app/managementForm$7.class
me/yigitcolakoglu/master_app/cameraForm$1.class
me/yigitcolakoglu/master_app/managementForm$7.class
me/yigitcolakoglu/master_app/managementForm.class
me/yigitcolakoglu/master_app/managementForm$1.class
me/yigitcolakoglu/master_app/managementForm$2.class
me/yigitcolakoglu/master_app/managementForm$8.class
me/yigitcolakoglu/master_app/managementForm$2.class
me/yigitcolakoglu/master_app/managementForm$6.class
me/yigitcolakoglu/master_app/managementForm$9.class
me/yigitcolakoglu/master_app/cameraForm$4.class


+ 3
- 3
master_app/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst View File

@ -1,3 +1,3 @@
/home/yigit/projects/MyCity/traffic_analyzer/master_app/src/main/java/me/yigitcolakoglu/master_app/managementForm.java
/home/yigit/projects/MyCity/traffic_analyzer/master_app/src/main/java/me/yigitcolakoglu/master_app/cameraForm.java
/home/yigit/projects/MyCity/traffic_analyzer/master_app/src/main/java/me/yigitcolakoglu/master_app/Main.java
/home/yigit/projects/MyCity/master_app/src/main/java/me/yigitcolakoglu/master_app/Main.java
/home/yigit/projects/MyCity/master_app/src/main/java/me/yigitcolakoglu/master_app/managementForm.java
/home/yigit/projects/MyCity/master_app/src/main/java/me/yigitcolakoglu/master_app/cameraForm.java

+ 0
- 0
master_app/target/test-classes/.netbeans_automatic_build View File


+ 3
- 2
server_side/api/app.py View File

@ -2,7 +2,7 @@ from flask import Flask, send_from_directory
from flask_restful import Api
from flask_cors import CORS, cross_origin
from modules import user_info, voting_system, rating_system, denunciation, navigation, bus_stops, announcements, complaint, car_crash
from modules import user_info, voting_system, rating_system, denunciation, navigation, bus_stops, announcements, complaint, car_crash,smart_park
from modules import utility
from modules import user_set
@ -31,6 +31,7 @@ if __name__ == '__main__':
api.add_resource(user_info.Users, '/users', '/users/')
api.add_resource(user_info.User, '/users/<path:user_id>', '/users/<path:user_id>/')
api.add_resource(user_info.Login, '/login', '/login/')
api.add_resource(user_info.Image, '/img', '/img/')
api.add_resource(user_info.ReducePoints, '/reduce', '/reduce/')
# api.add_resource(utility.Resources, '/resources', '/resources/')
@ -44,7 +45,7 @@ if __name__ == '__main__':
api.add_resource(announcements.Announcement, '/announcements', '/announcements/')
# api.add_resource(smart_park.Empty, '/parking', '/parking/')
api.add_resource(smart_park.Empty, '/parking', '/parking/')
api.add_resource(complaint.Complaint,"/complaint","/complaint/")
api.add_resource(complaint.Complaints,"/complaints","/complaints/")


+ 3
- 3
server_side/api/modules/SpotSelector.py View File

@ -4,9 +4,9 @@ import json
rects = []
#cam = cv2.VideoCapture("http://192.168.43.246:4747/mjpegfeed")
#ret,im = cam.read()
im = cv2.imread("c.jpeg")
cam = cv2.VideoCapture(2)
ret,im = cam.read()
cam.release()
if __name__ == '__main__' :
while(True):


+ 36
- 36
server_side/api/modules/car_crash.py View File

@ -75,10 +75,10 @@ def find_name(image):
return None
def rotate_img(img, angle):
if angle == 90:
return np.rot90(img)
elif angle == 270:
return np.rot90(np.rot90(np.rot90(img)))
if angle == 90:
return np.rot90(img)
elif angle == 270:
return np.rot90(np.rot90(np.rot90(img)))
def process_img(img_base64):
url = 'https://{}:5001/ai'.format(AI_IP) # Set destination URL here
@ -150,23 +150,23 @@ def process_img(img_base64):
pass
(height_person,width_person) = person.shape[:2]
if name is None:
rotated = rotate_img(person, 270)
face_locs = face_recognition.face_locations(rotated)[0]
name = find_name(rotated)
(top_face, right_face, bottom_face, left_face) = face_locs
face_locs_processed = (top + height_person - right_face,left+bottom_face,top + height_person - left_face,left+top_face)
else:
(top_face, right_face, bottom_face, left_face) = face_locs
person = cv2.rectangle(person, (width_person - bottom_face, left_face), (width_person - top_face, right_face), (0, 255, 0), 3)
face_locs_processed = (top + left_face,left + width_person - top_face,top + right_face,left + width_person - bottom_face)
people[index] = [0, face_locs_processed, name]
else:
face_locs = face_recognition.face_locations(person)[0]
(top_face, right_face, bottom_face, left_face) = face_locs
face_locs_processed = (top+face_locs[0],left+face_locs[1],top+face_locs[2],left+face_locs[3])
name = find_name(person)
people[index] = [1, face_locs_processed, name]
if name is None:
rotated = rotate_img(person, 270)
face_locs = face_recognition.face_locations(rotated)[0]
name = find_name(rotated)
(top_face, right_face, bottom_face, left_face) = face_locs
face_locs_processed = (top + height_person - right_face,left+bottom_face,top + height_person - left_face,left+top_face)
else:
(top_face, right_face, bottom_face, left_face) = face_locs
person = cv2.rectangle(person, (width_person - bottom_face, left_face), (width_person - top_face, right_face), (0, 255, 0), 3)
face_locs_processed = (top + left_face,left + width_person - top_face,top + right_face,left + width_person - bottom_face)
people[index] = [0, face_locs_processed, name]
else:
face_locs = face_recognition.face_locations(person)[0]
(top_face, right_face, bottom_face, left_face) = face_locs
face_locs_processed = (top+face_locs[0],left+face_locs[1],top+face_locs[2],left+face_locs[3])
name = find_name(person)
people[index] = [1, face_locs_processed, name]
@ -188,21 +188,21 @@ class Crash(Resource):
id = request.form['id']
lat, long = request.form['lat'], request.form['long']
image, car_count, injured,out,people = process_img(base64_img)
(top, right, bottom, left) = people[0][1]
top = int(top)
right = int(right)
left = int(left)
bottom = int(bottom)
img = load_image_into_numpy_array(Image.open(io.BytesIO(base64.b64decode(base64_img))))
cv2.rectangle(img,(left,top),(right,bottom),(0,255,0),3)
cv2.imshow('test.jpg', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
print(people)
priority = car_count + injured
if priority > 10:
priority = 10
image, car_count, injured,out,people = process_img(base64_img)
(top, right, bottom, left) = people[0][1]
top = int(top)
right = int(right)
left = int(left)
bottom = int(bottom)
img = load_image_into_numpy_array(Image.open(io.BytesIO(base64.b64decode(base64_img))))
cv2.rectangle(img,(left,top),(right,bottom),(0,255,0),3)
cv2.imshow('test.jpg', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
print(people)
priority = car_count + injured
if priority > 10:
priority = 10
crash = {
'img': image,


+ 114669
- 111650
server_side/api/modules/databases/bus.json
File diff suppressed because it is too large
View File


+ 42
- 0
server_side/api/modules/databases/complaints.json
File diff suppressed because it is too large
View File


+ 21
- 7
server_side/api/modules/databases/locations.json View File

@ -1,9 +1,23 @@
{
"0": {
"x1": 106,
"y1": 188,
"x2": 480,
"y2": 452,
"priority": 0
}
"0": {
"x1": 2,
"y1": 94,
"x2": 198,
"y2": 206,
"priority": 0
},
"1": {
"x1": 190,
"y1": 88,
"x2": 400,
"y2": 196,
"priority": 1
},
"2": {
"x1": 390,
"y1": 66,
"x2": 640,
"y2": 200,
"priority": 2
}
}

+ 391375
- 243479
server_side/api/modules/databases/park_data.json
File diff suppressed because it is too large
View File


+ 3
- 4
server_side/api/modules/smart_park.py View File

@ -102,7 +102,7 @@ def im2str(im):
imdata = pickle.dumps(im)
return base64.b64encode(imdata).decode('ascii')
cam = cv2.VideoCapture("http://192.168.43.246:4747/mjpegfeed")
cam = cv2.VideoCapture(2)
plt.axis("off")
with open("modules/databases/locations.json","r") as f:
@ -111,19 +111,18 @@ with open("modules/databases/locations.json","r") as f:
with open("modules/databases/park_data.json","r") as f:
data = json.loads(f.read())
while 0:
if 0:
ret,im = cam.read()
data = generateAvg(locs,im,data)
with open("modules/databases/park_data.json","w") as f:
f.write(json.dumps(data,indent=2))
exit(0)
class Empty(Resource):
def get(self):
ret,image = cam.read()
#image = cv2.imread("modules/lot.jpg")
#image = cv2.imread("module s/lot.jpg")
backup = image.copy()
spot_data = generateData(locs,image,data,["0","1","2"])
print(spot_data)


+ 12
- 1
server_side/api/modules/user_info.py View File

@ -98,7 +98,18 @@ class ReducePoints(Resource):
json.dump(users, f, indent=2)
else:
abort(404, error="User {} doesn't exist".format(user_id))
class Image(Resource):
def get(self, user_id):
try:
user = copy.deepcopy(utils.find_by_id(users.values(), user_id))
if not user:
raise Exception('User not found!')
del user['password']
resp = Response(user["image"])
resp.headers['Access-Control-Allow-Origin'] = '*'
return resp
except:
abort(404, error="User {} doesn't exist".format(user_id))
if __name__ == '__main__':
api.add_resource(Users, '/users', '/users/')


+ 6
- 0
telnet/.vscode/arduino.json View File

@ -0,0 +1,6 @@
{
"sketch": "main.ino",
"board": "esp8266:esp8266:generic",
"configuration": "xtal=80,vt=flash,exception=disabled,ssl=all,ResetMethod=ck,CrystalFreq=26,FlashFreq=40,FlashMode=dout,eesz=512K,led=2,sdk=nonosdk221,ip=lm2f,dbg=Disabled,lvl=None____,wipe=none,baud=115200",
"port": "/dev/ttyUSB0"
}

+ 19
- 0
telnet/.vscode/c_cpp_properties.json View File

@ -0,0 +1,19 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"/home/yigit/.arduino15/packages/esp8266/tools/**",
"/home/yigit/.arduino15/packages/esp8266/hardware/esp8266/2.5.2/**",
"/home/yigit/.arduino15/packages/esp8266/hardware/esp8266/2.5.2/cores/esp8266",
"/home/yigit/.arduino15/packages/esp8266/hardware/esp8266/2.5.2/libraries/ESP8266WiFi/src"
],
"forcedInclude": [],
"intelliSenseMode": "gcc-x64",
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 4
}

+ 5
- 0
telnet/.vscode/settings.json View File

@ -0,0 +1,5 @@
{
"files.associations": {
"new": "cpp"
}
}

+ 89
- 0
telnet/main.ino View File

@ -0,0 +1,89 @@
#include "Arduino.h"
#include "Esp.h"
#include "ESP8266WiFi.h"
const char* ssid = "AirTies_Air5343";
const char* password = "yigit007";
const int pins[2][3] = {{5,4,16},{2,14,0}};
WiFiServer listenServer(31);
WiFiServer broadcastServer(69);
int lights[2] = {0,2};
void setup() {
Serial.begin(115200);
pinMode(12,OUTPUT);
delay(1000);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
digitalWrite(12,HIGH);
delay(150);
Serial.println("Connecting..");
digitalWrite(12,LOW);
delay(150);
}
Serial.print("Connected to WiFi. IP:");
Serial.println(WiFi.localIP());
for(int i = 0; i<2;i++){
for(int j = 0; j<3; j++){
pinMode(pins[i][j],OUTPUT);
}
}
listenServer.begin();
broadcastServer.begin();
digitalWrite(12,HIGH);
}
void loop() {
WiFiClient listener = listenServer.available();
WiFiClient sender = broadcastServer.available();
String message = "";
if (listener) {
while (listener.connected()) {
if(!sender){
Serial.println("Waiting sender");
sender = broadcastServer.available();
}
message = "";
while (listener.available()>0) {
char c = listener.read();
message += c;
}
if(message != ""){
lights[0] =message.charAt(0)-'0';
lights[1] = message.charAt(2)-'0';
Serial.println(lights[0]);
Serial.println(lights[1]);
for(int i = 0; i<2;i++){
for(int j = 0; j<3; j++){
if(j == lights[i]){
digitalWrite(pins[i][j],HIGH);
continue;
}
digitalWrite(pins[i][j],LOW);
}
}
Serial.println(message);
Serial.print("Connected:");
Serial.println(sender.connected());
Serial.print("Available:");
Serial.println(sender.available());
if(sender && sender.connected()){
Serial.println("Bookmark 1");
sender.println(message);
}
}
delay(10);
}
sender.stop();https://www.hackthebox.eu/login
listener.stop();
}
}

+ 68
- 0
telnet/main/main.ino View File

@ -0,0 +1,68 @@
#include "Arduino.h"
#include "Esp.h"
#include "ESP8266WiFi.h"
const char* ssid = "AirTies_Air5343";
const char* password = "yigit007";
WiFiServer listenServer(31);
WiFiServer broadcastServer(69);
void setup() {
Serial.begin(115200);
pinMode(12,OUTPUT);
delay(1000);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
digitalWrite(12,HIGH);
delay(150);
Serial.println("Connecting..");
digitalWrite(12,LOW);
delay(150);
}
Serial.print("Connected to WiFi. IP:");
Serial.println(WiFi.localIP());
listenServer.begin();
broadcastServer.begin();
digitalWrite(12,HIGH);
}
void loop() {
WiFiClient listener = listenServer.available();
WiFiClient sender = broadcastServer.available();
String message = "";
if (listener) {
while (listener.connected()) {
if(!sender){
Serial.println("Waiting sender");
sender = broadcastServer.available();
}
message = "";
while (listener.available()>0) {
char c = listener.read();
message += c;
}
if(message != ""){
Serial.println(message);
Serial.print("Connected:");
Serial.println(sender.connected());
Serial.print("Available:");
Serial.println(sender.available());
if(sender && sender.connected()){
Serial.println("Bookmark 1");
sender.println(message);
sender.stop();
}
}
delay(10);
}
listener.stop();
}
}

+ 0
- 231
telnet/telnet.ino View File

@ -1,231 +0,0 @@
/*
WiFiTelnetToSerial - Example Transparent UART to Telnet Server for esp8266
Copyright (c) 2015 Hristo Gochkov. All rights reserved.
This file is part of the ESP8266WiFi library for Arduino environment.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <ESP8266WiFi.h>
#include <algorithm> // std::min
#ifndef STASSID
#define STASSID "AirTies_Air5343"
#define STAPSK "yigit007"
#endif
/*
SWAP_PINS:
0: use Serial1 for logging (legacy example)
1: configure Hardware Serial port on RX:GPIO13 TX:GPIO15
and use SoftwareSerial for logging on
standard Serial pins RX:GPIO3 and TX:GPIO1
*/
#define SWAP_PINS 0
/*
SERIAL_LOOPBACK
0: normal serial operations
1: RX-TX are internally connected (loopback)
*/
#define SERIAL_LOOPBACK 0
#define BAUD_SERIAL 115200
#define BAUD_LOGGER 115200
#define RXBUFFERSIZE 1024
#define ONE 12
#define TWO 14
////////////////////////////////////////////////////////////
#if SERIAL_LOOPBACK
#undef BAUD_SERIAL
#define BAUD_SERIAL 3000000
#include <esp8266_peri.h>
#endif
#if SWAP_PINS
#include <SoftwareSerial.h>
SoftwareSerial* logger = nullptr;
#else
#define logger (&Serial1)
#endif
#define STACK_PROTECTOR 512 // bytes
//how many clients should be able to telnet to this ESP8266
#define MAX_SRV_CLIENTS 2
const char* ssid = STASSID;
const char* password = STAPSK;
const int port = 23;
int led_one = 0;
int led_two = 0;
WiFiServer server(port);
WiFiClient serverClients[MAX_SRV_CLIENTS];
void setup() {
Serial.begin(BAUD_SERIAL);
Serial.setRxBufferSize(RXBUFFERSIZE);
#if SWAP_PINS
Serial.swap();
// Hardware serial is now on RX:GPIO13 TX:GPIO15
// use SoftwareSerial on regular RX(3)/TX(1) for logging
logger = new SoftwareSerial(3, 1);
logger->begin(BAUD_LOGGER);
logger->println("\n\nUsing SoftwareSerial for logging");
#else
logger->begin(BAUD_LOGGER);
logger->println("\n\nUsing Serial1 for logging");
#endif
logger->println(ESP.getFullVersion());
logger->printf("Serial baud: %d (8n1: %d KB/s)\n", BAUD_SERIAL, BAUD_SERIAL * 8 / 10 / 1024);
logger->printf("Serial receive buffer size: %d bytes\n", RXBUFFERSIZE);
#if SERIAL_LOOPBACK
USC0(0) |= (1 << UCLBE); // incomplete HardwareSerial API
logger->println("Serial Internal Loopback enabled");
#endif
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
logger->print("\nConnecting to ");
logger->println(ssid);
while (WiFi.status() != WL_CONNECTED) {
logger->print('.');
delay(500);
}
logger->println();
logger->print("connected, address=");
logger->println(WiFi.localIP());
//start server
server.begin();
server.setNoDelay(true);
logger->print("Ready! Use 'telnet ");
logger->print(WiFi.localIP());
logger->printf(" %d' to connect\n", port);
}
void loop() {
//check if there are any new clients
if (server.hasClient()) {
//find free/disconnected spot
int i;
for (i = 0; i < MAX_SRV_CLIENTS; i++)
if (!serverClients[i]) { // equivalent to !serverClients[i].connected()
serverClients[i] = server.available();
logger->print("New client: index ");
logger->print(i);
break;
}
//no free/disconnected spot so reject
if (i == MAX_SRV_CLIENTS) {
server.available().println("busy");
// hints: server.available() is a WiFiClient with short-term scope
// when out of scope, a WiFiClient will
// - flush() - all data will be sent
// - stop() - automatically too
logger->printf("server is busy with %d active connections\n", MAX_SRV_CLIENTS);
}
}
//check TCP clients for data
#if 1
// Incredibly, this code is faster than the bufferred one below - #4620 is needed
// loopback/3000000baud average 348KB/s
int val = 0;
for (int i = 0; i < MAX_SRV_CLIENTS; i++)
while (serverClients[i].available() && Serial.availableForWrite() > 0) {
// working char by char is not very efficient
char telnet_val = serverClients[i].read();
if (telnet_val == 48) { // 0
if (val++ == 0) {
led_one = 0;
} else {
led_two = 0;
}
} else if (telnet_val == 49) { // 1
if (val++ == 0) {
led_one = 1;
} else {
led_two = 1;
}
}
Serial.write(telnet_val);
}
#else
// loopback/3000000baud average: 312KB/s
for (int i = 0; i < MAX_SRV_CLIENTS; i++)
while (serverClients[i].available() && Serial.availableForWrite() > 0) {
size_t maxToSerial = std::min(serverClients[i].available(), Serial.availableForWrite());
maxToSerial = std::min(maxToSerial, (size_t)STACK_PROTECTOR);
uint8_t buf[maxToSerial];
size_t tcp_got = serverClients[i].read(buf, maxToSerial);
size_t serial_sent = Serial.write(buf, tcp_got);
if (serial_sent != maxToSerial) {
logger->printf("len mismatch: available:%zd tcp-read:%zd serial-write:%zd\n", maxToSerial, tcp_got, serial_sent);
}
}
#endif
digitalWrite(ONE, led_one);
digitalWrite(TWO, led_two);
// determine maximum output size "fair TCP use"
// client.availableForWrite() returns 0 when !client.connected()
size_t maxToTcp = 0;
for (int i = 0; i < MAX_SRV_CLIENTS; i++)
if (serverClients[i]) {
size_t afw = serverClients[i].availableForWrite();
if (afw) {
if (!maxToTcp) {
maxToTcp = afw;
} else {
maxToTcp = std::min(maxToTcp, afw);
}
} else {
// warn but ignore congested clients
logger->println("one client is congested");
}
}
//check UART for data
size_t len = std::min((size_t)Serial.available(), maxToTcp);
len = std::min(len, (size_t)STACK_PROTECTOR);
if (len) {
uint8_t sbuf[len];
size_t serial_got = Serial.readBytes(sbuf, len);
// push UART data to all connected telnet clients
for (int i = 0; i < MAX_SRV_CLIENTS; i++)
// if client.availableForWrite() was 0 (congested)
// and increased since then,
// ensure write space is sufficient:
if (serverClients[i].availableForWrite() >= serial_got) {
size_t tcp_sent = serverClients[i].write(sbuf, serial_got);
if (tcp_sent != len) {
logger->printf("len mismatch: available:%zd serial-read:%zd tcp-write:%zd\n", len, serial_got, tcp_sent);
}
}
}
}

Loading…
Cancel
Save