dp_user.c
资源名称:Profibus.rar [点击查看]
上传用户:hualang
上传日期:2022-04-11
资源大小:104k
文件大小:61k
源码类别:
能源行业(电力石油煤炭)
开发平台:
C/C++
- ///////////////////////////////////////////////////////////////
- // 文 件 名 : dp_user.c
- // 文件功能 : vpc3用户接口部分
- // 作 者 : 530
- // 创建时间 :
- // 项目名称 : Blackfin
- // 操作系统 :
- // 备 注 :
- // 历史记录 :
- ///////////////////////////////////////////////////////////////
- #include "......includeLmcInc.h"
- #include "..E5_Commu_PtlProfibus.h"
- extern void vpc3_neta_isr() ;
- extern void vpc3_netb_isr() ;
- extern void show_buffer(UBYTE dev_num,char * msg_ptr, UBYTE * ptr, UWORD length);
- extern int msac_c1_alarm_quit_wiscom(UBYTE dev_num, UBYTE sap,
- UBYTE slot_nr, UBYTE alarm_type, UBYTE seq_nr);
- #ifdef DP_TIMESTAMP
- /************************************************************************/
- /* 时间戳 */
- /************************************************************************/
- // One-based array of days in year at month start
- static const int16 _MonthDays[13] =
- {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
- //判断是否是闰年
- /*
- 闰年有两种情况,设年份为year,则:
- (1)当year是400的整倍数时为闰年,条件表示为:
- year%400= =0
- (2)当year是4的整倍数,但不是100的整倍数时为闰年,条件为:
- year%4= =0 && year%100 != 0
- */
- #define IsLeapYear(nYear) ((((nYear) & 3) == 0) && (((nYear) % 100) != 0 || ((nYear) % 400) == 0))
- //计算某年某月有多少天
- #define GetDaysInMonth(nYear, nMon) (_MonthDays[nMon] - _MonthDays[(nMon)-1] + (((nMon) == 2 && IsLeapYear(nYear)) ? 1 : 0))
- ///////////////////////////////////////////////////////////////
- // 函 数 名 : _SecondsFromTime
- // 函数功能 : 计算dt所对应时间离1900.1.1有多少秒
- // 处理过程 :
- // 备 注 :
- // 作 者 : 仲伟
- // 时 间 : 2006年1月6日
- // 返 回 值 : int32
- // 参数说明 : TDateTime dt
- ///////////////////////////////////////////////////////////////
- // static uint32 _SecondsFromTime(const TDateTime * dt)
- // {
- // //计算从1900.1.1到现在有多少天, 2000.1.1为1
- // uint32 nDate = 365L*(dt->y-1900) + (dt->y-1900)/4 - (dt->y-1900)/100 + (dt->y-1900)/400 +
- // _MonthDays[dt->mon-1] + dt->d;
- //
- // // If leap year and it's before March, subtract 1:
- // if (dt->mon <= 2 && IsLeapYear(dt->y))
- // --nDate;
- //
- // //计算多少秒
- // return (nDate*86400L+3600L*dt->h+60L*dt->min+dt->s);
- // }
- ///////////////////////////////////////////////////////////////
- /// brief : 从秒得到当前完整时间日期
- /// param int32 nS
- /// return TFullDateTime
- ///
- /// author : 仲伟
- /// date : 2006年12月31日
- /// note :
- ///////////////////////////////////////////////////////////////
- static TDateTime _TimeFromSeconds(uint32 nS)
- {
- TDateTime dt={1900, 1, 1, 0, 0, 0, 0};
- uint32 nYDays; //一年多少天
- uint32 nYSecs; //一天多少秒
- uint32 nMDays;
- while (1)
- {
- //计算本年有多少天,闰年加一天
- nYDays = 365 + (IsLeapYear(dt.y)?1:0);
- nYSecs = nYDays * 86400L;
- if(nYSecs > nS) //大于剩余秒数
- {
- //时间在本年内
- break;
- }
- else
- {
- nS -= nYSecs; //时间进位到下一年
- dt.y ++;
- }
- }
- //计算日期
- nYDays = nS / 86400L; //本年第几天
- for (dt.mon=1;dt.mon<=12;dt.mon++)
- {
- //计算一个月几天
- nMDays = _MonthDays[dt.mon]-_MonthDays[dt.mon-1];
- if(dt.mon == 2 && IsLeapYear(dt.y))
- {
- nMDays ++;
- }
- if(nYDays>=nMDays)
- {
- nYDays -= nMDays;
- //进入下一个月
- }
- else
- {
- //时间就在本月
- break;
- }
- }
- dt.d = 1+nYDays; //日
- //计算时间
- nS %= 86400L;
- dt.h = nS / 3600L; //时
- nS %= 3600L;
- dt.min = nS / 60; //分
- dt.s = nS % 60; //秒
- return dt;
- }
- #endif //DP_TIMESTAMP
- /*---------------------------------------------------------------------------*/
- /* defines, structures */
- /*---------------------------------------------------------------------------*/
- // -- defines for user alarm state
- #define USER_AL_STATE_CLOSED ((UBYTE)0x00)
- #define USER_AL_STATE_OPEN ((UBYTE)0x01)
- // -- defines for user state
- #define USER_STATE_CLEAR ((UBYTE)0x00)
- #define USER_STATE_RUN ((UBYTE)0x01)
- // -- defines for diagnostics
- #define USER_TYPE_DPV0 ((UBYTE)0xFA)
- #define USER_TYPE_PRM_OK ((UBYTE)0xFB)
- #define USER_TYPE_PRM_NOK ((UBYTE)0xFC)
- #define USER_TYPE_CFG_OK ((UBYTE)0xFD)
- #define USER_TYPE_CFG_NOK ((UBYTE)0xFE)
- #define USER_TYPE_APPL_RDY ((UBYTE)0xFF)
- // -- status message data (coded as device diagnosis) -------------------------
- // -- Modulstatus -------------------------------------------------------------
- typedef struct
- {
- UBYTE sign_len; // fix to 0x07
- UBYTE status_type; // fix to 0x82
- UBYTE slot_number; // fix to 0x00
- UBYTE specifier; // fix to 0x00
- UBYTE user_data[2];
- } tStatusDiag;
- #define sizeof_StatusDiag 6
- //SECTION_DEF_CommuData static tStatusDiag status_diag;
- #define MaxAlarmLength 64
- typedef struct
- {
- UBYTE state;
- UBYTE user_diag_active;
- UWORD old_diag;
- UBYTE user_diag[DIAG_BUFSIZE];
- UWORD event;
- UBYTE DPV1;
- UBYTE application_ready;
- CFG_STRUCT real_cfg; //real cfg data
- struct //alarm state machine data
- {
- UBYTE state;
- UBYTE buffer_used[ALARM_MAX_FIFO];
- UBYTE user_alarm_data[ALARM_MAX_FIFO][MaxAlarmLength];
- ALARM_STATUS_PDU alarm_buffers[ALARM_MAX_FIFO];
- }al;
- #ifdef DP_FDL
- UBYTE dpv1_rw_buffer[ C1_LEN ];
- #ifdef DPV1_IM_SUPP
- UWORD awImIndex[0x10];
- #endif//#ifdef DPV1_IM_SUPP
- #endif//#ifdef DP_FDL
- }USER_STRUC;
- static int g_nPrmCount[2];
- static int g_nCheckCfgCount[2];
- static int g_nC1ReadCount[2];
- static int g_nC1WriteCount[2];
- /*---------------------------------------------------------------------------*/
- /* global user data definitions */
- /*---------------------------------------------------------------------------*/
- SECTION_DEF_CommuData VPC3_STRUC_ERRCB vpc3_errcb[MAX_DEV_NUM]; // error structure
- SECTION_DEF_CommuData USER_STRUC user[MAX_DEV_NUM]; // user system structure
- /*---------------------------------------------------------------------------*/
- /* defines, structures and variables for our demo application */
- /*---------------------------------------------------------------------------*/
- //default configuration data for startup
- //SECTION_DEF_CommuData static UBYTE DefCfg[64] = {0x59,0x17,0x18,0x93,0x93,0x25};//WDZ-5233
- //#define CfgDataLength 6
- #ifdef DPV1_IM_SUPP
- SECTION_DEF_CommuData static ROMCONST__ UBYTE IM_DEFAULT[64] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Header, 10 Octets
- 0x00, 0x2A, // Manufacturer ID, 2 Octets
- 0x50, 0x41, 0x30, 0x30, 0x36, 0x33, 0x30, 0x30, 0x20, 0x20, // Order ID, 20 Octets, PA006300
- 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
- 0x30, 0x30, 0x30, 0x31, 0x31, 0x32, 0x20, 0x20, 0x20, 0x20, // SerialNumber, 16 Octets, 000112
- 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
- 0x00, 0x01, // HardwareRevision, 2 Octets, 1
- 0x56, 0x05, 0x00, 0x00, // SoftwareRevision, 4 Octets, V500
- 0x00, 0x00, // RevisionCounter
- 0x00, 0x00, // PROFILE ID, 2 Octets
- 0x00, 0x00, // PROFILE SPECIFIC TYPE, 2 Octets
- 0x01, 0x01, // IM Version, 2 Octets
- 0x00, 0x01 // IM Supported, 2 Octets
- };
- #endif//#ifdef DPV1_IM_SUPP
- // //counter module
- // SECTION_DEF_CommuData static UWORD counter_value[MAX_DEV_NUM];
- // SECTION_DEF_CommuData static UBYTE counter_timebase[MAX_DEV_NUM];
- // SECTION_DEF_CommuData static UBYTE counter_upper_limit[MAX_DEV_NUM];
- // SECTION_DEF_CommuData static UBYTE counter_lower_limit[MAX_DEV_NUM];
- #define MAX_OUTPUT_COUNT 32
- #define MAX_INPUT_COUNT 128
- typedef struct
- {
- UBYTE Data[MAX_OUTPUT_COUNT];
- } STRUC_OUTPUT;
- typedef struct
- {
- UBYTE Data[MAX_INPUT_COUNT];
- } STRUC_INPUT;
- typedef struct
- {
- UBYTE NrOfModules;
- STRUC_INPUT input;
- STRUC_OUTPUT output;
- } STRUC_SYSTEM;
- SECTION_DEF_CommuData static STRUC_SYSTEM sSystem[MAX_DEV_NUM];
- //初始化实际配置
- SECTION_DEF_CommuCode static void InitRealCfgData(UBYTE dev_num)
- {
- uint8* pRealCfgBuff;
- uint8 nRealCfgLen;
- pRealCfgBuff = GetRealCfgBuffer(dev_num, &nRealCfgLen);
- user[dev_num].real_cfg.length = nRealCfgLen;
- memcpy( &user[dev_num].real_cfg.cfg_data[0], &pRealCfgBuff[0], user[dev_num].real_cfg.length );
- }
- //组装周期性输入数据
- SECTION_DEF_CommuCode static void AssembleInput(UBYTE dev_num)
- {
- int i;
- uint8 nUserInputLen;
- uint8* pDataSrc = GetInputBuffer(dev_num, &nUserInputLen);
- UBYTE *pData = sSystem[dev_num].input.Data;
- for (i=0; i<nUserInputLen; i++)
- {
- pData[i] = pDataSrc[i];
- }
- SendProcess(dev_num,nUserInputLen);
- user[dev_num].event |= VPC3_EV_NEW_INPUT_DATA;
- }
- /*--------------------------------------------------------------------------*/
- /* user_alarm_init function */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode void user_alarm_init(UBYTE dev_num)
- {
- memset(&user[dev_num].al.buffer_used[0], 0, ALARM_MAX_FIFO );
- }
- /*--------------------------------------------------------------------------*/
- /* user_alarm_alloc function */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode ALARM_STATUS_PDU_PTR user_alarm_alloc(UBYTE dev_num)
- {
- ALARM_STATUS_PDU_PTR ptr;
- UBYTE i;
- ptr = NULL;
- for( i = 0; i < ALARM_MAX_FIFO; i++ )
- {
- if(user[dev_num].al.buffer_used[i] == FALSE)
- {
- ptr = &(user[dev_num].al.alarm_buffers[i]);
- user[dev_num].al.buffer_used[i] = TRUE;
- ptr->header = 0;
- ptr->type = 0;
- ptr->slot = 0;
- ptr->spec = 0;
- ptr->user_data_len = 0;
- ptr->user_data_ptr = &(user[dev_num].al.user_alarm_data[i][0]);
- break;
- }
- }
- return ptr;
- }
- /*--------------------------------------------------------------------------*/
- /* user_free_alarm_buffer function */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode void user_free_alarm_buffer(UBYTE dev_num,ALARM_STATUS_PDU_PTR alarm_ptr)
- {
- ALARM_STATUS_PDU_PTR ptr;
- UBYTE i;
- for( i = 0; i <= ALARM_MAX_FIFO; i++ )
- {
- if( user[dev_num].al.buffer_used[i] == TRUE )
- {
- ptr = &(user[dev_num].al.alarm_buffers[i]);
- if( ptr == alarm_ptr )
- {
- user[dev_num].al.buffer_used[i] = FALSE;
- break;
- }
- }
- }
- }
- /*---------------------------------------------------------------------------*/
- /* function: user_alarm (is also called from alarm state machine !!!! ) */
- /*---------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode UBYTE user_alarm(UBYTE dev_num, UBYTE alarm_type, UBYTE seq_nr, ALARM_STATUS_PDU_PTR alarm_ptr, UBYTE check_diag_flag )
- {
- VPC3_UNION_DIAG_PTR tmp_diag;
- UBYTE ret_value;
- UBYTE ext_diag;
- UBYTE len_diag;
- UBYTE error;
- UWORD diag;
- ret_value = 0x00;
- diag = ((UWORD)(alarm_type << 8) | ((UWORD)seq_nr) );
- if((diag != user[dev_num].old_diag) && (FALSE == user[dev_num].user_diag_active))
- {
- memset( &user[dev_num].user_diag[0], 0x00, sizeof( user[dev_num].user_diag ) );
- tmp_diag.byte_ptr = user[dev_num].user_diag;
- ext_diag = 0x00;
- len_diag = 0x00;
- switch( alarm_type )
- {
- case USER_TYPE_CFG_OK:
- {
- //ext_diag = STAT_DIAG_SET;
- break;
- }
- case USER_TYPE_CFG_NOK:
- {
- //modul_status diagnose
- //memcpy( tmp_diag.byte_ptr, &status_diag.sign_len, sizeof_StatusDiag );
- // ext_diag = EXT_DIAG_SET;
- //len_diag = sizeof_StatusDiag;
- break;
- }
- case ALARM_TYPE_DIAGNOSTIC:
- {
- // ext_diag = EXT_DIAG_SET;
- memcpy( tmp_diag.byte_ptr+len_diag, (UBYTE *)&alarm_ptr->header, szAlarmHeader );
- len_diag += szAlarmHeader;
- memcpy( tmp_diag.byte_ptr+len_diag, alarm_ptr->user_data_ptr, alarm_ptr->user_data_len );
- len_diag += alarm_ptr->user_data_len;
- break;
- }
- case ALARM_TYPE_PROCESS: //增加过程报警类型
- {
- // ext_diag = EXT_DIAG_SET;
- memcpy( tmp_diag.byte_ptr+len_diag, (UBYTE *)&alarm_ptr->header, szAlarmHeader );
- len_diag += szAlarmHeader;
- memcpy( tmp_diag.byte_ptr+len_diag, alarm_ptr->user_data_ptr, alarm_ptr->user_data_len );
- len_diag += alarm_ptr->user_data_len;
- break;
- }
- case USER_TYPE_DPV0:
- {
- // ext_diag = EXT_DIAG_SET;
- memcpy( tmp_diag.byte_ptr+len_diag, (UBYTE *)&alarm_ptr->header, szAlarmHeader );
- len_diag += szAlarmHeader;
- memcpy( tmp_diag.byte_ptr+len_diag, alarm_ptr->user_data_ptr, alarm_ptr->user_data_len );
- len_diag += alarm_ptr->user_data_len;
- break;
- }
- case USER_TYPE_APPL_RDY:
- case USER_TYPE_PRM_NOK:
- case USER_TYPE_PRM_OK:
- default:
- {
- ext_diag = 0x00;
- len_diag = 0x00;
- break;
- }
- }
- user[dev_num].user_diag_active = TRUE;
- error = set_diagnosis(dev_num, tmp_diag, len_diag, ext_diag, check_diag_flag );
- if( error == DP_OK )
- {
- user[dev_num].old_diag = diag;
- if( alarm_type >= USER_TYPE_PRM_OK )
- {
- user[dev_num].user_diag_active = FALSE;
- }
- ret_value = DP_OK;
- }
- else
- {
- user[dev_num].user_diag_active = FALSE;
- ret_value = error;
- }
- }
- return ret_value;
- }
- SECTION_DEF_CommuCode UBYTE user_demo_diagnostic(UBYTE dev_num)
- {
- static UBYTE diagnostic_alarm_seq_nr;
- ALARM_STATUS_PDU_PTR p_alarm;
- UBYTE ret_value;
- UBYTE callback;
- UBYTE diag_nr = 1;//test diagnostic
- uint8 *pData;
- ret_value = TRUE;
- p_alarm = user_alarm_alloc(dev_num);
- if( p_alarm != NULL )
- {
- callback = FALSE;
- switch(diag_nr)
- {
- case 0:
- case 1:
- diagnostic_alarm_seq_nr = (diagnostic_alarm_seq_nr + 1) & (MAX_SEQ_NR - 1);
- p_alarm->header = szAlarmHeader + 10; //假设10个用户诊断数据
- p_alarm->type = ALARM_TYPE_DIAGNOSTIC;
- p_alarm->slot = 1;
- p_alarm->spec = (1 == 1)?SPEC_APPEARS:SPEC_DISAPPEARS;
- p_alarm->spec += (diagnostic_alarm_seq_nr << SPEC_SEQ_START);
- p_alarm->user_data_len = 10;//假设10个用户诊断数据
- pData = p_alarm->user_data_ptr;
- *(pData + 0) = diag_nr;
- *(pData + 1) = 0x02;
- *(pData + 2) = 0x03;
- *(pData + 3) = 0x04;
- *(pData + 4) = 0x05;
- callback = TRUE;
- break;
- default:
- break;
- }
- if(user[dev_num].DPV1)
- {
- if( set_alarm(dev_num, p_alarm, callback ) != SET_ALARM_OK )
- {
- user_free_alarm_buffer(dev_num, p_alarm );
- ret_value = FALSE;
- }
- }
- else
- {
- //user_alarm(dev_num, USER_TYPE_DPV0, p_alarm->spec, p_alarm, FALSE );
- if((user_alarm(dev_num, USER_TYPE_DPV0, p_alarm->spec, p_alarm, FALSE )) != DP_OK)
- {
- ret_value = FALSE;
- }
- user_free_alarm_buffer(dev_num, p_alarm );
- }
- }
- return ret_value;
- }
- //组装动作SOE中的测量值信息,返回报文长度
- static uint16 _MeasureInSOEMsg(uint8 * pAddr, const TActionSOE * pSoe)
- {
- uint16 k=0;
- int i;
- for (i=0;i<NUM_MEASINSOE;i++) {
- if(pSoe->measure.Meas[i].MeasType!=MEAS_NONE)
- {
- //测量值类型
- pAddr[k++]=pSoe->measure.Meas[i].MeasType + 1; //测值ID+1
- //值L
- pAddr[k++]=LOBYTE(pSoe->measure.Meas[i].Measure);
- //值H
- pAddr[k++]=HIBYTE(pSoe->measure.Meas[i].Measure);
- }
- }
- return k;
- }
- SECTION_DEF_CommuCode uint8 SendUserDiagnostic(uint8 dev_num, uint8 nDiagType, const void * pDiagData, uint8 bAlarm)
- {
- static UBYTE diagnostic_alarm_seq_nr;
- ALARM_STATUS_PDU_PTR p_alarm;
- UBYTE ret_value;
- UBYTE callback;
- uint16 nMs;
- // uint8 *pData;
- const TActionSOE * pActSOE;
- const TDigitalSOE * pDISOE;
- TDateTime dt;
- int nCounter;
- ret_value = TRUE;
- p_alarm = user_alarm_alloc(dev_num);
- if( p_alarm != NULL )
- {
- callback = FALSE;
- switch(nDiagType)
- {
- case ALARM_ACTION:
- {
- nCounter = 0;
- pActSOE = (const TActionSOE *)pDiagData;
- diagnostic_alarm_seq_nr = (diagnostic_alarm_seq_nr + 1) & (MAX_SEQ_NR - 1);
- p_alarm->header = szAlarmHeader + nCounter; //用户诊断数据长度预留,最后填充
- p_alarm->type = ( user[dev_num].DPV1 == DPV1_STATUS_1_DPV1_ENABLE ) ? ALARM_TYPE_DIAGNOSTIC : STATUS_MESSAGE;//老400V使用诊断报警,照以前方式,500按过程报警上送
- p_alarm->slot = 1;
- p_alarm->spec = (1)?SPEC_APPEARS:SPEC_DISAPPEARS;
- p_alarm->spec += (diagnostic_alarm_seq_nr << SPEC_SEQ_START);
- p_alarm->user_data_len = nCounter;//用户诊断数据长度预留,最后填充
- // pData = p_alarm->user_data_ptr;
- //用户诊断数据
- //11 与GSD文件的诊断块定义对应,value从1开始
- p_alarm->user_data_ptr[0] = pActSOE->type;
- //12 //预留
- p_alarm->user_data_ptr[1] = 0;
- //13 //预留
- p_alarm->user_data_ptr[2] = 0;
- //14 信息类型=1---保护动作
- p_alarm->user_data_ptr[3] = 1;
- //15 报警状态 1---动作 0---复归
- p_alarm->user_data_ptr[4] = 1;
- //16 时
- p_alarm->user_data_ptr[5] = pActSOE->time.h;
- //17 分
- p_alarm->user_data_ptr[6] = pActSOE->time.min;
- //18 毫秒低字节
- //19 毫秒高字节
- nMs = pActSOE->time.ms + pActSOE->time.s*1000;
- p_alarm->user_data_ptr[7] = LOBYTE(nMs);
- p_alarm->user_data_ptr[8] = HIBYTE(nMs);
- //SET_WORD_DATA_(&p_alarm->user_data_ptr[7],);
- //20 故障相别
- p_alarm->user_data_ptr[9] = 0;
- //21 故障量个数n≤14
- p_alarm->user_data_ptr[10] = 0; //在后面填写故障量个数
- //22 故障量1类型
- //23 故障量1低字节
- //24 故障量1高字节
- nCounter = _MeasureInSOEMsg(p_alarm->user_data_ptr + 11, pActSOE);
- p_alarm->user_data_ptr[10] = nCounter/3; //在后面填写故障量个数
- //长度
- p_alarm->user_data_len = 11 + nCounter;
- p_alarm->header = p_alarm->user_data_len+4;
- if(!bAlarm)//使用状态消息
- p_alarm->type = STATUS_MESSAGE;
- callback = TRUE;
- }
- break;
- case ALARM_DI:
- {
- nCounter = 0;
- pDISOE = (const TDigitalSOE *)pDiagData;
- diagnostic_alarm_seq_nr = (diagnostic_alarm_seq_nr + 1) & (MAX_SEQ_NR - 1);
- p_alarm->header = szAlarmHeader + nCounter; //用户诊断数据长度预留,最后填充
- p_alarm->type = ( user[dev_num].DPV1 == DPV1_STATUS_1_DPV1_ENABLE ) ? ALARM_TYPE_DIAGNOSTIC : STATUS_MESSAGE;
- p_alarm->slot = 1;
- p_alarm->spec = (pDISOE->state)?SPEC_APPEARS:SPEC_DISAPPEARS;
- p_alarm->spec += (diagnostic_alarm_seq_nr << SPEC_SEQ_START);
- p_alarm->user_data_len = nCounter;//用户诊断数据长度预留,最后填充
- // pData = p_alarm->user_data_ptr;
- //用户诊断数据
- //11 与GSD文件的诊断块定义对应,value从1开始
- p_alarm->user_data_ptr[0] = pDISOE->type;
- //12 //预留
- p_alarm->user_data_ptr[1] = pDISOE->di;
- //13 //预留
- p_alarm->user_data_ptr[2] = 0;
- //14 信息类型=2---异常/开入变位
- p_alarm->user_data_ptr[3] = 2;
- //15 报警状态 1---动作 0---复归
- p_alarm->user_data_ptr[4] = pDISOE->state;
- //16 时
- p_alarm->user_data_ptr[5] = pDISOE->time.h;
- //17 分
- p_alarm->user_data_ptr[6] = pDISOE->time.min;
- //18 毫秒低字节
- //19 毫秒高字节
- nMs = pDISOE->time.ms + pActSOE->time.s*1000;
- p_alarm->user_data_ptr[7] = LOBYTE(nMs);
- p_alarm->user_data_ptr[8] = HIBYTE(nMs);
- //长度
- p_alarm->user_data_len = 9;
- p_alarm->header = p_alarm->user_data_len+4;
- if(!bAlarm)//使用状态消息
- p_alarm->type = STATUS_MESSAGE;
- callback = TRUE;
- }
- break;
- case ALARM_V0_DIAG:
- {
- diagnostic_alarm_seq_nr = (diagnostic_alarm_seq_nr + 1) & (MAX_SEQ_NR - 1);
- p_alarm->header = szAlarmHeader + MAX_DIAG_DATA_LEN; //用户诊断数据长度
- p_alarm->type = STATUS_MESSAGE;
- p_alarm->slot = 1;
- p_alarm->spec = SPEC_GENERAL + (diagnostic_alarm_seq_nr << SPEC_SEQ_START);
- p_alarm->user_data_len = MAX_DIAG_DATA_LEN;
- // pData = p_alarm->user_data_ptr;
- memset(p_alarm->user_data_ptr+szAlarmHeader, 0, p_alarm->user_data_len);
- memcpy( p_alarm->user_data_ptr, &g_ProfibusRam.V0_DiagData[0], MAX_DIAG_DATA_LEN );
- callback = TRUE;
- }
- break ;
- case ALARM_WAVE: //录波通知
- {
- diagnostic_alarm_seq_nr = (diagnostic_alarm_seq_nr + 1) & (MAX_SEQ_NR - 1);
- p_alarm->header = szAlarmHeader + 4;
- p_alarm->type = ( user[dev_num].DPV1 == DPV1_STATUS_1_DPV1_ENABLE ) ? ALARM_TYPE_DIAGNOSTIC : STATUS_MESSAGE;
- p_alarm->slot = 1;
- p_alarm->spec = SPEC_APPEARS;
- p_alarm->spec += (diagnostic_alarm_seq_nr << SPEC_SEQ_START);
- p_alarm->user_data_len = 0;
- //用户诊断数据
- //*(pData + 0) = 0x00;
- //*(pData + 1) = 0x00;
- //*(pData + 2) = 0x00;
- //*(pData + 3) = ALARM_WAVE;
- //11
- p_alarm->user_data_ptr[0] = 0;
- //12 //预留
- p_alarm->user_data_ptr[1] = 0;
- //13 //预留
- p_alarm->user_data_ptr[2] = 0;
- //14
- p_alarm->user_data_ptr[3] = ALARM_WAVE;
- //TDateTime dtTime; //故障时间,不等于第一区段的时间
- //uint16 nFirstFAN; //第一个故障序号(第一个区段的故障序号)
- //uint16 nNOF; //电网故障序号
- //uint8 nSOF; //故障的状态
- dt = WaveRecord.Config.Start[0].Time;
- p_alarm->user_data_ptr[4] = LOBYTE(dt.y);
- p_alarm->user_data_ptr[5] = HIBYTE(dt.y);
- p_alarm->user_data_ptr[6] = dt.mon;
- p_alarm->user_data_ptr[7] = dt.d;
- p_alarm->user_data_ptr[8] = dt.h;
- p_alarm->user_data_ptr[9] = dt.min;
- nMs = dt.s * 1000 + dt.ms;
- p_alarm->user_data_ptr[10] = LOBYTE(nMs);
- p_alarm->user_data_ptr[11] = HIBYTE(nMs);
- p_alarm->user_data_ptr[12] = LOBYTE(WaveRecord.wavenumber.fan);
- p_alarm->user_data_ptr[13] = HIBYTE(WaveRecord.wavenumber.fan);
- p_alarm->user_data_ptr[14] = LOBYTE(WaveRecord.wavenumber.nof );
- p_alarm->user_data_ptr[15] = HIBYTE(WaveRecord.wavenumber.nof);
- p_alarm->user_data_ptr[16] = LOBYTE(WaveRecord.wavenumber.sof);
- //长度
- p_alarm->user_data_len = 17;
- p_alarm->header = p_alarm->user_data_len+4;
- if(!bAlarm)//使用状态消息
- p_alarm->type = STATUS_MESSAGE;
- callback = TRUE;
- }
- break ;
- default:
- break;
- }
- if(user[dev_num].DPV1 && bAlarm)//增加只有需要报警时才走报警通道
- {
- if( set_alarm(dev_num, p_alarm, callback ) != SET_ALARM_OK )
- {
- //TRACE("set_alarm return not SET_ALARM_OK...");
- user_free_alarm_buffer(dev_num, p_alarm );
- ret_value = FALSE;
- }
- }
- else
- {
- //user_alarm(dev_num, USER_TYPE_DPV0, p_alarm->spec, p_alarm, FALSE );
- if((user_alarm(dev_num, USER_TYPE_DPV0, p_alarm->spec, p_alarm, FALSE )) != DP_OK)
- {
- ret_value = FALSE;
- }
- user_free_alarm_buffer(dev_num, p_alarm );
- }
- }
- else
- {
- //TRACE("user_alarm_alloc return null...");
- ret_value = FALSE;
- }
- return ret_value;
- }
- SECTION_DEF_CommuCode void read_input_data(UBYTE dev_num)
- {
- VPC3_UNSIGNED8_PTR input_buf_ptr; // pointer to input buffer
- int nBlackfinLoop;
- uint16* pBlackfinAddr;
- // uint16* pSrcAddr;
- // write DIN data to VPC3
- if(input_buf_ptr = vpc3_get_dinbufptr (dev_num))
- {
- //memcpy( input_buf_ptr, sSystem[dev_num].input.Data, dp_sys[dev_num].inp_data_len );
- pBlackfinAddr = (uint16*)input_buf_ptr;
- for (nBlackfinLoop=0; nBlackfinLoop<dp_sys[dev_num].inp_data_len; nBlackfinLoop++)
- {
- pBlackfinAddr[nBlackfinLoop] = sSystem[dev_num].input.Data[nBlackfinLoop];
- }
- dp_sys[dev_num].vpc3_con = VPC3_INPUT_UPDATE(dev_num);
- }
- }
- SECTION_DEF_CommuCode void application_ready(UBYTE dev_num)
- {
- #ifdef DPV1_IM_SUPP
- user[dev_num].awImIndex[ 0x03 ] = 0x0000;
- #endif//#ifdef DPV1_IM_SUPP
- read_input_data(dev_num);
- user_alarm(dev_num, USER_TYPE_APPL_RDY, 0, (ALARM_STATUS_PDU_PTR) NULL_PTR, FALSE );
- user[dev_num].application_ready = TRUE;
- }
- SECTION_DEF_CommuCode bool16 InitVPC3(int dev_num, uint8 nAddr)
- {
- DP_ERROR_CODE error;
- //用户数据结构
- memset( &user[dev_num], 0, sizeof(USER_STRUC) );
- user[dev_num].user_diag_active = FALSE;
- user[dev_num].application_ready = FALSE;
- user[dev_num].state = USER_STATE_CLEAR;
- //VPC3 使用的数据结构
- memset( &sSystem[dev_num], 0, sizeof(STRUC_SYSTEM) );
- //初始化实际配置信息
- InitRealCfgData(dev_num);
- //复位芯片
- ResetVPC3(dev_num);
- //芯片及协议栈初始化
- error = vpc3_initialization(dev_num, nAddr, user[dev_num].real_cfg );
- if( DP_OK == error )
- {
- START_VPC3(dev_num);
- }
- else
- {
- vpc3_errcb[dev_num].error_code = error;
- fatal_error(dev_num, _DP_USER, __LINE__, &vpc3_errcb[dev_num] );
- }
- return (error == DP_OK);
- }
- SECTION_DEF_CommuCode int GetProfibusBaudRate(int dev_num)
- {
- return VPC3_GET_BAUDRATE(dev_num);
- }
- SECTION_DEF_CommuCode bool16 IsInDPV1Status(uint8 nDevID)
- {
- return user[nDevID].DPV1 == DPV1_STATUS_1_DPV1_ENABLE;
- }
- SECTION_DEF_CommuCode int GetProfibusPrmCount(int dev_num)
- {
- return g_nPrmCount[dev_num];
- }
- SECTION_DEF_CommuCode int GetProfibusCheckCfgCount(int dev_num)
- {
- return g_nCheckCfgCount[dev_num];
- }
- SECTION_DEF_CommuCode int GetProfibusMasterAddr(int dev_num)
- {
- return vpc3_get_master(dev_num);
- }
- SECTION_DEF_CommuCode int GetProfibusDPState(int dev_num)
- {
- return VPC3_GET_DP_STATE(dev_num);
- }
- SECTION_DEF_CommuCode int GetProfibusC1ReadCount(int dev_num)
- {
- return g_nC1ReadCount[dev_num];
- }
- SECTION_DEF_CommuCode int GetProfibusC1WriteCount(int dev_num)
- {
- return g_nC1WriteCount[dev_num];
- }
- /*---------------------------------------------------------------------------*/
- /* user main function */
- /*---------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode void user_main(int if_num)
- {
- VPC3_UNSIGNED8_PTR output_buf_ptr; // pointer to output buffer
- // DP_ERROR_CODE error;
- UBYTE outp_state; // state of output data
- UBYTE dev_num = (UBYTE)if_num;
- UBYTE dp_state;
- // UBYTE i=0;
- // UWORD cnt=0;
- int nBlackfinLoop;
- // uint16* pBlackfinAddr;
- uint16* pSrcAddr;
- // int nBaudRate = VPC3_GET_BAUDRATE(dev_num) ;
- if( 1 )
- {
- //toggle user watchdog
- VPC3_RESET_USER_WD(dev_num);
- vpc3_isr(dev_num);
- if( user[dev_num].state == USER_STATE_CLEAR )
- {
- memset(sSystem[dev_num].input.Data , 0, MAX_INPUT_COUNT);
- memset(sSystem[dev_num].output.Data , 0, MAX_OUTPUT_COUNT);
- user[dev_num].state = USER_STATE_RUN;
- }
- vpc3_dpv1_statemachine(dev_num);
- dp_state = VPC3_GET_DP_STATE(dev_num);
- switch(dp_state)
- {
- case WAIT_PRM:
- case WAIT_CFG:
- case DP_ERROR:
- {
- if( user[dev_num].event & VPC3_EV_DX_OUT )
- {
- user[dev_num].event &= ~VPC3_EV_DX_OUT; // clear event
- }
- SetDataExchangeLED(FALSE);
- break;
- }
- case DATA_EX:
- {
- if((user[dev_num].application_ready == TRUE) && (user[dev_num].state == USER_STATE_RUN))
- {
- SetDataExchangeLED(TRUE);
- //处理周期性输出
- if( user[dev_num].event & VPC3_EV_DX_OUT )
- {
- user[dev_num].event &= ~VPC3_EV_DX_OUT;
- if( output_buf_ptr = vpc3_get_doutbufptr (dev_num,&outp_state) )
- {
- //memcpy( sSystem[dev_num].output.Data, output_buf_ptr, dp_sys[dev_num].outp_data_len);
- pSrcAddr = (uint16*)output_buf_ptr;
- for (nBlackfinLoop=0; nBlackfinLoop<dp_sys[dev_num].outp_data_len; nBlackfinLoop++)
- {
- sSystem[dev_num].output.Data[nBlackfinLoop] = pSrcAddr[nBlackfinLoop];
- }
- //处理输出数据
- SetOutputBuffer(dev_num, sSystem[dev_num].output.Data, dp_sys[dev_num].outp_data_len);
- ReceiveProcess(dev_num,dp_sys[dev_num].outp_data_len);
- }
- }
- //处理诊断
- AlarmProcess(dev_num);
- //处理输入信息
- AssembleInput(dev_num);
- if( user[dev_num].event & VPC3_EV_NEW_INPUT_DATA )
- {
- read_input_data(dev_num);
- user[dev_num].event &= ~VPC3_EV_NEW_INPUT_DATA;
- }
- //其他空闲任务处理
- DoEventInDxState(dev_num);
- //CS中断
- if (user[dev_num].event & VPC3_EV_MAC_RESET)
- {
- user[dev_num].event &= ~VPC3_EV_MAC_RESET; // clear event
- //print_cs_buffer();
- }
- }
- break;
- }
- default:
- {
- SetDataExchangeLED(FALSE);
- vpc3_errcb[dev_num].error_code = VPC3_GET_DP_STATE(dev_num);
- fatal_error(dev_num, _DP_USER, __LINE__, &vpc3_errcb[dev_num] );
- break;
- }
- }
- //handle here profibus interrupt events
- if( user[dev_num].event & VPC3_EV_NEW_CFG_DATA )
- {
- application_ready(dev_num);
- user[dev_num].event &= ~VPC3_EV_NEW_CFG_DATA;
- }
- }
- }
- /*---------------------------------------------------------------------------*/
- /* */
- /* function: fatal_error */
- /* */
- /*---------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode void fatal_error(UBYTE dev_num, DP_ERROR_FILE file, UWORD line, VPC3_ERRCB_PTR errcb_ptr)
- {
- }
- /*---------------------------------------------------------------------------*/
- /* function: user_isr_new_prm_data */
- /* */
- /* todo : check the prm-data */
- /* return: DP_OK - prm-data OK */
- /* DP_NOK - prm-data not OK */
- /*---------------------------------------------------------------------------*/
- #if( ISR_ENABLE_VPC3_INT_NEW_PRM_DATA == 1 )
- SECTION_DEF_CommuCode UBYTE user_chk_new_prm_data(UBYTE dev_num, VPC3_UNSIGNED8_PTR prm_ptr, UBYTE len )
- {
- typedef struct
- {
- UBYTE len;
- UBYTE slot_nr;
- UBYTE user_data;
- }STRUC_MODULE_PRM_BLOCK;
- #define VPC3_STRUC_MODULE_PRM_BLOCK_PTR STRUC_MODULE_PRM_BLOCK PTR_ATTR *
- // VPC3_STRUC_MODULE_PRM_BLOCK_PTR module_block;
- VPC3_STRUC_PRM_PTR prm_data;
- UBYTE ret_value;
- UWORD Clock_Sync_Interval;
- UBYTE i;
- UBYTE theUserPrmDataBuff[64];
- user[dev_num].DPV1 = 0x00;
- ret_value = DP_OK;
- #ifdef DP_TIMESTAMP
- //设置时钟同步报文间隔
- Clock_Sync_Interval = 100; //10ms单位, 1S校时一次
- p_Vpc3[dev_num]->cs.clock.sync_interval[0] = HIBYTE(Clock_Sync_Interval);
- p_Vpc3[dev_num]->cs.clock.sync_interval[1] = LOBYTE(Clock_Sync_Interval);
- #endif
- if( len == 0x0B )
- {
- g_nPrmCount[dev_num]++; //参数化计数器
- prm_data = (VPC3_STRUC_PRM_PTR)prm_ptr;
- //DPV1 Statusbyte 1
- user[dev_num].DPV1 = (prm_data->dpv1_status_1 & DPV1_STATUS_1_DPV1_ENABLE );
- g_ProfibusRam.bDPV1Enable = !!user[dev_num].DPV1;//DPV1启用标志
- if( user[dev_num].DPV1 == DPV1_STATUS_1_DPV1_ENABLE )
- {
- // DPV1 enabled
- if( (( prm_data->dpv1_status_1 & 0x18 ) != 0x00 )
- || (( prm_data->dpv1_status_2 & 0x03 ) != 0x00 )
- || ((prm_data->dpv1_status_3 & 0xFF ) != 0x00 )
- )
- {
- ret_value = DP_PRM_DPV1_STATUS;
- }
- }//if( user[dev_num].DPV1 == DPV1_STATUS_1_DPV1_ENABLE )
- else
- {
- //DP-Mode
- if( (( prm_data->dpv1_status_1 & 0x18 ) != 0x00 )
- || (( prm_data->dpv1_status_2 & 0xFF ) != 0x00 )
- || (( prm_data->dpv1_status_3 & 0xFF ) != 0x00 )
- )
- {
- ret_value = DP_PRM_DPV1_STATUS;
- }
- }//else of if( user[dev_num].DPV1 == DPV1_STATUS_1_DPV1_ENABLE )
- //用户参数化数据
- for(i=0; i<len-10; i++)
- {
- theUserPrmDataBuff[i] = *( ((BLACKFINDATATYPE*)&prm_data->user_data) + i);
- }
- //检查用户参数化数据
- if(SetPrmBuffer(dev_num, theUserPrmDataBuff, len-10))
- {
- ret_value = DP_OK;
- }
- else
- {
- ret_value = DP_NOK;
- }
- }
- else
- {
- ret_value = DP_PRM_LEN_ERROR;
- }
- if( ( VPC3_GET_DP_STATE(dev_num) == DATA_EX ) && (ret_value == DP_OK ) )
- {
- //don't send diagnostic here
- }
- else
- {
- user_alarm(dev_num, USER_TYPE_PRM_OK, 0, (ALARM_STATUS_PDU_PTR) NULL_PTR, FALSE );
- }
- return ret_value;
- }
- #endif
- /*---------------------------------------------------------------------------*/
- /* function: user_isr_new_ext_prm_data */
- /* */
- /* todo : check the prm-data */
- /* return: DP_OK - prm-data OK */
- /* DP_NOK - prm-data not OK */
- /*---------------------------------------------------------------------------*/
- #if( ISR_ENABLE_VPC3_INT_NEW_EXT_PRM_DATA == 1 )
- SECTION_DEF_CommuCode UBYTE user_chk_new_ext_prm_data(UBYTE dev_num, VPC3_STRUC_PRM_BLOCK_PTR prmblock_ptr, UBYTE len )
- {
- UBYTE ret_value;
- ret_value = DP_OK;
- len = len;
- // TRACE("user_chk_new_ext_prm_data len:%d cmd:%d slot:%d index:%d ",
- // prmblock_ptr->len&0xff,
- // prmblock_ptr->command&0xff,
- // prmblock_ptr->slot_nr&0xff,
- // prmblock_ptr->index&0xff
- // );
- //
- // if( (prmblock_ptr->command == PBC_USER_PRM_DATA )
- // && (prmblock_ptr->len == 0x0C )
- // && (prmblock_ptr->slot_nr == 0x00 )
- // && (prmblock_ptr->index == 0x00 )
- // )
- // {
- // //copy counter parameter data
- // memcpy( &sSystem[dev_num].prm, &prmblock_ptr->user_data+1, 7 );
- //
- // //check parameter of counter module
- // if( (sSystem[dev_num].prm.alarm & 0xFC ) //check alarm
- // || (sSystem[dev_num].prm.mode > 0x01 ) //check counter mode
- // || ( sSystem[dev_num].prm.time_base > 0x05 ) //check counter timebase
- // )
- // {
- // //error
- // ret_value = DP_PRM_ENTRY_ERROR;
- // }//if( (counter.prm.len != 9 ) ...
- // }
- // else
- // {
- // ret_value = DP_PRM_BLOCK_ERROR;
- // }
- return ret_value;
- }
- #endif
- /*---------------------------------------------------------------------------*/
- /* function: user_isr_new_cfg_data */
- /* */
- /* todo : check cfg data */
- /* */
- /* return: VPC3_CFG_OK 0 */
- /* VPC3_CFG_FAULT 1 */
- /* VPC3_CFG_UPDATE 2 */
- /*---------------------------------------------------------------------------*/
- #if( ISR_ENABLE_VPC3_INT_NEW_CFG_DATA == 1 )
- SECTION_DEF_CommuCode UBYTE user_chk_new_cfg_data(UBYTE mdev_num)
- {
- VPC3_UNSIGNED8_PTR cfg_ptr; // pointer check config buffer
- UBYTE ret_value = VPC3_CFG_OK;
- UBYTE cfg_len;
- UBYTE i;
- UBYTE bBU_DO_ModuleExist;
- UBYTE bBU_DI_ModuleExist;
- UBYTE dev_num = mdev_num;
- UBYTE real_cfg_len;
- cfg_ptr = VPC3_GET_CFG_BUF_PTR(dev_num);
- cfg_len = VPC3_GET_CFG_LEN(dev_num)&0xff;
- if(!g_ProfibusRam.bSiemensCompatiable)
- {
- //和公司主控通讯时
- real_cfg_len = user[dev_num].real_cfg.length&0xff;
- if( (cfg_len) != real_cfg_len )
- {
- ret_value = VPC3_CFG_FAULT;
- }//if( cfg_len != real_cfg_len )
- else
- {
- if( xmemcmp( &user[dev_num].real_cfg.cfg_data[0], cfg_ptr, user[dev_num].real_cfg.length&0xff ) == 0 )
- {
- SetHaveSOEModule(1);//默认只使用1条SOE的空间
- ret_value = VPC3_CFG_UPDATE;//更新配置
- }
- else
- {
- SetHaveSOEModule(0);
- ret_value = VPC3_CFG_FAULT;
- }
- }
- }
- else
- {
- //和其他单位主控通讯时
- bBU_DO_ModuleExist = FALSE;
- bBU_DI_ModuleExist = FALSE;
- if(cfg_len % 4)
- {
- //先检查长度是否合理,1个模建配置数据为4个字节
- ret_value = VPC3_CFG_FAULT;
- }
- else
- {
- //解析模件配置信息
- g_ProfibusRam.nModuleCount = cfg_len/4;
- if(g_ProfibusRam.nModuleCount > MaxModule)
- {
- ret_value = VPC3_CFG_FAULT;
- }
- else
- {
- for (i=0; i<g_ProfibusRam.nModuleCount; i++)
- {
- //检查配置配置信息是否合理
- g_ProfibusRam.CfgModules[i].nModuleID = cfg_ptr[3]&0xff; //模件ID号
- if(g_ProfibusRam.CfgModules[i].nModuleID == ID_MODULE_BUDIDO) //判段是否含有基本输入输出模件
- {
- bBU_DO_ModuleExist = TRUE;
- bBU_DI_ModuleExist = TRUE;
- }
- else if(g_ProfibusRam.CfgModules[i].nModuleID == ID_MODULE_SOE)//判断是否含有SOE模件
- SetHaveSOEModule(1);//默认只使用1条SOE的空间
- if((cfg_ptr[0]&0xff) == 0x82) //输出模件
- {
- g_ProfibusRam.CfgModules[i].nModuleInputBytes = 0;
- g_ProfibusRam.CfgModules[i].nModuleOutputBytes = cfg_ptr[1] & 0x3f;
- }
- else if ((cfg_ptr[0]&0xff) == 0x42)//输入模件
- {
- g_ProfibusRam.CfgModules[i].nModuleInputBytes = cfg_ptr[1] & 0x3f;
- g_ProfibusRam.CfgModules[i].nModuleOutputBytes = 0;
- }
- else if((cfg_ptr[0]&0xff) == 0xC1)//输入输出模件,BU及SOE模件均含输入输出
- {
- g_ProfibusRam.CfgModules[i].nModuleInputBytes = cfg_ptr[1] & 0x3f;
- g_ProfibusRam.CfgModules[i].nModuleOutputBytes = cfg_ptr[2] & 0x3f;
- }
- else
- {
- //其他的不支持
- ret_value = VPC3_CFG_FAULT;
- }
- cfg_ptr += 4;
- }
- //如果基本开入开出模件不存在,认为是配置出错
- if (!bBU_DO_ModuleExist || !bBU_DI_ModuleExist)
- {
- ret_value = VPC3_CFG_FAULT;
- }
- }
- //更新本地配置数据信息
- if (ret_value != VPC3_CFG_FAULT)
- {
- ret_value = VPC3_CFG_UPDATE;
- }
- }
- }
- if( ret_value == VPC3_CFG_OK || ret_value == VPC3_CFG_UPDATE)
- {
- g_nCheckCfgCount[dev_num]++; //累计检查配置次数
- user_alarm(dev_num, USER_TYPE_CFG_OK, 0, (ALARM_STATUS_PDU_PTR) NULL_PTR, FALSE );
- user[dev_num].event |= VPC3_EV_NEW_CFG_DATA;
- }
- /*
- else
- {
- user_alarm(dev_num, USER_TYPE_CFG_NOK, status_diag.user_data[ 0 ], (ALARM_STATUS_PDU_PTR) NULL_PTR, FALSE );
- }//else of if( ret_value == VPC3_CFG_UPDATE )*/
- user_alarm_init(dev_num);
- return ret_value;
- }
- #endif
- /*---------------------------------------------------------------------------*/
- /* function: user_isr_go_leave_data_ex */
- /*---------------------------------------------------------------------------*/
- #if( ISR_ENABLE_VPC3_INT_GO_LEAVE_DATA_EX == 1 )
- SECTION_DEF_CommuCode void user_isr_go_leave_data_ex(UBYTE dev_num)
- {
- if( VPC3_GET_DP_STATE(dev_num) != DATA_EX )
- {
- user[dev_num].state = USER_STATE_CLEAR;
- user[dev_num].application_ready = FALSE;
- }
- // TRACE("user_isr_go_leave_data_ex %d", dev_num);
- }
- #endif
- /*---------------------------------------------------------------------------*/
- /* function: user_isr_dx_out */
- /*---------------------------------------------------------------------------*/
- #if( ISR_ENABLE_VPC3_INT_DX_OUT == 1 )
- SECTION_DEF_CommuCode void user_isr_dx_out(UBYTE dev_num)
- {
- user[dev_num].event |= VPC3_EV_DX_OUT;
- }
- #endif
- /*---------------------------------------------------------------------------*/
- /* function: user_isr_diag_buf_changed */
- /*---------------------------------------------------------------------------*/
- #if( ISR_ENABLE_VPC3_INT_DIAG_BUF_CHANGED == 1 )
- SECTION_DEF_CommuCode void user_isr_diag_buf_changed(UBYTE dev_num)
- {
- // diagnosis buffer has been changed
- user[dev_num].user_diag_active = FALSE;
- // Fetch new diagnosis buffer
- dp_sys[dev_num].diag_buf_ptr.byte_ptr = vpc3_get_diagbufptr(dev_num);
- }
- #endif
- /*---------------------------------------------------------------------------*/
- /* function: user_isr_new_wd_timeout */
- /*---------------------------------------------------------------------------*/
- #if( ISR_ENABLE_VPC3_INT_WD_DP_TIMEOUT == 1 )
- SECTION_DEF_CommuCode void user_isr_new_wd_dp_timeout(UBYTE dev_num)
- {
- reset_diagnostic_buffer(dev_num);
- }
- #endif
- /*---------------------------------------------------------------------------*/
- /* function: user_isr_mac_reset */
- /*---------------------------------------------------------------------------*/
- #if( ISR_ENABLE_VPC3_INT_MAC_RESET == 1 )
- #define CS_SET_TIME 0x01
- #define CS_Clock_Sync_Violation 0X02
- SECTION_DEF_CommuCode void user_isr_mac_reset(UBYTE dev_num)
- {
- #ifdef DP_TIMESTAMP
- TDateTime fullDt;
- TClockSync* pCS = &p_Vpc3[dev_num]->cs;
- uint64 ullVal;
- uint32 nRcvDelay;//接收延时
- uint32 nTotalSec;
- uint32 nTotalMs;
- user[dev_num].event |= VPC3_EV_MAC_RESET;
- //用于时钟同步功能
- if (p_Vpc3[dev_num]->mode_reg0_L & 0x80)//启用了时钟同步
- {
- if (g_ProfibusRam.bClockSyncEnabled)
- {
- //判断时钟状态
- if (p_Vpc3[dev_num]->cs.clock.status & CS_SET_TIME)
- {
- nTotalSec = MAKEDWORD(MAKEWORD(pCS->clock.cv_time_event[3],pCS->clock.cv_time_event[2]),MAKEWORD(pCS->clock.cv_time_event[1],pCS->clock.cv_time_event[0]));
- ullVal = MAKEDWORD(MAKEWORD(pCS->clock.cv_time_event[3+4],pCS->clock.cv_time_event[2+4]),MAKEWORD(pCS->clock.cv_time_event[1+4],pCS->clock.cv_time_event[0+4])) ;
- ullVal *= 1000000;
- nRcvDelay = MAKEDWORD(MAKEWORD(pCS->clock.rd_time[3],pCS->clock.rd_time[2]),MAKEWORD(pCS->clock.rd_time[1],pCS->clock.rd_time[0]));
- nTotalMs = ( (ullVal >> 32) + nRcvDelay) / 1000;
- if(nTotalMs > 1000)
- {
- nTotalSec+=nTotalMs/1000;
- nTotalMs%=1000;
- }
- //将Profibus时间戳格式转换成全时间格式
- fullDt = _TimeFromSeconds(nTotalSec);
- fullDt.ms = nTotalMs;
- //校正系统时钟
- fullDt.y %= 100; //2000年开始范围 <= 99
- SetDeviceSystemTime(&fullDt);
- }
- else if(p_Vpc3[dev_num]->cs.clock.status & CS_Clock_Sync_Violation)
- {
- // TRACE("Clock_Sync_Violation");
- }
- }
- }
- else
- {
- // TRACE("user_isr_mac_reset");
- }
- #endif
- }
- #endif
- /*---------------------------------------------------------------------------*/
- /* function: user_isr_baudrate_detect */
- /*---------------------------------------------------------------------------*/
- #if( ISR_ENABLE_VPC3_INT_BAUDRATE_DETECT == 1 )
- SECTION_DEF_CommuCode void user_isr_baudrate_detect(UBYTE dev_num)
- {
- //not used in our application
- }
- #endif
- /*---------------------------------------------------------------------------*/
- /* function: user_isr_new_gc_command */
- /*---------------------------------------------------------------------------*/
- #if( ISR_ENABLE_VPC3_INT_NEW_GC_COMMAND == 1 )
- SECTION_DEF_CommuCode void user_isr_new_gc_command(UBYTE dev_num)
- {
- //not used in our application
- }
- #endif
- /*---------------------------------------------------------------------------*/
- /* function: user_isr_new_ssa_data */
- /*---------------------------------------------------------------------------*/
- #if( ISR_ENABLE_VPC3_INT_NEW_SSA_DATA == 1 )
- SECTION_DEF_CommuCode void user_isr_new_ssa_data(UBYTE dev_num)
- {
- //not used in our application
- VPC3_STRUC_SSA_BLOCK_PTR ssa_ptr;
- ssa_ptr = (VPC3_STRUC_SSA_BLOCK_PTR) VPC3_GET_SSA_BUF_PTR(dev_num);
- //一般不使用该功能
- SetSlaveAddressReq(ssa_ptr->address);
- }
- #endif
- /*---------------------------------------------------------------------------*/
- /* function: user_isr_user_timer_clock (10ms) */
- /*---------------------------------------------------------------------------*/
- #if( ISR_ENABLE_VPC3_INT_USER_TIMER_CLOCK == 1 )
- SECTION_DEF_CommuCode void user_isr_user_timer_clock(UBYTE dev_num)
- {
- //not used in our application
- }
- #endif
- #ifdef DP_SUBSCRIBER
- /*---------------------------------------------------------------------------*/
- /* function: user_isr_dxb_out */
- /*---------------------------------------------------------------------------*/
- #if( ISR_ENABLE_VPC3_INT_DXB_OUT == 1 )
- SECTION_DEF_CommuCode void user_isr_dxb_out(UBYTE dev_num)
- {
- user[dev_num].event |= VPC3_EV_DXB_OUT;
- }
- #endif
- /*---------------------------------------------------------------------------*/
- /* function: user_isr_dxb_link_error */
- /*---------------------------------------------------------------------------*/
- #if( ISR_ENABLE_VPC3_INT_DXB_LINK_ERROR == 1 )
- SECTION_DEF_CommuCode void user_isr_dxb_link_error(UBYTE dev_num)
- {
- user[dev_num].event |= VPC3_EV_DXB_LINK_ERROR;
- }
- #endif
- #endif//#ifdef DP_SUBSCRIBER
- #ifdef DP_ALARM
- /*--------------------------------------------------------------------------*/
- /* user_alarm_state_info (UBYTE dev_num,called by DPV1) */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode void user_alarm_state_info(UBYTE dev_num, UBYTE alarm_type_bit_field, UBYTE sequence_depth )
- {
- UBYTE i;
- sequence_depth = sequence_depth;
- if( alarm_type_bit_field == ALARM_TYPE_NONE_VALUE )
- {
- //alarmstatemachine stopped, remove pending alarms
- for( i = 0; i <= ALARM_MAX_FIFO; i++ )
- {
- if( user[dev_num].al.buffer_used[i] == TRUE )
- {
- user[dev_num].al.buffer_used[i] = FALSE;
- }//if( user[dev_num].al.buffer_used[i] == TRUE )
- }//for( i = 0; i <= ALARM_MAX_FIFO; i++ )
- clear_alarm(dev_num, ALARM_TYPE_ALL_VALUE, SEQUENCE_NUMBER_ALL );
- user[dev_num].al.state = USER_AL_STATE_CLOSED;
- }//if( alarm_type_bit_field == 0 )
- else
- {
- //enable setted alarms
- user[dev_num].al.state = USER_AL_STATE_OPEN;
- }
- }
- /*--------------------------------------------------------------------------*/
- /* user_alarm_ack_req (UBYTE dev_num,called by DPV1) */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode void user_alarm_ack_req(UBYTE dev_num, ALARM_STATUS_PDU_PTR alarm_ptr )//SOE ACK---DPV1
- {
- logMsg("receive user_alarm_ack_req!n",0,0,0,0,0,0);
- // alarm_ack from master received
- // todo: do your alarm-acknowledge handling here
- user_free_alarm_buffer(dev_num, alarm_ptr );
- AlarmACK(dev_num);//报警确认
- reset_diagnostic_buffer(dev_num);
- }
- #endif // #ifdef DP_ALARM
- #ifdef DP_MSAC_C2
- /*--------------------------------------------------------------------------*/
- /* msac_c2_initiate_req (UBYTE dev_num,called by DPV1) */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode DPV1_RET_VAL user_c2_initiate_req(UBYTE dev_num, UBYTE sap, DPV1_PTR pdu )
- {
- MSAC_C2_INITIATE_SUB_PARAM PTR_ATTR * d_addr_ptr;
- DPV1_RET_VAL ret_value;
- sap = sap; //avoid warning
- #ifdef DPV1_IM_SUPP
- user[dev_num].awImIndex[ (sap & 0x0F ) ] = 0x0000;
- #endif//#ifdef DPV1_IM_SUPP
- #ifdef _KEIL_C51
- d_addr_ptr=(MSAC_C2_INITIATE_SUB_PARAM PTR_ATTR * ) &(pdu->initiate_req.addr_data + BFWORD2BYTE(pdu->initiate_req.s_len)); //C51
- #else
- d_addr_ptr=(MSAC_C2_INITIATE_SUB_PARAM PTR_ATTR* )(pdu->initiate_req.addr_data + BFWORD2BYTE(pdu->initiate_req.s_len)); //166
- #endif //#ifdef _KEIL_C51
- if( BFWORD2BYTE(d_addr_ptr->api) == 0 )
- {
- // in this example only API 0 is supported */
- if( msac_c2_initiate_req_to_res(dev_num,pdu) == DPV1_OK)
- {
- //如果界面允许可以跟踪子站所接收的连接情况
- EDD_C2_InitiateReq(dev_num);
- // Initiate-Request-PDU has been changed to Initiate-Response-PDU */
- ret_value = DPV1_OK;
- }
- else
- {
- // D-Typ is no endpoint of connection
- // user must handle Initiate-PDU (no change by MSAC_C2)
- // in this example slave must always be endpoint
- // create negative response
- pdu->neg.err_code1 = DPV1_ERRCL_APPLICATION | DPV1_ERRCL_APP_NOTSUPP;
- pdu->neg.err_code2 = 0x00;
- ret_value = DPV1_NOK;
- }
- }
- else
- {
- /* create ABORT-PDU */
- pdu->abort.subnet = MSAC_C2_SUBNET_NO;
- pdu->abort.instance_reason = MSAC_C2_INSTANCE_MSAC_C2 | MSAC_C2_ABT_IA;
- ret_value = DPV1_ABORT;
- }
- return ret_value;
- }//DPV1_RET_VAL user_c2_initiate_req(UBYTE dev_num, UBYTE sap, DPV1_PTR pdu )
- /*--------------------------------------------------------------------------*/
- /* user_c2_data_transport_req (UBYTE dev_num,called by DPV1) */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode DPV1_RET_VAL user_c2_data_transport_req(UBYTE dev_num, UBYTE sap, DPV1_PTR pdu )
- {
- DPV1_RET_VAL ret_value;
- int nBlackfinLoop;
- //uint16* pBlackfinAddr;
- uint16* pSrcAddr;
- if( sap == DP_C1_RD_WR_SAP_NR )
- {
- pdu->neg.err_code1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_PARAM;
- pdu->neg.err_code2 = 0x00;
- ret_value = DPV1_NOK;
- }//if( sap == DP_C1_RD_WR_SAP_NR )
- else
- {
- if( BFWORD2BYTE( pdu->transport.length) > (C2_LEN-4) )
- {
- pdu->transport.length = (C2_LEN-4);
- }
- if( BFWORD2BYTE(pdu->transport.slot_num) == 0x00 )
- {
- if( BFWORD2BYTE(pdu->transport.index) == 0x02 )
- {
- //memcpy( &user[dev_num].dpv1_rw_buffer[0], &pdu->transport.pdu_data[0], pdu->transport.length );
- pSrcAddr = (uint16*)&pdu->transport.pdu_data[0];
- for (nBlackfinLoop=0; nBlackfinLoop<BFWORD2BYTE(pdu->transport.length); nBlackfinLoop++)
- {
- user[dev_num].dpv1_rw_buffer[nBlackfinLoop] = pSrcAddr[nBlackfinLoop];
- }
- ret_value = DPV1_OK;
- }//if( pdu->transport.index == 0x00 )
- else
- {
- pdu->neg.err_code1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_INDEX;
- pdu->neg.err_code2 = 0x00;
- ret_value = DPV1_NOK;
- }//else of if( pdu->v.index == 0x00 )
- }//if( pdu->transport.slot_num == 0x00 )
- else
- {
- pdu->neg.err_code1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_SLOT;
- pdu->neg.err_code2 = 0x00;
- ret_value = DPV1_NOK;
- }//else of if( pdu->transport.slot_num == 0x00 )
- }//else of if( sap == DP_C1_RD_WR_SAP_NR )
- return ret_value;
- }//DPV1_RET_VAL user_c2_data_transport_req(UBYTE dev_num,UBYTE sap, DPV1_PTR pdu)
- /*--------------------------------------------------------------------------*/
- /* dpv1_abort_ind (UBYTE dev_num,called by DPV1) */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode DPV1_RET_VAL user_c2_abort_ind(UBYTE dev_num,UBYTE sap, DPV1_PTR pdu)
- {
- sap = sap; //avoid warning
- pdu = pdu; //avoid warning
- #ifdef DPV1_IM_SUPP
- user[dev_num].awImIndex[ (sap & 0x0F ) ] = 0x0000;
- #endif//#ifdef DPV1_IM_SUPP
- EDD_C2_AbortInd(dev_num);
- return DPV1_OK;
- }//DPV1_RET_VAL user_c2_abort_ind(UBYTE dev_num,UBYTE sap, DPV1_PTR pdu)
- #endif //#ifdef DP_MSAC_C2
- #ifdef DP_FDL
- /*--------------------------------------------------------------------------*/
- /* user_dpv1_read_req (called by DPV1) */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode DPV1_RET_VAL user_dpv1_read_req(UBYTE dev_num, UBYTE sap, DPV1_PTR pdu)//dpv1 read complete the task data from user to buffer
- {
- DPV1_RET_VAL ret_value;
- UBYTE max_length=0;
- //int nBlackfinLoop;
- //uint16* pBlackfinAddr;
- int i;
- uint8* pDataRet;
- uint8 nDataLenRet;
- uint8 nErrCode1, nErrCode2;
- g_nC1ReadCount[dev_num]++;
- ret_value = DPV1_OK;
- #ifdef DPV1_IM_SUPP
- psIMCALL ps_ImCall;
- #endif//#ifdef DPV1_IM_SUPP
- #ifdef DPV1_IM_SUPP
- if( BFWORD2BYTE(pdu->read.index) == 255 )
- {
- if( BFWORD2BYTE(pdu->read.slot_num) == 0 )
- {
- //check_extended function number, reserved byte and IM_INDEX
- if( user[dev_num].awImIndex[ ( sap & 0x0F ) ] == IM0_INDEX )
- {
- ps_ImCall = (psIMCALL)&pdu->read.pdu_data[0];
- ps_ImCall->bExtendedFunctionNumber = IM_FN_CALL;
- ps_ImCall->bReserved = 0x00;
- ps_ImCall->wIndex = BFWORD2LONG(user[dev_num].awImIndex[ ( sap & 0x0F ) ]);
- //memcpy( &pdu->read.pdu_data[4], &IM_DEFAULT[0], SizeOfIM0 );
- pBlackfinAddr = (uint16*)&pdu->read.pdu_data[4];
- for (nBlackfinLoop=0; nBlackfinLoop<SizeOfIM0; nBlackfinLoop++)
- {
- pBlackfinAddr[nBlackfinLoop] = IM_DEFAULT[nBlackfinLoop];
- }
- if( BFWORD2BYTE(pdu->read.length) > (4 + SizeOfIM0) )
- {
- pdu->read.length = 4 + SizeOfIM0;
- }
- }//if( user.awImIndex[ ( sap & 0x0F ) ] == IM0_INDEX )
- else
- {
- pdu->neg.err_code1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_PARAM;
- pdu->neg.err_code2 = 0x00;
- ret_value = DPV1_NOK;
- }//else of if( user.awImIndex[ ( sap & 0x0F ) ] == IM0_INDEX )
- }//if( pdu->read.slot_num == 0 )
- else
- {
- pdu->neg.err_code1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_SLOT;
- pdu->neg.err_code2 = 0x00;
- ret_value = DPV1_NOK;
- }//else of if( pdu->read.slot_num == 0 )
- }
- #else
- if( BFWORD2BYTE(pdu->read.index) == 255 )
- {
- pdu->neg.err_code1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_INDEX;
- pdu->neg.err_code2 = 0x00;
- ret_value = DPV1_NOK;
- }
- #endif//#ifdef DPV1_IM_SUPP
- //应用处理部分
- else if(ret_value == DPV1_OK)
- {
- switch(BFWORD2BYTE( pdu->read.slot_num ))
- {
- case SlotNum_Read_BhPara:
- case SlotNum_Read_Energy:
- case SlotNum_Read_WaveConfig:
- case SlotNum_Read_WaveData_File_Zone0:
- case SlotNum_Read_WaveData_File_Zone1:
- case SlotNum_Read_WaveData_File_Zone2:
- case SlotNum_Read_WaveData_File_Zone3:
- case SlotNum_Read_WaveData_Sample_Zone0:
- case SlotNum_Read_WaveData_Sample_Zone1:
- case SlotNum_Read_WaveData_Sample_Zone2:
- case SlotNum_Read_WaveData_Sample_Zone3:
- case SlotNum_Read_WaveData_Sample_Zone4:
- case SlotNum_Read_WaveData_Sample_Zone5:
- case SlotNum_Read_BhPara_Zone0:
- case SlotNum_Read_BhPara_Zone1:
- case SlotNum_Read_BhPara_Zone2:
- case SlotNum_Read_BhPara_Zone3:
- case SlotNum_Read_BhPara_Zone4:
- case SlotNum_Read_BhPara_Zone5:
- case SlotNum_Read_DeviceInfo:
- case SlotNum_Read_WaveData_Comtrade_Zone0:
- case SlotNum_Read_WaveData_Comtrade_Zone1:
- case SlotNum_Read_WaveData_Comtrade_Zone2:
- case SlotNum_Read_WaveData_Comtrade_Zone3:
- case SlotNum_Read_WaveData_Comtrade_Zone4:
- case SlotNum_Read_WaveData_Comtrade_Zone5:
- case SlotNum_Read_WaveData_Comtrade_Zone6:
- case SlotNum_Read_WaveData_Comtrade_Zone7:
- case SlotNum_Read_WaveData_Comtrade_Zone8:
- case SlotNum_50:
- case SlotNum_51:
- case SlotNum_52:
- case SlotNum_53:
- case SlotNum_54:
- case SlotNum_55:
- {
- ret_value = DPV1_ReadReq(dev_num, pdu->read.slot_num&0xff, pdu->read.index&0xff, pdu->read.length&0xff, &pDataRet, &nDataLenRet,
- &nErrCode1, &nErrCode2);
- if(ret_value == DPV1_OK && pDataRet)
- {
- for(i=0; i<mmin(MAX_DPV1_DU_COUNT, nDataLenRet); i++)
- {
- pdu->read.pdu_data[i] = pDataRet[i];
- }
- max_length = nDataLenRet;
- if( BFWORD2BYTE(pdu->read.length) > max_length )
- {
- pdu->read.length = max_length;
- }
- }
- else
- {
- pdu->neg.err_code1 = nErrCode1;
- pdu->neg.err_code2 = nErrCode2;
- }
- }
- break;
- default:
- {
- pdu->neg.err_code1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_SLOT;
- pdu->neg.err_code2 = 0x00;
- ret_value = DPV1_NOK;
- break;
- }
- }
- }
- return ret_value;
- }//DPV1_RET_VAL user_dpv1_read_req(UBYTE sap, DPV1_PTR pdu)
- /*--------------------------------------------------------------------------*/
- /* user_dpv1_write_req (called by DPV1) */
- /*--------------------------------------------------------------------------*/
- SECTION_DEF_CommuCode DPV1_RET_VAL user_dpv1_write_req(UBYTE dev_num, UBYTE sap, DPV1_PTR pdu)
- {
- DPV1_RET_VAL ret_value;
- //UBYTE max_length;
- #ifdef DPV1_IM_SUPP
- psIMCALL ps_ImCall;
- #endif//#ifdef DPV1_IM_SUPP
- int i;
- uint8 nErrCode1, nErrCode2;
- SECTION_DEF_CommuData static uint8 WriteBuffer[240];
- g_nC1WriteCount[dev_num]++;
- ret_value = DPV1_OK;
- #ifdef DPV1_IM_SUPP
- if( BFWORD2BYTE(pdu->write.index) == 255 )
- {
- if( BFWORD2BYTE(pdu->write.slot_num) == 0 )
- {
- //check_extended function number, reserved byte and IM_INDEX
- ps_ImCall = (psIMCALL)&pdu->write.pdu_data[0];
- if( ( BFWORD2BYTE(ps_ImCall->bExtendedFunctionNumber) == IM_FN_CALL )
- && ( BFWORD2BYTE(ps_ImCall->bReserved) == 0x00 )
- )
- {
- //check IM_INDEX
- if( BFLONG2WORD(ps_ImCall->wIndex) == IM0_INDEX )
- {
- //OK, save IM_INDEX
- user[dev_num].awImIndex[ ( sap & 0x0F ) ] = IM0_INDEX;
- }//if( ps_ImCall->wIndex == IM0_INDEX )
- else
- {
- pdu->neg.err_code1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_APP_NOTSUPP;
- pdu->neg.err_code2 = 0x00;
- ret_value = DPV1_NOK;
- }//else of if( ps_ImCall->wIndex == IM0_INDEX )
- }//if( ( ps_ImCall->bExtendedFunctionNumber == IM_FN_CALL ) ...
- else
- {
- pdu->neg.err_code1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_PARAM;
- pdu->neg.err_code2 = 0x00;
- ret_value = DPV1_NOK;
- }//else of if( ( ps_ImCall->bExtendedFunctionNumber == IM_FN_CALL ) ...
- }//if( pdu->write.slot_num == 0 )
- else
- {
- pdu->neg.err_code1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_SLOT;
- pdu->neg.err_code2 = 0x00;
- ret_value = DPV1_NOK;
- }//if( pdu->write.slot_num == 0 )
- }
- #else
- if( BFWORD2BYTE(pdu->write.index) == 255 )
- {
- pdu->neg.err_code1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_INDEX;
- pdu->neg.err_code2 = 0x00;
- ret_value = DPV1_NOK;
- }
- #endif//#ifdef DPV1_IM_SUPP
- else
- {
- switch( BFWORD2BYTE(pdu->write.slot_num ))
- {
- case SlotNum_Write_BhPara:
- case SlotNum_Write_StartWave:
- case SlotNum_Write_ModifyTime:
- case SlotNum_Write_CtrlSelect:
- case SlotNum_Write_CtrlExecute:
- case SlotNum_Write_CtrlCancel:
- case SlotNum_Write_ResetSignal:
- case SlotNum_Write_BhPara_Zone0:
- case SlotNum_Write_BhPara_Zone1:
- case SlotNum_Write_BhPara_Zone2:
- case SlotNum_Write_BhPara_Zone3:
- case SlotNum_Write_BhPara_Zone4:
- case SlotNum_Write_BhPara_Zone5:
- case SlotNum_50:
- case SlotNum_51:
- case SlotNum_52:
- case SlotNum_53:
- case SlotNum_54:
- case SlotNum_55:
- {
- //转换成uint8型数据
- for(i=0; i<BFWORD2BYTE(pdu->write.length); i++)
- {
- WriteBuffer[i] = pdu->write.pdu_data[i];
- }
- ret_value = DPV1_WriteReq(dev_num, pdu->write.slot_num&0xff, pdu->write.index&0xff, pdu->write.length&0xff, WriteBuffer, &nErrCode1, &nErrCode2);
- if(ret_value == DPV1_NOK)
- {
- pdu->neg.err_code1 = nErrCode1;
- pdu->neg.err_code2 = nErrCode2;
- }
- }
- break;
- default:
- {
- pdu->neg.err_code1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_SLOT;
- pdu->neg.err_code2 = 0x00;
- ret_value = DPV1_NOK;
- break;
- }
- }
- }
- return ret_value;
- }//DPV1_RET_VAL user_dpv1_write_req(UBYTE sap, DPV1_PTR pdu)
- #endif // #ifdef DP_FDL