21 changed files with 251 additions and 82 deletions
-
BINapp.db
-
6src/main/java/com/iflytop/uf/UfActuator.java
-
35src/main/java/com/iflytop/uf/UfActuatorBase.java
-
88src/main/java/com/iflytop/uf/UfActuatorCmdExecutor.java
-
10src/main/java/com/iflytop/uf/UfActuatorCommand.java
-
10src/main/java/com/iflytop/uf/UfActuatorHandler.java
-
1src/main/java/com/iflytop/uf/UfApplication.java
-
14src/main/java/com/iflytop/uf/UfApplicationRunner.java
-
59src/main/java/com/iflytop/uf/actuator/UfActStepperMotor.java
-
64src/main/java/com/iflytop/uf/connection/UfZcancmderWebsocket.java
-
2src/main/java/com/iflytop/uf/controller/UfApiActuator.java
-
3src/main/java/com/iflytop/uf/model/UfMdbActuator.java
-
8src/main/resources/application.yml
-
17src/main/resources/db/migration/V1_1__alter_table_actuators_add_column_type.sql
-
3src/main/resources/static/uf/css/app.5595db20.css
-
3src/main/resources/static/uf/css/app.eacba97d.css
-
2src/main/resources/static/uf/index.html
-
2src/main/resources/static/uf/js/app.66d72d84.js
-
1src/main/resources/static/uf/js/app.66d72d84.js.map
-
2src/main/resources/static/uf/js/app.98f78643.js
-
1src/main/resources/static/uf/js/app.98f78643.js.map
@ -0,0 +1,6 @@ |
|||
package com.iflytop.uf; |
|||
import com.iflytop.uf.model.UfMdbActuatorCmd; |
|||
public interface UfActuator { |
|||
// execute |
|||
String execute( UfMdbActuatorCmd command ); |
|||
} |
@ -0,0 +1,35 @@ |
|||
package com.iflytop.uf; |
|||
import com.iflytop.uf.model.UfMdbActuatorCmd; |
|||
import java.lang.reflect.InvocationTargetException; |
|||
import java.lang.reflect.Method; |
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
abstract public class UfActuatorBase implements UfActuator { |
|||
// method map |
|||
private final Map<String, Method> methodMap; |
|||
|
|||
// constructor |
|||
public UfActuatorBase() { |
|||
this.methodMap = new HashMap<>(); |
|||
for ( var method : this.getClass().getMethods() ) { |
|||
var annotation = method.getAnnotation(UfActuatorCommand.class); |
|||
if ( annotation != null ) { |
|||
methodMap.put(annotation.name(), method); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public String execute(UfMdbActuatorCmd command) { |
|||
if ( !methodMap.containsKey(command.cmdKey) ) { |
|||
return UfActuatorCmdExecutor.getExecutor().sendCommandToConnection(command); |
|||
} |
|||
|
|||
var method = methodMap.get(command.cmdKey); |
|||
try { |
|||
return (String)method.invoke(this, command); |
|||
} catch (IllegalAccessException | InvocationTargetException e) { |
|||
throw new RuntimeException(e); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,10 @@ |
|||
package com.iflytop.uf; |
|||
import java.lang.annotation.ElementType; |
|||
import java.lang.annotation.Retention; |
|||
import java.lang.annotation.RetentionPolicy; |
|||
import java.lang.annotation.Target; |
|||
@Retention(RetentionPolicy.RUNTIME) |
|||
@Target({ElementType.METHOD}) |
|||
public @interface UfActuatorCommand { |
|||
String name(); |
|||
} |
@ -0,0 +1,10 @@ |
|||
package com.iflytop.uf; |
|||
import java.lang.annotation.ElementType; |
|||
import java.lang.annotation.Retention; |
|||
import java.lang.annotation.RetentionPolicy; |
|||
import java.lang.annotation.Target; |
|||
@Retention(RetentionPolicy.RUNTIME) |
|||
@Target({ElementType.TYPE}) |
|||
public @interface UfActuatorHandler { |
|||
String name(); |
|||
} |
@ -0,0 +1,14 @@ |
|||
package com.iflytop.uf; |
|||
import org.springframework.boot.ApplicationArguments; |
|||
import org.springframework.boot.ApplicationRunner; |
|||
import org.springframework.core.annotation.Order; |
|||
import org.springframework.stereotype.Component; |
|||
@Order(1) |
|||
@Component |
|||
public class UfApplicationRunner implements ApplicationRunner { |
|||
@Override |
|||
public void run(ApplicationArguments args) throws Exception { |
|||
UfApplication.getApp().connections.setup(); |
|||
UfActuatorCmdExecutor.setup(); |
|||
} |
|||
} |
@ -0,0 +1,59 @@ |
|||
package com.iflytop.uf.actuator; |
|||
import com.iflytop.uf.*; |
|||
import com.iflytop.uf.model.UfMdbActuator; |
|||
import com.iflytop.uf.model.UfMdbActuatorCmd; |
|||
@UfActuatorHandler(name = "stepper-motor") |
|||
public class UfActStepperMotor extends UfActuatorBase { |
|||
@UfActuatorCommand(name = "motor_easy_move_to_zero") |
|||
public String easyMoveToZero(UfMdbActuatorCmd cmd) { |
|||
var executor = UfActuatorCmdExecutor.getExecutor(); |
|||
|
|||
var result = executor.sendCommandToConnection(cmd); |
|||
|
|||
// wait for finish |
|||
var waitCmd = new UfMdbActuatorCmd(); |
|||
waitCmd.actuatorId = cmd.actuatorId; |
|||
waitCmd.cmdId = "0104"; |
|||
waitCmd.cmdKey = "module_get_status"; |
|||
waitCmd.cmdFlags = cmd.cmdFlags; |
|||
waitCmd.parameters = ""; |
|||
waitCmd.connectionKey = cmd.connectionKey; |
|||
do { |
|||
String statusText = executor.sendCommandToConnection(waitCmd); |
|||
int status = Integer.parseInt(statusText); |
|||
if ( 0 == status ) { |
|||
break; |
|||
} |
|||
} while ( true ); |
|||
return result; |
|||
} |
|||
// |
|||
// // cmd motor easy move to |
|||
// public void cmdMotorEasyMoveTo(UfMdbActuatorCmd command) { |
|||
// this.executeDeviceCommand(command); |
|||
// this.waitForActuatorFinish(command); |
|||
// |
|||
// var actuator = UfActiveRecord.findOne(UfMdbActuator.class, command.actuatorId); |
|||
// var encoderAvailable = actuator.getProperty("encoderAvailable"); |
|||
// if ( null == encoderAvailable || !encoderAvailable.asBoolean() ) { |
|||
// return ; |
|||
// } |
|||
// |
|||
// var destValue = Integer.parseInt(command.parameters); |
|||
// var encoderValue = this.getActuatorEncoderValue(command); |
|||
// if ( Math.abs(encoderValue - destValue) > 10 ) { |
|||
// throw new RuntimeException(String.format("电机 [%s] 移动失败,目标位置:%d,当前位置:%d", actuator.name, destValue, encoderValue)); |
|||
// } |
|||
// } |
|||
// |
|||
// // cmd motor read enc val |
|||
// private Integer getActuatorEncoderValue(UfMdbActuatorCmd srcCmd) { |
|||
// var command = new UfMdbActuatorCmd(); |
|||
// command.actuatorId = srcCmd.actuatorId; |
|||
// command.cmdId = "0219"; |
|||
// command.cmdKey = "motor_read_enc_val"; |
|||
// command.cmdFlags = srcCmd.cmdFlags; |
|||
// String value = this.executeDeviceCommand(command); |
|||
// return Integer.parseInt(value); |
|||
// } |
|||
} |
@ -0,0 +1,17 @@ |
|||
-- rename table to backup |
|||
ALTER TABLE app_actuators RENAME TO app_actuators_bk_202405061735; |
|||
|
|||
-- create new table with new columns |
|||
CREATE TABLE app_actuators ( |
|||
"id" text NOT NULL, |
|||
"moduleId" text NOT NULL, |
|||
"key" TEXT NOT NULL, |
|||
"name" TEXT NOT NULL, |
|||
"type" TEXT NOT NULL, |
|||
"properties" TEXT NOT NULL DEFAULT "{}", |
|||
PRIMARY KEY ("id") |
|||
); |
|||
|
|||
-- copy data from backup table to new table |
|||
INSERT INTO app_actuators (id, moduleId, key, name, type, properties) |
|||
SELECT id, moduleId, key, name, '', properties FROM app_actuators_bk_202405061735; |
3
src/main/resources/static/uf/css/app.5595db20.css
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
3
src/main/resources/static/uf/css/app.eacba97d.css
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -1 +1 @@ |
|||
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/uf/favicon.ico"><title>web</title><script defer="defer" src="/uf/js/chunk-vendors.0f638fda.js"></script><script defer="defer" src="/uf/js/app.66d72d84.js"></script><link href="/uf/css/app.eacba97d.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but web doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html> |
|||
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/uf/favicon.ico"><title>web</title><script defer="defer" src="/uf/js/chunk-vendors.0f638fda.js"></script><script defer="defer" src="/uf/js/app.98f78643.js"></script><link href="/uf/css/app.5595db20.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but web doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html> |
2
src/main/resources/static/uf/js/app.66d72d84.js
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
1
src/main/resources/static/uf/js/app.66d72d84.js.map
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
2
src/main/resources/static/uf/js/app.98f78643.js
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
1
src/main/resources/static/uf/js/app.98f78643.js.map
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
Write
Preview
Loading…
Cancel
Save
Reference in new issue