123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515 |
- /*******************************************************************
- Copyright (C):
- File name : Iec10x.h
- DESCRIPTION :
- AUTHOR :
- Version : 1.0
- Date : 2014/07/23
- Others :
- History :
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 1) Date: 2014/07/23 Author: ChenDajie
- content:
- add iec104
- *******************************************************************/
- #ifndef _IEC10X_H
- #define _IEC10X_H
- #include "iec10x_conf.h"
- #include "iec10x_prio_queue.h"
- #include "iec10x_type.h"
- #include <stdio.h>
- #include <string.h>
- /*
- * CONFIGURE
- * */
- #define IEC10XLOCK
- #define PRIO_QUEUE
- #ifdef IEC101_STM32
- #define IEC10X_PRIO_MAX 7
- #elif defined(IEC104_STM32)
- #define IEC10X_PRIO_MAX 7
- #endif
- #define IEC10X_HEADER_LENGTH 1
- /*
- * PRIO
- * */
- #define IEC10X_PRIO_INITLINK 0
- #define IEC10X_PRIO_CALLALL 1
- #define IEC10X_PRIO_CALLGROUP 2
- #define IEC10X_PRIO_CLOCK 3
- #define IEC10X_PRIO_DELAY 3
- #define IEC10X_PRIO_PULSE 0
- #define IEC10X_PRIO_SPON 0
- /*
- * Transmission Priority Queue.
- */
- typedef struct IEC10X_CallbackArg
- {
- iec_8u *value;
- iec_32u PicSn;
- iec_32u FramSerialNum;
- } Iec10x_CallbackArg_T;
- typedef struct IEC10X_NODE
- {
- iec_16u Length;
- struct IEC10X_NODE *Next;
- void (*CallBack)(Iec10x_CallbackArg_T *Arg);
- Iec10x_CallbackArg_T CallBackArg;
- iec_8u value[1];
- } Iec10x_PrioNode_T;
- typedef struct IEC10X_QUEUE
- {
- struct IEC10X_NODE *Header;
- struct IEC10X_NODE *Tail;
- unsigned char ElementNum;
- } Iec10x_PrioQueue_T;
- /*
- *********************************************************************************************************
- * BLOCK SIZE AND NUMBER
- *
- * if add part, please change OS_MAX_MEM_PART in ucosii.h.
- *********************************************************************************************************
- */
- /* IEC10X_PARTITION 1 size==256*8 */
- #define IEC10X_PARTITION_NUM_1 5
- #define IEC10X_PARTITION_SIZE_1 512
- #define IEC10X_PARTITION_1 (IEC10X_PARTITION_SIZE_1 - 16)
- /* IEC10X_PARTITION 2 size==(1300+16)*1 */
- #define IEC10X_PARTITION_NUM_2 20
- #define IEC10X_PARTITION_2 128
- #define IEC10X_PARTITION_SIZE_2 (IEC10X_PARTITION_2 + sizeof(Iec10x_PrioNode_T))
- /* IEC10X_PARTITION 1 size==64*20 */
- #define IEC10X_PARTITION_NUM_3 10
- #define IEC10X_PARTITION_3 32
- #define IEC10X_PARTITION_SIZE_3 (IEC10X_PARTITION_3 + sizeof(Iec10x_PrioNode_T))
- /*
- *********************************************************************************************************
- * ASDU
- *********************************************************************************************************
- */
- /*
- * ASDU TYPE
- * */
- #define Iec10x_M_EI_NA_1 0X46
- #define IEC10X_C_IC_NA_1 0X64 /*CALL*/
- #define IEC10X_C_CS_NA_1 103
- #define IEC10X_C_CD_NA_1 106 /*CALL*/
- /*Set data*/
- #define IEC10X_C_SE_NA_1 48
- #define IEC10X_C_SE_NC_1 50
- /*
- * ASDU REASON
- * */
- #define IEC10X_ASDU_REASON_INIT 0X04
- #define IEC10X_ASDU_REASON_ACT 0X06
- #define IEC10X_ASDU_REASON_ACTCON 0X07 /*CALL*/
- #define IEC10X_ASDU_REASON_ACTFIN 0X08 /*CALL FINISH*/
- #define IEC10X_ASDU_REASON_ACTTERM 0X0a /*CALL Terminal*/
- #define IEC10X_ASDU_COT_UNKNOW 45
- /*
- * INFO ADDR
- * */
- #define IEC10X_INFO_ADDR_NONE 0X00
- /*
- *********************************************************************************************************
- * REMOTE SIGNAL
- *********************************************************************************************************
- */
- /*
- * Asdu type (TI)
- * */
- #define IEC10X_M_SP_NA_1 0X01
- #define IEC10X_M_DP_NA_1 0X03
- #define IEC10X_M_SP_TB_1 30
- #define IEC10X_M_DP_TB_1 31
- /*
- * Asdu reason (COT)
- * */
- #define IEC10X_COT_BACK 2
- #define IEC10X_COT_SPONT 3
- #define IEC10X_COT_ACT 6
- #define IEC10X_COT_ACTCON 7
- #define IEC10X_COT_REQ 5
- #define IEC10X_COT_RETREM 11
- #define IEC10X_COT_RETLOC 12
- #define IEC10X_COT_INTROGEN 20
- #define IEC10X_COT_INTRO1 21
- #define IEC10X_COT_INTRO2 22
- /*
- * Asdu addr
- * */
- #define IEC10X_INFO_ADDR_SIG_BASE 0X0001
- #define IEC10X_INFO_ADDR_SIG_TEMP_HX_OFF 0x1000
- /*
- *********************************************************************************************************
- * REMOTE DECTET
- *********************************************************************************************************
- */
- /*
- * Asdu type (TI)
- * */
- #define IEC10X_M_ME_NA_1 9
- #define IEC10X_M_ME_NC_1 13
- #define IEC10X_M_ME_TD_1 34
- #define IEC10X_M_ME_TF_1 36
- /*
- * Asdu reason (COT)
- * */
- #define IEC10X_COT_PER_CYC 1
- #define IEC10X_COT_BACK 2
- #define IEC10X_COT_SPONT 3
- #define IEC10X_COT_REQ 5
- #define IEC10X_COT_INTROGEN 20
- #define IEC10X_COT_INTRO9 29
- #define IEC10X_COT_INTRO10 30
- /*
- * Asdu addr
- * */
- #define IEC10X_INFO_ADDR_DET 0X4001
- #define IEC10X_INFO_ADDR_DET_TEMP_HX_OFF 0x1000
- /*
- *********************************************************************************************************
- * CALL QOI
- *********************************************************************************************************
- */
- #define IEC10X_CALL_QOI_TOTAL 20
- #define IEC10X_CALL_QOI_GROUP1 21
- #define IEC10X_CALL_QOI_GROUP2 22
- #define IEC10X_CALL_QOI_GROUP9 29
- #define IEC10X_CALL_QOI_GROUP10 30
- /*
- *********************************************************************************************************
- * INFO ADDREST
- * TD -- temprature device
- * PD -- pullotion device
- *********************************************************************************************************
- */
- #define IEC10X_SET_TD_UPCYCLE 0X100001
- #define IEC10X_SET_TD_MAXIMUM 0X100002
- #define IEC10X_SET_TD_MINIMUM 0X100003
- #define IEC10X_SET_TD_DETCYCLE 0X100004
- #define IEC10X_SET_TD_TEMPRISE 0X100005
- #define IEC10X_SET_PD_DETCYCLE 0X100006
- #define IEC10X_SET_PD_PULPSE 0X100007
- #define IEC10X_SET_PD_SELFDETCYCLE 0X100008
- /*
- *********************************************************************************************************
- * Fujian Huixing Add
- *********************************************************************************************************
- */
- /* TI. */
- #define IEC10X_TI_FIRM_UPDATE 128
- #define IEC10X_TI_AP_FIRM_BACKOFF 129
- #define IEC10X_TI_AP_BASE_INFO 130
- /* COT. */
- #define IEC10X_COT_ACT_TERMINAL 8
- #define IEC10X_COT_ACT_TERMINAL_ACK 9
- #define IEC10X_COT_DATA 14
- #define IEC10X_COT_DATA_ACK 15
- #define IEC10X_COT_DATA_FIN 16
- #define IEC10X_COT_DATA_FIN_ACK 17
- #define IEC10X_COT_DATA_NEEDACK 0X100E
- #pragma pack(1)
- /*
- * asdu number
- * */
- typedef struct
- {
- iec_8u _num : 7;
- iec_8u _sq : 1;
- } ASDU_NUM_T;
- /*
- * asdu reason
- * */
- typedef struct
- {
- #ifdef IEC101_STM32
- iec_8u _reason : 6;
- iec_8u _pn : 1;
- iec_8u _test : 1;
- #elif defined(IEC104_STM32)
- iec_16u _reason : 14;
- iec_16u _pn : 1;
- iec_16u _test : 1;
- #endif
- } ASDU_REASON_T;
- /*
- * asdu
- * */
- typedef struct
- {
- iec_8u _type;
- ASDU_NUM_T _num;
- ASDU_REASON_T _reason;
- iec_16u _addr;
- iec_8u _info[1];
- } IEC10X_ASDU_T, *PIEC10X_ASDU_T;
- /*
- * asdu info
- * */
- typedef struct
- {
- #ifdef IEC101_STM32
- iec_16u _addr;
- #elif defined(IEC104_STM32)
- iec_8u _addr[3];
- #endif
- iec_8u _element[1];
- } ASDU_INFO_T, *PASDU_INFO_T;
- /*
- * asdu info remote signal with time flag
- * */
- typedef struct
- {
- iec_8u _signal;
- iec_8u _time;
- } SIGNAL_TIME_T, *PSIGNAL_TIME_T;
- /*
- * asdu info remote detect with time flag
- * */
- /*int */
- typedef struct
- {
- iec_16s _detect;
- iec_8u _qds;
- } IEC10X_DETECT_T, *PIEC10X_DETECT_T;
- /*float*/
- typedef struct
- {
- float _detect;
- iec_8u _qds;
- } IEC10X_DETECT_F_T, *PIEC10X_DETECT_F_T;
- /*int sq=0 */
- typedef struct
- {
- #ifdef IEC101_STM32
- iec_16u _addr;
- #elif defined(IEC104_STM32)
- iec_8u _addr[3];
- #endif
- iec_16s _detect;
- iec_8u _qds;
- } IEC10X_DETECT_SQ0_T, *PIEC10X_DETECT_SQ0_T;
- /*float sq=0*/
- typedef struct
- {
- #ifdef IEC101_STM32
- iec_16u _addr;
- #elif defined(IEC104_STM32)
- iec_8u _addr[3];
- #endif
- float _detect;
- iec_8u _qds;
- } IEC10X_DETECT_SQ0_F_T, *PIEC10X_DETECT_SQ0_F_T;
- /*
- * asdu info CP56Time2a
- * */
- typedef struct
- {
- iec_8u _minutes : 6;
- iec_8u _res : 1;
- iec_8u _iv : 1;
- } IEC10X_Time_Min_T, *PIEC10X_Time_Min_T;
- typedef struct
- {
- iec_8u _hours : 5;
- iec_8u _res : 2;
- iec_8u _su : 1;
- } IEC10X_Time_Hour_T, *PIEC10X_Time_Hour_T;
- typedef struct
- {
- iec_8u _dayofmonth : 5;
- iec_8u _dayofweek : 3;
- } IEC10X_Time_Day_T, *PIEC10X_Time_Day_T;
- typedef struct
- {
- iec_8u _month : 4;
- iec_8u _res : 3;
- } IEC10X_Time_Month_T, *PIEC10X_Time_Month_T;
- typedef struct
- {
- iec_8u _year : 7;
- iec_8u _res : 1;
- } IEC10X_Time_Year_T, *PIEC10X_Time_Year_T;
- typedef struct
- {
- iec_16u _milliseconds;
- IEC10X_Time_Min_T _min;
- IEC10X_Time_Hour_T _hour;
- IEC10X_Time_Day_T _day;
- IEC10X_Time_Month_T _month;
- IEC10X_Time_Year_T _year;
- } CP56Time2a_T, *PCP56Time2a_T;
- /*
- * asdu info remote detect with time flag
- * */
- typedef struct
- {
- iec_16u _detect;
- iec_8u _qds;
- CP56Time2a_T _time;
- } DETECT_TIME_T, *PDETECT_TIME_T;
- #pragma pack()
- /*
- * Iec10x init
- */
- typedef struct _iec10x
- {
- char *name;
- int (*Init)(void);
- void (*Delay_ms)(iec_16u);
- void (*CloseLink)(void);
- void *(*Malloc)(iec_8u nbyte);
- void (*Free)(void *buffer);
- iec_8u (*enqueue)(Iec10x_PrioQueue_T *QueueHdr, Iec10x_PrioNode_T *newnode);
- Iec10x_PrioNode_T *(*dequeue)(Iec10x_PrioQueue_T *QueueHdr);
- Iec10x_PrioNode_T *(*FindQHead)(Iec10x_PrioQueue_T *QueueHdr);
- char (*GetPrio)(void);
- void (*InitQueue)(Iec10x_PrioQueue_T *PrioQueue);
- void (*ClearQueue)(Iec10x_PrioQueue_T *QueueHdr);
- iec_8u (*Send)(int socketfd, char *data, int len);
- iec_32u (*SetTime)(PCP56Time2a_T time);
- iec_32u (*GetTime)(PCP56Time2a_T time);
- iec_8s (*GetStationState)(iec_16u Addr, iec_8u DevType);
- float (*GetStaValue)(iec_16u Addr, iec_8u DevType);
- iec_16u (*GetLinkAddr)(void);
- iec_8s (*GetInfoNum)(iec_8u *InfoNum, iec_8u DevType);
- iec_8s (*SetConfig)(long Value, iec_32u addr);
- iec_8s (*SaveFirmware)(iec_8u FirmLen, iec_8u *buf, iec_32u FirmwareType, iec_32u Iec10x_Update_SeekAddr);
- iec_8s (*CheckFirmware)(iec_32u FirmwareType, iec_32u TotalLen);
- iec_8s (*UpdateFirmware)(iec_32u FirmwareType);
- iec_8s (*BackoffFirmware)(iec_32u FirmwareType);
- #ifdef IEC10XLOCK
- void (*LOCK)(void);
- void (*UNLOCK)(void);
- #endif
- } * PIEC10X_T, IEC10X_T;
- /*
- * BIG ENDIAN
- * */
- #ifdef BIG_ENDIAN
- #define n2hs(x) (x)
- #define h2ns(x) (x)
- #define n2hl(x) (x)
- #define h2nl(x) (x)
- /* LITTLE ENDIAN */
- #else
- #define n2hs(x) ((((x) >> 8) & 0xFF) | (((x)&0xFF) << 8))
- #define h2ns(x) ((((x) >> 8) & 0xFF) | (((x)&0xFF) << 8))
- #define n2hl(x) ((((x) >> 24) & 0xFF) | (((x) >> 8) & 0xFF00) | \
- (((x)&0xFF00) << 8) | (((x)&0xFF) << 24))
- #define h2nl(x) ((((x) >> 24) & 0xFF) | (((x) >> 8) & 0xFF00) | \
- (((x)&0xFF00) << 8) | (((x)&0xFF) << 24))
- #endif /* BIG_ENDIAN */
- /*
- *********************************************************************************************************
- * EXTERN VARIABLE
- *********************************************************************************************************
- */
- extern PIEC10X_T IEC10X;
- extern iec_16u Iec10x_Sta_Addr;
- extern iec_32s Iec104_BuildSendSn;
- extern iec_32s Iec104_BuildRecvSn;
- extern iec_16u IEC10X_Cp16time2a;
- extern iec_16u IEC10X_Cp16time2a_V;
- extern CP56Time2a_T IEC10X_Cp56time2a;
- extern iec_8u Iec10x_FirmwareUpdateFlag;
- /*
- *********************************************************************************************************
- * QUEUE FUNCTION PROTOTYPES
- *********************************************************************************************************
- */
- /*
- * Prio
- * */
- iec_8u IEC10X_PrioEnQueue(Iec10x_PrioQueue_T *QueueHdr, Iec10x_PrioNode_T *new_p);
- Iec10x_PrioNode_T *IEC10X_PrioDeQueue(Iec10x_PrioQueue_T *QueueHdr);
- char IEC10X_HighestPrio(void);
- void IEC10X_PrioInitQueue(Iec10x_PrioQueue_T *PrioQueue);
- void IEC10X_Prio_ClearQueue(Iec10x_PrioQueue_T *QueueHdr);
- Iec10x_PrioNode_T *IEC10X_PrioFindQueueHead(Iec10x_PrioQueue_T *QueueHdr);
- /*
- * Iec10x queue
- * */
- void IEC10X_InitQ(void);
- void IEC10X_ClearQ(void);
- iec_8u IEC10X_GetPrio(iec_8u State);
- void IEC10X_Enqueue(iec_8u *EnQBuf, iec_16u Length, iec_8u Prio,
- void (*IEC10XCallBack)(Iec10x_CallbackArg_T *Arg), Iec10x_CallbackArg_T *CallbackArg);
- void Iec10x_Scheduled(int socketfd);
- Iec10x_PrioNode_T *IEC10X_Dequeue(void);
- iec_32s RegisterIEC10XMoudle(void *_IEC10X);
- void IEC10X_ClearQ(void);
- void Iec10x_Lock(void);
- void Iec10x_UnLock(void);
- #endif /*_IEC10X_H*/
|