dpv1_ReadWrite.c
资源名称:Profibus.rar [点击查看]
上传用户:hualang
上传日期:2022-04-11
资源大小:104k
文件大小:56k
源码类别:
能源行业(电力石油煤炭)
开发平台:
C/C++
- ///////////////////////////////////////////////////////////////
- // 文 件 名 : dpv1_ReadWrite.c
- // 文件功能 : DPV1非周期读写
- // 作 者 :
- // 创建时间 :
- // 项目名称 : LPC3
- // 操作系统 :
- // 备 注 :
- // 历史记录 :
- //
- //
- ///////////////////////////////////////////////////////////////
- #include "....includeLmcInc.h"
- #include "....includePublic.h"
- #include "....includeProtLogic.h"
- #include "....includeCtrlLogic.h"
- #include "....includesoe.h"
- #include "E5_Commu_PtlProfibus.h"
- extern int16 ProcessRemoteCtrlExec(uint8 control_obj, uint8 control_code, uint16 * pInfo);
- extern uint16 GetCurSampleFreq(void);
- extern int16 profi_ModifySettings(int16 nIDOffset, uint8 * pBuff, uint16 nBufLen, uint8 bBigEdin, uint16 * pInfo);
- extern void SignalReset(uint16 reset_type);
- #define BIT_CONVERT_FP32_TO_UINT32(fl) (*((uint32 *)((fp32 *)(&fl))))
- #define TEN_MULTIPLE(n) TenMultiple[n]
- #define CURRENT_LANG GetSysCfgValue(ID_SYS_LANGUAGE)
- #define CRC_CODE Ram.CodeChkSum //程序CRC校验码
- typedef struct
- {
- const char * strArr[2];
- }TStringResource;
- //组装非周期数据的缓存区
- static uint8 m_nSendCount;
- static uint8 m_SendBuffer[256];
- static uint8 m_nSoeType;
- static uint16 m_nSoeIndex;
- //报文显示使用的字符串资源
- static const TStringResource g_strAction[]=
- {
- "接地保护", "Earthing",
- "","",
- "","",
- };
- static const TStringResource g_strAbnormal[]=
- {
- "EEPROM", "EEPROM",
- "RAM", "RAM",
- "时钟", "CLOCK",
- "定值", "SETTING",
- "保护精度系数","Prot. Gains",
- "测量精度系数","Meas. Gains",
- "系统设置", "System Cfg.",
- "工程配置", "Field Cfg.",
- "开入开出配置","DI/DO Cfg.",
- "开出24V电源", "24V Monitor",
- "外部接线", "CTRL Circuit ",
- "可执行代码", "Exe. Code",
- "","",
- "","",
- "","",
- };
- static const TStringResource g_strRun[]=
- {
- "冷启动", "Cool startup",
- "面板复归", "Panel Revert",
- "开入信号复归", "DI Revert",
- "通讯复归", "Com. Revert",
- "修改定值", "Modify Settings",
- "EEPROM初始化", "Init. EEPROM",
- "进入调试态", "Enter Debug",
- "退出调试态", "Exit Debug",
- "","",
- "","",
- "","",
- };
- static const TStringResource g_strControl[]=
- {
- "面板合闸", "Panel Switch On",
- "面板分闸", "Panel Switch Off",
- "本地端子分闸", "Local DI Switch On",
- "本地端子合闸", "Local DI Switch Off",
- "远方端子分闸", "Remote DI Switch Off",
- "远方端子合闸", "Remote DI Switch On",
- "通讯合闸", "Commu. Switch On",
- "通讯分闸", "Commu. Switch Off",
- "合闸失败", "Switch On Failure",
- "分闸失败", "Switch Off Failure",
- "分通用继电器1", "Commu. Switch Off DO1",
- "合通用继电器1", "Commu. Switch On DO1",
- "分通用继电器2", "Commu. Switch Off DO2",
- "合通用继电器2", "Commu. Switch On DO2",
- "分通用继电器3", "Commu. Switch Off DO3",
- "合通用继电器3", "Commu. Switch On DO3",
- "分通用继电器4", "Commu. Switch Off DO4",
- "合通用继电器4", "Commu. Switch On DO4",
- "","",
- "","",
- "","",
- };
- static const TStringResource g_strVirtualDI[]=
- {
- "本地远程", "Local/Remote",
- "控制权限辅助开入", "Control Limit",
- "分闸状态", "Switch Off",
- "合闸状态", "Switch On",
- "脱扣状态", "Dropaway",
- "工作位置", "Work Status",
- "试验位置", "Test Status",
- "分闸命令", "Switch Off",
- "合闸命令", "Switch On",
- "就地分闸命令", "Switch Off Local",
- "就地合闸命令", "Switch On Local",
- "远方分闸命令", "Switch Off Remote",
- "远方合闸命令", "Switch On Remote",
- "复归命令", "Signal Reset",
- "退出所有保护", "Exit All PROT",
- // "控制电源状态", "Control Power Status",
- "开入预留定义1", "DI Reserved1",
- "开入预留定义2", "DI Reserved2",
- "","",
- "","",
- };
- static const TStringResource g_strUtility[]=
- {
- "[常开]","[NO]",
- "[常闭]","[NC]",
- "[成功]","[SUCCESS]",
- "[据跳]","[TRIP FAIL]",
- "[据合]","[CLOSE FAIL]",
- "[告警]","[WARNING]",
- "[失败]","[FAILURE]",
- "","",
- "","",
- "","",
- };
- enum{
- ID_UTILITY_NO,
- ID_UTILITY_NC,
- ID_UTILITY_ACT_RESULT_SUCCESS,
- ID_UTILITY_ACT_RESULT_TRIPFAIL,
- ID_UTILITY_ACT_RESULT_CLOSEFAIL,
- ID_UTILITY_ACT_RESULT_WARNING,
- ID_UTILITY_ACT_RESULT_FAIL
- };
- //获取物理开入的名称
- static const char * str_GetRealDiNameString(int nRealID)
- {
- static char szBuffer[40];
- char szTmp[32];
- memset(szBuffer, 0, sizeof(szBuffer));
- //开入名
- sprintf(szTmp, "DI%d", nRealID+1);
- strcat(szBuffer, szTmp);
- //常开常闭
- if(Ram.Current_DiDoConfig.DiOpenOrClose[nRealID] == DI_NORMAL_OPEN)
- {
- strcat(szBuffer, g_strUtility[ID_UTILITY_NO].strArr[CURRENT_LANG] );
- }
- else
- {
- strcat(szBuffer, g_strUtility[ID_UTILITY_NC].strArr[CURRENT_LANG] );
- }
- strcat(szBuffer, " ");
- //虚拟开入
- if (Ram.Current_DiDoConfig.DiOpenOrClose[nRealID]&0xff != 0xFF)
- {
- strcat(szBuffer, g_strVirtualDI[nRealID].strArr[CURRENT_LANG] ) ;
- }
- return szBuffer;
- }
- uint8 AssembByte(uint8* pDest, uint8 nBtVal)
- {
- *pDest = nBtVal;
- return 1;
- }
- uint8 AssembNBytes(uint8* pDest, const uint8 * p, uint32 count)
- {
- memcpy(pDest, p, count);
- return count;
- }
- void AssembBit(uint8* pDest, uint8 nBitPos, uint8 nBitVal)
- {
- uint8 nLeftBit = (nBitPos%8);
- uint8 nBytePos = (nBitPos/8);
- if (nBitVal)
- *(pDest+nBytePos) |= (1<<nLeftBit);
- else
- *(pDest+nBytePos) &= ~(1<<nLeftBit);
- }
- uint8 AssembWordLittleEdin(uint8* pDest, uint16 nWordVal)
- {
- *pDest = LOBYTE(nWordVal);
- *(pDest+1) = HIBYTE(nWordVal);
- return 2;
- }
- uint8 AssembWordBigEdin(uint8* pDest, uint16 nWordVal)
- {
- *pDest = HIBYTE(nWordVal);
- *(pDest+1) = LOBYTE(nWordVal);
- return 2;
- }
- uint8 AssembDWordBigEdin(uint8* pDest, uint32 nDWordVal)
- {
- *pDest = HIBYTE(HIWORD(nDWordVal));
- *(pDest+1) = LOBYTE(HIWORD(nDWordVal));
- *(pDest+2) = HIBYTE(LOWORD(nDWordVal));
- *(pDest+3) = LOBYTE(LOWORD(nDWordVal));
- return 4;
- }
- uint8 AssembDWordLittleEdin(uint8* pDest, uint32 nDWordVal)
- {
- *(pDest+0) = LOBYTE(LOWORD(nDWordVal));
- *(pDest+1) = HIBYTE(LOWORD(nDWordVal));
- *(pDest+2) = LOBYTE(HIWORD(nDWordVal));
- *(pDest+3) = HIBYTE(HIWORD(nDWordVal));
- return 4;
- }
- uint8 DissembWordLittleEdin(uint8* pDest, uint16* nWordVal)
- {
- *nWordVal = MAKEWORD( LOBYTE(*(pDest)), LOBYTE(*(pDest+1)));
- return 2;
- }
- uint8 DissembWordBigEdin(uint8* pDest, uint16* nWordVal)
- {
- *nWordVal = MAKEWORD(*(pDest+1) & 0xff, *pDest & 0xff);
- return 2;
- }
- //读定值,公司主控连接
- static int ProcessC2ReadProtSettingsWiscom(uint8 nIndex, uint8 nReadLen, uint8* nErrCode1, uint8* nErrCode2)
- {
- int id;
- m_nSendCount = 0;
- for (id = 0; id< NUM_SETTINGS ;id++)
- {
- int32 nVal = GetSettingValue(id);
- m_nSendCount += AssembWordLittleEdin(&m_SendBuffer[m_nSendCount], nVal);
- }
- return DPV1_OK;
- }
- //读表计数值,内部使用,低字节在前
- static int ProcessC1ReadEgyInfoWiscom(uint8 nIndex, uint8 nReadLen, uint8* nErrCode1, uint8* nErrCode2)
- {
- uint32 u32Value;
- m_nSendCount = 0;
- u32Value = Ram.TotalEnergy.PE;
- m_nSendCount += AssembDWordLittleEdin(&m_SendBuffer[m_nSendCount], u32Value);
- u32Value = Ram.TotalEnergy.QE;
- m_nSendCount += AssembDWordLittleEdin(&m_SendBuffer[m_nSendCount], u32Value);
- return DPV1_OK;
- }
- //读设备软件版本信息
- static int ProcessReadDeviceInfoWiscom(void)
- {
- char strVersion[12]; //版本信息固定为12个字节
- memset(strVersion,0,12);
- m_nSendCount = 0;
- //装置类型,字符串 固定12个字符,方便主站处理
- strcpy(strVersion,device_model);
- m_nSendCount += AssembNBytes(&m_SendBuffer[m_nSendCount],(uint8 *)strVersion, 12);
- m_nSendCount += AssembWordLittleEdin(&m_SendBuffer[m_nSendCount], SOFTWARE_VERSION);
- return DPV1_OK;
- }
- //读录波配置
- static int ProcessWaveCfgWiscom(uint8 nIndex)
- {
- int i;
- m_nSendCount = 0;
- //录波数据格式
- m_SendBuffer[m_nSendCount++] = 2;//采样数据
- //录波报文总共包数
- m_nSendCount += AssembWordLittleEdin(&m_SendBuffer[m_nSendCount], WaveRecord.Config.MsgCount);
- //录波数据长度
- m_nSendCount += AssembWordLittleEdin(&m_SendBuffer[m_nSendCount], WaveRecord.Config.Length);
- //模拟通道的数目 //M=1,2,……9,为模拟通道标号,最大为9;
- m_SendBuffer[m_nSendCount++]=NUM_SIMPLE_WAVEDATA_CHANNELS;
- m_SendBuffer[m_nSendCount++]=NUM_REAL_DI_COUNT;
- for(i=0;i<NUM_SIMPLE_WAVEDATA_CHANNELS;i++)
- {
- //模拟通道1标识
- m_SendBuffer[m_nSendCount++]=i;
- //通道系数
- m_nSendCount += AssembWordLittleEdin(&m_SendBuffer[m_nSendCount], WaveRecord.Config.Analog[i].max);
- //偏移量
- m_nSendCount += AssembWordLittleEdin(&m_SendBuffer[m_nSendCount], 0);
- //采样时滞
- m_nSendCount += AssembWordLittleEdin(&m_SendBuffer[m_nSendCount], WaveRecord.Config.Analog[i].skew);
- //采样最小值
- m_nSendCount += AssembWordLittleEdin(&m_SendBuffer[m_nSendCount], (uint16)-2048);
- //采样最大值
- m_nSendCount += AssembWordLittleEdin(&m_SendBuffer[m_nSendCount], (uint16)2047);
- }
- //状态通道标识
- for(i=0; i<NUM_REAL_DI_COUNT; i++)
- {
- m_SendBuffer[m_nSendCount++]=i;
- }
- //系统频率
- m_nSendCount += AssembWordLittleEdin(&m_SendBuffer[m_nSendCount], 5000);// 系统频率
- //采样频率数目
- m_SendBuffer[m_nSendCount++]=1;
- //采样频率
- m_nSendCount += AssembWordLittleEdin(&m_SendBuffer[m_nSendCount], GetCurSampleFreq()); //采样频率*/
- //采样频率对应的最后一点
- m_nSendCount += AssembWordLittleEdin(&m_SendBuffer[m_nSendCount], WaveRecord.Config.Length);// 系统频率
- //录波启动原因:上送1个
- for(i=0;i<1;i++)
- {
- //启动录波1原因
- m_nSendCount += AssembDWordLittleEdin(&m_SendBuffer[m_nSendCount], WaveRecord.Config.Start[i].Cause);
- //启动录波1时间
- m_SendBuffer[m_nSendCount++]=WaveRecord.Config.Start[i].Time.y;
- m_SendBuffer[m_nSendCount++]=WaveRecord.Config.Start[i].Time.mon;
- m_SendBuffer[m_nSendCount++]=WaveRecord.Config.Start[i].Time.d;
- m_SendBuffer[m_nSendCount++]=WaveRecord.Config.Start[i].Time.h;
- m_SendBuffer[m_nSendCount++]=WaveRecord.Config.Start[i].Time.min;
- m_SendBuffer[m_nSendCount++]=WaveRecord.Config.Start[i].Time.s;
- m_nSendCount += AssembWordLittleEdin(&m_SendBuffer[m_nSendCount], WaveRecord.Config.Start[i].Time.ms);
- }
- //录波动作原因
- m_SendBuffer[m_nSendCount++]=1;
- m_SendBuffer[m_nSendCount++]=0;
- m_SendBuffer[m_nSendCount++]=0;
- m_SendBuffer[m_nSendCount++]=0;
- m_SendBuffer[m_nSendCount++]=8;
- m_SendBuffer[m_nSendCount++]=8;
- m_SendBuffer[m_nSendCount++]=8;
- m_SendBuffer[m_nSendCount++]=8;
- m_SendBuffer[m_nSendCount++]=8;
- m_SendBuffer[m_nSendCount++]=8;
- m_SendBuffer[m_nSendCount++]=8;
- m_SendBuffer[m_nSendCount++]=8;
- //时标的倍增系数
- m_SendBuffer[m_nSendCount++]=0;
- return DPV1_OK;
- }
- //读录波数据
- static int ProcessWaveDataWiscom(uint8 nSlot, uint8 nIndex, uint8* nErrCode1, uint8* nErrCode2)
- {
- uint16 info;
- int i,h;
- uint32 temp1;
- m_nSendCount = 0;
- //info 从1开始 index:0~254
- info = (nSlot-SlotNum_Read_WaveData_Sample_Zone0)*255 + nIndex+1;
- //总包数判断
- if (info > WaveRecord.Config.MsgCount)
- {
- *nErrCode1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_RANGE;
- *nErrCode2 = ErrCode2_Read_WaveData;
- return DPV1_NOK;
- }
- temp1=WaveRecord.Config.Length%WAVE_MSG_AMOUNT;
- m_SendBuffer[m_nSendCount++]=info; //数据包数
- m_SendBuffer[m_nSendCount++]=info>>8;
- if((temp1!=0) && (info==WaveRecord.Config.MsgCount)) // 最后一包(不是一整包)
- {
- for(i=(info-1)*WAVE_MSG_AMOUNT;i<(info-1)*WAVE_MSG_AMOUNT+temp1;i++) //i为数据点数
- {
- for(h=0;h<NUM_SIMPLE_WAVEDATA_CHANNELS;h++)//每一点传所有通道
- {
- //数据
- m_nSendCount += AssembWordLittleEdin(&m_SendBuffer[m_nSendCount], WaveRecord.Data.Analog[h][i]);
- }
- m_nSendCount += AssembWordLittleEdin(&m_SendBuffer[m_nSendCount], WaveRecord.Data.Ki[i]); //每一点传一次开入信息
- }
- }
- else
- {
- for(i=(info-1)*WAVE_MSG_AMOUNT;i<info*WAVE_MSG_AMOUNT;i++)
- {
- for(h=0;h<NUM_SIMPLE_WAVEDATA_CHANNELS;h++)
- {
- //数据
- m_nSendCount += AssembWordLittleEdin(&m_SendBuffer[m_nSendCount], WaveRecord.Data.Analog[h][i]);
- }
- m_nSendCount += AssembWordLittleEdin(&m_SendBuffer[m_nSendCount], WaveRecord.Data.Ki[i]); //每一点传一次开入信息
- }
- }
- return DPV1_OK;
- }
- //读系统信息
- static void ProcessC2ReadSysInfo(void)
- {
- char strTmp[32];
- TDateTime dt;
- m_nSendCount = 0;
- //软件版本 32字节
- strcpy(strTmp, main_soft_ver);
- m_nSendCount += AssembNBytes(&m_SendBuffer[m_nSendCount],(uint8 *)strTmp, 32);
- //编译时间 32字节
- dt = Ram.dtBuildTime;
- sprintf(strTmp,"%04u-%02u-%02u %02u:%02u:%02u",(dt.y+2000)%10000,dt.mon%100,dt.d%100,dt.h,dt.min,dt.s);
- m_nSendCount += AssembNBytes(&m_SendBuffer[m_nSendCount],(uint8 *)strTmp, 32);
- //加载时间 32字节
- dt = Ram.dtLoadTime;
- sprintf(strTmp,"%04u-%02u-%02u %02u:%02u:%02u",(dt.y+2000)%10000,dt.mon%100,dt.d%100,dt.h,dt.min,dt.s);
- m_nSendCount += AssembNBytes(&m_SendBuffer[m_nSendCount],(uint8 *)strTmp, 32);
- //CRC校验 8字节
- sprintf(strTmp, "0x%04X", CRC_CODE);
- m_nSendCount += AssembNBytes(&m_SendBuffer[m_nSendCount],(uint8 *)strTmp, 8);
- //物理开入数目
- m_nSendCount += AssembByte(&m_SendBuffer[m_nSendCount], DI_REALCOUNT);
- //物理开出数目
- m_nSendCount += AssembByte(&m_SendBuffer[m_nSendCount], NUM_REAL_DO_COUNT);
- }
- //读工程配置
- static void ProcessC2ReadDeviceModel(void)
- {
- int id;
- m_nSendCount = 0;
- for (id = 0; id< NUM_DEVICEMODELS ;id++)
- {
- int32 nVal = GetDeviceModelValue(id);
- m_nSendCount += AssembWordBigEdin(&m_SendBuffer[m_nSendCount], nVal);
- }
- }
- //读系统设置
- static void ProcessC2ReadSysCfg(void)
- {
- //特殊处理,只上送需要显示的量
- int id;
- int16 nVal;
- m_nSendCount = 0;
- for (id = ID_SYS_OUTPUTI1; id< NUM_SYSCFGS ;id++)
- {
- nVal = GetSysCfgValue(id);
- m_nSendCount += AssembWordBigEdin(&m_SendBuffer[m_nSendCount], nVal);
- }
- }
- //读保护定值(外部系统)
- static void ProcessC2ReadProtSettings(void)
- {
- int id;
- m_nSendCount = 0;
- for (id = 0; id< NUM_SETTINGS ;id++)
- {
- int32 nVal = GetSettingValue(id);
- m_nSendCount += AssembWordBigEdin(&m_SendBuffer[m_nSendCount], nVal);
- }
- }
- //读开入配置
- static void ProcessC2ReadDiCfg(void)
- {
- int nID;
- m_nSendCount = 0;
- for (nID=0; nID<DI_REALCOUNT; nID++)
- {
- //关联的虚拟ID
- m_nSendCount += AssembByte(&m_SendBuffer[m_nSendCount], LOBYTE(Ram.Current_DiDoConfig.DiConfig[nID] ));
- }
- }
- //读常开常闭配置
- static void ProcessC2ReadDiNoNcCfg(void)
- {
- int nID;
- m_nSendCount = 0;
- for (nID=0; nID<DI_REALCOUNT; nID++)
- {
- //开入常开常闭
- m_nSendCount += AssembByte(&m_SendBuffer[m_nSendCount], !!Ram.Current_DiDoConfig.DiOpenOrClose[nID] );
- }
- }
- //读开出配置
- static void ProcessC2ReadDoCfg(void)
- {
- int nID;
- m_nSendCount = 0;
- for (nID=0; nID<NUM_REAL_DO_COUNT; nID++)
- {
- //关联的虚拟ID
- m_nSendCount += AssembByte(&m_SendBuffer[m_nSendCount], LOBYTE( Ram.Current_DiDoConfig.DoConfig[nID] ));
- }
- }
- //读用户密码
- static void ProcessC2ReadUserPw(void)
- {
- int16 nVal = GetSysCfgValue(ID_SYS_PASSWORD);
- m_nSendCount = 0;
- m_nSendCount += AssembWordBigEdin(&m_SendBuffer[m_nSendCount], nVal);
- }
- //读语言
- static void ProcessC2ReadUserLang(void)
- {
- int16 nVal = GetSysCfgValue(ID_SYS_LANGUAGE);
- m_nSendCount = 0;
- m_nSendCount += AssembWordBigEdin(&m_SendBuffer[m_nSendCount], nVal);
- }
- //读取实际测量值,浮点数格式送外部系统
- static fp32 _GetMeasFP32Value(int nMeasureID)
- {
- int32 iVal;
- fp32 fVal=0;
- fp32 fK = 1.0;
- const TMeasureDefine * pDef = &MeasDefine[nMeasureID];
- //1. 有些测量值特殊处理,比如功率,电能需要合并成一个数值
- if(nMeasureID == MEAS_MEAS_P_L ||
- nMeasureID == MEAS_MEAS_Q_L ||
- nMeasureID == MEAS_MEAS_S_L ||
- nMeasureID == MEAS_MEAS_Pa_L ||
- nMeasureID == MEAS_MEAS_Qa_L ||
- nMeasureID == MEAS_MEAS_Sa_L ||
- nMeasureID == MEAS_MEAS_Pb_L ||
- nMeasureID == MEAS_MEAS_Qb_L ||
- nMeasureID == MEAS_MEAS_Sb_L ||
- nMeasureID == MEAS_MEAS_Pc_L ||
- nMeasureID == MEAS_MEAS_Qc_L ||
- nMeasureID == MEAS_MEAS_Sc_L ||
- nMeasureID == MEAS_PE_L||
- nMeasureID == MEAS_QE_L||
- nMeasureID == MEAS_PEa_L||
- nMeasureID == MEAS_QEa_L||
- nMeasureID == MEAS_PEb_L||
- nMeasureID == MEAS_QEb_L||
- nMeasureID == MEAS_PEc_L||
- nMeasureID == MEAS_QEc_L)
- {
- iVal = MAKEDWORD(Ram.CurrentMeasure.Arr[nMeasureID],
- Ram.CurrentMeasure.Arr[nMeasureID+1]);
- }
- else
- {
- iVal = Ram.CurrentMeasure.Arr[nMeasureID];
- }
- //2. 需要将数值转换成实际数值显示
- switch(pDef->Character) {
- case MEAS_CHARACTER_I: //电流型数据
- {
- if (pDef->uTypeID==ID_STRING_MEASTYPE_MEAS)
- {
- fK = 0.001*GetDeviceModelValue(ID_DEVICEMODEL_CT_SECONDARYIE)/10 *GetSysCfgValue(ID_SYS_CT_SCALE)/ 10; // 增加CT变比 升级
- }
- else
- {
- fK = 0.001*GetDeviceModelValue(ID_DEVICEMODEL_CT_SECONDARYIE)/10 ; //增加CT变比 升级
- }
- }
- break;
- case MEAS_CHARACTER_U: //电压型数据
- {
- if (pDef->uTypeID==ID_STRING_MEASTYPE_MEAS)
- {
- fK = 0.001 * GetSysCfgValue(ID_SYS_PT_SCALE) * GetDeviceModelValue(ID_DEVICEMODEL_PT_SECONDARYUE) /1732 ;
- }
- else
- {
- fK = 0.001 * GetDeviceModelValue(ID_DEVICEMODEL_PT_SECONDARYUE)*10 /1732 ;
- }
- }
- break;
- case MEAS_CHARACTER_UL: //线电压数据
- {
- if (pDef->uTypeID==ID_STRING_MEASTYPE_MEAS)
- {
- fK = 0.001 * GetSysCfgValue(ID_SYS_PT_SCALE) * GetDeviceModelValue(ID_DEVICEMODEL_PT_SECONDARYUE) / 1000 ;
- }
- else
- {
- fK = 0.001 * GetDeviceModelValue(ID_DEVICEMODEL_PT_SECONDARYUE) / 100 ;
- }
- }
- break ;
- case MEAS_CHARACTER_I0: //零序型数据
- {
- if (GetDeviceModelValue(ID_DEVICEMODEL_MODEL_L)==MODEL_HAVEI0)
- {
- fK = 0.001 * GetDeviceModelValue(ID_DEVICEMODEL_SECONDARYI0)/10;
- }
- else
- {
- fK = 0.001 * GetDeviceModelValue(ID_DEVICEMODEL_CT_SECONDARYIE)/10 ;
- }
- }
- break;
- default: //其他类型
- {
- //电能信息
- fK = 1.0 / TEN_MULTIPLE(pDef->point);
- }
- }
- //转换成浮点数格式
- fVal = fK * iVal; //转为浮点数
- return fVal;
- }
- //读上送测值实际值
- static void ProcessC2ReadMeas(int nFolderID)
- {
- fp32 fVal;
- int nMeasureID;
- int nTmpCounter=0;
- //找到测量页的起始ID号
- for (nMeasureID=0; nMeasureID<NUM_MEASURES; nMeasureID++)
- {
- nTmpCounter++;
- if(nMeasureID == MEAS_MEAS_P_L ||
- nMeasureID == MEAS_MEAS_Q_L ||
- nMeasureID == MEAS_MEAS_S_L ||
- nMeasureID == MEAS_MEAS_Pa_L ||
- nMeasureID == MEAS_MEAS_Qa_L ||
- nMeasureID == MEAS_MEAS_Sa_L ||
- nMeasureID == MEAS_MEAS_Pb_L ||
- nMeasureID == MEAS_MEAS_Qb_L ||
- nMeasureID == MEAS_MEAS_Sb_L ||
- nMeasureID == MEAS_MEAS_Pc_L ||
- nMeasureID == MEAS_MEAS_Qc_L ||
- nMeasureID == MEAS_MEAS_Sc_L ||
- nMeasureID == MEAS_PE_L||
- nMeasureID == MEAS_QE_L||
- nMeasureID == MEAS_PEa_L||
- nMeasureID == MEAS_QEa_L||
- nMeasureID == MEAS_PEb_L||
- nMeasureID == MEAS_QEb_L||
- nMeasureID == MEAS_PEc_L||
- nMeasureID == MEAS_QEc_L)
- {
- nMeasureID++; //跳过高WORD
- continue ;
- }
- if(nTmpCounter > 50*nFolderID)
- break ;
- }
- nTmpCounter = 0;
- m_nSendCount = 0;
- for ( ;nMeasureID<NUM_MEASURES; nMeasureID++)
- {
- nTmpCounter++;
- if(nTmpCounter > 50) //每页50个
- break ;
- fVal = _GetMeasFP32Value(nMeasureID);
- m_nSendCount += AssembDWordBigEdin(&m_SendBuffer[m_nSendCount], BIT_CONVERT_FP32_TO_UINT32(fVal));
- if(nMeasureID == MEAS_MEAS_P_L ||
- nMeasureID == MEAS_MEAS_Q_L ||
- nMeasureID == MEAS_MEAS_S_L ||
- nMeasureID == MEAS_MEAS_Pa_L ||
- nMeasureID == MEAS_MEAS_Qa_L ||
- nMeasureID == MEAS_MEAS_Sa_L ||
- nMeasureID == MEAS_MEAS_Pb_L ||
- nMeasureID == MEAS_MEAS_Qb_L ||
- nMeasureID == MEAS_MEAS_Sb_L ||
- nMeasureID == MEAS_MEAS_Pc_L ||
- nMeasureID == MEAS_MEAS_Qc_L ||
- nMeasureID == MEAS_MEAS_Sc_L ||
- nMeasureID == MEAS_PE_L||
- nMeasureID == MEAS_QE_L||
- nMeasureID == MEAS_PEa_L||
- nMeasureID == MEAS_QEa_L||
- nMeasureID == MEAS_PEb_L||
- nMeasureID == MEAS_QEb_L||
- nMeasureID == MEAS_PEc_L||
- nMeasureID == MEAS_QEc_L)
- {
- nMeasureID++; //跳过高WORD
- }
- }
- }
- //读调试数据
- static void ProcessC2ReadDebugData(int nFolderID)
- {
- //暂无调试数据
- }
- //读趋势图及棒图的测量值
- static void ProcessC2ReadCommuMeas(int bTrendView)
- {
- fp32 fVal;
- int i;
- unsigned char sendMeasID[]={
- MEAS_MEAS_Ia,
- MEAS_MEAS_Ib,
- MEAS_MEAS_Ic,
- MEAS_MEAS_Ua, //Ua
- MEAS_MEAS_Ub, //Ub
- MEAS_MEAS_Uc, //Uc
- MEAS_MEAS_Uab,
- MEAS_MEAS_Ubc,
- MEAS_MEAS_Uca,
- MEAS_MEAS_P_L,
- MEAS_MEAS_Q_L,
- MEAS_MEAS_S_L,
- MEAS_MEAS_FACT,
- MEAS_F,
- };
- unsigned char nCount = sizeof(sendMeasID)/sizeof(unsigned char);
- //通讯上送的量与组态工具设置的要一致
- m_nSendCount = 0;
- for (i=0; i<nCount; i++)
- {
- fVal = _GetMeasFP32Value(sendMeasID[i]);
- m_nSendCount += AssembDWordBigEdin(&m_SendBuffer[m_nSendCount], BIT_CONVERT_FP32_TO_UINT32(fVal));
- }
- }
- //读开入值
- static void ProcessC2ReadDiData(void)
- {
- int i;
- m_nSendCount = 0;
- for (i=0; i<DI_REALCOUNT; i++)
- {
- m_nSendCount += AssembByte(&m_SendBuffer[m_nSendCount], GetRealDigiIn(i) );
- }
- }
- //读开出值
- static void ProcessC2ReadDoData(void)
- {
- int i;
- m_nSendCount = 0;
- for (i=0; i<NUM_REAL_DO_COUNT; i++)
- {
- m_nSendCount += AssembByte(&m_SendBuffer[m_nSendCount], GetRealDigiOut(i) );
- }
- }
- //读虚拟点值
- static void ProcessC2ReadPtData(void)
- {
- int i;
- m_nSendCount = 0;
- for (i=0; i<0; i++)
- {
- m_nSendCount += AssembByte(&m_SendBuffer[m_nSendCount], 0 );
- }
- }
- //读软压板值
- static void ProcessC2ReadSoftStrap(void)
- {
- int i;
- m_nSendCount = 0;
- for (i=0; i<0; i++)
- {
- m_nSendCount += AssembByte(&m_SendBuffer[m_nSendCount], 0 );
- }
- }
- //读异常信号值
- static void ProcessC2ReadAbnlSignal(void)
- {
- int i;
- m_nSendCount = 0;
- for ( i=0; i<NUM_ABNORMAL_COUNT; i++)
- {
- m_nSendCount += AssembByte(&m_SendBuffer[m_nSendCount], IsAbnormal(i) );
- }
- }
- //读动作信号值
- static void ProcessC2ReadActSignal(void)
- {
- int i;
- m_nSendCount = 0;
- for ( i=0; i<NUM_PROT_ACTION_COUNT; i++)
- {
- m_nSendCount += AssembByte(&m_SendBuffer[m_nSendCount], GetProtActionSignal(i) );
- }
- }
- //读电能信息
- static void ProcessC2ReadEgyInfo(void)
- {
- fp32 fValue;
- m_nSendCount = 0;
- fValue = 1.0*Ram.TotalEnergy.PE/100;
- m_nSendCount += AssembDWordBigEdin(&m_SendBuffer[m_nSendCount], BIT_CONVERT_FP32_TO_UINT32(fValue));
- fValue = 1.0*Ram.TotalEnergy.QE/100;
- m_nSendCount += AssembDWordBigEdin(&m_SendBuffer[m_nSendCount], BIT_CONVERT_FP32_TO_UINT32(fValue));
- }
- //读统计信息
- static void ProcessC2ReadStatInfo(void)
- {
- int i;
- fp32 fValue;
- const TMeasureDefine* pMeasDef;
- m_nSendCount = 0;
- for (i=0; i<NUM_STATISTICS; i++)
- {
- pMeasDef = &StatisticDefine[i];
- fValue = 1.0*Ram.Eeprom.save.Statistic.Arr[i]/TEN_MULTIPLE(pMeasDef->point);
- m_nSendCount += AssembDWordBigEdin(&m_SendBuffer[m_nSendCount], BIT_CONVERT_FP32_TO_UINT32(fValue));
- }
- }
- //读Profibus当前和1类主站信息
- static void ProcessC2ReadProfibusStatInfo(void)
- {
- #define __WAIT_PRM ( ( uint8)0x00)
- #define __WAIT_CFG ( ( uint8)0x10)
- #define __DATA_EX ( ( uint8)0x20)
- #define __DP_ERROR ( ( uint8)0x30)
- uint8 nBaudRate=255;
- uint8 nDPStat=__WAIT_PRM;
- uint8 nMasterAddr=0;
- uint8 bDPV1=0;
- uint32 nPrmCount=0;
- uint32 nChkCfgCount=0;
- //通讯状态
- nBaudRate = GetProfibusBaudRate(0);
- nDPStat = GetProfibusDPState(0);
- nMasterAddr = vpc3_get_master(0);
- m_nSendCount = 0;
- if (nBaudRate > 9)
- {
- nBaudRate = 255;
- }
- switch(nDPStat)
- {
- case __WAIT_PRM:
- nDPStat = 0;
- break;
- case __WAIT_CFG:
- nDPStat = 1;
- break;
- case __DATA_EX:
- nDPStat = 2;
- break;
- case __DP_ERROR:
- nDPStat = 3;
- break;
- default:
- nDPStat = 4;
- break;
- }
- //波特率
- m_nSendCount += AssembByte(&m_SendBuffer[m_nSendCount], nBaudRate );
- //DP状态
- m_nSendCount += AssembByte(&m_SendBuffer[m_nSendCount], nDPStat );
- //主站地址
- m_nSendCount += AssembByte(&m_SendBuffer[m_nSendCount], nMasterAddr );
- //DPV1 是否启用
- m_nSendCount += AssembByte(&m_SendBuffer[m_nSendCount], bDPV1 );
- //参数化次数
- //检查配置次数
- m_nSendCount += AssembDWordBigEdin(&m_SendBuffer[m_nSendCount], nPrmCount);
- //检查配置次数
- m_nSendCount += AssembDWordBigEdin(&m_SendBuffer[m_nSendCount], nChkCfgCount);
- }
- enum{
- SOE_ACTION___, /*!< 保护动作事件 */
- SOE_WARNING___, /*!< 保护告警事件 */
- SOE_DIEVENT___, /*!< 开入变位事件 */
- SOE_ABNORMAL___, /*!< 异常事件 */
- SOE_DOEVENT___, /*!< 开出变位事件 */
- SOE_RUN___, /*!< 运行事件 */
- SOE_CONTROL___, /*!< 控制事件 */
- SOE_INFO___, /*!< 信息事件-没有事件编号,事件信息就是字符串,可以附加测值 */
- SOE_CUSTOM1___, /*!< 自定义事件1 */
- SOE_CUSTOM2___, /*!< 自定义事件2 */
- SOE_CUSTOM3___, /*!< 自定义事件3 */
- SOE_CUSTOM4___, /*!< 自定义事件4 */
- SOE_WAVE_FILE___, //录波文件数量
- SOE_TRACE___, /*!< 调试信息 */
- SOE_OPERATE___, //操作报告
- SOE_TYPE_COUNT ///< SOE类型
- };
- //格式化时间信息
- static const char * str_GetDateTimeString(const TDateTime * pDateTime, char *pCh)
- {
- sprintf(pCh, "%04u-%02u-%02u %02u:%02u:%02u.%03u", pDateTime->y+2000, pDateTime->mon,
- pDateTime->d,pDateTime->h,pDateTime->min,pDateTime->s,pDateTime->ms);
- return pCh;
- }
- //格式化测量值显示
- static const char* str_GetMeasValueString(int nMeasID)
- {
- static char szBuffer[32];
- char ch[8];
- const TMeasureDefine* pMeasDef = &MeasDefine[nMeasID];
- fp32 fValue= _GetMeasFP32Value(nMeasID);
- sprintf(ch,"%%.%df",pMeasDef->point);
- sprintf(szBuffer, ch, fValue);
- return szBuffer;
- }
- //取指定序号动作报告
- static const TActionSOE * soe_GetActionSOE(int index)
- {
- int count = soe_GetActionSOECount();
- if(index > count || index <0)
- {
- return NULL; //无报告
- }
- else
- {
- index = soe_GetActionSOESerialNumber(index)%NUM_ACTIONSOE; //报文所在位置
- return &ExramSOESave.SOESave.ActionSOESave.soe[index];
- }
- }
- //取指定序号开入报告
- static const TDigitalSOE * soe_GetDiEventSOE(int index)
- {
- int count = soe_GetDigitalSOECount();
- if(index > count || index <0)
- {
- return NULL; //无报告
- }
- else
- {
- index = soe_GetDigitalSOESerialNumber(index)%NUM_DIGITALSOE; //报文所在位置
- return &ExramSOESave.SOESave.DigitalSOESave.soe[index];
- }
- }
- //取指定序号异常报告
- static const TAbnormalSOE * soe_GetAbnormalSOE(int index)
- {
- int count = soe_GetAbnormalSOECount();
- if(index > count || index <0)
- {
- return NULL; //无报告
- }
- else
- {
- index = soe_GetAbnormalSOESerialNumber(index)%NUM_ABNORMALSOE; //报文所在位置
- return &ExramSOESave.SOESave.AbnormalSOESave.soe[index];
- }
- }
- //取指定序号运行报告
- static const TRunSOE * soe_GetRunSOE(int index)
- {
- int count = soe_GetRunSOECount();
- if(index > count || index <0)
- {
- return NULL; //无报告
- }
- else
- {
- index = soe_GetRunSOESerialNumber(index)%NUM_RUNSOE; //报文所在位置
- return &ExramSOESave.SOESave.RunSOESave.soe[index];
- }
- }
- //取指定序号控制报告
- static const TControlSOE* soe_GetControlSOE(int index)
- {
- int count = soe_GetControlSOECount();
- if(index > count || index <0)
- {
- return NULL; //无报告
- }
- else
- {
- index = soe_GetControlSOESerialNumber(index)%NUM_CONTROLSOE; //报文所在位置
- return &ExramSOESave.SOESave.ControlSOESave.soe[index];
- }
- }
- //读取SOE事件
- static int ProcessC2ReadSoe(uint8 nIndex, uint8* nErrCode1, uint8* nErrCode2)
- {
- // PDM侧读取事件方式:
- // 0. PDM先发送写命令下发要读取的事件类型保存在m_nSoeType
- // 1. PDM然后读取该类型的报文个数( 240+事件类型用于读取指定类型报告的个数)
- // 2. PDM然后读取每条报告中各个子报告项信息
- int nRetCode = 0;//DPV1_OK
- //然后判断读取指定类型的信息命令
- const TMeasureDefine * pMeasDef;
- const TActionSOE * pActionSOE;
- const TDigitalSOE * pDiEventSOE;
- const TAbnormalSOE * pAbnormalSOE;
- const TRunSOE * pRunSOE;
- const TControlSOE * pControlSOE;
- // const TTraceSOE * pTraceSOE;
- //const TMotorSOE* pMotorSOE;
- char szBuffer[40];
- // char szValue[40];
- int idTmp;
- int nMaxMeasID;
- int ii;
- m_nSendCount = 0;
- //先判断获取SOE个数的index
- switch(nIndex)
- {
- case 240 + SOE_ACTION___:
- m_nSendCount += AssembWordBigEdin(&m_SendBuffer[m_nSendCount], soe_GetActionSOECount() );
- break;
- case 240 + SOE_WARNING___:
- m_nSendCount += AssembWordBigEdin(&m_SendBuffer[m_nSendCount], 0 );
- break;
- case 240 + SOE_DIEVENT___:
- m_nSendCount += AssembWordBigEdin(&m_SendBuffer[m_nSendCount], soe_GetDigitalSOECount() );
- break;
- case 240 + SOE_ABNORMAL___:
- m_nSendCount += AssembWordBigEdin(&m_SendBuffer[m_nSendCount], soe_GetAbnormalSOECount() );
- break;
- case 240 + SOE_DOEVENT___:
- m_nSendCount += AssembWordBigEdin(&m_SendBuffer[m_nSendCount], 0 );
- break;
- case 240 + SOE_RUN___:
- m_nSendCount += AssembWordBigEdin(&m_SendBuffer[m_nSendCount], soe_GetRunSOECount() );
- break;
- case 240 + SOE_CONTROL___:
- m_nSendCount += AssembWordBigEdin(&m_SendBuffer[m_nSendCount], soe_GetControlSOECount() );
- break;
- case 240 + SOE_INFO___:
- m_nSendCount += AssembWordBigEdin(&m_SendBuffer[m_nSendCount], 0 );
- break;
- case 240 + SOE_CUSTOM1___://不支持
- case 240 + SOE_CUSTOM2___:
- case 240 + SOE_CUSTOM3___:
- case 240 + SOE_CUSTOM4___:
- m_nSendCount += AssembWordBigEdin(&m_SendBuffer[m_nSendCount], 0 );
- break;
- case 240 + SOE_WAVE_FILE___:
- m_nSendCount += AssembWordBigEdin(&m_SendBuffer[m_nSendCount], 0 );
- break;
- case 240 + SOE_OPERATE___:
- m_nSendCount += AssembWordBigEdin(&m_SendBuffer[m_nSendCount], 0 );
- break;
- case 240 + SOE_TRACE___:
- m_nSendCount += AssembWordBigEdin(&m_SendBuffer[m_nSendCount], soe_GetTraceSOECount() );
- break;
- default:
- nRetCode = 0x81;//DPV1_NOK
- *nErrCode1 = 0xB0;//DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_INDEX;
- *nErrCode2 = 0xff;
- break;
- }
- if(nIndex > 240)
- return nRetCode;
- switch(m_nSoeType)
- {
- case SOE_ACTION___:
- {
- pActionSOE = soe_GetActionSOE(m_nSoeIndex+1);
- if (pActionSOE)
- {
- if (nIndex == 0)
- {
- //时间
- str_GetDateTimeString(&pActionSOE->time, szBuffer);
- m_nSendCount += AssembNBytes(&m_SendBuffer[m_nSendCount], (uint8*)szBuffer, 40 );
- //事件类型
- strcpy(szBuffer, g_strAction[pActionSOE->type-ID_SET_PROTTYPE].strArr[CURRENT_LANG]);
- strcat(szBuffer, " ");
- //动作结果
- strcat(szBuffer, g_strUtility[pActionSOE->result + ID_UTILITY_ACT_RESULT_SUCCESS].strArr[CURRENT_LANG] );
- m_nSendCount += AssembNBytes(&m_SendBuffer[m_nSendCount], (uint8*)szBuffer, 40 );
- }
- else
- {
- //动作测量量
- nMaxMeasID = NUM_MEASINSOE;
- for (ii=0; ii<NUM_MEASINSOE; ii++)
- {
- if (pActionSOE->measure.Meas[ii].MeasType == MEAS_NONE)
- {
- nMaxMeasID = ii;
- break;
- }
- }
- //故障测量值
- if(nIndex<=nMaxMeasID && pActionSOE->measure.Meas[nIndex-1].MeasType != MEAS_NONE)
- {
- idTmp = pActionSOE->measure.Meas[nIndex-1].MeasType; //测值ID
- pMeasDef = &MeasDefine[idTmp];
- sprintf(szBuffer, "%s=%s %s", pMeasDef->pName,
- str_GetMeasValueString(idTmp),
- pMeasDef->unit);
- //故障测量值信息
- m_nSendCount += AssembNBytes(&m_SendBuffer[m_nSendCount], (uint8*)szBuffer, 40 );
- }
- else
- {
- nRetCode = 0x81;//DPV1_NOK
- *nErrCode1 = 0xB7;//DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_RANGE;
- *nErrCode2 = 0xff;
- }
- }
- }
- else
- {
- memset(szBuffer, 0, 40);
- if(nIndex == 0)
- {
- //时间
- m_nSendCount += AssembNBytes(&m_SendBuffer[m_nSendCount], (uint8*)szBuffer, 40 );
- //事件类型
- m_nSendCount += AssembNBytes(&m_SendBuffer[m_nSendCount], (uint8*)szBuffer, 40 );
- }
- else
- {
- nRetCode = 0x81;//DPV1_NOK
- *nErrCode1 = 0xB7;//DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_RANGE;
- *nErrCode2 = 0xff;
- }
- }
- }
- break;
- case SOE_DIEVENT___:
- {
- pDiEventSOE = soe_GetDiEventSOE(m_nSoeIndex+1);
- if (pDiEventSOE)
- {
- if(nIndex == 0)
- {
- //时间
- str_GetDateTimeString(&pDiEventSOE->time, szBuffer);
- m_nSendCount += AssembNBytes(&m_SendBuffer[m_nSendCount], (uint8*)szBuffer, 40 );
- //事件类型
- sprintf(szBuffer, str_GetRealDiNameString(pDiEventSOE->di)); //物理名称
- strcat(szBuffer, " ");
- //变位类型
- if(pDiEventSOE->state == DI_OFF)
- strcat(szBuffer, "1->0 ");
- else
- strcat(szBuffer, "0->1 ");
- m_nSendCount += AssembNBytes(&m_SendBuffer[m_nSendCount], (uint8*)szBuffer, 40 );
- }
- else
- {
- nRetCode = 0x81;//DPV1_NOK
- *nErrCode1 = 0xB7;//DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_RANGE;
- *nErrCode2 = 0xff;
- }
- }
- else
- {
- memset(szBuffer, 0, 40);
- if(nIndex == 0)
- {
- //时间
- m_nSendCount += AssembNBytes(&m_SendBuffer[m_nSendCount], (uint8*)szBuffer, 40 );
- //事件类型
- m_nSendCount += AssembNBytes(&m_SendBuffer[m_nSendCount], (uint8*)szBuffer, 40 );
- }
- else
- {
- nRetCode = 0x81;//DPV1_NOK
- *nErrCode1 = 0xB7;//DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_RANGE;
- *nErrCode2 = 0xff;
- }
- }
- }
- break;
- case SOE_ABNORMAL___:
- {
- pAbnormalSOE = soe_GetAbnormalSOE(m_nSoeIndex+1);
- if (pAbnormalSOE != NULL)
- {
- if(nIndex == 0)
- {
- //时间
- str_GetDateTimeString(&pAbnormalSOE->time, szBuffer);
- m_nSendCount += AssembNBytes(&m_SendBuffer[m_nSendCount], (uint8*)szBuffer, 40 );
- //事件类型
- sprintf(szBuffer, g_strAbnormal[pAbnormalSOE->type-ABNORMAL_FIRST].strArr[CURRENT_LANG] );
- m_nSendCount += AssembNBytes(&m_SendBuffer[m_nSendCount], (uint8*)szBuffer, 40 );
- }
- else
- {
- nRetCode = 0x81;//DPV1_NOK
- *nErrCode1 = 0xB7;//DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_RANGE;
- *nErrCode2 = 0xff;
- }
- }
- else
- {
- memset(szBuffer, 0, 40);
- if(nIndex == 0)
- {
- //时间
- m_nSendCount += AssembNBytes(&m_SendBuffer[m_nSendCount], (uint8*)szBuffer, 40 );
- //事件类型
- m_nSendCount += AssembNBytes(&m_SendBuffer[m_nSendCount], (uint8*)szBuffer, 40 );
- }
- else
- {
- nRetCode = 0x81;//DPV1_NOK
- *nErrCode1 = 0xB7;//DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_RANGE;
- *nErrCode2 = 0xff;
- }
- }
- }
- break;
- case SOE_RUN___:
- {
- pRunSOE = soe_GetRunSOE(m_nSoeIndex+1);
- if (pRunSOE != NULL)
- {
- if(nIndex == 0)
- {
- //时间
- str_GetDateTimeString(&pRunSOE->time, szBuffer);
- m_nSendCount += AssembNBytes(&m_SendBuffer[m_nSendCount], (uint8*)szBuffer, 40 );
- //事件类型
- sprintf(szBuffer, g_strRun[pRunSOE->type-RUN_COOL_STARTUP].strArr[CURRENT_LANG] );
- m_nSendCount += AssembNBytes(&m_SendBuffer[m_nSendCount], (uint8*)szBuffer, 40 );
- }
- else
- {
- nRetCode = 0x81;//DPV1_NOK
- *nErrCode1 = 0xB7;//DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_RANGE;
- *nErrCode2 = 0xff;
- }
- }
- else
- {
- memset(szBuffer, 0, 40);
- if(nIndex == 0)
- {
- //时间
- m_nSendCount += AssembNBytes(&m_SendBuffer[m_nSendCount], (uint8*)szBuffer, 40 );
- //事件类型
- m_nSendCount += AssembNBytes(&m_SendBuffer[m_nSendCount], (uint8*)szBuffer, 40 );
- }
- else
- {
- nRetCode = 0x81;//DPV1_NOK
- *nErrCode1 = 0xB7;//DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_RANGE;
- *nErrCode2 = 0xff;
- }
- }
- }
- break;
- case SOE_CONTROL___:
- {
- pControlSOE = soe_GetControlSOE(m_nSoeIndex+1);
- if (pControlSOE != NULL)
- {
- if(nIndex == 0)
- {
- //时间
- str_GetDateTimeString(&pControlSOE->time, szBuffer);
- m_nSendCount += AssembNBytes(&m_SendBuffer[m_nSendCount], (uint8*)szBuffer, 40 );
- //事件类型
- sprintf(szBuffer, g_strControl[pControlSOE->type-CONTROL_FIRST].strArr[CURRENT_LANG] );
- m_nSendCount += AssembNBytes(&m_SendBuffer[m_nSendCount], (uint8*)szBuffer, 40 );
- }
- else
- {
- nRetCode = 0x81;//DPV1_NOK
- *nErrCode1 = 0xB7;//DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_RANGE;
- *nErrCode2 = 0xff;
- }
- }
- else
- {
- memset(szBuffer, 0, 40);
- if(nIndex == 0)
- {
- //时间
- m_nSendCount += AssembNBytes(&m_SendBuffer[m_nSendCount], (uint8*)szBuffer, 40 );
- //事件类型
- m_nSendCount += AssembNBytes(&m_SendBuffer[m_nSendCount], (uint8*)szBuffer, 40 );
- }
- else
- {
- nRetCode = 0x81;//DPV1_NOK
- *nErrCode1 = 0xB7;//DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_RANGE;
- *nErrCode2 = 0xff;
- }
- }
- }
- break;
- case SOE_TRACE___:
- {
- }
- break;
- default:
- break;
- }
- return nRetCode;
- }
- //写工程配置
- static int ProcessWriteDeviceModel(uint8 nWriteLen, uint8* pDataWrite, uint8* nErrCode1, uint8* nErrCode2)
- {
- //写工程配置
- uint8 nCount = nWriteLen/2;//定值个数
- uint8 tmpBuffer[120*3];//最多一次120个定值
- uint16 nBufferLen = nCount*3; //ID + WORD
- int bOK = TRUE;
- int id;
- int nRet = DPV1_OK;
- uint16 nValue;
- uint8 nIndex = 0;//数值修改的Offset从0开始
- if(nCount>0)
- {
- //检查
- bOK = TRUE;
- for (id=nIndex;id<(nIndex+nCount);id++)
- {
- if(id>=NUM_DEVICEMODELS)
- {
- *nErrCode1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_INDEX;
- *nErrCode2 = 0;
- nRet = DPV1_NOK;
- bOK = FALSE;
- break;
- }
- DissembWordBigEdin(&pDataWrite[(id-nIndex)*2], &nValue);
- if(!CheckDeviceModelValue(id, nValue))
- {
- *nErrCode1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_RANGE;
- *nErrCode2 = 0;
- nRet = DPV1_NOK;
- bOK = FALSE;
- break;
- }
- else
- {
- //组织修改缓存区
- tmpBuffer[(id-nIndex)*3 + 0 ] = id;
- tmpBuffer[(id-nIndex)*3 + 1 ] = LOBYTE(nValue);
- tmpBuffer[(id-nIndex)*3 + 2 ] = HIBYTE(nValue);
- }
- }
- if(bOK) //检查正确,开始修改
- {
- eepwri_ModifyDeviceModelsByComm(tmpBuffer, nBufferLen );
- }
- }
- return nRet;
- }
- //写保护定值
- static int ProcessWriteProtectSettings(uint8 nWriteLen, uint8* pDataWrite, uint8* nErrCode1, uint8* nErrCode2)
- {
- //写保护定值
- uint8 nCount = nWriteLen/2;//定值个数
- uint8 tmpBuffer[120*3];//最多一次120个定值
- uint16 nBufferLen = nCount*3; //ID + WORD
- int bOK = TRUE;
- int id;
- int nRet = DPV1_OK;
- uint16 nValue;
- uint8 nIndex = 0;//数值修改的Offset从0开始
- if(nCount>0)
- {
- //检查
- bOK = TRUE;
- for (id=nIndex;id<(nIndex+nCount);id++)
- {
- if(id>=NUM_SETTINGS)
- {
- *nErrCode1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_INDEX;
- *nErrCode2 = 0;
- nRet = DPV1_NOK;
- bOK = FALSE;
- break;
- }
- DissembWordBigEdin(&pDataWrite[(id-nIndex)*2], &nValue);
- if(!CheckSettingValue(id, nValue))
- {
- *nErrCode1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_RANGE;
- *nErrCode2 = 0;
- nRet = DPV1_NOK;
- bOK = FALSE;
- break;
- }
- else
- {
- //组织修改缓存区
- tmpBuffer[(id-nIndex)*3 + 0 ] = id;
- tmpBuffer[(id-nIndex)*3 + 1 ] = LOBYTE(nValue);
- tmpBuffer[(id-nIndex)*3 + 2 ] = HIBYTE(nValue);
- }
- }
- if(bOK) //检查正确,开始修改
- {
- eepwri_ModifySettingsByComm(tmpBuffer, nBufferLen );
- }
- }
- return nRet;
- }
- //写开入配置
- static int ProcessWriteDiCfg(uint8 nWriteLen, uint8* pDataWrite, uint8* nErrCode1, uint8* nErrCode2)
- {
- int nRet = DPV1_OK;
- int i;
- int nRealWriteLen = 0;
- uint8 tmpBuffer[120*2];//最多一次120个定值
- //允许可编程状态才能进行设置
- if (GetDeviceModelValue(ID_DEVICEMODEL_PROGRAMMABLE) == PROGRAMMABLE_ON)
- {
- for (i=0;i<min(nWriteLen, DI_REALCOUNT);i++)
- {
- //检查定值编号是否合法
- if(i>=NUM_REAL_DI_COUNT || ((1<<i) & DI_MASK)==0) //id不在允许的可配置范围内
- {
- *nErrCode1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_INDEX;
- *nErrCode2 = ErrCode2_Write_DICFG;
- nRet = DPV1_NOK;
- return nRet;
- }
- //检查值是否在范围内
- if(!CheckDiConfigValue(pDataWrite[i]&0xff))
- {
- *nErrCode1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_RANGE;
- *nErrCode2 = ErrCode2_Write_DICFG;
- nRet = DPV1_NOK;
- return nRet;
- }
- //组织修改缓存区
- tmpBuffer[i*2 + 0 ] = i;
- tmpBuffer[i*2 + 1 ] = pDataWrite[i]&0xff;
- nRealWriteLen += 2;
- }
- eepwri_ModifyDiConfigsByComm(tmpBuffer, nRealWriteLen);
- }
- else
- {
- *nErrCode1 = DPV1_ERRCL_APPLICATION | DPV1_ERRCL_APP_WRITE;
- *nErrCode2 = ErrCode2_Write_DICFG;
- nRet = DPV1_NOK;
- }
- return nRet;
- }
- //写开出配置
- static int ProcessWriteDoCfg(uint8 nWriteLen, uint8* pDataWrite, uint8* nErrCode1, uint8* nErrCode2)
- {
- int nRet = DPV1_OK;
- int i;
- uint8 tmpBuffer[120*2];//最多一次120个定值
- int nRealWriteLen = 0;
- //允许可编程状态才能进行设置
- if (GetDeviceModelValue(ID_DEVICEMODEL_PROGRAMMABLE) == PROGRAMMABLE_ON)
- {
- for (i=0;i<min(nWriteLen, NUM_REAL_DO_COUNT);i++)
- {
- //检查定值编号是否合法
- if(i>=NUM_REAL_DO_COUNT)
- {
- *nErrCode1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_INDEX;
- *nErrCode2 = ErrCode2_Write_DOCFG;
- nRet = DPV1_NOK;
- return nRet;
- }
- //检查值是否在范围内
- if(!CheckDoConfigValue(pDataWrite[i]&0xff))
- {
- *nErrCode1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_RANGE;
- *nErrCode2 = ErrCode2_Write_DOCFG;
- nRet = DPV1_NOK;
- return nRet;
- }
- //组织修改缓存区
- tmpBuffer[i*2 + 0 ] = i;
- tmpBuffer[i*2 + 1 ] = pDataWrite[i]&0xff;
- nRealWriteLen+=2;
- }
- eepwri_ModifyDoConfigsByComm(tmpBuffer, nRealWriteLen);
- }
- else
- {
- *nErrCode1 = DPV1_ERRCL_APPLICATION | DPV1_ERRCL_APP_WRITE;
- *nErrCode2 = ErrCode2_Write_DOCFG;
- nRet = DPV1_NOK;
- }
- return nRet;
- }
- //写开入常开常闭配置
- static int ProcessWriteDiNoNcCfg(uint8 nWriteLen, uint8* pDataWrite, uint8* nErrCode1, uint8* nErrCode2)
- {
- int nRet = DPV1_OK;
- int i;
- uint8 tmpBuffer[120*2];//最多一次120个定值
- int nRealWriteLen = 0;
- //允许可编程状态才能进行设置
- if (GetDeviceModelValue(ID_DEVICEMODEL_DIOPENORCLOSE)==PROGRAMMABLE_ON)
- {
- for (i=0;i<min(nWriteLen, DI_REALCOUNT);i++)
- {
- //检查定值编号是否合法
- if(i>=NUM_REAL_DI_COUNT || ((1<<i) & DI_MASK)==0) //id不在允许的可配置范围内
- {
- *nErrCode1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_INDEX;
- *nErrCode2 = ErrCode2_Write_DINONCCFG;
- nRet = DPV1_NOK;
- return nRet;
- }
- //检查值是否在范围内
- if(!CheckDiOpenOrCloseValue(pDataWrite[i]&0xff))
- {
- *nErrCode1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_RANGE;
- *nErrCode2 = ErrCode2_Write_DINONCCFG;
- nRet = DPV1_NOK;
- return nRet;
- }
- //组织修改缓存区
- tmpBuffer[i*2 + 0 ] = i;
- tmpBuffer[i*2 + 1 ] = pDataWrite[i]&0xff;
- nRealWriteLen+=2;
- }
- eepwri_ModifyDiOpenOrCloseByComm(tmpBuffer, nRealWriteLen);
- }
- else
- {
- *nErrCode1 = DPV1_ERRCL_APPLICATION | DPV1_ERRCL_APP_WRITE;
- *nErrCode2 = ErrCode2_Write_DINONCCFG;
- nRet = DPV1_NOK;
- }
- return nRet;
- }
- //处理遥控
- static int ProcessRemoteCtrl(uint8 nCtrlObj, uint8 nCtrlType ,uint8* nErrCode1, uint8* nErrCode2)
- {
- int nRet = DPV1_OK;
- uint16 info;
- if(ProcessRemoteCtrlExec(nCtrlObj+1,nCtrlType+1, &info))
- {
- }
- else
- {
- *nErrCode1 = DPV1_ERRCL_APPLICATION | DPV1_ERRCL_APP_WRITE;
- *nErrCode2 = ErrCode2_Write_Control;
- nRet = DPV1_NOK;
- }
- return nRet;
- }
- //处理写系统设置
- static int ProcessWriteSysCfg(uint8 nWriteLen, uint8* pDataWrite, uint8* nErrCode1, uint8* nErrCode2)
- {
- //写系统设置
- //注意系统设置只从ID_SYS_OUTPUTI1开始进行设置
- uint8 nCount = nWriteLen/2;//定值个数
- uint8 tmpBuffer[120*3];//最多一次120个定值
- uint16 nBufferLen = nCount*3; //ID + WORD
- int bOK = TRUE;
- int id;
- int nRet = DPV1_OK;
- uint16 nValue;
- //只有一个写操作, 从4~20mA交流量输出1定义开始设置
- uint8 nIndex = ID_SYS_OUTPUTI1;
- if(nCount>0)
- {
- //检查
- bOK = TRUE;
- for (id=nIndex;id<(nIndex+nCount);id++)
- {
- if(id>=NUM_SYSCFGS)
- {
- *nErrCode1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_INDEX;
- *nErrCode2 = 0;
- nRet = DPV1_NOK;
- bOK = FALSE;
- break;
- }
- DissembWordBigEdin(&pDataWrite[(id-nIndex)*2], &nValue);
- if(!CheckSysCfgValue(id, nValue))
- {
- *nErrCode1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_RANGE;
- *nErrCode2 = 0;
- nRet = DPV1_NOK;
- bOK = FALSE;
- break;
- }
- else
- {
- //组织修改缓存区
- tmpBuffer[(id-nIndex)*3 + 0 ] = id;
- tmpBuffer[(id-nIndex)*3 + 1 ] = LOBYTE(nValue);
- tmpBuffer[(id-nIndex)*3 + 2 ] = HIBYTE(nValue);
- }
- }
- if(bOK) //检查正确,开始修改
- {
- eepwri_ModifySysCfgsByComm(tmpBuffer, nBufferLen );
- }
- }
- return nRet;
- }
- //处理启动录波
- static int ProcessStartWaveRecord(uint8* nErrCode1, uint8* nErrCode2)
- {
- int nRet = DPV1_OK;
- // if(GetCurrentControlLimit()==CONTROL_LMT_REMOTE)
- {
- if(!WaveFlag.RecordFlag)
- {
- WaveFlag.TestRemote=1;
- if(GetSysCfgValue(ID_SYS_WAVETIME) >0)
- {
- WaveFlag.WaveTestLen=GetSysCfgValue(ID_SYS_WAVETIME)*12;
- }
- else
- {
- WaveFlag.WaveTestLen=0;
- }
- }
- else
- {
- *nErrCode1 = DPV1_ERRCL_APPLICATION | DPV1_ERRCL_APP_WRITE;
- *nErrCode2 = 0;
- nRet = DPV1_NOK;
- }
- }
- // else
- // {
- // *nErrCode1 = DPV1_ERRCL_APPLICATION | DPV1_ERRCL_APP_WRITE;
- // *nErrCode2 = 0;
- // nRet = DPV1_NOK;
- // }
- return nRet;
- }
- //二类主站建立联接请求
- void EDD_C2_InitiateReq(uint8 nDevID)
- {
- }
- //二类主站联接断掉通知
- void EDD_C2_AbortInd(uint8 nDevID)
- {
- }
- int DPV1_ReadReq(uint8 nDevID, uint8 nSlot, uint8 nIndex, uint8 nReadLen, uint8** pDataRet, uint8* pLenAssemb, uint8* nErrCode1, uint8* nErrCode2)
- {
- int nRet = DPV1_OK;
- *pDataRet = NULL;
- *pLenAssemb = 0;
- *nErrCode1 = 0x00;
- *nErrCode2 = 0x00;
- g_ProfibusRam.nDisConnTimer = 0;//有非周期读写(二类)也表示处于正常连接状态
- switch(nSlot&0xff)
- {
- /************************************************************************/
- /* 一类主站与公司主控通讯 */
- /************************************************************************/
- case SlotNum_Read_BhPara:
- {
- //低字节在前
- nRet = ProcessC2ReadProtSettingsWiscom(nIndex, nReadLen, nErrCode1, nErrCode2);
- }
- break;
- case SlotNum_Read_Energy:
- {
- //低字节在前
- nRet = ProcessC1ReadEgyInfoWiscom(nIndex, nReadLen, nErrCode1, nErrCode2);
- }
- break;
- case SlotNum_Read_WaveConfig:
- {
- //低字节在前
- nRet = ProcessWaveCfgWiscom(nIndex);
- }
- break;
- case SlotNum_Read_WaveData_File_Zone0:
- case SlotNum_Read_WaveData_File_Zone1:
- case SlotNum_Read_WaveData_File_Zone2:
- case SlotNum_Read_WaveData_File_Zone3:
- {
- //不支持
- *nErrCode1 = DPV1_ERRCL_APPLICATION | DPV1_ERRCL_APP_NOTSUPP;
- *nErrCode2 = 0;
- nRet = DPV1_NOK;
- }
- break;
- 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:
- {
- //采样点方式,低字节在前
- nRet = ProcessWaveDataWiscom(nSlot, nIndex, nErrCode1, nErrCode2);
- }
- break;
- 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:
- {
- //不支持
- *nErrCode1 = DPV1_ERRCL_APPLICATION | DPV1_ERRCL_APP_NOTSUPP;
- *nErrCode2 = 0;
- nRet = DPV1_NOK;
- }
- break;
- case SlotNum_Read_DeviceInfo:
- {
- //低字节在前
- nRet = ProcessReadDeviceInfoWiscom();
- }
- break;
- 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:
- {
- //不支持
- *nErrCode1 = DPV1_ERRCL_APPLICATION | DPV1_ERRCL_APP_NOTSUPP;
- *nErrCode2 = 0;
- nRet = DPV1_NOK;
- }
- break;
- /************************************************************************/
- /* 二类主站,与CP5611卡,软件西门子PDM管理软件, 高字节在前 */
- /************************************************************************/
- case SlotNum_50:
- {
- switch(nIndex)
- {
- case SlotNum_50_SYSINFO:
- {
- ProcessC2ReadSysInfo();
- }
- break;
- case SlotNum_50_DEVMODEL:
- {
- ProcessC2ReadDeviceModel();
- }
- break;
- case SlotNum_50_SYSCFG:
- {
- ProcessC2ReadSysCfg();
- }
- break;
- case SlotNum_50_PROTSETTING:
- {
- ProcessC2ReadProtSettings();
- }
- break;
- case SlotNum_50_DICFG:
- {
- ProcessC2ReadDiCfg();
- }
- break;
- case SlotNum_50_DOCFG:
- {
- ProcessC2ReadDoCfg();
- }
- break;
- case SlotNum_50_PW:
- {
- ProcessC2ReadUserPw();
- }
- break;
- case SlotNum_50_DI_NONC:
- {
- ProcessC2ReadDiNoNcCfg();
- }
- break;
- case SlotNum_50_LANGUAGE:
- {
- ProcessC2ReadUserLang();
- }
- break ;
- default:
- {
- *nErrCode1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_INDEX;
- *nErrCode2 = 0;
- nRet = DPV1_NOK;
- }
- break;
- }
- }
- break;
- case SlotNum_51:
- {
- switch(nIndex)
- {
- case SlotNum_51_MEASFOLDER0:
- case SlotNum_51_MEASFOLDER1:
- case SlotNum_51_MEASFOLDER2:
- {
- ProcessC2ReadMeas(nIndex);
- }
- break;
- case SlotNum_51_MEAS_COMMUSEND_BARVAL:
- case SlotNum_51_MEAS_COMMUSEND_TRENDVIEW:
- {
- ProcessC2ReadCommuMeas(nIndex==SlotNum_51_MEAS_COMMUSEND_TRENDVIEW);
- }
- break;
- default:
- {
- *nErrCode1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_INDEX;
- *nErrCode2 = 0;
- nRet = DPV1_NOK;
- }
- break;
- }
- }
- break;
- case SlotNum_52:
- {
- switch(nIndex)
- {
- case SlotNum_52_DBGDATA_FOLDER0:
- case SlotNum_52_DBGDATA_FOLDER1:
- case SlotNum_52_DBGDATA_FOLDER2:
- {
- ProcessC2ReadDebugData(nIndex);
- }
- break;
- default:
- {
- *nErrCode1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_INDEX;
- *nErrCode2 = 0;
- nRet = DPV1_NOK;
- }
- break;
- }
- }
- break;
- case SlotNum_53:
- {
- switch(nIndex)
- {
- case SlotNum_53_DI:
- {
- ProcessC2ReadDiData();
- }
- break;
- case SlotNum_53_DO:
- {
- ProcessC2ReadDoData();
- }
- break;
- case SlotNum_53_PT:
- {
- ProcessC2ReadPtData();
- }
- break;
- case SlotNum_53_SOFTSTRAP:
- {
- ProcessC2ReadSoftStrap();
- }
- break;
- case SlotNum_53_ABNLSIG:
- {
- ProcessC2ReadAbnlSignal();
- }
- break;
- case SlotNum_53_ACTSIG:
- {
- ProcessC2ReadActSignal();
- }
- break;
- case SlotNum_53_ENERGY:
- {
- ProcessC2ReadEgyInfo();
- }
- break;
- case SlotNum_53_STAT:
- {
- ProcessC2ReadStatInfo();
- }
- break;
- case SlotNum_53_PBSTAT:
- {
- ProcessC2ReadProfibusStatInfo();
- }
- break;
- default:
- {
- *nErrCode1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_INDEX;
- *nErrCode2 = 0;
- nRet = DPV1_NOK;
- }
- break;
- }
- }
- break;
- case SlotNum_54: //读取指定类型的SOE事件
- {
- ProcessC2ReadSoe(nIndex, nErrCode1, nErrCode2);
- }
- break;
- }
- *pDataRet = m_SendBuffer;
- *pLenAssemb = m_nSendCount&0xff;
- return nRet;
- }
- int DPV1_WriteReq(uint8 nDevID, uint8 nSlot, uint8 nIndex, uint8 nWriteLen, uint8* pDataWrite, uint8* nErrCode1, uint8* nErrCode2)
- {
- int nRet = DPV1_OK;
- uint16 nValue;
- uint16 nInfo;
- int nMaxLen;
- TDateTime time;
- *nErrCode1 = 0x00;
- *nErrCode2 = 0x00;
- g_ProfibusRam.nDisConnTimer = 0;//有非周期读写(二类)也表示处于正常连接状态
- switch(nSlot)
- {
- case SlotNum_Write_BhPara:
- {
- //判断index是否在范围内
- if(nIndex < NUM_SETTINGS)
- {
- nMaxLen = ( (nIndex*2+nWriteLen)>sizeof(TSettings) )?(sizeof(TSettings)-nIndex*2):nWriteLen;
- //写定值, 与自己系统通讯,低字节在前
- if(profi_ModifySettings(nIndex, pDataWrite, nMaxLen, FALSE, &nInfo))
- {
- }
- else
- {
- *nErrCode1 = DPV1_ERRCL_APPLICATION | DPV1_ERRCL_APP_WRITE;
- *nErrCode2 = 0;
- nRet = DPV1_NOK;
- }
- }
- else
- {
- *nErrCode1 = DPV1_ERRCL_APPLICATION | DPV1_ERRCL_APP_WRITE;
- *nErrCode2 = 0;
- nRet = DPV1_NOK;
- }
- }
- break;
- case SlotNum_Write_StartWave:
- {
- if(!WaveFlag.RecordFlag)
- {
- WaveFlag.TestRemote=1;
- if(GetSysCfgValue(ID_SYS_WAVETIME) >0)
- {
- WaveFlag.WaveTestLen=GetSysCfgValue(ID_SYS_WAVETIME)*12;
- }
- else
- {
- WaveFlag.WaveTestLen=0;
- }
- }
- else
- {
- *nErrCode1 = DPV1_ERRCL_APPLICATION | DPV1_ERRCL_APP_WRITE;
- *nErrCode2 = 0;
- nRet = DPV1_NOK;
- }
- }
- break;
- case SlotNum_Write_ModifyTime:
- {
- if(nIndex==0)
- {
- if(nWriteLen==7)
- {
- //通讯校时,只较到秒
- DissembWordLittleEdin(&pDataWrite[0], &nValue);
- time.y = nValue%100; //年范围0~99 表示2000~2099
- time.mon = pDataWrite[2] & 0xff;
- time.d = pDataWrite[3] & 0xff;
- time.h = pDataWrite[4] & 0xff;
- time.min = pDataWrite[5] & 0xff;
- time.s = pDataWrite[6] & 0xff;
- time.ms = Now().ms;
- //设置装置时间
- if(SetDeviceSystemTime(&time)!=TRUE) //时间违法
- {
- *nErrCode1 = DPV1_ERRCL_APPLICATION | DPV1_ERRCL_APP_WRITE;
- *nErrCode2 = 0;
- nRet = DPV1_NOK;
- }
- }
- else
- {
- *nErrCode1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_WRITE_LEN;
- *nErrCode2 = 0;
- nRet = DPV1_NOK;
- }
- }
- else
- {
- *nErrCode1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_INDEX;
- *nErrCode2 = 0;
- nRet = DPV1_NOK;
- }
- }
- break;
- case SlotNum_Write_CtrlSelect:
- case SlotNum_Write_CtrlCancel:
- {
- //不支持真遥控
- *nErrCode1 = DPV1_ERRCL_APPLICATION | DPV1_ERRCL_APP_WRITE;
- *nErrCode2 = 0;
- nRet = DPV1_NOK;
- }
- break ;
- case SlotNum_Write_CtrlExecute:
- {
- //只有遥控执行
- nRet = ProcessRemoteCtrl(nIndex, pDataWrite[0] & 0xff, nErrCode1, nErrCode2);
- }
- break;
- case SlotNum_Write_ResetSignal:
- {
- SignalReset(RUN_RESET_COMM);
- }
- break;
- 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:
- {
- *nErrCode1 = DPV1_ERRCL_APPLICATION | DPV1_ERRCL_APP_WRITE;
- *nErrCode2 = 0;
- nRet = DPV1_NOK;
- }
- break;
- case SlotNum_50:
- {
- switch(nIndex)
- {
- case SlotNum_50_DEVMODEL:
- {
- nRet = ProcessWriteDeviceModel(nWriteLen, pDataWrite, nErrCode1, nErrCode2);
- }
- break;
- case SlotNum_50_SYSCFG:
- {
- nRet = ProcessWriteSysCfg(nWriteLen, pDataWrite, nErrCode1, nErrCode2);
- }
- break;
- case SlotNum_50_PROTSETTING:
- {
- nRet = ProcessWriteProtectSettings(nWriteLen, pDataWrite, nErrCode1, nErrCode2);
- }
- break;
- //400V增加开入开出及开入常开常闭设置功能
- case SlotNum_50_DICFG:
- {
- nRet = ProcessWriteDiCfg(nWriteLen, pDataWrite, nErrCode1, nErrCode2);
- }
- break;
- case SlotNum_50_DOCFG:
- {
- nRet = ProcessWriteDoCfg(nWriteLen, pDataWrite, nErrCode1, nErrCode2);
- }
- break;
- case SlotNum_50_DI_NONC:
- {
- nRet = ProcessWriteDiNoNcCfg(nWriteLen, pDataWrite, nErrCode1, nErrCode2);
- }
- break;
- case SlotNum_50_PW:
- {
- DissembWordBigEdin(&pDataWrite[0], &nValue);
- eepwri_SetSysCfg(0, nValue);
- }
- break;
- case SlotNum_50_CTRLOBJ:
- {
- nRet = ProcessRemoteCtrl(pDataWrite[0] & 0xff, pDataWrite[1] & 0xff, nErrCode1, nErrCode2);
- }
- break;
- case SlotNum_50_SOFTSTRAP:
- {
- //无
- }
- break;
- case SlotNum_50_SIGNALRESET:
- {
- SignalReset(RUN_RESET_COMM);
- }
- break;
- case SlotNum_50_STARTWAVE:
- {
- nRet = ProcessStartWaveRecord(nErrCode1, nErrCode2);
- }
- break;
- case SlotNum_50_LANGUAGE:
- {
- DissembWordBigEdin(&pDataWrite[0], &nValue);
- eepwri_SetSysCfg(ID_SYS_LANGUAGE, nValue);
- }
- break ;
- default:
- {
- *nErrCode1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_INDEX;
- *nErrCode2 = 0;
- nRet = DPV1_NOK;
- }
- break;
- }
- }
- break;
- case SlotNum_51:
- case SlotNum_52:
- case SlotNum_53:
- {
- //不支持读写
- *nErrCode1 = DPV1_ERRCL_ACCESS | DPV1_ERRCL_ACC_INV_SLOT;
- *nErrCode2 = 0x00;
- nRet = DPV1_NOK;
- }
- break;
- case SlotNum_54:
- {
- //保存要读取的事件类型和事件编号
- m_nSoeType = pDataWrite[0] & 0xff;
- DissembWordBigEdin(&pDataWrite[1], &m_nSoeIndex);
- }
- break;
- }
- return nRet;
- }