ProtocolParam.java 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package com.mes.netty;
  2. import org.slf4j.Logger;
  3. import org.slf4j.LoggerFactory;
  4. // 固定格式报文各参数获取方法
  5. public class ProtocolParam {
  6. public static final Logger log = LoggerFactory.getLogger(ProtocolParam.class);
  7. // bbbbfffffARWAQDWGWOP100 GY100000ID151245P00000106200123062900001 RSOKDA2023-09-07ZT10:16:58
  8. public static Integer fixedLength = 96; // 固定长度
  9. // 获取消息类型 所有报文都可使用
  10. public static String getMsgType(String msg){
  11. log.info(msg);
  12. if(msg.length() < 16){
  13. return "";
  14. }
  15. return msg.substring(12,16);
  16. }
  17. // 获取工位号
  18. public static String getOprno(String msg){
  19. if(msg.length() < 24){
  20. return "";
  21. }
  22. return msg.substring(18,24);
  23. }
  24. // 获取工艺号
  25. public static String getCraft(String msg){
  26. if(msg.length() < 32){
  27. return "";
  28. }
  29. return msg.substring(26,32);
  30. }
  31. // 获取镭雕码或设备报警故障代码
  32. public static String getSn(String msg){
  33. if(msg.length() < 70){
  34. return "";
  35. }
  36. return msg.substring(34,70);
  37. }
  38. public static String getLx(String msg){
  39. if(msg.length() < 72){
  40. return "";
  41. }
  42. return msg.substring(70,72);
  43. }
  44. // 获取结果
  45. public static String getResult(String msg){
  46. if(msg.length() < 74){
  47. return "";
  48. }
  49. return msg.substring(72,74);
  50. }
  51. // 获取日期
  52. public static String getDay(String msg){
  53. if(msg.length() < 86){
  54. return "";
  55. }
  56. return msg.substring(76,86);
  57. }
  58. // 获取时间
  59. public static String getTime(String msg){
  60. if(msg.length() < 96){
  61. return "";
  62. }
  63. return msg.substring(88,96);
  64. }
  65. }