?? cb_f3.cpp
字號:
#include "CB_F3.h"
#include "CB_String.h"
#include "CB_Unit.h"
#include "CB_String.h"
#include "Afx.h"
#include "CB_SysParam.h"
#include "CB_Point.h"
//##ModelId=40AEA1EE037A
int CB_F3::instance(char *str, char *fileName)
{
FILE *pFile;
pFile = fopen(fileName,"r+");
SENSOR sensor_src,sensor_dest;
strToStrt(str,&sensor_src);
while(1==1)
{
if(fread(&sensor_dest,sizeof(SENSOR),1,pFile)<1 )
{
dispose_new(&sensor_src,pFile);
break;
}
char index_src_all[80];
strcpy(index_src_all,sensor_src.index);
strcat(index_src_all,sensor_src.index_colliery);
char *pIndex_file = sensor_dest.index;
CB_Unit::trim(pIndex_file);
char *pIndex_index_colliery_file = sensor_dest.index_colliery;
CB_Unit::trim(pIndex_index_colliery_file);
char index_dest_all[80];
strcpy(index_dest_all,sensor_dest.index);
strcat(index_dest_all,sensor_dest.index_colliery);
char *pAffirm = sensor_dest.affirm;
CB_Unit::trim(pAffirm);
char *pState = sensor_dest.state;
int nState = atoi(pState);
if(strcmp(index_src_all,index_dest_all)==0){
dispose_update(&sensor_src,&sensor_dest,pFile);
break;
}
}
fclose(pFile);
return 0;
}
//##ModelId=409B237C00CE
int CB_F3::strToStrt(char *str, SENSOR *sensor)
{
CB_String string;
string.split(str,',');
char *pResult = string.getNext();
CB_Unit::trim(pResult);
strcpy(sensor->index_colliery,pResult);
pResult = string.getNext();
CB_Unit::trim(pResult);
strcpy(sensor->index,pResult);
pResult = string.getNext();
CB_Unit::trim(pResult);
strcpy(sensor->name,pResult);
pResult = string.getNext();
CB_Unit::trim(pResult);
strcpy(sensor->upper_limit,pResult);
pResult = string.getNext();
CB_Unit::trim(pResult);
strcpy(sensor->lower_limit,pResult);
pResult = string.getNext();
CB_Unit::trim(pResult);
strcpy(sensor->unit,pResult);
pResult = string.getNext();
CB_Unit::trim(pResult);
strcpy(sensor->time_produce,pResult);
strcpy(sensor->state,"0");
strcpy(sensor->affirm,"0");
pResult = string.getNext();
CB_Unit::trim(pResult);
strcpy(sensor->subposition,pResult);
pResult = string.getNext();
CB_Unit::trim(pResult);
strcpy(sensor->on_off,pResult);
return 0;
}
//##ModelId=409B24FC00F8
int CB_F3::dispose_new(SENSOR *sensor, FILE *pFile)
{
int len = sizeof(SENSOR);
strcpy(sensor->state,"1");
strcpy(sensor->affirm,"0");
fwrite(sensor,len,1,pFile);
return 0;
}
//##ModelId=409B290802BB
int CB_F3::dispose_update(SENSOR *sensor_src, SENSOR *sensor_dest, FILE *pFile)
{
int len = sizeof(SENSOR);
char *pState = sensor_dest->state;
int nState = atoi(pState);
char *pName = sensor_dest->name;
CB_Unit::trim(pName);
if(strcmp(sensor_src->name,sensor_dest->name)!=0 ||
strcmp(sensor_src->upper_limit,sensor_dest->upper_limit)!=0 ){
if(nState ==1){
strcpy(sensor_src->state,"1");
}else{
strcpy(sensor_src->state,"2");
}
fseek(pFile,-len,SEEK_CUR);
if(fwrite(sensor_src,len,1,pFile)<1){
return -1;
}
}
return 0;
}
//##ModelId=40D7AE24006A
void CB_F3::setSysParam(CB_SysParam *sysParam)
{
m_sysParam = sysParam;
}
//##ModelId=40D7AE2501A2
CB_SysParam *CB_F3::getSysParam()
{
return m_sysParam;
}
//##ModelId=40D7AEBF00E5
CB_F3::CB_F3()
{
initiaze();
}
//##ModelId=40D7AEBF0136
CB_F3::~CB_F3()
{
}
//##ModelId=40D7AF39038A
void CB_F3::initiaze()
{
//m_sysParam = NULL;
}
//##ModelId=40D7CA8C00FD
int CB_F3::updatePoint(char *index_colliery, char *index_sensor)
{
CB_Unit::trim(index_colliery);
CB_Unit::trim(index_sensor);
int nRtn = 0;
FILE *pFile;
pFile = fopen(m_sysParam->getPoint(),"r+");
if(pFile == NULL)
{
return -1;
}
POINT point_dest;
int len = sizeof(POINT);
char index_src_all[120];
char index_dest_all[120];
CB_Unit::clearBuf(index_src_all,120);
strcpy(index_src_all,index_colliery);
strcat(index_src_all,index_sensor);
CB_Unit::trim(index_src_all);
while(1==1)
{
if(fread(&point_dest,len,1,pFile)<1)
{
if(feof(pFile)!=0){
break;
}else{
break;
}
}
char *p;
CB_Unit::clearBuf(index_dest_all,120);
p = point_dest.index_colliery;
CB_Unit::trim(p);
strcpy(index_dest_all,p);
p = point_dest.index_sensor;
CB_Unit::trim(p);
strcat(index_dest_all,p);
CB_Unit::trim(index_dest_all);
if(strcmp(index_src_all,index_dest_all) == 0)
{
int nState = atoi(point_dest.state);
int nAffirm= atoi(point_dest.affirm);
if((nState==1) && (nAffirm==0))
{
strcpy(point_dest.state,"1");
strcpy(point_dest.affirm,"0");
}else if( (nState==1) && (nAffirm==1))
{
strcpy(point_dest.state,"2");
strcpy(point_dest.affirm,"0");
}else if( nState==2)
{
strcpy(point_dest.state,"2");
strcpy(point_dest.affirm,"0");
}
if(fseek(pFile,-len,SEEK_CUR)!=0)
{
nRtn = -1;
goto Stop;
}
if(fwrite(&point_dest,len,1,pFile)<1)
{
nRtn = -1;
goto Stop;
}
continue;
}
}
Stop:
if(pFile != NULL)
{
fclose(pFile);
}
return nRtn;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -