/*
 * config sensor sdr in here.
 * Author:Jimbo
 */

#include "sensor_sdr.h"
#include "sensor_thread.h"
#include <stdio.h>
#include <stdint.h>
#include "bmc_main.h"
#include "bmc_type.h"
/*
 * sensor sdr table, use sensor number as index.
 */

static INT16U SDR_ReserveSDRRepository (void);

static MgmtCtrlrDevLocator_T MgmtCtrlrDevLocator =
{
        /* SDR Record Header */
        0x01,                   /* Record ID */
        0x51,                   /* SDR Version */
        0x12,                   /* Record Type */
        11 + MAX_ID_STR_LEN,//sizeof "AST2300",/* Record Length = 11+ string length*/
        /* Record Key Bytes*/
        0x2a,                   /* Slave address - 0x20 Primary BMC */
        0x00,                   /* ChannelNumber - 0x00 Primary BMC */
        /* Record Body Bytes */
        0x0,                    /* power state notification */
        0xff,                   /* Device Capablities */
        {0x00,0x00,0x00},       /* RESERVED */
        0x0,                    /* Entity ID */
        0x1,                    /* Entity Instance */
        0x0,                    /* OEM */
        0xc0 + MAX_ID_STR_LEN,               /* ID String Type / Length Code */
        "AST2300"

};

static SDRRec_T sdr_tbl[]=
{

/*
 * sensor number: 0
 * sensor name:	LM73
 * brief:	temporary
 */
(FullSensorRec_T){
	/* SDR Record Header */
	0x02,	//Record ID
	0x51,	//SDR Version
	0x01,	//Record Type
	43+MAX_ID_STR_LEN,//MAX_ID_STR_LEN,//0x43+MAX_ID_STR_LEN,	//Record Length = 43+string length
	/* Record Key Bytes */
	0x20,	//Sensor Owner ID
	0x0,	//Sensor Owner LUN
	0x0,//0x1//sensor_tbl[0].sensor_number,	//Sensor Number
	/* Record Body Bytes */
	0x7,	//Entity ID
	0x1,	//Entity Instance	
	0x7f,	//Entity Initialization
	0x68,	//Sensor Capabilities
	0x01,	//Sensor Type
	0x01,	//Event / Reading Type
	0x7a95,	//Lower Threshold Reading Mask
	0x7a95, //Upper Threshold Reading Mask
	0x3f3f,	//Settable / Readable Threshold Mask
	(0x2<<6)+(0x0<<3)+(0x0<<1)+0x0,	//Sensor Units 1
	0x1,	//Sensor Units 2 - Base Unit
	0x0,	//Sensor Units 3 - Modifier Unit
	0x0,	//Linerization
	0x2,	//M
	((0x2>>2)&0xC0)+(0x0&0x3F),	//M,Tolerance
	0x0,	//B
	((0x0>>2)&0xC0)+(0x0&0x3F),	//B,Accuracy
	((0x0>>2)&0xF0)+(0x0&0x0C)+0x0,	//Accuracy,Accuracy exponent
	(0x0<<4)+(0x0&0x0F),		//R exponent,B exponent
	0x0,	//Analog Characteristics Flags
	0x7f,	//Nominal Reading
	0x7f,	//Normal Maximum
	0x80,	//Normal Minimum
	0x7f,	//Sensor Maximum Reading
	0x80,	//Sensor Minimum Reading
	0x7f,	//Upper Non-Recoverable Threshold
	0x7f,	//Upper Critical Threshold
	0x7f,	//Upper Non-Critical Threshold
	0x80,	//Lower Non-Recoverable Threshold
	0x80,	//Lower Critical Threshold
	0x80,	//Lower Non-Critical threshold
	0x0,	//Positive - threshold Hysteresis value
	0x0,	//Negative - threshold Hysteresis value
	0x0,	//Reserved
	0x0,	//Reserved
	0x0,	//OEM
	0xC0+MAX_ID_STR_LEN,//MAX_ID_STR_LEN,	//ID String Type / Length Code
	"lm73_1"
},

/*
 * sensor number: 1
 * sensor name:	LM73
 * brief:	temporary
 */
(FullSensorRec_T){
	/* SDR Record Header */
	0x03,	//Record ID
	0x51,	//SDR Version
	0x01,	//Record Type
	43+MAX_ID_STR_LEN,//0x43+MAX_ID_STR_LEN,	//Record Length = 43+string length
	/* Record Key Bytes */
	0x20,	//Sensor Owner ID
	0x0,	//Sensor Owner LUN
	0x1,//sensor_tbl[1].sensor_number,	//Sensor Number
	/* Record Body Bytes */
	0x8,	//Entity ID
	0x1,	//Entity Instance	
	0x7f,	//Entity Initialization
	0x68,	//Sensor Capabilities
	0x02,	//Sensor Type
	0x01,	//Event / Reading Type
	0x7a95,	//Lower Threshold Reading Mask
	0x7a95, //Upper Threshold Reading Mask
	0x3f3f,	//Settable / Readable Threshold Mask
	(0x2<<6)+(0x0<<3)+(0x0<<1)+0x0,	//Sensor Units 1
	0x4,	//Sensor Units 2 - Base Unit
	0x0,	//Sensor Units 3 - Modifier Unit
	0x0,	//Linerization
	0x2,	//M
	((0x2>>2)&0xC0)+(0x0&0x3F),	//M,Tolerance
	0x0,	//B
	((0x0>>2)&0xC0)+(0x0&0x3F),	//B,Accuracy
	((0x0>>2)&0xF0)+(0x0&0x0C)+0x0,	//Accuracy,Accuracy exponent
	(0x0<<4)+(0x0&0x0F),		//R exponent,B exponent
	0x0,	//Analog Characteristics Flags
	0x7f,	//Nominal Reading
	0x7f,	//Normal Maximum
	0x80,	//Normal Minimum
	0x7f,	//Sensor Maximum Reading
	0x80,	//Sensor Minimum Reading
	0x7f,	//Upper Non-Recoverable Threshold
	0x7f,	//Upper Critical Threshold
	0x7f,	//Upper Non-Critical Threshold
	0x80,	//Lower Non-Recoverable Threshold
	0x80,	//Lower Critical Threshold
	0x80,	//Lower Non-Critical threshold
	0x0,	//Positive - threshold Hysteresis value
	0x0,	//Negative - threshold Hysteresis value
	0x0,	//Reserved
	0x0,	//Reserved
	0x0,	//OEM
	0xC0+MAX_ID_STR_LEN,	//ID String Type / Length Code
	"lm73_2"	
},
/*
 *  * sensor number: 1
 *   * sensor name: LM73
 *    * brief:       temporary
 *     */
(FullSensorRec_T){
        /* SDR Record Header */
        0x04,   //Record ID_H
        0x51,   //SDR Version
        0x01,   //Record Type
        43+MAX_ID_STR_LEN,    //Record Length = 43+string length
        /* Record Key Bytes */
        0x20,   //Sensor Owner ID
        0x0,    //Sensor Owner LUN
        0x2,//sensor_tbl[2].sensor_number,    //Sensor Number
        /* Record Body Bytes */
        0x8,    //Entity ID
        0x1,    //Entity Instance       
        0x7f,   //Entity Initialization
        0x68,   //Sensor Capabilities
        0x02,   //Sensor Type
        0x01,    //Event / Reading Type
        0x7a95, //Lower Threshold Reading Mask
        0x7a95, //Upper Threshold Reading Mask
        0x3f3f, //Settable / Readable Threshold Mask
        (0x00<<6)+(0x0<<3)+(0x0<<1)+0x0, //Sensor Units 1
        0x4,    //Sensor Units 2 - Base Unit
        0x0,    //Sensor Units 3 - Modifier Unit
        0x0,    //Linerization
        16,    //M
        ((0x2>>2)&0xC0)+(0x0&0x3F),     //M,Tolerance
        0x0,    //B
        ((0x0>>2)&0xC0)+(0x0&0x3F),     //B,Accuracy
        ((0x0>>2)&0xF0)+(0x0&0x0C)+0x0, //Accuracy,Accuracy exponent
        (13<<4)+(0x0&0x0F),            //R exponent,B exponent
	0x0,    //Analog Characteristics Flags
        0x0,   //Nominal Reading
        0xff,   //Normal Maximum
        0x00,   //Normal Minimum
        0xff,   //Sensor Maximum Reading
        0x00,   //Sensor Minimum Reading
        0xff,   //Upper Non-Recoverable Threshold
        0xff,   //Upper Critical Threshold
        0xff,   //Upper Non-Critical Threshold
        0x00,   //Lower Non-Recoverable Threshold
        0x00,   //Lower Critical Threshold
        0x00,   //Lower Non-Critical threshold
        0x0,    //Positive - threshold Hysteresis value
        0x0,    //Negative - threshold Hysteresis value
        0x0,    //Reserved
        0x0,    //Reserved
        0x0,    //OEM
        0xC0+MAX_ID_STR_LEN,    //ID String Type / Length Code
        "3V3_Vlot"
},

(FullSensorRec_T){
        /* SDR Record Header */
        0x05,   //Record ID_H
        0x51,   //SDR Version
        0x01,   //Record Type
        43+MAX_ID_STR_LEN,    //Record Length = 43+string length
        /* Record Key Bytes */
        0x20,   //Sensor Owner ID
        0x0,    //Sensor Owner LUN
        0x3,//sensor_tbl[2].sensor_number,    //Sensor Number
        /* Record Body Bytes */
        0x8,    //Entity ID
        0x1,    //Entity Instance       
        0x7f,   //Entity Initialization
        0x68,   //Sensor Capabilities
        0x02,   //Sensor Type
        0x01,    //Event / Reading Type
        0x7a95, //Lower Threshold Reading Mask
        0x7a95, //Upper Threshold Reading Mask
        0x3f3f, //Settable / Readable Threshold Mask
        (0x00<<6)+(0x0<<3)+(0x0<<1)+0x0, //Sensor Units 1
        0x4,    //Sensor Units 2 - Base Unit
        0x0,    //Sensor Units 3 - Modifier Unit
        0x0,    //Linerization
        32,    //M
        ((0x2>>2)&0xC0)+(0x0&0x3F),     //M,Tolerance
        0x0,    //B
        ((0x0>>2)&0xC0)+(0x0&0x3F),     //B,Accuracy
        ((0x0>>2)&0xF0)+(0x0&0x0C)+0x0, //Accuracy,Accuracy exponent
        (13<<4)+(0x0&0x0F),            //R exponent,B exponent
        0x0,    //Analog Characteristics Flags
        0x0,   //Nominal Reading
        0xff,   //Normal Maximum
        0x00,   //Normal Minimum
        0xff,   //Sensor Maximum Reading
        0x00,   //Sensor Minimum Reading
        0xff,   //Upper Non-Recoverable Threshold
        0xff,   //Upper Critical Threshold
        0xff,   //Upper Non-Critical Threshold
        0x00,   //Lower Non-Recoverable Threshold
        0x00,   //Lower Critical Threshold
        0x00,   //Lower Non-Critical threshold
        0x0,    //Positive - threshold Hysteresis value
        0x0,    //Negative - threshold Hysteresis value
        0x0,    //Reserved
        0x0,    //Reserved
        0x0,    //OEM
        0xC0+MAX_ID_STR_LEN,    //ID String Type / Length Code
        "5V0_Volt"
},

(FullSensorRec_T){
        /* SDR Record Header */
        0x06,   //Record ID_H
        0x51,   //SDR Version
        0x01,   //Record Type
        43+MAX_ID_STR_LEN,    //Record Length = 43+string length
        /* Record Key Bytes */
        0x20,   //Sensor Owner ID
        0x0,    //Sensor Owner LUN
        0x4,//sensor_tbl[2].sensor_number,    //Sensor Number
        /* Record Body Bytes */
        0x8,    //Entity ID
        0x1,    //Entity Instance       
        0x7f,   //Entity Initialization
        0x68,   //Sensor Capabilities
        0x02,   //Sensor Type
        0x01,    //Event / Reading Type
        0x7a95, //Lower Threshold Reading Mask
        0x7a95, //Upper Threshold Reading Mask
        0x3f3f, //Settable / Readable Threshold Mask
        (0x00<<6)+(0x0<<3)+(0x0<<1)+0x0, //Sensor Units 1
        0x4,    //Sensor Units 2 - Base Unit
        0x0,    //Sensor Units 3 - Modifier Unit
        0x0,    //Linerization
        64,    //M
        ((0x2>>2)&0xC0)+(0x0&0x3F),     //M,Tolerance
        0x0,    //B
        ((0x0>>2)&0xC0)+(0x0&0x3F),     //B,Accuracy
        ((0x0>>2)&0xF0)+(0x0&0x0C)+0x0, //Accuracy,Accuracy exponent
        (13<<4)+(0x0&0x0F),            //R exponent,B exponent
        0x0,    //Analog Characteristics Flags
        0x0,   //Nominal Reading
        0xff,   //Normal Maximum
        0x00,   //Normal Minimum
        0xff,   //Sensor Maximum Reading
        0x00,   //Sensor Minimum Reading
        0xff,   //Upper Non-Recoverable Threshold
        0xff,   //Upper Critical Threshold
        0xff,   //Upper Non-Critical Threshold
        0x00,   //Lower Non-Recoverable Threshold
        0x00,   //Lower Critical Threshold
        0x00,   //Lower Non-Critical threshold
        0x0,    //Positive - threshold Hysteresis value
        0x0,    //Negative - threshold Hysteresis value
        0x0,    //Reserved
        0x0,    //Reserved
        0x0,    //OEM
        0xC0+MAX_ID_STR_LEN,    //ID String Type / Length Code
        "12V0_Volt"
},

(FullSensorRec_T){
        /* SDR Record Header */
        0x07,   //Record ID_H
        0x51,   //SDR Version
        0x01,   //Record Type
        43+MAX_ID_STR_LEN,    //Record Length = 43+string length
        /* Record Key Bytes */
        0x20,   //Sensor Owner ID
        0x0,    //Sensor Owner LUN
        0x5,//sensor_tbl[2].sensor_number,    //Sensor Number
        /* Record Body Bytes */
        0x8,    //Entity ID
        0x1,    //Entity Instance       
        0x7f,   //Entity Initialization
        0x68,   //Sensor Capabilities
        0x03,   //Sensor Type
        0x01,    //Event / Reading Type
        0x7a95, //Lower Threshold Reading Mask
        0x7a95, //Upper Threshold Reading Mask
        0x3f3f, //Settable / Readable Threshold Mask
        (0x00<<6)+(0x0<<3)+(0x0<<1)+0x0, //Sensor Units 1
        0x5,    //Sensor Units 2 - Base Unit
        0x0,    //Sensor Units 3 - Modifier Unit
        0x0,    //Linerization
        2,    //M
        ((0x2>>2)&0xC0)+(0x0&0x3F),     //M,Tolerance
        0x0,    //B
        ((0x0>>2)&0xC0)+(0x0&0x3F),     //B,Accuracy
        ((0x0>>2)&0xF0)+(0x0&0x0C)+0x0, //Accuracy,Accuracy exponent
        (14<<4)+(0x0&0x0F),            //R exponent,B exponent
        0x0,    //Analog Characteristics Flags
        0x0,   //Nominal Reading
        0xff,   //Normal Maximum
        0x00,   //Normal Minimum
        0xff,   //Sensor Maximum Reading
        0x00,   //Sensor Minimum Reading
        0xff,   //Upper Non-Recoverable Threshold
        0xff,   //Upper Critical Threshold
        0xff,   //Upper Non-Critical Threshold
        0x00,   //Lower Non-Recoverable Threshold
        0x00,   //Lower Critical Threshold
        0x00,   //Lower Non-Critical threshold
        0x0,    //Positive - threshold Hysteresis value
        0x0,    //Negative - threshold Hysteresis value
        0x0,    //Reserved
        0x0,    //Reserved
        0x0,    //OEM
        0xC0+MAX_ID_STR_LEN,    //ID String Type / Length Code
        "3V3_Amps"
},

(FullSensorRec_T){
        /* SDR Record Header */
        0x08,   //Record ID_H
        0x51,   //SDR Version
        0x01,   //Record Type
        43+MAX_ID_STR_LEN,    //Record Length = 43+string length
        /* Record Key Bytes */
        0x20,   //Sensor Owner ID
        0x0,    //Sensor Owner LUN
        0x6,//sensor_tbl[2].sensor_number,    //Sensor Number
        /* Record Body Bytes */
        0x8,    //Entity ID
        0x1,    //Entity Instance       
        0x7f,   //Entity Initialization
        0x68,   //Sensor Capabilities
        0x03,   //Sensor Type
        0x01,    //Event / Reading Type
        0x7a95, //Lower Threshold Reading Mask
        0x7a95, //Upper Threshold Reading Mask
        0x3f3f, //Settable / Readable Threshold Mask
        (0x00<<6)+(0x0<<3)+(0x0<<1)+0x0, //Sensor Units 1
        0x5,    //Sensor Units 2 - Base Unit
        0x0,    //Sensor Units 3 - Modifier Unit
        0x0,    //Linerization
        2,    //M
        ((0x2>>2)&0xC0)+(0x0&0x3F),     //M,Tolerance
        0x0,    //B
        ((0x0>>2)&0xC0)+(0x0&0x3F),     //B,Accuracy
        ((0x0>>2)&0xF0)+(0x0&0x0C)+0x0, //Accuracy,Accuracy exponent
        (14<<4)+(0x0&0x0F),            //R exponent,B exponent
        0x0,    //Analog Characteristics Flags
        0x0,   //Nominal Reading
        0xff,   //Normal Maximum
        0x00,   //Normal Minimum
        0xff,   //Sensor Maximum Reading
        0x00,   //Sensor Minimum Reading
        0xff,   //Upper Non-Recoverable Threshold
        0xff,   //Upper Critical Threshold
        0xff,   //Upper Non-Critical Threshold
        0x00,   //Lower Non-Recoverable Threshold
        0x00,   //Lower Critical Threshold
        0x00,   //Lower Non-Critical threshold
        0x0,    //Positive - threshold Hysteresis value
        0x0,    //Negative - threshold Hysteresis value
        0x0,    //Reserved
        0x0,    //Reserved
        0x0,    //OEM
        0xC0+MAX_ID_STR_LEN,    //ID String Type / Length Code
        "5V0_Amps"
},

(FullSensorRec_T){
        /* SDR Record Header */
        0x09,   //Record ID_H
        0x51,   //SDR Version
        0x01,   //Record Type
        43+MAX_ID_STR_LEN,    //Record Length = 43+string length
        /* Record Key Bytes */
        0x20,   //Sensor Owner ID
        0x0,    //Sensor Owner LUN
        0x7,//sensor_tbl[2].sensor_number,    //Sensor Number
        /* Record Body Bytes */
        0x8,    //Entity ID
        0x1,    //Entity Instance       
        0x7f,   //Entity Initialization
        0x68,   //Sensor Capabilities
        0x03,   //Sensor Type
        0x01,    //Event / Reading Type
        0x7a95, //Lower Threshold Reading Mask
        0x7a95, //Upper Threshold Reading Mask
        0x3f3f, //Settable / Readable Threshold Mask
        (0x00<<6)+(0x0<<3)+(0x0<<1)+0x0, //Sensor Units 1
        0x5,    //Sensor Units 2 - Base Unit
        0x0,    //Sensor Units 3 - Modifier Unit
        0x0,    //Linerization
        2,    //M
        ((0x2>>2)&0xC0)+(0x0&0x3F),     //M,Tolerance
        0x0,    //B
        ((0x0>>2)&0xC0)+(0x0&0x3F),     //B,Accuracy
        ((0x0>>2)&0xF0)+(0x0&0x0C)+0x0, //Accuracy,Accuracy exponent
        (14<<4)+(0x0&0x0F),            //R exponent,B exponent
        0x0,    //Analog Characteristics Flags
        0x0,   //Nominal Reading
        0xff,   //Normal Maximum
        0x00,   //Normal Minimum
        0xff,   //Sensor Maximum Reading
        0x00,   //Sensor Minimum Reading
        0xff,   //Upper Non-Recoverable Threshold
        0xff,   //Upper Critical Threshold
        0xff,   //Upper Non-Critical Threshold
        0x00,   //Lower Non-Recoverable Threshold
        0x00,   //Lower Critical Threshold
        0x00,   //Lower Non-Critical threshold
        0x0,    //Positive - threshold Hysteresis value
        0x0,    //Negative - threshold Hysteresis value
        0x0,    //Reserved
        0x0,    //Reserved
        0x0,    //OEM
        0xC0+MAX_ID_STR_LEN,    //ID String Type / Length Code
        "12V0_Amps"
},

{0}	//dummy sdr when 0 sensors
};

SDRRec_T *getSensorSdr(uint8_t sensorNum)
{
	uint8_t temp = 0;
	temp = sizeof(sdr_tbl)/sizeof(SDRRec_T);
	if(temp != MAX_SENSOR_NUM+1)	//there is a dummy sdr
	{
		printf("Error:Invalid sdr table!\n");
		return NULL;
	}

	if(sensorNum >= MAX_SENSOR_NUM)
	{
		printf("Error: Invalid sensor number!\n");
		return NULL;
	}

	return &sdr_tbl[sensorNum];
}


/*---------------------------------------
 *  * GetSDRRepositoryInfo
 *   *---------------------------------------*/
int
GetSDRRepositoryInfo (_NEAR_ INT8U* pReq, INT8U ReqLen, _NEAR_ INT8U* pRes,_NEAR_ int BMCInst)
{
//	printf("start GetSDRRepositoryInfo\n");
    	_NEAR_ SDRRepositoryInfo_T* pSDRRepInfoRes =(_NEAR_ SDRRepositoryInfo_T*) pRes;
	
	memset (pSDRRepInfoRes, 0, sizeof (SDRRepositoryInfo_T));
	pSDRRepInfoRes->CompletionCode = 0x00;
	pSDRRepInfoRes->Version=0x51;
	pSDRRepInfoRes->RecCt=MAX_SENSOR_NUM+1;
	pSDRRepInfoRes->FreeSpace=0x5023;
	pSDRRepInfoRes->AddTimeStamp=0x00;
	pSDRRepInfoRes->EraseTimeStamp=0x00;
	pSDRRepInfoRes->OpSupport=0x27;
	SessionSequenceNumberCount=SessionSequenceNumberCount+1;
    	return sizeof (SDRRepositoryInfo_T);
}

/*---------------------------------------
 *  * ReserveSDRRepository
 *   *---------------------------------------*/
int ReserveSDRRepository (_NEAR_ INT8U* pReq, INT8U ReqLen, _NEAR_ INT8U* pRes,_NEAR_ int BMCInst)
{
    BMCInfo_t *pBMCInfo = &g_BMCInfo;//[BMCInst];
    _NEAR_  ReserveSDRRepositoryRes_T*  pResSDRRepRes =
                                    (_NEAR_ ReserveSDRRepositoryRes_T*) pRes;
    INT16U ID;
    memset(pResSDRRepRes,0,sizeof(ReserveSDRRepositoryRes_T)-1);
    ID=SDR_ReserveSDRRepository();
//    printf("ID is %d\n",ID);      
    pResSDRRepRes->ReservationID_H  = ID&0x00ff;//ID>>8;
    pResSDRRepRes->ReservationID_L  = ID>>8;
    pResSDRRepRes->CompletionCode = 0x00;//CC_NORMAL;
    SessionSequenceNumberCount=SessionSequenceNumberCount+1;

    return sizeof (ReserveSDRRepositoryRes_T);
}

/*---------------------------------------
 *  * GetSDR
 *   *---------------------------------------*/
int
GetSDR (_NEAR_ INT8U* pReq, INT8U ReqLen, _NEAR_ INT8U* pRes,_NEAR_ int BMCInst)
{
//	printf("start GetSDR:\n");
	char * pFullSensorRec;
	int i=0;
    	_NEAR_ GetSDRReq_T*     pGetSDRReq = (_NEAR_ GetSDRReq_T*) pReq;
    	_NEAR_ GetSDRRes_T*     pGetSDRRes = (_NEAR_ GetSDRRes_T*) pRes;
    	_FAR_ BMCInfo_t* pBMCInfo = &g_BMCInfo;//[BMCInst];
	char	RecID = pGetSDRReq->RecID;
	INT16U  recordoffset=pGetSDRReq->Offset;
	
    	if(RecID==0)
		pFullSensorRec=&MgmtCtrlrDevLocator;
	else	
	{
		if(RecID != pBMCInfo->sensorInfo[RecID-2].sensorSdr->full_sensor_rec.hdr.ID)
		{
			printf("sdr_tbl ID err\n");
			return 1;
		}
		pFullSensorRec=&pBMCInfo->sensorInfo[RecID-2].sensorSdr->Data;
	}
    	pGetSDRRes->CompletionCode = 0x00;
    	if(RecID==0)
		{
		pGetSDRRes->NextRecID    = 0x02;
		}
	else if(RecID==MAX_SENSOR_NUM+1)
		{
		pGetSDRRes->NextRecID    = 0xffff;
		}	
	else
		{
		pGetSDRRes->NextRecID    = RecID+1;
		}
	/*from 4 byte to 1byte change*/
	uint8_t	*Res=pGetSDRRes;
    	memcpy(&Res[3],&pFullSensorRec[recordoffset],pGetSDRReq->Size);

	SessionSequenceNumberCount=SessionSequenceNumberCount+1;
    	return sizeof (GetSDRRes_T) + pGetSDRReq->Size;
}

static INT16U SDR_ReserveSDRRepository ()
{
    BMCInfo_t *pBMCInfo = &g_BMCInfo;
    
//    printf("pBMCInfo->SDRConfig.ReservationID is %d,\n",pBMCInfo->SDRConfig.ReservationID);
    if (0xffff == pBMCInfo->SDRConfig.ReservationID)
    {
        pBMCInfo->SDRConfig.ReservationID = 1;
    }else
    {
        pBMCInfo->SDRConfig.ReservationID++;
    }
    SessionSequenceNumberCount=SessionSequenceNumberCount+1;
    return pBMCInfo->SDRConfig.ReservationID;

}

