Эх сурвалжийг харах

New Chassis Manage Function

zhangbo 5 жил өмнө
parent
commit
fe040c63c6

+ 3 - 0
app/bmc/Api.c

@@ -95,6 +95,9 @@ int PlatformInit(void)
 
 	g_BMCInfo.ChassisIdentify		=	FALSE;
 	g_BMCInfo.PowerGoodFlag =  	1;
+	g_BMCInfo.BladeManageEn = 0;
+	g_BMCInfo.isChMC 		= 0;
+	g_BMCInfo.IndexInChassis = 1;
 	
 	//init DevGUID
 	g_BMCInfo.DeviceGUID[0]	=	0x01;

+ 5 - 0
app/bmc/BmcType.h

@@ -130,6 +130,11 @@ typedef struct
 	uint8_t				FwMajorVer;
 	uint8_t				FwMinorVer;
 
+	//global_flags
+	uint8_t 			BladeManageEn;
+	uint8_t 			isChMC;
+	uint8_t 			IndexInChassis;	//刀片插在机箱里的第几个槽,index从0开始。
+
 } BMCInfo_t;
 
 

+ 1 - 1
app/bmc/ChassisTimer/ChassisTimerTask.c

@@ -124,7 +124,7 @@ void *ChassisTimerTask(void* pArg)
 		}
 		
 		//Chassis Identify
-		if(g_BMCInfo.ChassisIdentify == TRUE)
+		if(g_BMCInfo.ChassisIdentify == TRUE)		//新开个线程实现,默认灯闪烁10s,参考IPMI协议
 		{
 			if(IdentifyTickCnt == 5)	//0.5s
 			{

BIN
app/bmc/bmc_app


+ 8 - 1
app/bmc/main.c

@@ -46,7 +46,14 @@ FanInfo_T	gFanInfo[FAN_NUMBERS] = {
 									{2, {"Fan3"}, 0, 0, 0 },
 									{3, {"Fan4"}, 0, 0, 0 },
 								};
-
+BladeStatus_T gBladeStatus[BLADE_NUMBERS] = {
+								/*  healthStatus | name | slotID | pwrStatus */
+									{ 0, "---", 0, 0},
+									{ 1, "IPMC1", 2, 1},
+									{ 0, "---", 0, 0},
+									{ 0, "---", 0, 0},
+									{ 0, "---", 0, 0},
+								};
 //void *test_thread(void *var);
 //uint8_t test_flag = 0;
 //pthread_mutex_t mutex;

+ 3 - 2
app/bmc/main.h

@@ -104,8 +104,9 @@ extern PendingSeqNoTbl_T		m_PendingSeqNoTbl[16][MAX_PENDING_SEQ_NO];
 extern KCSBridgeResInfo_T       m_KCSBridgeResInfo;
 extern TimerTaskTbl_T    		m_TimerTaskTbl [20];
 
-extern BMCInfo_t 	g_BMCInfo;
+extern BMCInfo_t 			g_BMCInfo;
 extern SensorHistoryInfo_T 	gSensorHistoryInfo[SENSOR_NUMBERS];
-extern FanInfo_T				gFanInfo[FAN_NUMBERS];
+extern FanInfo_T			gFanInfo[FAN_NUMBERS];
+extern BladeStatus_T 		gBladeStatus[BLADE_NUMBERS];
 
 #endif /* __MAIN_H__ */

+ 5 - 2
app/bmc/msghndlr/PDKCmds.c

@@ -343,8 +343,11 @@ const CmdHndlrMap_T g_Storlead_CmdHndlr [] =
     { CMD_AUTHOR_VERIFY,        PRIV_USER,      Storlead_AuthorVerify,     0xff,  0xAAAA  ,0xFFFF},
     { CMD_GET_SENSOR_HISTORY,   PRIV_USER,      Storlead_GetSensorHistory,     0xff,  0xAAAA  ,0xFFFF},
     { CMD_GET_FAN_INFO,         PRIV_USER,      Storlead_GetFanInfo,         0xff,  0xAAAA  ,0xFFFF},
-    { CMD_SET_FAN_INFO,         PRIV_USER,      Storlead_SetFanInfo,         0xff,  0xAAAA  ,0xFFFF},
-    { 0x00,                     0x00,           0x00,                 0x00, 0x0000  ,  0x0000},
+    { CMD_GET_BLADE_INFO,        PRIV_USER,      Storlead_getAllBladeStatus,         0xff,  0xAAAA  ,0xFFFF},
+    { CMD_SET_MANAGE_FN,         PRIV_USER,      Storlead_SetBladeManageFn,         0xff,  0xAAAA  ,0xFFFF},     { CMD_SET_FAN_INFO,         PRIV_USER,      Storlead_SetFanInfo,         0xff,  0xAAAA  ,0xFFFF},
+    { CMD_GET_MANAGE_FN,         PRIV_USER,      Storlead_GetBladeManageFn,         0xff,  0xAAAA  ,0xFFFF},
+    { CMD_GET_CHASSIS_INFO,      PRIV_USER,      Storlead_GetChassisInfo,         0xff,  0xAAAA  ,0xFFFF},
+     { 0x00,                     0x00,           0x00,                 0x00, 0x0000  ,  0x0000},
 };
 
 

+ 48 - 1
app/bmc/msghndlr/Storlead/Storlead.c

@@ -433,4 +433,51 @@ int Storlead_SetFanInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
     }
 
     return 1;
-}
+}
+
+int Storlead_getAllBladeStatus(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
+{
+    pRes[0] = CC_NORMAL;
+    memcpy(pRes+1, gBladeStatus, (BLADE_NUMBERS*sizeof(BladeStatus_T)));
+    return 1+(BLADE_NUMBERS*sizeof(BladeStatus_T));
+}
+
+int Storlead_SetBladeManageFn(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
+{
+    if(pReq[0] > 1)
+    {
+        printf("Invalid param %d\n", pReq[0]);
+        pRes[0] = CC_PARAM_OUT_OF_RANGE;
+        return 1;
+    }
+    
+    g_BMCInfo.BladeManageEn = pReq[0];
+    pRes[0] = CC_NORMAL;
+    return 1;
+}
+
+int Storlead_GetBladeManageFn(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
+{
+    
+    pRes[0] = CC_NORMAL;
+    pRes[1] = g_BMCInfo.BladeManageEn;
+    return 2;
+}
+
+int Storlead_GetChassisInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
+{
+    /*
+    typedef struct{
+    uint8_t slotNum; //total slot numbers of chassis.
+    uint8_t supportChassisManageFn;
+    uint8_t chassisManageFnEnable;
+    uint8_t curIndex;
+} OemChassisInfo_T;
+*/
+    pRes[0] = CC_NORMAL;
+    pRes[1] = BLADE_NUMBERS;
+    pRes[2] = g_BMCInfo.isChMC;
+    pRes[3] = g_BMCInfo.BladeManageEn;
+    pRes[4] = g_BMCInfo.IndexInChassis;
+    return 5;
+}

+ 5 - 1
app/bmc/msghndlr/Storlead/Storlead.h

@@ -9,4 +9,8 @@ int  Storlead_GetSELEntires(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes);
 int Storlead_AuthorVerify(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes);
 int Storlead_GetSensorHistory(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes);
 int Storlead_GetFanInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes);
-int Storlead_SetFanInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes);
+int Storlead_SetFanInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes);
+int Storlead_getAllBladeStatus(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes);
+int Storlead_SetBladeManageFn(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes);
+int Storlead_GetBladeManageFn(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes);
+int Storlead_GetChassisInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes);

+ 4 - 0
app/bmc/msghndlr/cmdselect.c

@@ -804,6 +804,10 @@ const NetFnCmds_T g_Storlead [] =
 	{ CMD_GET_SENSOR_HISTORY          ,ENABLED},	
 	{ CMD_GET_FAN_INFO          ,ENABLED},	
 	{ CMD_SET_FAN_INFO          ,ENABLED},	
+	{ CMD_GET_BLADE_INFO          ,ENABLED},	
+	{ CMD_SET_MANAGE_FN          ,ENABLED},	
+	{ CMD_GET_MANAGE_FN          ,ENABLED},	
+	{ CMD_GET_CHASSIS_INFO          ,ENABLED},	
 	{0,				0		},
 };
 

+ 1 - 1
app/common_include/com_BMCCfg.h

@@ -2,7 +2,7 @@
 #define __COM_BMC_CFG_H__
 
 #define 	FAN_NUMBERS		4
-
+#define 	BLADE_NUMBERS	5
 
 
 

+ 6 - 1
app/common_include/com_BmcType.h

@@ -322,7 +322,12 @@ typedef struct{
     uint32_t speed;   //RPM 
 } FanInfo_T;
 
-
+typedef struct{
+    uint8_t healthStatus;
+    uint8_t bladeName[12];
+    uint8_t slotID;
+    uint8_t pwrStatus;
+} BladeStatus_T;
 
 #pragma pack()
 #endif /* __BMC_TYPE_H__ */

+ 5 - 0
app/common_include/com_IPMI_Storlead.h

@@ -8,5 +8,10 @@
 #define CMD_GET_SENSOR_HISTORY  0x4
 #define CMD_GET_FAN_INFO		0x5
 #define CMD_SET_FAN_INFO		0x6
+#define CMD_GET_BLADE_INFO		0x7
+#define CMD_SET_MANAGE_FN		0x8
+#define CMD_GET_MANAGE_FN		0x9
+#define CMD_GET_CHASSIS_INFO	0xA
+
 
 #endif /* __COM_IPMI_STORLEAD_H__ */

+ 6 - 0
app/goahead-3.6.5/src/goahead.c

@@ -181,6 +181,12 @@ websDefineAction("getDeviceInfo", getDeviceInfo);
 websDefineAction("getSysInfo", getSysInfo);
 websDefineAction("getCardInfo", getCardInfo);
 websDefineAction("getSensorInfo", getSensorInfo);
+websDefineAction("getChassisInfo", getChassisInfo);
+websDefineAction("getBladeManage", getBladeManage);
+websDefineAction("setBladeManage", setBladeManage);
+websDefineAction("getAllBladeInfo", getAllBladeInfo);
+
+
 //remote control
 websDefineAction("chassisPwrCtrl", chassisPwrCtrl);
 websDefineAction("getChassisStatus", getChassisStatus);

+ 6 - 11
app/goahead-3.6.5/src/libipmi/inc/libipmi_storlead_OEM.h

@@ -43,15 +43,10 @@ typedef struct{
 	uint8_t slotNum; //total slot numbers of chassis.
 	uint8_t supportChassisManageFn;
 	uint8_t chassisManageFnEnable;
-	uint8_t chMCIndex;
+	uint8_t curIndex;
 } OemChassisInfo_T;
 
-typedef struct{
-	uint8_t status;
-	uint8_t bladeName[12];
-	uint8_t slotID;
-	uint8_t bladePowerStatus;
-} OemBladeStatus_T;
+
 
 typedef struct{
 	uint8_t supportEventLogs;
@@ -65,7 +60,7 @@ typedef struct{
 
 typedef struct{
 	uint8_t IPMBAddr;
-	OemBladeStatus_T bladeStatus;
+	BladeStatus_T bladeStatus;
 } OemBladeInfo_T;
 
 typedef struct{
@@ -101,10 +96,10 @@ uint16_t LIBIPMI_HL_GetSysInfo( IPMI20_UDS_SESSION_T *pUDSSession, SysInfo_T *pS
 uint16_t LIBIPMI_HL_GetSensorHistory( IPMI20_UDS_SESSION_T *pUDSSession, sensor_history_st *pSensorHistory_st, int card_index, int sensor_number, int IPMB_ADDR);
 //uint16_t LIBIPMI_HL_GetAllCards(IPMI20_UDS_SESSION_T *pUDSSession, CardStatus_T*	pResBladeSts, int timeout);
 //int	 LIBIPMI_HL_GetChassisInfo(IPMI20_UDS_SESSION_T *pUDSSession, OemChassisInfo_T* pBladeInfo, int timeout);
-//int 	 LIBIPMI_HL_GetBladeStatus(IPMI20_UDS_SESSION_T *pUDSSession, OemBladeStatus_T* pBladeStatus, int timeout);
+int 	 LIBIPMI_HL_GetBladeStatus(IPMI20_UDS_SESSION_T *pUDSSession, BladeStatus_T* pBladeStatus, int timeout);
 //int LIBIPMI_HL_GetIPMCCapability(IPMI20_UDS_SESSION_T *pUDSSession, uint8_t bladeIndex, OemIPMCCapability_T* pIPMCCapability, int timeout);
-//int LIBIPMI_HL_SetBladeManageFn(IPMI20_UDS_SESSION_T *pUDSSession, uint8_t enable, int timeout);
-//int LIBIPMI_HL_GetManageWebName(IPMI20_UDS_SESSION_T *pUDSSession, char* webName, int timeout);
+int LIBIPMI_HL_SetBladeManageFn(IPMI20_UDS_SESSION_T *pUDSSession, uint8_t enable, int timeout);
+int LIBIPMI_HL_GetBladeManageFn(IPMI20_UDS_SESSION_T *pUDSSession, uint8_t *enable, int timeout);
 int LIBIPMI_HL_GetFanInfo(IPMI20_UDS_SESSION_T *pUDSSession, FanInfo_T* pFanInfo, int timeout);
 //int LIBIPMI_HL_GetSensorHistoryCapability(IPMI20_UDS_SESSION_T *pUDSSession, uint8_t sensorNum, SensorHistoryCapability_T* pSensorHistoryCapability, int timeout);
 //int LIBIPMI_HL_GetSensorHistoryEn(IPMI20_UDS_SESSION_T *pUDSSession, uint8_t* SensorHistoryEnable, int timeout);

+ 70 - 103
app/goahead-3.6.5/src/libipmi/src/libipmi_storlead_OEM.c

@@ -404,42 +404,42 @@ LIBIPMI_HL_GetSensorHistory( IPMI20_UDS_SESSION_T *pUDSSession, sensor_history_s
 // }
 
 // /************************************************* new add **********************************************************************/
-// int LIBIPMI_HL_GetChassisInfo(IPMI20_UDS_SESSION_T *pUDSSession, OemChassisInfo_T* pChassisInfo, int timeout)
-// {
-// 	uint8_t pRes[10];
-// 	int wRet = 0;
-// 	uint32_t	dwResLen;
-// 	wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,  
-// 							0x2e<<2, 0x80,
-// 							NULL, 0,
-// 							(uint8_t*)pRes,  &dwResLen,
-// 							timeout);
-// 	if( wRet != 0 )
-// 		printf("Error getting Blade Status Info\n");
+int LIBIPMI_HL_GetChassisInfo(IPMI20_UDS_SESSION_T *pUDSSession, OemChassisInfo_T* pChassisInfo, int timeout)
+{
+	uint8_t pRes[10];
+	int wRet = 0;
+	uint32_t	dwResLen;
+	wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,  
+							NETFNLUN_IPMI_STORLEAD, CMD_GET_CHASSIS_INFO,
+							NULL, 0,
+							(uint8_t*)pRes,  &dwResLen,
+							timeout);
+	if( wRet != 0 )
+		printf("Error getting Blade Status Info\n");
 		
-// 	pChassisInfo->slotNum = pRes[1];
-// 	pChassisInfo->supportChassisManageFn = pRes[2];
-// 	pChassisInfo->chassisManageFnEnable = pRes[3];
-// 	pChassisInfo->chMCIndex = pRes[4];
-// 	return 0;
-// }
+	pChassisInfo->slotNum = pRes[1];
+	pChassisInfo->supportChassisManageFn = pRes[2];
+	pChassisInfo->chassisManageFnEnable = pRes[3];
+	pChassisInfo->curIndex = pRes[4];
+	return 0;
+}
 
-// int LIBIPMI_HL_GetBladeStatus(IPMI20_UDS_SESSION_T *pUDSSession, OemBladeStatus_T BladeStatus[], int timeout)
-// {
-// 	int wRet = 0;
-// 	uint32_t	dwResLen;
-// 	uint8_t pRes[MAX_BLADE_NUM*sizeof(OemBladeStatus_T)+1];
-// 	wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,  
-// 							0x2e<<2, 0x81,
-// 							NULL, 0,
-// 							(uint8_t*)pRes,  &dwResLen,
-// 							timeout);
-// 	if( wRet != 0 )
-// 			printf("Error getting Blade Status Info\n");
+int LIBIPMI_HL_GetBladeStatus(IPMI20_UDS_SESSION_T *pUDSSession, BladeStatus_T *BladeStatus, int timeout)
+{
+	int wRet = 0;
+	uint32_t	dwResLen;
+	uint8_t pRes[BLADE_NUMBERS*sizeof(BladeStatus_T)+1];
+	wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,  
+							NETFNLUN_IPMI_STORLEAD, CMD_GET_BLADE_INFO,
+							NULL, 0,
+							(uint8_t*)pRes,  &dwResLen,
+							timeout);
+	if( wRet != 0 )
+			printf("Error getting Blade Status Info\n");
 		
-// 	memcpy(BladeStatus, pRes+1, g_OemWebFlags.bladeNum*sizeof(OemBladeStatus_T));
-// 	return 0;
-// }
+	memcpy(BladeStatus, pRes+1, BLADE_NUMBERS*sizeof(BladeStatus_T));
+	return 0;
+}
 
 // int LIBIPMI_HL_GetIPMCCapability(IPMI20_UDS_SESSION_T *pUDSSession, uint8_t bladeIndex, OemIPMCCapability_T* pIPMCCapability, int timeout)
 // {
@@ -474,43 +474,46 @@ LIBIPMI_HL_GetSensorHistory( IPMI20_UDS_SESSION_T *pUDSSession, sensor_history_s
 // 	return 0;
 // }
 
-// int LIBIPMI_HL_SetBladeManageFn(IPMI20_UDS_SESSION_T *pUDSSession, uint8_t enable, int timeout)
-// {
-// 	int wRet = 0;
-// 	uint32_t	dwResLen;
-// 	uint8_t pReq[10];
-// 	uint8_t pRes[10];
+int LIBIPMI_HL_SetBladeManageFn(IPMI20_UDS_SESSION_T *pUDSSession, uint8_t enable, int timeout)
+{
+	int wRet = 0;
+	uint32_t	dwResLen;
+	uint8_t pReq[10];
+	uint8_t pRes[10];
 	
-// 	pReq[0] = enable;
-// 	wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,  
-// 							0x2e<<2, 0x8a,
-// 							(uint8_t*)pReq,	(uint32_t)1,
-// 							(uint8_t*)pRes,  &dwResLen,
-// 							timeout);
-// 	if( wRet != 0 )
-// 			printf("Error LIBIPMI_HL_SetBladeManageFn\n");
+	pReq[0] = enable;
+	wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,  
+							NETFNLUN_IPMI_STORLEAD, CMD_SET_MANAGE_FN,
+							(uint8_t*)pReq,	(uint32_t)1,
+							(uint8_t*)pRes,  &dwResLen,
+							timeout);
+	if( wRet != 0 )
+			printf("Error LIBIPMI_HL_SetBladeManageFn\n");
 		
-// 	return 0;
-// }
+	return 0;
+}
+
+int LIBIPMI_HL_GetBladeManageFn(IPMI20_UDS_SESSION_T *pUDSSession, uint8_t *enable, int timeout)
+{
+	int wRet = 0;
+	uint32_t	dwResLen;
+	uint8_t pRes[10];
+
+	wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,  
+							NETFNLUN_IPMI_STORLEAD, CMD_GET_MANAGE_FN,
+							NULL,	(uint32_t)0,
+							(uint8_t*)pRes,  &dwResLen,
+							timeout);
+	if(( wRet != 0 ) || (pRes[0] != 0))
+	{
+			printf("Error LIBIPMI_HL_SetBladeManageFn\n");
+			return -1;
+	}
+		
+	*enable = pRes[1];
+	return 0;
+}
 
-// int LIBIPMI_HL_GetManageWebName(IPMI20_UDS_SESSION_T *pUDSSession, char* webName, int timeout)
-// {
-// 	int wRet = 0;
-// 	uint32_t	dwResLen;
-// 	uint8_t pRes[20];
-	
-// 	wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession,  
-// 							0x2e<<2, 0x84,
-// 							NULL,	0,
-// 							(uint8_t*)pRes,  &dwResLen,
-// 							timeout);
-// 	if( wRet != 0 )
-// 			printf("Error LIBIPMI_HL_SetBladeManageFn\n");
-	
-// 	memset(webName, 0, 16);
-// 	memcpy(webName, pRes+1, 16);
-// 	return 0;
-// }
 
 int LIBIPMI_HL_GetFanInfo(IPMI20_UDS_SESSION_T *pUDSSession, FanInfo_T* pFanInfo, int timeout)
 {
@@ -597,42 +600,6 @@ int LIBIPMI_HL_GetFanInfo(IPMI20_UDS_SESSION_T *pUDSSession, FanInfo_T* pFanInfo
 //  return 0;
 // }
 
-// uint16_t IPMICMD_GetSensorInfo(IPMI20_UDS_SESSION_T *pUDSSession, uint8_t SensorIndex, StorleadGetSensorInfoRes_T *pGetSensorInfoRes,int timeout)
-// {
-// 	uint16_t wRet;
-// 	uint32_t dwResLen = 0;
-// 	uint8_t Req[20];
-	
-// 	Req[0] = SensorIndex;
-// 	wRet = LIBIPMI_Send_RAW_IPMI2_0_Command(pUDSSession, 	//notice!
-// 						(NETFN_STORLEAD << 2), CMD_GET_SENSOR_INFO,
-// 						Req, 1,
-// 						(uint8_t*)pGetSensorInfoRes, &dwResLen,
-// 						timeout);
-	
-// 	return (wRet);
-// }
-
-// uint16_t LIBIPMI_HL_GetSensorInfo(IPMI20_UDS_SESSION_T *pUDSSession,SenInfo_T *pSensorInfo,uint32_t nNumSensor,int timeout)
-// {
-// 	uint16_t wRet = 0;
-// 	StorleadGetSensorInfoRes_T GetSensorInfoRes;
-// 	int i;
-
-// 	for(i=0;i<nNumSensor;i++)
-// 	{
-// 		wRet = IPMICMD_AMIGetSensorInfo(pUDSSession, i, &GetSensorInfoRes,timeout);
-// 		if(wRet == LIBIPMI_E_SUCCESS)
-// 		{
-// 			memcpy((uint8_t *)&pSensorInfo[i], GetSensorInfoRes.SensorInfo);
-// 		}
-// 		else
-// 		{
-// 			printf("error getting sensor info %d\n",wRet);
-// 		}
-// 	}
-// 	return (wRet);
-// }
 
 /*
 *@fn IPMICMD_AMIGetSELEntires

+ 4 - 0
app/goahead-3.6.5/src/web_interface/inc/dashboard.h

@@ -12,6 +12,10 @@ void getSensorInfo(Webs *wp);
 void actionTest(Webs *wp);
 void buy(Webs *wp);
 
+void getBladeManage(Webs *wp);
+void setBladeManage(Webs *wp);
+void getAllBladeInfo(Webs *wp);
+void getChassisInfo(Webs *wp);
 
 
 #endif /* __DASHBOARD_H__ */

+ 210 - 61
app/goahead-3.6.5/src/web_interface/src/dashboard.c

@@ -5,6 +5,7 @@
 #include    "cJSON.h"
 #include    "libipmi_storlead_OEM.h"
 #include    "libsensor.h"
+#include    "com_BMCCfg.h"
 #include    <stdio.h>
 #include <sys/socket.h>
 #include <sys/un.h>
@@ -373,51 +374,6 @@ void buy(Webs *wp)
 
 
 
-// /*
-//     Implement /action/actionTest. Parse the form variables: name, address and echo back.
-//  */
-// void actionTest(Webs *wp)
-// {
-
-//     printf("sid value is >>>>>>>>>>>>>: %d<<<<<<<<<<<\n", wp->sid);
-//     IPMI20_UDS_SESSION_T    UDSSession;
-//     GetDevIDRes_T   DeviceID;
-
-//     //Create session
-//     printf("actionTest!\n");
-//     LIBIPMI_CreateSession(&UDSSession, 10);
-//     IPMICMD_GetDeviceID( &UDSSession, &DeviceID, DEFAULT_TIMEOUT);
-
-//     printf("sid value is >>>>>1>>>>>>>>: %d<<<<<<<\n", wp->sid);
-
-
-//     char *pStr;
-
-//     char *testStr;
-//     testStr = malloc(500); 
-//     //sprintf(testStr, "{data: {\"Version\": \"%s\", \"MAC\": \"%s\", \"IP\": \"%s\"}, \"msg\":\"\"}", FwVersion, MacAddr, IpAddr);
-
-//     sprintf(testStr, "{\"data\": {\"buildTime\":\"%s\",\"fwVersion\":\"%s\",\"macAddr\":\"%s\",\"ipAddr\":\"%s\"},\"msg\":\"\",\"code\": %d}", \
-//         BuildTime, FwVersion, MacAddr, IpAddr, 200);
-
-
-//     //sprintf(testStr, "jimbo and lusa are very confused, please git me some tips, my god!");
-
-//      pStr = testStr;
-
-
-//     char name[] = "jimbo";
-//     char address[] = "shanghai";
-//     printf("name: %s, address: %s\n", name, address);
-//     websSetStatus(wp, 200);
-//     websWriteHeaders(wp, -1, 0);
-//     websWriteEndHeaders(wp);
-//     websWrite(wp,  testStr);
-//     websFlush(wp, 0);
-//     websDone(wp);
-//     // LIBIPMI_CloseSession(&UDSSession );
-// }
-
 
 void actionTest(Webs *wp)
 {
@@ -487,22 +443,7 @@ void actionTest(Webs *wp)
     // cJSON * root =  cJSON_CreateObject();
     // cJSON * data =  cJSON_CreateObject();
     printf("log1\n");
-    // cJSON_AddItemToObject(root, "data", data);//根节点下添加
-    // cJSON_AddItemToObject(root, "msg", cJSON_CreateString(""));
-    // cJSON_AddItemToObject(root, "code", cJSON_CreateString("200"));
-    // cJSON_AddStringToObject(data, "buildTime", BuildTime);
-    // cJSON_AddStringToObject(data, "fwVersion", FwVersion);
-    // cJSON_AddStringToObject(data, "macAddr", MacAddr);
-    // cJSON_AddStringToObject(data, "ipAddr", IpAddr);
-    // pStr = cJSON_Print(root);     //include malloc
- //    cJSON_AddItemToObject(root, "data", data);//根节点下添加
- //    cJSON_AddStringToObject(root, "msg", NULL);
- //    cJSON_AddNumberToObject(root, "code", 200);
- // //   cJSON_AddStringToObject(data, "buildTime", BuildTime);
- // //   cJSON_AddStringToObject(data, "fwVersion", FwVersion);
- // //   cJSON_AddStringToObject(data, "macAddr", MacAddr);
- // //   cJSON_AddStringToObject(data, "ipAddr", IpAddr);
- //    pStr = cJSON_Print(root);     //include malloc
+   
     
     printf("%s\n", pStr);
     websSetStatus(wp, 200);
@@ -519,4 +460,212 @@ void actionTest(Webs *wp)
     // cJSON_Delete(data);
 
     
+}
+
+void getAllBladeInfo(Webs *wp){
+    uint16_t    wRet = LIBIPMI_E_SUCCESS;
+    
+    IPMI20_UDS_SESSION_T    UDSSession;
+    BladeStatus_T   *pBladeStatus = walloc(BLADE_NUMBERS*sizeof(BladeStatus_T));
+
+    //Create session
+    LIBIPMI_CreateSession(&UDSSession, DEFAULT_TIMEOUT);
+
+    wRet = LIBIPMI_HL_GetBladeStatus(&UDSSession, pBladeStatus, DEFAULT_TIMEOUT);
+    if(wRet != 0)
+    {
+        printf("Get Blade status error!\n");
+        websError(wp, 404, "Get Blade status error!");
+        wfree(pBladeStatus);
+        return;
+    }
+    //Close session
+    LIBIPMI_CloseSession(&UDSSession );
+    
+    char *pStr;
+    cJSON * root =  cJSON_CreateObject();
+    cJSON  *pJsonArry,*pJsonsub;
+    pJsonArry=cJSON_CreateArray();   /*创建数组*/
+    cJSON_AddItemToObject(root, "data", pJsonArry);//根节点下添加
+    cJSON_AddStringToObject(root, "msg", "");
+    cJSON_AddNumberToObject(root, "code", 200);
+
+    int i;
+    for(i=0;i<BLADE_NUMBERS;i++)
+    {
+        cJSON_AddItemToArray(pJsonArry,pJsonsub=cJSON_CreateObject()); /* 给创建的数组增加对对象*/
+        cJSON_AddNumberToObject(pJsonsub, "status", pBladeStatus[i].healthStatus); //0:灰色, 1: 绿色 2:红色
+        cJSON_AddNumberToObject(pJsonsub, "slot", pBladeStatus[i].slotID); 
+        cJSON_AddNumberToObject(pJsonsub, "power", pBladeStatus[i].pwrStatus); 
+        cJSON_AddStringToObject(pJsonsub, "name", pBladeStatus[i].bladeName); 
+    }
+  
+    pStr = cJSON_PrintUnformatted(root);
+
+    printf("---> cJSON Str:\n%s\n", pStr);
+    websSetStatus(wp, 200);
+    websWriteHeaders(wp, -1, 0);
+    websWriteEndHeaders(wp);
+    websWrite(wp, "%s", pStr);
+    websFlush(wp, 0);
+    websDone(wp);
+
+    if(pStr)
+        wfree(pStr);
+    if(root)
+        cJSON_Delete(root);
+    if(pBladeStatus)
+        wfree(pBladeStatus);
+
+}
+
+void setBladeManage(Webs *wp){
+    uint16_t    wRet = LIBIPMI_E_SUCCESS;
+    IPMI20_UDS_SESSION_T    UDSSession;
+
+    char *strEnable = websGetVar(wp, "enable", NULL);
+    uint8_t enable = atoi(strEnable);
+
+    if(enable > 1)
+    {
+        websError(wp, 404, "Invalid param");
+        return ;
+    } 
+    
+
+    //Create session
+    LIBIPMI_CreateSession(&UDSSession, DEFAULT_TIMEOUT);
+
+    wRet = LIBIPMI_HL_SetBladeManageFn(&UDSSession, enable, DEFAULT_TIMEOUT);
+    if(wRet != 0)
+    {
+        printf("Set Blade Manage error!\n");
+        websError(wp, 404, "Set Blade Manage Error!");
+        LIBIPMI_CloseSession(&UDSSession );
+        return;
+    }
+
+    //Close session
+    LIBIPMI_CloseSession(&UDSSession );
+
+    
+    char *pStr;
+    cJSON * root =  cJSON_CreateObject();
+    cJSON * data =  cJSON_CreateObject();
+    cJSON_AddItemToObject(root, "data", data);//根节点下添加
+    cJSON_AddStringToObject(root, "msg", "");
+    cJSON_AddNumberToObject(root, "code", 200);
+    
+    pStr = cJSON_PrintUnformatted(root);
+
+    printf("---> cJSON Str:\n%s\n", pStr);
+    websSetStatus(wp, 200);
+    websWriteHeaders(wp, -1, 0);
+    websWriteEndHeaders(wp);
+    websWrite(wp, "%s", pStr);
+    websFlush(wp, 0);
+    websDone(wp);
+
+    if(pStr)
+        wfree(pStr);
+    if(root)
+        cJSON_Delete(root);
+
+}
+
+void getBladeManage(Webs *wp){
+    uint16_t    wRet = LIBIPMI_E_SUCCESS;
+    IPMI20_UDS_SESSION_T    UDSSession;
+    uint8_t     enable = 0;
+
+    //Create session
+    LIBIPMI_CreateSession(&UDSSession, DEFAULT_TIMEOUT);
+
+    wRet = LIBIPMI_HL_GetBladeManageFn(&UDSSession, &enable, DEFAULT_TIMEOUT);
+    if(wRet != 0)
+    {
+        printf("Set Blade Manage error!\n");
+        websError(wp, 404, "Set Blade Manage Error!");
+        LIBIPMI_CloseSession(&UDSSession );
+        return;
+    }
+
+    //Close session
+    LIBIPMI_CloseSession(&UDSSession );
+
+    
+    char *pStr;
+    cJSON * root =  cJSON_CreateObject();
+    cJSON * data =  cJSON_CreateObject();
+    cJSON_AddItemToObject(root, "data", data);//根节点下添加
+    cJSON_AddStringToObject(root, "msg", "");
+    cJSON_AddNumberToObject(root, "code", 200);
+
+    cJSON_AddNumberToObject(data, "isEnable", enable);  //机箱管理功能是否已经打开    
+    
+    pStr = cJSON_PrintUnformatted(root);
+
+    printf("---> cJSON Str:\n%s\n", pStr);
+    websSetStatus(wp, 200);
+    websWriteHeaders(wp, -1, 0);
+    websWriteEndHeaders(wp);
+    websWrite(wp, "%s", pStr);
+    websFlush(wp, 0);
+    websDone(wp);
+
+    if(pStr)
+        wfree(pStr);
+    if(root)
+        cJSON_Delete(root);
+
+}
+
+
+void getChassisInfo(Webs *wp){
+    uint16_t    wRet = LIBIPMI_E_SUCCESS;
+    IPMI20_UDS_SESSION_T    UDSSession;
+    OemChassisInfo_T ChassisInfo;
+
+    //Create session
+    LIBIPMI_CreateSession(&UDSSession, DEFAULT_TIMEOUT);
+
+    wRet = LIBIPMI_HL_GetChassisInfo(&UDSSession, &ChassisInfo, DEFAULT_TIMEOUT);
+    if(wRet != 0)
+    {
+        websError(wp, 404, "Get Chassis Info Error!");
+        LIBIPMI_CloseSession(&UDSSession );
+        return;
+    }
+
+    //Close session
+    LIBIPMI_CloseSession(&UDSSession );
+
+    
+    char *pStr;
+    cJSON * root =  cJSON_CreateObject();
+    cJSON * data =  cJSON_CreateObject();
+    cJSON_AddItemToObject(root, "data", data);//根节点下添加
+    cJSON_AddStringToObject(root, "msg", "");
+    cJSON_AddNumberToObject(root, "code", 200);
+
+    cJSON_AddNumberToObject(data, "slotNum", ChassisInfo.slotNum);    //机箱内一共有多少个槽位
+    cJSON_AddNumberToObject(data, "supportManage", ChassisInfo.supportChassisManageFn); //是否支持机箱管理功能。 0:不支持, 1:支持
+    cJSON_AddNumberToObject(data, "ManageEn", ChassisInfo.chassisManageFnEnable);   //是否打开机箱管理功能。0:关闭, 1:打开
+    cJSON_AddNumberToObject(data, "curIndex", ChassisInfo.curIndex);   //当前刀片插在第几个槽位。
+    
+    pStr = cJSON_PrintUnformatted(root);
+
+    printf("---> cJSON Str:\n%s\n", pStr);
+    websSetStatus(wp, 200);
+    websWriteHeaders(wp, -1, 0);
+    websWriteEndHeaders(wp);
+    websWrite(wp, "%s", pStr);
+    websFlush(wp, 0);
+    websDone(wp);
+
+    if(pStr)
+        wfree(pStr);
+    if(root)
+        cJSON_Delete(root);
+
 }