ProtocolParam.java 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package com.mes.netty;
  2. // 固定格式报文各参数获取方法
  3. // 协议 v2(2026-06-29 修订):oprno 字段从 6 字符扩到 8 字符,后续字段偏移整体 +2
  4. public class ProtocolParam {
  5. // bbbbfffffARWAQDWGWOP100 GY100000ID151245P00000106200123062900001 RSOKDA2023-09-07ZT10:16:58
  6. public static Integer fixedLength = 98; // 固定长度(响应报文,v1=96,v2 扩 oprno 后 +2)
  7. // 获取消息类型 所有报文都可使用
  8. public static String getMsgType(String msg){
  9. System.out.print(msg);
  10. if(msg.length() < 16){
  11. return "";
  12. }
  13. return msg.substring(12,16);
  14. }
  15. // 获取工位号(8 字符)
  16. public static String getOprno(String msg){
  17. if(msg.length() < 26){
  18. return "";
  19. }
  20. return msg.substring(18,26);
  21. }
  22. // 获取工艺号
  23. public static String getCraft(String msg){
  24. if(msg.length() < 34){
  25. return "";
  26. }
  27. return msg.substring(28,34);
  28. }
  29. // 获取镭雕码或设备报警故障代码
  30. public static String getSn(String msg){
  31. if(msg.length() < 72){
  32. return "";
  33. }
  34. return msg.substring(36,72);
  35. }
  36. public static String getLx(String msg){
  37. if(msg.length() < 74){
  38. return "";
  39. }
  40. return msg.substring(72,74);
  41. }
  42. // 获取结果
  43. public static String getResult(String msg){
  44. if(msg.length() < 76){
  45. return "";
  46. }
  47. return msg.substring(74,76);
  48. }
  49. // 获取日期
  50. public static String getDay(String msg){
  51. if(msg.length() < 88){
  52. return "";
  53. }
  54. return msg.substring(78,88);
  55. }
  56. // 获取时间
  57. public static String getTime(String msg){
  58. if(msg.length() < 98){
  59. return "";
  60. }
  61. return msg.substring(90,98);
  62. }
  63. }