Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #define BYTE unsigned char
  2. #define WORD unsigned int
  3. #define DWORD unsigned long
  4.  
  5. #define STX1 0x55 //Header1
  6. #define STX2 0xAA //Header2
  7. #define SB_OEM_PKT_SIZE 12
  8. #define SB_OEM_CHK_SUM_SIZE 2
  9. enum {CMD_OPEN = 0x01}
  10.  
  11.  
  12. typedef struct {
  13. BYTE Head1;
  14. BYTE Head2;
  15. WORD wDevId;
  16. DWORD nParam;
  17. WORD wCmd;// or nAck
  18. WORD wChkSum;
  19. } SB_OEM_PKT;
  20.  
  21. WORD CalcChkSumOfCmdAckPkt( SB_OEM_PKT* pPkt ){
  22. WORD wChkSum = 0;
  23. BYTE* pBuf = (BYTE*)pPkt;
  24. int i;
  25. for(i=0;i<(sizeof(SB_OEM_PKT)-SB_OEM_CHK_SUM_SIZE);i++){
  26. wChkSum += pBuf[i];
  27. }
  28. return wChkSum;
  29. }
  30.  
  31. void SendCmdOrAck(WORD wDevID, WORD wCmdOrAck, DWORD nParam) {
  32. SB_OEM_PKT pkt;
  33. int nSentBytes;
  34.  
  35. pkt.Head1 = (BYTE)STX1;
  36. pkt.Head2 = (BYTE)STX2;
  37. pkt.wDevId = wDevID;
  38. pkt.wCmd = wCmdOrAck;
  39. pkt.nParam = nParam;
  40. pkt.wChkSum = CalcChkSumOfCmdAckPkt( &pkt );
  41.  
  42. nSentBytes = gtmSerial->write( (BYTE*)&pkt,SB_OEM_PKT_SIZE);
  43. }
  44.  
  45. WORD gwDevID = 1;
  46. int main(){
  47. SendCmdOrAck(gwDevID, CMD_OPEN, 1);
  48. return 0;
  49. }
  50.  
  51. ser.write(pack('<BBILII', 0x55,0xAA,0x0001,1,1,258))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement