📄 snmphelper.cpp
字号:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/sem.h>
#include <string.h>
#include "common.h"
#include "MibStructure.h"
#include "shmop.h"
#include "DVBMibShare.h"
#include "transfer.h"
#include "XString.h"
#include "tinyxml.h"
#include "configfile.h"
#include "DM642Helper.h"
#include "snmpSendTrap.h"
BOOL gCut = 0;
STATUS snmpWriteBladeInfo()
{
//for share memory of BladeInfo
key_t keyShmBladeInfo;
int shmBladeInfo_id;
UINT8* shmBladeInfo;
struct bladeInfo* pBladeInfo;
UINT32 index;
//init share memory of BladeInfo
keyShmBladeInfo = ftok(FTOKPATH_BLADE,1);
shmBladeInfo_id = shmget(keyShmBladeInfo,SEGBLADESIZE,0);
if(-1 == shmBladeInfo_id){
DebugPrint(g_DbgLevel,g_fpLogFile," create shared memory of BladeInfo error\n");
return STATUS_ERROR;
}
shmBladeInfo= (UINT8 *)shmat(shmBladeInfo_id,0,0);
if (-1 == (int)shmBladeInfo){
DebugPrint(g_DbgLevel,g_fpLogFile," attach shared memory error\n");
return STATUS_ERROR;
}
pBladeInfo=(struct bladeInfo*)shmBladeInfo;
/*
typedef struct
{
//For Index;
UINT32 BladeNo;
char BladeIPv4[20];//R/W
char BladeIPv6[46];//R/W
char BladeGateway[20];//R/W
enum_BladeStatus BladeStatus;//R/W
enum_MCUStatus MCUStatus;//R/W
UINT32 BackBladeNo;//R/W
char BackBladeIPv4[20];//R/W
char BackBladeIPv6[46];//R/W
char BackBladeGateway[20];//R/W
enum_BladeStatus BackBladeStatus;//R/W
enum_MCUStatus BackMCUStatus;//R/W
}struct_BladeInfo;
*/
//change to
pBladeInfo->dvbMasterBladeNumber=g_BladeInfo.BladeNo;
strcpy(pBladeInfo->dvbMasterBladeIPv4,g_BladeInfo.BladeIPv4);
strcpy(pBladeInfo->dvbMasterBladeIPv6,g_BladeInfo.BladeIPv6);
strcpy(pBladeInfo->dvbMasterBladeGateway,g_BladeInfo.BladeGateway);
printf("g_BladeInfo.BladeStatus=%d\n",g_BladeInfo.BladeStatus);
pBladeInfo->dvbMasterBladeStatus=(long)g_BladeInfo.BladeStatus;
pBladeInfo->dvbMasterMCUStatus=(long)g_BladeInfo.MCUStatus;
pBladeInfo->dvbSlaveBladeNumber=g_BladeInfo.BackBladeNo;
strcpy(pBladeInfo->dvbSlaveBladeIPv4,g_BladeInfo.BackBladeIPv4);
strcpy(pBladeInfo->dvbSlaveBladeIPv6,g_BladeInfo.BackBladeIPv6);
strcpy(pBladeInfo->dvbSlaveBladeGateway,g_BladeInfo.BackBladeGateway);
pBladeInfo->dvbSlaveBladeStatus=(long)g_BladeInfo.BackBladeStatus;
pBladeInfo->dvbSlaveMCUStatus=(long)g_BladeInfo.BackMCUStatus;
shmdt(shmBladeInfo);
return STATUS_OK;
}
STATUS snmpWriteSITableAll()
{
//for share memory of SITable
key_t keyShmSITable;
int shmSITable_id;
UINT8* shmSITable;
struct dvbSITable_entry* pSITable;
UINT32 index;
//init share memory of SITable
keyShmSITable = ftok(FTOKPATH_SI,1);
shmSITable_id = shmget(keyShmSITable,SEGSISIZE,0);
if(-1 == shmSITable_id){
DebugPrint(g_DbgLevel,g_fpLogFile," create shared memory of SITable error\n");
return STATUS_ERROR;
}
shmSITable= (UINT8 *)shmat(shmSITable_id,0,0);
if (-1 == (int)shmSITable){
DebugPrint(g_DbgLevel,g_fpLogFile," attach shared memory error\n");
return STATUS_ERROR;
}
for(index=0;index<MAXSUBBOARD*MAXVIDEOPORT*MAXPROGRAM;index++)
{
pSITable=((struct dvbSITable_entry*)shmSITable)+index;
/*
typedef struct
{
//For Index;
UINT32 BladeNo;
UINT32 SubboardNo;
UINT32 VideoPortNo;
UINT32 ProgramNo; //0-9
//from DM642 PSI
UINT32 ServiceRate;//single program rate
UINT32 VideoPID; // Video PID in original PMT
UINT32 AudioPID; // Audio PID in original PMT
//from DM642 SDT
UINT32 HasSDT;
char ServiceName[128];
char ServiceProviderName[128];
enum_Encrypted Encrypted;
enum_ServiceFormat InputFormat;
enum_ChannelType ChannelType;
UINT32 ServiceID;
UINT32 TransportStreamID;
UINT32 OriginalNetworkID;
}struct_SITable;
*/
//change to
pSITable->dvbBladeNo=g_SITable[index].BladeNo;
pSITable->dvbSubboardNo=g_SITable[index].SubboardNo;
pSITable->dvbVideoPortNo=g_SITable[index].VideoPortNo;
pSITable->dvbProgramNo=g_SITable[index].ProgramNo;
pSITable->dvbSIServiceRate=g_SITable[index].ServiceRate;
pSITable->dvbSIVideoPID=g_SITable[index].VideoPID;
pSITable->dvbSIAudioPID=g_SITable[index].AudioPID;
pSITable->dvbSIHasSDT=g_SITable[index].HasSDT;
strcpy(pSITable->dvbSIServiceName,g_SITable[index].ServiceName);
strcpy(pSITable->dvbSIServiceProviderName,g_SITable[index].ServiceProviderName);
pSITable->dvbSIEncrypted=(long)g_SITable[index].Encrypted;
pSITable->dvbSIInputFormat=(long)g_SITable[index].InputFormat;
pSITable->dvbSIChannelType=(long)g_SITable[index].ChannelType;
pSITable->dvbSIServiceID=g_SITable[index].ServiceID;
pSITable->dvbSITransportStreamID=g_SITable[index].TransportStreamID;
pSITable->dvbSIOriginalNetworkID=g_SITable[index].OriginalNetworkID;
}
printf("in the snmpWriteSITableAll()\n");
shmdt(shmSITable);
return STATUS_OK;
}
STATUS snmpWriteSITable(int index)
{
//for share memory of SITable
key_t keyShmSITable;
int shmSITable_id;
UINT8* shmSITable;
struct dvbSITable_entry* pSITable;
//init share memory of SITable
keyShmSITable = ftok(FTOKPATH_SI,1);
shmSITable_id = shmget(keyShmSITable,SEGSISIZE,0);
if(-1 == shmSITable_id){
DebugPrint(g_DbgLevel,g_fpLogFile," create shared memory of SITable error\n");
return STATUS_ERROR;
}
shmSITable= (UINT8 *)shmat(shmSITable_id,0,0);
if (-1 == (int)shmSITable){
DebugPrint(g_DbgLevel,g_fpLogFile," attach shared memory error\n");
return STATUS_ERROR;
}
pSITable=((struct dvbSITable_entry*)shmSITable)+index;
/*
typedef struct
{
//For Index;
UINT32 BladeNo;
UINT32 SubboardNo;
UINT32 VideoPortNo;
UINT32 ProgramNo; //0-9
//from DM642 PSI
UINT32 ServiceRate;//single program rate
UINT32 VideoPID; // Video PID in original PMT
UINT32 AudioPID; // Audio PID in original PMT
//from DM642 SDT
UINT32 HasSDT;
char ServiceName[128];
char ServiceProviderName[128];
enum_Encrypted Encrypted;
enum_ServiceFormat InputFormat;
enum_ChannelType ChannelType;
UINT32 ServiceID;
UINT32 TransportStreamID;
UINT32 OriginalNetworkID;
}struct_SITable;
*/
//change to
pSITable->dvbBladeNo=g_SITable[index].BladeNo;
pSITable->dvbSubboardNo=g_SITable[index].SubboardNo;
pSITable->dvbVideoPortNo=g_SITable[index].VideoPortNo;
pSITable->dvbProgramNo=g_SITable[index].ProgramNo;
pSITable->dvbSIServiceRate=g_SITable[index].ServiceRate;
pSITable->dvbSIVideoPID=g_SITable[index].VideoPID;
pSITable->dvbSIAudioPID=g_SITable[index].AudioPID;
pSITable->dvbSIHasSDT=g_SITable[index].HasSDT;
strcpy(pSITable->dvbSIServiceName,g_SITable[index].ServiceName);
strcpy(pSITable->dvbSIServiceProviderName,g_SITable[index].ServiceProviderName);
pSITable->dvbSIEncrypted=(long)g_SITable[index].Encrypted;
pSITable->dvbSIInputFormat=(long)g_SITable[index].InputFormat;
pSITable->dvbSIChannelType=(long)g_SITable[index].ChannelType;
pSITable->dvbSIServiceID=g_SITable[index].ServiceID;
pSITable->dvbSITransportStreamID=g_SITable[index].TransportStreamID;
pSITable->dvbSIOriginalNetworkID=g_SITable[index].OriginalNetworkID;
shmdt(shmSITable);
return STATUS_OK;
}
STATUS snmpWriteVideoPortTableAll()
{
//for share memory of VideoPortTable
key_t keyShmVideoPortTable;
int shmVideoPortTable_id;
UINT8* shmVideoPortTable;
struct dvbVideoPortInfoTable_entry* pVideoPortTable;
UINT32 index;
//init share memory of VideoPortTable
keyShmVideoPortTable = ftok(FTOKPATH_VIDEOPORT,1);
shmVideoPortTable_id = shmget(keyShmVideoPortTable,SEGVIDEOSIZE,0);
if(-1 == shmVideoPortTable_id){
DebugPrint(g_DbgLevel,g_fpLogFile," create shared memory of VideoPortTable error\n");
return STATUS_ERROR;
}
shmVideoPortTable= (UINT8 *)shmat(shmVideoPortTable_id,0,0);
if (-1 == (int)shmVideoPortTable){
DebugPrint(g_DbgLevel,g_fpLogFile," attach shared memory error\n");
return STATUS_ERROR;
}
for(index=0;index<MAXSUBBOARD*MAXVIDEOPORT*MAXPROGRAM;index++)
{
pVideoPortTable=((struct dvbVideoPortInfoTable_entry*)shmVideoPortTable)+index;
/*
typedef struct
{
//For Index;
UINT32 BladeNo;
UINT32 SubboardNo;
UINT32 VideoPortNo;
enum_VideoPortStatus VideoPortStatus;
enum_WorkSetting VideoPortWorkSetting;//RW
UINT32 VideoPortProgramNumber;
}struct_VideoPortInfo;
*/
//change to
pVideoPortTable->dvbBladeNo=g_VideoPortInfo[index].BladeNo;
pVideoPortTable->dvbSubboardNo=g_VideoPortInfo[index].SubboardNo;
pVideoPortTable->dvbVideoPortNo=g_VideoPortInfo[index].VideoPortNo;
pVideoPortTable->dvbVideoPortStatus=(long)g_VideoPortInfo[index].VideoPortStatus;
pVideoPortTable->dvbVideoPortWorkSetting=(long)g_VideoPortInfo[index].VideoPortWorkSetting;
pVideoPortTable->dvbVideoPortProgramNumber=g_VideoPortInfo[index].VideoPortProgramNumber;
}
printf("in the snmpWriteVideoTableAll()\n");
shmdt(shmVideoPortTable);
return STATUS_OK;
}
STATUS snmpWriteVideoPortTable(int index)
{
//for share memory of VideoPortTable
key_t keyShmVideoPortTable;
int shmVideoPortTable_id;
UINT8* shmVideoPortTable;
struct dvbVideoPortInfoTable_entry* pVideoPortTable;
//init share memory of VideoPortTable
keyShmVideoPortTable = ftok(FTOKPATH_VIDEOPORT,1);
shmVideoPortTable_id = shmget(keyShmVideoPortTable,SEGVIDEOSIZE,0);
if(-1 == shmVideoPortTable_id){
DebugPrint(g_DbgLevel,g_fpLogFile," create shared memory of VideoPortTable error\n");
return STATUS_ERROR;
}
shmVideoPortTable= (UINT8 *)shmat(shmVideoPortTable_id,0,0);
if (-1 == (int)shmVideoPortTable){
DebugPrint(g_DbgLevel,g_fpLogFile," attach shared memory error\n");
return STATUS_ERROR;
}
pVideoPortTable=((struct dvbVideoPortInfoTable_entry*)shmVideoPortTable)+index;
/*
typedef struct
{
//For Index;
UINT32 BladeNo;
UINT32 SubboardNo;
UINT32 VideoPortNo;
enum_VideoPortStatus VideoPortStatus;
enum_WorkSetting VideoPortWorkSetting;//RW
UINT32 VideoPortProgramNumber;
}struct_VideoPortInfo;
*/
//change to
pVideoPortTable->dvbBladeNo=g_VideoPortInfo[index].BladeNo;
pVideoPortTable->dvbSubboardNo=g_VideoPortInfo[index].SubboardNo;
pVideoPortTable->dvbVideoPortNo=g_VideoPortInfo[index].VideoPortNo;
pVideoPortTable->dvbVideoPortStatus=(long)g_VideoPortInfo[index].VideoPortStatus;
pVideoPortTable->dvbVideoPortWorkSetting=(long)g_VideoPortInfo[index].VideoPortWorkSetting;
pVideoPortTable->dvbVideoPortProgramNumber=g_VideoPortInfo[index].VideoPortProgramNumber;
shmdt(shmVideoPortTable);
return STATUS_OK;
}
STATUS snmpWriteConfTableAll()
{
//for share memory of ConfTable
key_t keyShmConfTable;
int shmConfTable_id;
UINT8* shmConfTable;
struct dvbConfigTable_entry* pConfTable;
UINT32 index;
//init share memory of ConfTable
keyShmConfTable = ftok(FTOKPATH_CONFIG,1);
shmConfTable_id = shmget(keyShmConfTable,SEGCONFSIZE,0);
if(-1 == shmConfTable_id){
DebugPrint(g_DbgLevel,g_fpLogFile," create shared memory of config table error\n");
return STATUS_ERROR;
}
shmConfTable= (UINT8 *)shmat(shmConfTable_id,0,0);
if (-1 == (int)shmConfTable){
DebugPrint(g_DbgLevel,g_fpLogFile," attach shared memory error\n");
return STATUS_ERROR;
}
for(index=0;index<MAXSUBBOARD*MAXVIDEOPORT*MAXPROGRAM;index++)
{
pConfTable=((struct dvbConfigTable_entry*)shmConfTable)+index;
/*
typedef struct
{
//For Index;
UINT32 BladeNo;
UINT32 SubboardNo;
UINT32 VideoPortNo;
UINT32 ProgramNo;
UINT32 IsSet;
enum_ServiceFormat OutputFormat;//RW
UINT32 OutputRate;//RW
char DestAddr[30];//RW
char DestPort[5];//RW
enum_Protocol Protocol;
UINT32 PoolPort;//RW
}struct_ConfTable;
*/
//change to
pConfTable->dvbBladeNo=g_ConfTable[index].BladeNo;
pConfTable->dvbSubboardNo=g_ConfTable[index].SubboardNo;
pConfTable->dvbVideoPortNo=g_ConfTable[index].VideoPortNo;
pConfTable->dvbProgramNo=g_ConfTable[index].ProgramNo;
pConfTable->dvbConfIsSet=g_ConfTable[index].IsSet;
pConfTable->dvbConfOutputFormat=(long)g_ConfTable[index].OutputFormat;
pConfTable->dvbConfOutputRate=g_ConfTable[index].OutputRate;
strcpy(pConfTable->dvbConfDestAddr,g_ConfTable[index].DestAddr);
pConfTable->dvbConfDestPort=atoi(g_ConfTable[index].DestPort);
pConfTable->dvbConfProtocol=(long)g_ConfTable[index].Protocol;
pConfTable->dvbConfPoolPort=g_ConfTable[index].PoolPort;
}
printf("in the snmpWriteConfTableAll()\n");
shmdt(shmConfTable);
return STATUS_OK;
}
STATUS snmpWriteConfTable(int index)
{
//for share memory of ConfTable
key_t keyShmConfTable;
int shmConfTable_id;
UINT8* shmConfTable;
struct dvbConfigTable_entry* pConfTable;
//init share memory of ConfTable
keyShmConfTable = ftok(FTOKPATH_CONFIG,1);
shmConfTable_id = shmget(keyShmConfTable,SEGCONFSIZE,0);
if(-1 == shmConfTable_id){
DebugPrint(g_DbgLevel,g_fpLogFile," create shared memory of config table error\n");
return STATUS_ERROR;
}
shmConfTable= (UINT8 *)shmat(shmConfTable_id,0,0);
if (-1 == (int)shmConfTable){
DebugPrint(g_DbgLevel,g_fpLogFile," attach shared memory error\n");
return STATUS_ERROR;
}
pConfTable=((struct dvbConfigTable_entry*)shmConfTable)+index;
/*
typedef struct
{
//For Index;
UINT32 BladeNo;
UINT32 SubboardNo;
UINT32 VideoPortNo;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -