NsIec104.h
上传用户:liao421
上传日期:2013-01-30
资源大小:11k
文件大小:6k
开发平台:

C/C++

  1. #define          NS_IEC_104_YK_BASE_PORT                16
  2. #define          NS_IEC104_YK_PERMIT_TIME               16
  3. #define          NS_IEC_104_TOTAL_YX_TIMES              9
  4. #define          NS_IEC_104_ONCE_YX                     120
  5. #define          NS_IEC_104_ONCE_YX_BYTES               120/8
  6. #define          NS_IEC_104_TOTAL_YC_TIMES              16
  7. #define          NS_IEC_104_ONCE_YC                     32
  8. #define          NS_IEC_104_TOTAL_YM_TIMES              8
  9. #define          NS_IEC_104_ONCE_YM                     16
  10. #define          NS_IEC_104_MIN_LENGTH            6
  11. #define          NS_IEC_104_HEAD                  0x68
  12. #define          NS_IEC_104_STARTDT               0x04
  13. #define          NS_IEC_104_STOPDT                0x10
  14. #define          NS_IEC_104_TESTFR                0x40
  15. #define          NS_IEC_104_QCC_POSITION          15
  16. #define          NS_IEC_104_TIME_POSITION         15
  17. #define          NS_IEC_104_REASONBYTE            2
  18. #define          NS_IEC_104_ASDUADDRESSBYTE       2
  19. #define          NS_IEC_104_INFORMATIONBYTE       3
  20. /* Location Which Bytes In Receive Buffer  */
  21. #define          NS_STARTREASON                   8
  22. #define          NS_STARTASDUADDRESS              10 
  23. #define          NS_STARTINFORMATION              12
  24. #define          NS_STARTQUALIFIER                15
  25. #define          NS_IEC_104_GROUP_BYTE            15 
  26. #define          NS_IEC104_GROUP_BEGIN            21
  27. #define          NS_IEC104_GROUP_END              36 
  28. #define          NS_IEC104_YX_START_OBJECT        0x01
  29. #define          NS_IEC104_YC_START_OBJECT        0x701
  30. #define          NS_IEC104_YCYX_OBJECT_INDEX      0x80
  31. #define          NS_IEC104_SENDBUFFER             256
  32. #define          NS_IEC104_RECEIVEBUFFER          128
  33. #define          NS_CONNECTED                     0x02
  34. #define          NS_DISCONNECTED                  0x20
  35. #define          NS_IEC104_PERMIT_TIME            30
  36. #define          NS_IEC104_MAX_K                  12
  37. #define          NS_IEC104_MAX_W                  8
  38. #define          NS_IEC104_MAX_GROUP              30
  39. #define          NS_IEC104_MAX_YC                 512
  40. #define          NS_IEC104_CHANGE_YC_CYCLE        16
  41. #define          NS_IEC104_ONCE_YC_COUNT          32
  42. typedef struct   NS_IEC_104_NS_
  43.                  {
  44.                 struct sockaddr_in   ServerAddress;
  45.                     int              NsNewSocketId;
  46.                     unsigned char    LinkState;
  47.                     unsigned long    LinkValidTime;
  48.                     unsigned char    Card;
  49.                     short            Port;
  50.                     unsigned char    ReceiveBuffer[NS_IEC104_RECEIVEBUFFER];
  51.                     unsigned char    SendBuffer[NS_IEC104_SENDBUFFER];
  52.                              short   SendLength;
  53.                              short   ReceiveLength;
  54.                     unsigned short   ReceiveIndex;
  55.                              short   ReceiveIndexLength;
  56.                     unsigned char    ApciCode;
  57.                    
  58.                     unsigned char    TransmitReason[2];
  59.                     unsigned char    CommonAsduAddress[2];
  60.                     unsigned char    InformationObject[4];
  61.                     unsigned char    FormatType;
  62.                     unsigned char    UCommand;
  63.                     unsigned char    ReceiveHimNumber[2];
  64.                     unsigned short   SendMeNumber;
  65.                     unsigned short   ApduLength;
  66.                     unsigned char    AsduType;
  67.                     unsigned char    AsduQualifier;
  68.                     unsigned char    Qcc;
  69.                     unsigned char    FreezeSign;
  70.                     unsigned char    PulseGroup;
  71.                     unsigned char    TimeSave[8];
  72.                     unsigned char    Table;
  73.                     unsigned short   HasSendNumber;
  74.                     unsigned short   NeedSendNumber;
  75.                     unsigned short   LeftSendNumber;
  76.                     unsigned short   K;
  77.                     unsigned short   W;
  78.                     unsigned short   ReceiveYkId;
  79.                     unsigned char    YkCellAction;
  80.                     unsigned short   YkCellNumber;
  81.                     unsigned short   YkKgNumber;
  82.                     unsigned char    YkNowState;
  83.                     unsigned short   MediaNumber;
  84.                     unsigned char    YkError;
  85.                     unsigned char    YkYtType;
  86.                     unsigned char    YkStartSign;
  87.                     unsigned long    YkStartTime;
  88.                     unsigned short   SystemState;
  89.                     unsigned char    DataBuff[160];
  90.                     unsigned char    SetTimeFlag;
  91.                     unsigned char    GroupSendBuffer[NS_IEC104_MAX_GROUP][NS_IEC104_SENDBUFFER];
  92.                     unsigned short   GroupSendLength[NS_IEC104_MAX_GROUP];
  93.                              short   YcLastValue[NS_IEC104_MAX_YC];
  94.                     unsigned char    YcNap[NS_IEC104_MAX_YC];
  95.                     unsigned char    YcChangeCycle;         
  96.                     unsigned short   YcLibIndex;
  97.                     unsigned short   YcChangeCount;
  98.                     unsigned char    CosSign;
  99.                     unsigned char    NetRunSign;
  100.                     unsigned char    SetNetSign;
  101.                     
  102.                     unsigned char TableNo;
  103. /*unsigned short XYxNum;
  104. unsigned short XYmNum;*/
  105. unsigned short XYcNum;
  106. unsigned short XYcCycleNum;
  107.                  }NS_IEC104_MAIN;
  108. #define   NS_IEC104_USE_CYCLE        5
  109. static    NS_SEND_TIME_NAP           NsIec104Cycle[NS_IEC104_USE_CYCLE];
  110. static    unsigned short             NsIec104Nap[NS_IEC104_USE_CYCLE]={/*5*/120,15,20,25,30};
  111.               
  112.