404 lines
9.2 KiB
C
404 lines
9.2 KiB
C
![]() |
#include "script.h"
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>ʵʱ<CAB5><CAB1><EFBFBD>ݿ<EFBFBD>
|
|||
|
int OpenRamRt()
|
|||
|
{
|
|||
|
#ifdef OS_WIN
|
|||
|
char chRamName[30] ;
|
|||
|
HANDLE hFile;
|
|||
|
HANDLE hMapFile = 0;
|
|||
|
LPVOID lpMapAddress = 0;
|
|||
|
strcpy( chRamName, "RAMRT" );
|
|||
|
|
|||
|
if ( lpMapAddress ) UnmapViewOfFile( lpMapAddress );
|
|||
|
if ( hMapFile ) CloseHandle( hMapFile );
|
|||
|
|
|||
|
hFile = (HANDLE) 0xFFFFFFFF ;
|
|||
|
|
|||
|
hMapFile = CreateFileMapping( hFile, NULL, PAGE_READWRITE, 0, STATION_SIZE , (LPCTSTR)chRamName );
|
|||
|
if ( hMapFile == NULL ){
|
|||
|
lpMapAddress = NULL;
|
|||
|
return 0;
|
|||
|
}
|
|||
|
lpMapAddress = MapViewOfFile( hMapFile,FILE_MAP_ALL_ACCESS,0,0,0 );
|
|||
|
pSysItem = ( double * )lpMapAddress ;
|
|||
|
pStation = ( StructStation * )( ( double * )lpMapAddress + MAX_SYSITEM ) ;
|
|||
|
return 1 ;
|
|||
|
#endif
|
|||
|
|
|||
|
#ifdef OS_UNIX
|
|||
|
int shmid ;
|
|||
|
void *shmptr ;
|
|||
|
|
|||
|
if((shmid = shmget( SHMDBKEYRTRAM_RT , STATION_SIZE , SHM_MODE ) ) < 0 ){
|
|||
|
return 0 ;
|
|||
|
}
|
|||
|
shmptr = shmat( shmid, 0, 0 ) ;
|
|||
|
|
|||
|
if ( shmptr == (void*) -1 ) {
|
|||
|
return 0 ;
|
|||
|
}
|
|||
|
|
|||
|
pSysItem = ( double * )shmptr ;
|
|||
|
pStation = ( StructStation * )( ( double * )shmptr + MAX_SYSITEM );
|
|||
|
return 1 ;
|
|||
|
#endif
|
|||
|
}
|
|||
|
|
|||
|
//gaowf 2016.7.25
|
|||
|
char CreateRam(int iStationNum, int nMaxIndex)
|
|||
|
{
|
|||
|
//qDebug( "createram %d", iStationNum );
|
|||
|
#ifdef OS_WIN
|
|||
|
char chRamName[30] ;
|
|||
|
if(iStationNum == 0)
|
|||
|
strcpy( chRamName, "RAMRT" );
|
|||
|
else
|
|||
|
sprintf(chRamName, "%s%d", "RAMRT", iStationNum);
|
|||
|
|
|||
|
if ( lpMapAddress ) UnmapViewOfFile( lpMapAddress );
|
|||
|
if ( hMapFile ) CloseHandle( hMapFile );
|
|||
|
|
|||
|
HANDLE hFile = (HANDLE) 0xFFFFFFFF ;
|
|||
|
|
|||
|
int iSize2 ;
|
|||
|
|
|||
|
nMaxDataNum = nMaxIndex+1;
|
|||
|
iSize2 = sizeof( StructStation) + MAX_SYSITEM * sizeof( double ) ;
|
|||
|
iSize2 += sizeof(StructData)*(nMaxIndex+1);
|
|||
|
|
|||
|
hMapFile = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, (LPCTSTR)chRamName);
|
|||
|
if(!hMapFile)
|
|||
|
hMapFile = CreateFileMapping( hFile, NULL, PAGE_READWRITE, 0, iSize2 , (LPCTSTR)chRamName );
|
|||
|
if ( hMapFile == NULL ){
|
|||
|
char chMsg[100];
|
|||
|
strcpy( chMsg, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ" );
|
|||
|
::MessageBox( NULL, (LPCTSTR)chMsg , NULL, MB_OK );
|
|||
|
lpMapAddress = NULL;
|
|||
|
return 0;
|
|||
|
}
|
|||
|
lpMapAddress = MapViewOfFile( hMapFile,FILE_MAP_ALL_ACCESS,0,0,0 );
|
|||
|
pSysItem = ( double * )lpMapAddress ;
|
|||
|
pStation = ( StructStation * )( ( double * )lpMapAddress + MAX_SYSITEM ) ;
|
|||
|
DataValue = (StructData *)(pStation + 1);
|
|||
|
#endif
|
|||
|
|
|||
|
#ifdef OS_UNIX
|
|||
|
int shmid ;
|
|||
|
void *shmptr ;
|
|||
|
|
|||
|
int iSize2=0;
|
|||
|
nMaxDataNum = nMaxIndex+1;
|
|||
|
iSize2 = sizeof( StructStation) + MAX_SYSITEM * sizeof( double ) ;
|
|||
|
iSize2 += sizeof(StructData)*(nMaxIndex+1);
|
|||
|
|
|||
|
if((shmid = shmget( SHMDBKEYRTRAM_RT , iSize2 , SHM_MODE ) ) < 0 ){
|
|||
|
printf("shmget error");
|
|||
|
return 0 ;
|
|||
|
}
|
|||
|
shmptr = shmat( shmid, 0, 0 ) ;
|
|||
|
//qDebug("shmat %d", shmptr );
|
|||
|
|
|||
|
if ( shmptr == (void*) -1 ) {
|
|||
|
//qDebug( "shmat error" );
|
|||
|
return 0 ;
|
|||
|
}
|
|||
|
//qDebug ( "shared memory attached" );
|
|||
|
pSysItem = ( double * )shmptr ;
|
|||
|
pStation = ( StructStation * )( ( double * )shmptr + MAX_SYSITEM );
|
|||
|
DataValue = (StructData *)(pStation + 1);
|
|||
|
|
|||
|
#endif
|
|||
|
pStation->iVersion = 1 ;
|
|||
|
return 1;
|
|||
|
}
|
|||
|
|
|||
|
//<2F><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
|||
|
void waitForMillisec(int millisec)
|
|||
|
{
|
|||
|
#ifdef OS_WIN
|
|||
|
Sleep(millisec);
|
|||
|
#endif
|
|||
|
|
|||
|
#ifdef OS_UNIX
|
|||
|
usleep(millisec*1000);
|
|||
|
#endif
|
|||
|
}
|
|||
|
|
|||
|
//<2F><>ȡʵʱ<CAB5><CAB1><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD>Ӧid<69><64><EFBFBD><EFBFBD>ֵ
|
|||
|
double GetItemValue( int iStationid , int id )
|
|||
|
{
|
|||
|
if( bEmbed ) iStationid = 0 ;
|
|||
|
StructStation * pStation1 ;
|
|||
|
pStation1 = pStation + iStationid;
|
|||
|
|
|||
|
if ( id >= nMaxDataNum )
|
|||
|
return 0;
|
|||
|
else
|
|||
|
return DataValue[ id ].dValue ;
|
|||
|
}
|
|||
|
|
|||
|
//<2F><>ȡʵʱ<CAB5><CAB1><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD>Ӧid<69><64><EFBFBD><EFBFBD><EFBFBD>ݽṹ<DDBD><E1B9B9><EFBFBD><EFBFBD>Ϣ
|
|||
|
StructData* GetItem(int iStationid,int id)
|
|||
|
{
|
|||
|
if( bEmbed ) iStationid = 0 ;
|
|||
|
StructStation * pStation1 ;
|
|||
|
pStation1 = pStation + iStationid;
|
|||
|
|
|||
|
if ( id >= nMaxDataNum )
|
|||
|
return 0;
|
|||
|
else
|
|||
|
return &DataValue[ id ] ;
|
|||
|
}
|
|||
|
|
|||
|
//<2F><>ȡʵʱ<CAB5><CAB1><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD>Ӧid<69><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
|||
|
char GetItemChangeState( int iStationid, int id )
|
|||
|
{
|
|||
|
if( bEmbed ) iStationid = 0 ;
|
|||
|
StructStation * pStation1 ;
|
|||
|
pStation1 = pStation + iStationid;
|
|||
|
|
|||
|
if ( id >= nMaxDataNum )
|
|||
|
return 0;
|
|||
|
else
|
|||
|
return DataValue[ id ].bChangeState ;
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>ʵʱ<CAB5><CAB1><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD>Ӧid<69><64><EFBFBD><EFBFBD>ֵ
|
|||
|
void SetItemValue( int iStationid , int id , double dValue )
|
|||
|
{
|
|||
|
if( bEmbed ) iStationid = 0 ;
|
|||
|
StructStation * pStation1 ;
|
|||
|
pStation1 = pStation + iStationid;
|
|||
|
|
|||
|
if ( id >= nMaxDataNum ) return ;
|
|||
|
|
|||
|
DataValue[id].dValue = dValue ;
|
|||
|
}
|
|||
|
|
|||
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|||
|
StructKcData *GetKcData( int iStationid )
|
|||
|
{
|
|||
|
if( bEmbed ) iStationid = 0 ;
|
|||
|
StructStation * pStation1 ;
|
|||
|
pStation1 = pStation + iStationid ;
|
|||
|
|
|||
|
return &pStation1->DataKC;
|
|||
|
}
|
|||
|
|
|||
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD>־<EFBFBD><D6BE>״̬
|
|||
|
int GetKcFlag( int iStationid )
|
|||
|
{
|
|||
|
if( bEmbed ) iStationid = 0 ;
|
|||
|
StructStation * pStation1 ;
|
|||
|
pStation1 = pStation + iStationid ;
|
|||
|
|
|||
|
return pStation1->DataKCFlag;
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>ʵʱ<CAB5><CAB1><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD>Ӧid<69><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
|||
|
void SetDataState(int iStationid, int id, char bAlarm , char bChangeState)
|
|||
|
{
|
|||
|
if( bEmbed ) iStationid = 0 ;
|
|||
|
StructStation * pStation1 ;
|
|||
|
pStation1 = pStation + iStationid;
|
|||
|
|
|||
|
if ( id >= nMaxDataNum ) return ;
|
|||
|
|
|||
|
DataValue[id].bAlarm = bAlarm ;
|
|||
|
DataValue[id].bChangeState = bChangeState ;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//<2F><><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
|
|||
|
void SetKcFlag(int iStationid, int flag)
|
|||
|
{
|
|||
|
if( bEmbed ) iStationid = 0 ;
|
|||
|
StructStation * pStation1 ;
|
|||
|
pStation1 = pStation + iStationid;
|
|||
|
|
|||
|
pStation1->DataKCFlag = flag;
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD>ÿ<EFBFBD><C3BF>ƴ<EFBFBD> noΪ<6F><CEAA><EFBFBD>ݵ<EFBFBD>id<69><64>data<74>·<EFBFBD><C2B7><EFBFBD>Ϣ
|
|||
|
void SetKcData(int iStationid, int no , char *data)
|
|||
|
{
|
|||
|
if( bEmbed ) iStationid = 0 ;
|
|||
|
StructStation * pStation1 ;
|
|||
|
pStation1 = pStation + iStationid;
|
|||
|
|
|||
|
pStation1->DataKC.kcNo = no;
|
|||
|
// pStation1->DataKC.dataKC = data;
|
|||
|
memset(&pStation1->DataKC.dataKC,0,sizeof(pStation1->DataKC.dataKC));
|
|||
|
memcpy(pStation1->DataKC.dataKC, data, strlen(data));
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
void SetKcClear(int iStationid,int flag)
|
|||
|
{
|
|||
|
if( bEmbed ) iStationid = 0 ;
|
|||
|
StructStation * pStation1 ;
|
|||
|
pStation1 = pStation + iStationid;
|
|||
|
|
|||
|
if(!flag){
|
|||
|
char data[200] = {0} ;
|
|||
|
pStation1->DataKCFlag = flag ;
|
|||
|
strcpy(pStation1->DataKC.dataKC,data);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD>ö<EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD>Žṹ<C5BD><E1B9B9><EFBFBD><EFBFBD>Ϣ
|
|||
|
void SetStruct(int iNum,char *chMsg)
|
|||
|
{
|
|||
|
int iStationid = 0 ;
|
|||
|
if( bEmbed ) iStationid = 0 ;
|
|||
|
StructStation * pStation1 ;
|
|||
|
pStation1 = pStation + iStationid;
|
|||
|
|
|||
|
strcpy(pStation1->chStruct[iNum],chMsg);
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD>ýṹ<C3BD><E1B9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
void SetStructNum(int iStructNum)
|
|||
|
{
|
|||
|
int iStationid = 0 ;
|
|||
|
if( bEmbed ) iStationid = 0 ;
|
|||
|
StructStation * pStation1 ;
|
|||
|
pStation1 = pStation + iStationid;
|
|||
|
|
|||
|
pStation1->StructNum = iStructNum;
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>Ϣ
|
|||
|
void SetStructUp(int iNum,char *chMsg)
|
|||
|
{
|
|||
|
int iStationid = 0 ;
|
|||
|
if( bEmbed ) iStationid = 0 ;
|
|||
|
StructStation * pStation1 ;
|
|||
|
pStation1 = pStation + iStationid;
|
|||
|
|
|||
|
strcpy(pStation1->chStructUp[iNum],chMsg);
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
void SetStructUpNum(int iStructNum)
|
|||
|
{
|
|||
|
int iStationid = 0 ;
|
|||
|
if( bEmbed ) iStationid = 0 ;
|
|||
|
StructStation * pStation1 ;
|
|||
|
pStation1 = pStation + iStationid;
|
|||
|
|
|||
|
pStation1->StructUpNum = iStructNum;
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD><C2B4>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>Ϣ
|
|||
|
void SetStructDown(int iNum, char *chMsg)
|
|||
|
{
|
|||
|
int iStationid = 0 ;
|
|||
|
if( bEmbed ) iStationid = 0 ;
|
|||
|
StructStation * pStation1 ;
|
|||
|
pStation1 = pStation + iStationid;
|
|||
|
|
|||
|
strcpy(pStation1->chStructDown[iNum],chMsg);
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD><C2B4>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
void SetStructDownNum(int iProg ,int iNum)
|
|||
|
{
|
|||
|
int iStationid = 0 ;
|
|||
|
if( bEmbed ) iStationid = 0 ;
|
|||
|
StructStation * pStation1 ;
|
|||
|
pStation1 = pStation + iStationid;
|
|||
|
|
|||
|
pStation1->StructDownProg = iProg;
|
|||
|
pStation1->StructDownNum = iNum;
|
|||
|
}
|
|||
|
|
|||
|
//<2F><>ȡ<EFBFBD><C8A1>ӦiNum<75>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>Ϣ
|
|||
|
char * GetStruct(int iNum)
|
|||
|
{
|
|||
|
int iStationid = 0 ;
|
|||
|
if( bEmbed ) iStationid = 0 ;
|
|||
|
StructStation * pStation1 ;
|
|||
|
pStation1 = pStation + iStationid;
|
|||
|
|
|||
|
return pStation1->chStruct[iNum];
|
|||
|
}
|
|||
|
|
|||
|
//<2F><>ȡ<EFBFBD>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
|
|||
|
int GetStructNum()
|
|||
|
{
|
|||
|
int iStationid = 0 ;
|
|||
|
if( bEmbed ) iStationid = 0 ;
|
|||
|
StructStation * pStation1 ;
|
|||
|
pStation1 = pStation + iStationid;
|
|||
|
|
|||
|
return pStation1->StructNum;
|
|||
|
}
|
|||
|
|
|||
|
//<2F><>ȡ<EFBFBD><C8A1>ӦiNum<75>ϴ<EFBFBD><CFB4>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>Ϣ
|
|||
|
char *GetStructUp(int iNum)
|
|||
|
{
|
|||
|
int iStationid = 0 ;
|
|||
|
if( bEmbed ) iStationid = 0 ;
|
|||
|
StructStation * pStation1 ;
|
|||
|
pStation1 = pStation + iStationid;
|
|||
|
|
|||
|
return pStation1->chStructUp[iNum];
|
|||
|
}
|
|||
|
|
|||
|
//<2F><>ȡ<EFBFBD>ϴ<EFBFBD><CFB4>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
|
|||
|
int GetStructUpNum()
|
|||
|
{
|
|||
|
int iStationid = 0 ;
|
|||
|
if( bEmbed ) iStationid = 0 ;
|
|||
|
StructStation * pStation1 ;
|
|||
|
pStation1 = pStation + iStationid;
|
|||
|
|
|||
|
return pStation1->StructUpNum;
|
|||
|
}
|
|||
|
|
|||
|
//<2F><>ȡ<EFBFBD><C8A1>ӦiNum<75>´<EFBFBD><C2B4>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>Ϣ
|
|||
|
char *GetStructDown(int iNum)
|
|||
|
{
|
|||
|
int iStationid = 0 ;
|
|||
|
if( bEmbed ) iStationid = 0 ;
|
|||
|
StructStation * pStation1 ;
|
|||
|
pStation1 = pStation + iStationid;
|
|||
|
|
|||
|
return pStation1->chStructDown[iNum];
|
|||
|
}
|
|||
|
|
|||
|
//<2F><>ȡ<EFBFBD>´<EFBFBD><C2B4>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
|
|||
|
int GetStructDownNum()
|
|||
|
{
|
|||
|
int iStationid = 0 ;
|
|||
|
if( bEmbed ) iStationid = 0 ;
|
|||
|
StructStation * pStation1 ;
|
|||
|
pStation1 = pStation + iStationid;
|
|||
|
|
|||
|
return pStation1->StructDownNum;
|
|||
|
}
|
|||
|
|
|||
|
int GetStructDownProgId()
|
|||
|
{
|
|||
|
int iStationid = 0 ;
|
|||
|
if( bEmbed ) iStationid = 0 ;
|
|||
|
StructStation * pStation1 ;
|
|||
|
pStation1 = pStation + iStationid;
|
|||
|
|
|||
|
return pStation1->StructDownProg;
|
|||
|
}
|
|||
|
|
|||
|
//<2F><>ȡϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|||
|
double GetSysItem(int id)
|
|||
|
{
|
|||
|
return *( pSysItem + id ) ;
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|||
|
void SetSysItem( int id , double dValue)
|
|||
|
{
|
|||
|
*( pSysItem + id ) = dValue ;
|
|||
|
}
|