Skip to content

Commit 2b8ec32

Browse files
authored
Add files via upload
1 parent 1917845 commit 2b8ec32

File tree

7 files changed

+204
-0
lines changed

7 files changed

+204
-0
lines changed

CTS To Vmix data and triggers.iml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="library" name="jSerialComm-2.10.3" level="project" />
11+
</component>
12+
</module>
Binary file not shown.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Data in Configuration
2+
port.name=COM3
3+
port.baud=9600
4+
5+
# Vmix Configuration
6+
vmix.url=10.168.0.20:8088
7+
vmix.StartCamNumber=1
8+
vmix.WideCamNumber=2
9+
10+
#Debug Info
11+
Debug.enabled=false
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
Main-Class: Main
3+
6.69 KB
Binary file not shown.

src/META-INF/MANIFEST.MF

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
Main-Class: Main
3+

src/Main.java

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
import com.fazecast.jSerialComm.SerialPort;
2+
import com.fazecast.jSerialComm.SerialPortTimeoutException;
3+
import java.net.HttpURLConnection;
4+
import java.net.URL;
5+
import java.io.IOException;
6+
import java.io.InputStream;
7+
import java.util.regex.Matcher;
8+
import java.util.regex.Pattern;
9+
import java.io.FileInputStream;
10+
import java.util.Properties;
11+
public class Main {
12+
13+
public static void main(String[] args) {
14+
Properties properties = new Properties();
15+
try (FileInputStream input = new FileInputStream("Config.txt")) {
16+
properties.load(input);
17+
} catch (IOException e) {
18+
e.printStackTrace();
19+
}
20+
21+
// Accessing configuration values
22+
String comPort1 = properties.getProperty("port.name");
23+
int BaudRate = Integer.parseInt(properties.getProperty("port.baud"));
24+
String vmixUrl = properties.getProperty("vmix.url");
25+
int startCamNumber = Integer.parseInt(properties.getProperty("vmix.StartCamNumber"));
26+
int WideNumber = Integer.parseInt(properties.getProperty("vmix.WideCamNumber"));
27+
String testdebug = properties.getProperty("Debug.enabled");
28+
29+
boolean debug = false;
30+
if(testdebug.equals("true")){
31+
debug=true;
32+
}
33+
else {
34+
debug=false;
35+
}
36+
37+
if (debug) {
38+
// Printing configuration values
39+
System.out.println("Listed below is the list of values pulled form the Config:");
40+
System.out.println("Com Port: " + comPort1);
41+
System.out.println("Baud Rate: " + BaudRate);
42+
System.out.println("Vmix Ip And Port: " + vmixUrl);
43+
System.out.println("The Input number of your wide shot: " + startCamNumber);
44+
System.out.println("The Input number of your start shot: " + WideNumber);
45+
}
46+
47+
String comPortName = comPort1; // Replace with the actual COM port name
48+
49+
int inputNumber = 1;
50+
SerialPort comPort = SerialPort.getCommPort(comPortName);
51+
comPort.setBaudRate(BaudRate);
52+
53+
if (comPort.openPort()) {
54+
System.out.println("Port opened successfully.");
55+
comPort.setComPortTimeouts(SerialPort.TIMEOUT_READ_SEMI_BLOCKING, 100, 0); // Adjust timeout as needed
56+
InputStream inputStream = comPort.getInputStream();
57+
58+
StringBuilder messageBuilder = new StringBuilder();
59+
boolean receivingData = false;
60+
61+
try {
62+
while (true) {
63+
String lane = "";
64+
try {
65+
int data = inputStream.read();
66+
if (data == -1) {
67+
if(debug) {
68+
System.out.println("No more data to read.");
69+
}
70+
break; // End of stream
71+
}
72+
73+
char c = (char) data;
74+
75+
if (c == 1) { // <SOH>
76+
messageBuilder.setLength(0);
77+
receivingData = true; // Start receiving data
78+
} else if (c == 4 && receivingData) { // <EOT> when receiving data
79+
String message = messageBuilder.toString().trim();
80+
//System.out.println("Received Data: " + message);
81+
82+
if (message.startsWith("SR") && message.length() >= 7) {
83+
String mm_ss_t = message.substring(2,9); // Extract mm:ss.t including the decimal part
84+
if(debug) {
85+
System.out.println(mm_ss_t);
86+
}
87+
if(mm_ss_t.equals(" : .0")) {
88+
cut(vmixUrl, startCamNumber, debug);
89+
CutWithDelay(5000,vmixUrl, WideNumber,debug);
90+
}
91+
92+
} else {
93+
// Use a regular expression to extract relevant information
94+
Pattern pattern = Pattern.compile("FT\\s*(\\d+)\\s*(\\d+)\\s*((?:\\d+:)?\\d{2}\\.\\d{2})");
95+
Matcher matcher = pattern.matcher(message);
96+
97+
if (matcher.find()) {
98+
lane = matcher.group(1);
99+
String place = matcher.group(2);
100+
String mm_ss_tt = matcher.group(3);
101+
cut(vmixUrl, startCamNumber, debug );
102+
if(debug) {
103+
System.out.println("Score Data: Lane " + lane + ", Place " + place + ", Time " + mm_ss_tt);
104+
}
105+
}
106+
}
107+
108+
receivingData = false; // Stop receiving after processing
109+
} else if (receivingData) {
110+
messageBuilder.append(c);
111+
}
112+
} catch (SerialPortTimeoutException timeoutException) {
113+
// Handle timeout exception (no data received)
114+
//System.out.println("Timeout: No data received.");
115+
}
116+
}
117+
} catch (IOException e) {
118+
e.printStackTrace();
119+
} finally {
120+
comPort.closePort();
121+
System.out.println("Port closed.");
122+
}
123+
} else {
124+
System.err.println("Failed to open the port.");
125+
}
126+
}
127+
// Method to cut to a specific input in vMix
128+
public static void cut (String vmixApiUrl, int Input,boolean debug){
129+
try {
130+
cutToInput(vmixApiUrl, Input, debug );
131+
} catch (Exception e){
132+
e.printStackTrace();
133+
}
134+
}
135+
public static void cutToInput(String vmixApiUrl, int inputNumber, boolean debug) throws Exception {
136+
try {
137+
// Create a URL object for the vMix API endpoint
138+
URL url = new URL("http://"+vmixApiUrl + "/API/?Function=CutDirect&input=" + inputNumber);
139+
140+
// Open a connection to the URL
141+
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
142+
connection.setRequestMethod("GET");
143+
144+
// Get the response from the vMix API
145+
int responseCode = connection.getResponseCode();
146+
if(debug) {
147+
System.out.println(connection.getResponseCode());
148+
}
149+
// Close the connection
150+
connection.disconnect();
151+
152+
// Return true if the request was successful (HTTP status code 200)
153+
154+
} catch (Exception e) {
155+
e.printStackTrace();
156+
// Return false if an exception occurred
157+
158+
}
159+
}
160+
private static void CutWithDelay(int delay, String vmixUrl, int cam, boolean debug) {
161+
// Create a thread to print "test the test2" after 1 second
162+
Thread delayedThread = new Thread(() -> {
163+
try {
164+
Thread.sleep(delay); // Delay for 1 second
165+
cut(vmixUrl, cam, debug);
166+
} catch (InterruptedException e) {
167+
e.printStackTrace();
168+
}
169+
});
170+
171+
// Start the delayed thread
172+
delayedThread.start();
173+
}
174+
175+
}

0 commit comments

Comments
 (0)