野心家
2023-11-04 98d2aecd3899b1b8419aca65a4f899b9dc9c5b3a
显示器显示拣料全板信息
2个文件已修改
1个文件已添加
269 ■■■■■ 已修改文件
src/main/java/com/zy/common/utils/News.java 195 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/MainProcess.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/thread/LedThread.java 72 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/common/utils/News.java
New file
@@ -0,0 +1,195 @@
package com.zy.common.utils;
import lombok.extern.slf4j.Slf4j;
import java.lang.reflect.Array;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * news stories for zoneyung
 * Created by vincent on 2022/12/22
 */
@Slf4j
public class News {
    public static void main(String[] args) {
        News.info("info{}", 1);
        News.warn("warn{}", 2);
        News.error("error{}", 3);
        System.out.println(News.print());
    }
    interface NewsSupport<T> { boolean execute(T t); }
    private static final NewsQueue<NewsDomain> NEWS_QUEUE = new NewsQueue<>(NewsDomain.class, 1024);
    @SuppressWarnings({"unchecked"})
    static class NewsQueue<T> {
        private final transient Class<T> cls;
        private final T[] arr;
        private final int capacity;
        private int head;
        private int tail;
        { this.head = 0; this.tail = 0; }
        public NewsQueue(Class<T> cls, int capacity) {
            this.cls = cls;
            this.arr = (T[]) Array.newInstance(cls, capacity);
            this.capacity = capacity;
        }
        public synchronized boolean offer(T t) {
            if (this.tail == this.capacity) {
                this.peek();
            }
            this.reform();
            this.arr[this.tail] = t;
            this.tail ++;
            return true;
        }
        public synchronized boolean put(T t) {
            if (this.tail == this.capacity) {
                return false;
            } else {
                this.reform();
            }
            this.arr[this.tail] = t;
            this.tail ++;
            return true;
        }
        public synchronized T peek() {
            if (this.head == this.tail) {
                return null;
            }
            T t = this.arr[this.head];
            this.head ++;
            this.reform();
            return t;
        }
        private void reform() {
            for (int i = this.head; i < this.tail; i++) {
                this.arr[i-this.head] = this.arr[i];
            }
            this.tail -= this.head;
            this.head = 0;
        }
        public synchronized int size() {
            return this.tail - this.head;
        }
        public synchronized List<T> data() {
            T[] ts = (T[]) Array.newInstance(this.cls, size());
            if (this.tail - this.head >= 0) {
                System.arraycopy(this.arr, this.head, ts, 0, this.tail - this.head);
            }
            return Arrays.asList(ts);
        }
    }
    public static void info(String format, Object... arguments) {
        log.info(format, arguments);
        offer(NewsLevel.INFO, format, arguments);
    }
    public static void warn(String format, Object... arguments) {
        log.warn(format, arguments);
        offer(NewsLevel.WARN, format, arguments);
    }
    public static void error(String format, Object... arguments) {
        log.error(format, arguments);
        offer(NewsLevel.ERROR, format, arguments);
    }
    public static void infoNoLog(String format, Object... arguments) {
        offer(NewsLevel.INFO, format, arguments);
    }
    public static void warnNoLog(String format, Object... arguments) {
        offer(NewsLevel.WARN, format, arguments);
    }
    public static void errorNoLog(String format, Object... arguments) {
        offer(NewsLevel.ERROR, format, arguments);
    }
    public static String printStr() {
        StringBuilder sb = new StringBuilder("[");
        List<NewsDomain> domains = NEWS_QUEUE.data();
        for (int i = 0; i < domains.size(); i++) {
            NewsDomain domain = domains.get(i);
            sb.append("{");
            sb.append("\"l\":").append(domain.level.idx).append(",");
            sb.append("\"v\":\"").append(domain.content).append("\"").append(",");
            sb.append("\"t\":\"").append(domain.date).append("\"");
            sb.append("}");
            if (i < domains.size() - 1) {
                sb.append(",");
            }
        }
        sb.append("]");
        return sb.toString();
    }
    public static List<Map<String, Object>> print() {
        List<Map<String, Object>> res = new ArrayList<>();
        for (NewsDomain datum : NEWS_QUEUE.data()) {
            Map<String, Object> map = new HashMap<>();
            map.put("l", datum.level.idx);
            map.put("v", datum.content);
            map.put("t", datum.date);
            res.add(map);
        }
        return res;
    }
    private static boolean offer(NewsLevel level, String msg, Object[] args) {
        return NEWS_QUEUE.offer(new NewsDomain(level, replace(msg, args), (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date())));
    }
    private static String replace(String str, Object[] objs){
        if (null == objs || objs.length == 0 || null == str || "".equals(str.trim())) {
            return str;
        } else {
            StringBuilder sb = new StringBuilder(str);
            for (Object obj : objs) {
                int idx = sb.indexOf("{}");
                if (idx == -1) { break; }
                sb.replace(idx, idx + 2, String.valueOf(obj));
            }
            return sb.toString();
        }
    }
    static class NewsDomain {
        public NewsLevel level;
        public String content;
        public String date;
        public NewsDomain(NewsLevel level, String content, String date) {
            this.level = level;
            this.content = content;
            this.date = date;
        }
    }
    enum NewsLevel {
        INFO(1),
        WARN(2),
        ERROR(3),
        ;
        public int idx;
        NewsLevel(int idx) {
            this.idx = idx;
        }
    }
}
src/main/java/com/zy/core/MainProcess.java
@@ -85,6 +85,8 @@
                    // 穿梭车 ===>> 小车电量检测充电
                    mainService.loopShuttleCharge();
                    mainService.executeShuttleCharge();
                    // 出库  ===>> 工作档信息写入led显示器
                    mainService.ledExecute();
                    // 间隔
                    Thread.sleep(200);
src/main/java/com/zy/core/thread/LedThread.java
@@ -1,6 +1,7 @@
package com.zy.core.thread;
import com.zy.common.model.MatDto;
import com.zy.common.utils.News;
import com.zy.core.Slave;
import com.zy.core.ThreadHandler;
import com.zy.core.cache.MessageQueue;
@@ -10,6 +11,7 @@
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import onbon.bx05.Bx5GEnv;
import onbon.bx05.Bx5GException;
import onbon.bx05.Bx5GScreenClient;
import onbon.bx05.area.TextCaptionBxArea;
import onbon.bx05.area.page.TextBxPage;
@@ -28,6 +30,10 @@
@Slf4j
public class LedThread implements Runnable, ThreadHandler {
    private Bx5GScreenClient screen;
    private ProgramBxFile pf;
    private TextCaptionBxArea area;
    DisplayStyleFactory.DisplayStyle[] styles = DisplayStyleFactory.getStyles().toArray(new DisplayStyleFactory.DisplayStyle[0]);
    private Slave slave;
    private Set<Integer> workNos = new HashSet<>();
    private boolean ledMk = false;
@@ -77,28 +83,53 @@
        }
    }
    private void write(List<LedCommand> list) {
        commandList = list;
    private void write(List<LedCommand> list) throws Bx5GException {
        if (!connect()) {
            return;
        }
        StringBuilder sb = new StringBuilder();
        pf = new ProgramBxFile( 0, screen.getProfile());
        pf.setFrameShow(false);
        // 分别输入X,Y,width,height
        area = new TextCaptionBxArea( 0,0,96,48, screen.getProfile());
        // 创建一个数据页
        TextBxPage page = new TextBxPage();
        for (LedCommand command : list) {
            sb.append(command.getTitle()).append("(").append(command.getWorkNo()).append(")").append("\n");
            sb.append("源库位:").append(command.getSourceLocNo()).append("\n");
            sb.append("目标站:").append(command.getStaNo()).append("\n");
            page.newLine(command.getTitle() +"("+command.getWorkNo()+")");
            page.newLine("库位:"+ (command.getIoType() < 100 ? command.getLocNo() : command.getSourceLocNo()));
            page.newLine("目标站:"+command.getStaNo());
            if (!command.isEmptyMk()) {
                for (MatDto matDto : command.getMatDtos()) {
                    sb.append("物料编码:").append(matDto.getMatnr()).append("\n");
                    sb.append("名称:").append(matDto.getMaknx()).append("\n");
                    sb.append("数量:").append(matDto.getCount()).append("\n");
                    sb.append("规格:").append(matDto.getSpecs()).append("\n");
                    //去掉小数点
                    String strQty = matDto.getCount().toString();
                    int idx = strQty.lastIndexOf(".");
                    if(idx >= 0){
                        strQty.substring(0,idx);
                    }
                    page.newLine(matDto.getMaknx() + "[数量" + strQty +"]");
//                    page.newLine(matDto.getMaknx() + "【数量" + matDto.getCount() +"】");
                }
            }
            sb.append("\n");
            page.newLine("\n");
        }
        stringBuffer.delete(0, stringBuffer.length());
        stringBuffer.append(sb.toString());
        errorReset();
        // 设置字体
        page.setFont(new Font("宋体",Font.PLAIN,12));
        // 设置文本颜色
        page.setForeground(Color.red);
        // 设置显示特技为快速打出
        page.setDisplayStyle(styles[6]);
        area.clearPages();
        area.addPage(page);
        pf.addArea(area);
        if (pf.validate() != null) {
            News.info("Led"+" - 2"+" - pf out of range");
        } else {
            // 更新节目
            screen.writeProgram(pf);
//            resetStatus = false;
        }
        close();
    }
@@ -120,7 +151,18 @@
    @Override
    public boolean connect() {
        return true;
        boolean connRes = false;
        try {
            connRes = screen.connect(slave.getIp(),slave.getPort());
            screen.turnOn();
        } catch (Exception ignore) {
        }
        if (connRes) {
            News.info("Led"+" - 4"+" - led连接成功 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
        } else {
            News.error("Led"+" - 5"+" - led连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
        }
        return connRes;
    }
    @Override