StartUploadParamsRequest.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using PlcSiemens.O;
  2. using PlcSiemens.Protocol.Common;
  3. namespace PlcSiemens.Protocol.Upload
  4. {
  5. public class StartUploadParamsRequest
  6. {
  7. public byte FunSUpld; // function start upload 0x1D
  8. public byte[] Uk6; // Unknown 6 bytes
  9. public byte UploadID;// At begining is 0) we will put upload id incoming from plc
  10. public byte Len1;
  11. public byte Prefix;
  12. public byte BlkPrfx; // always 0x30
  13. public byte BlkType;
  14. public byte[] AsciiBlk; // BlockNum in ascii
  15. public byte A; // always 0x41 ('A')
  16. public ushort PacketLength
  17. {
  18. get
  19. {
  20. return 0x12;
  21. }
  22. }
  23. public void GetByteBuffer(ByteBuffer buffer)
  24. {
  25. buffer.Push(FunSUpld);
  26. buffer.Push(Uk6);
  27. buffer.Push(UploadID);
  28. buffer.Push(Len1);
  29. buffer.Push(Prefix);
  30. buffer.Push(BlkPrfx);
  31. buffer.Push(BlkType);
  32. buffer.Push(AsciiBlk);
  33. buffer.Push(A);
  34. }
  35. public void Build(BlockType blockType, ushort blockNum)
  36. {
  37. FunSUpld = (byte)PduFuncType.PduStartUpload;
  38. byte byte00 = 0x00;
  39. Uk6 = new[] { byte00, byte00, byte00, byte00, byte00, byte00 };
  40. UploadID = 0x00;
  41. Len1 = 0x09;
  42. Prefix = 0x5F;
  43. BlkPrfx = 0x30; // '0'
  44. BlkType = (byte)blockType;
  45. int tmp = blockNum;
  46. AsciiBlk = new byte[5];
  47. AsciiBlk[0] = (byte)((tmp / 10000) + 0x30);
  48. tmp = tmp % 10000;
  49. AsciiBlk[1] = (byte)((tmp / 1000) + 0x30);
  50. tmp = tmp % 1000;
  51. AsciiBlk[2] = (byte)((tmp / 100) + 0x30);
  52. tmp = tmp % 100;
  53. AsciiBlk[3] = (byte)((tmp / 10) + 0x30);
  54. tmp = tmp % 10;
  55. AsciiBlk[4] = (byte)((tmp / 1) + 0x30);
  56. A = 0x41; // 'A'
  57. }
  58. }
  59. }