📄 buff.c
字号:
return TRUE;
}
else
{
return FALSE;
}
}
//*****************************************************************************
// Vrati zpracovany RB s odpovidajicim HID
//
// vrati pouze odkaz
//
BOOLEAN ResB_GetByHID( PTResultBuffer ResB, fdl_rb **rb, int HID )
{
int First;
int pos;
if (!ResB) {
DbgPrint("Profim ResB_Add: NULL pointer!");
return FALSE;
}
First = ResB->First;
while ( ResB->Last != First )
{
pos = First;
*rb = &( ResB->Buffer[First++] );
if ( First >= RS_BUFFER_SIZE )
First = 0;
if ( ReadHIDfromRB( *rb ) == HID )
{
PB_DbgPrintL2( "ProfiM ResB: Z pozice %d byl precten vysledek.", pos );
return TRUE;
}
}
return FALSE;
}
//*****************************************************************************
BOOLEAN ResB_DeleteByHID( PTResultBuffer ResB, int HID )
{
int i;
int pos;
int First;
fdl_rb * rb;
if (!ResB) {
DbgPrint("Profim ResB_Add: NULL pointer!");
return FALSE;
}
First = ResB->First;
while ( ResB->Last != First )
{
pos = First;
rb = &( ResB->Buffer[First] );
if ( ReadHIDfromRB( rb ) == HID )
{
// posunuti vysledku
if ( ResB->Last > First )
{
for ( i = First; i < ResB->Last - 1; i++ )
ResB->Buffer[i] = ResB->Buffer[i + 1];
}
else
{
for ( i = First; i < RS_BUFFER_SIZE - 1; i++ )
ResB->Buffer[i] = ResB->Buffer[i + 1];
if ( ResB->Last > 0 )
ResB->Buffer[RS_BUFFER_SIZE - 1] = ResB->Buffer[0];
for ( i = 0; i < ResB->Last - 1; i++ )
ResB->Buffer[i] = ResB->Buffer[i + 1];
}
ResB->Last--; if ( ResB->Last < 0 )
ResB->Last = RS_BUFFER_SIZE - 1;
PB_DbgPrintL2( "ProfiM ResB: Z pozice %d byl smazan vysledek (Last=%d).", pos, ResB->Last );
return TRUE;
}
First++;
if ( First >= RS_BUFFER_SIZE )
First = 0;
}
return FALSE;
}
//*****************************************************************************
//*****************************************************************************
//**
//** Irp Buffer (I/O Request Packet Buffer)
//**
//*****************************************************************************
//*****************************************************************************
void IrpB_Init ( PTIrpBuffer IrpB, void *_DeviceExtension )
{
IrpB->First = 0; // ukazatel na nejstarsi prvek
IrpB->Last = 0; // ukazatel na prvni prazdne misto
IrpB->DeviceExtension = _DeviceExtension;
}
//*****************************************************************************
void IrpB_Close( PTIrpBuffer IrpB )
{
}
//*****************************************************************************
BOOLEAN IrpB_Empty( PTIrpBuffer IrpB )
{
return ( IrpB->First == IrpB->Last );
}
//*****************************************************************************
BOOLEAN IrpB_Full( PTIrpBuffer IrpB )
{
return ( IrpB->Last + 1 == IrpB->First ) ||
( IrpB->Last == IRP_BUFFER_SIZE - 1 && IrpB->First == 0 );
}
//*****************************************************************************
void IrpB_Add( PTIrpBuffer IrpB, int _HID, int _MID, PIRP _IRP )
{
//
// Je-li fronta plna, zahodime nejstarsi vysledek.
//
if ( IrpB_Full( IrpB ) )
{
IrpB->First++;
if ( IrpB->First >= IRP_BUFFER_SIZE )
IrpB->First = 0;
}
if ( (IrpB->Last >= 0) && (IrpB->Last < IRP_BUFFER_SIZE) )
{
IrpB->HID[IrpB->Last] = _HID;
IrpB->MID[IrpB->Last] = _MID;
IrpB->IRP[IrpB->Last] = _IRP;
}
else
DbgPrint("Profim IRP Buff: Write index ERROR!");
IrpB->Last++;
if ( IrpB->Last >= IRP_BUFFER_SIZE )
IrpB->Last = 0;
}
//*****************************************************************************
PIRP IrpB_GetFirstIrp( PTIrpBuffer IrpB, int _HID )
{
int First = IrpB->First;
while ( IrpB->Last != First )
{
if ( IrpB->HID[First] == _HID )
return IrpB->IRP[First];
First++;
if ( First >= IRP_BUFFER_SIZE )
First = 0;
}
return NULL;
}
//*****************************************************************************
void IrpB_DeleteFirstIrp( PTIrpBuffer IrpB, int _HID )
{
int First = IrpB->First;
while ( IrpB->Last != First )
{
if ( IrpB->HID[First] == _HID )
{
IrpB_Delete( IrpB, First );
return;
}
First++;
if ( First >= IRP_BUFFER_SIZE )
First = 0;
}
}
//*****************************************************************************
PIRP IrpB_DeleteIrp( PTIrpBuffer IrpB, int _HID, int _MID )
{
int First = IrpB->First;
PIRP Res;
while ( IrpB->Last != First )
{
if ( IrpB->HID[First] == _HID && IrpB->MID[First] == _MID )
{
Res = IrpB->IRP[First];
IrpB_Delete( IrpB, First );
return Res;
}
First++;
if ( First >= IRP_BUFFER_SIZE )
First = 0;
}
return NULL;
}
//*****************************************************************************
void IrpB_Delete( PTIrpBuffer IrpB, int pos )
{
int i;
if ( ! ( pos >= 0 && pos < IRP_BUFFER_SIZE ) )
return;
if ( pos == IrpB->First )
{
IrpB->First++;
if ( IrpB->First >= IRP_BUFFER_SIZE )
IrpB->First = 0;
return;
}
//
// posun v bufferu
//
if ( IrpB->Last > pos )
{
for ( i = pos; i < IrpB->Last - 1; i++ )
{
IrpB->HID[i] = IrpB->HID[i + 1];
IrpB->MID[i] = IrpB->MID[i + 1];
IrpB->IRP[i] = IrpB->IRP[i + 1];
}
}
else
{
for ( i = pos; i < IRP_BUFFER_SIZE - 1; i++ )
{
IrpB->HID[i] = IrpB->HID[i + 1];
IrpB->MID[i] = IrpB->MID[i + 1];
IrpB->IRP[i] = IrpB->IRP[i + 1];
}
if ( IrpB->Last > 0 )
{
IrpB->HID[IRP_BUFFER_SIZE - 1] = IrpB->HID[0];
IrpB->MID[IRP_BUFFER_SIZE - 1] = IrpB->MID[0];
IrpB->IRP[IRP_BUFFER_SIZE - 1] = IrpB->IRP[0];
}
for ( i = 0; i < IrpB->Last - 1; i++ )
{
IrpB->HID[i] = IrpB->HID[i + 1];
IrpB->MID[i] = IrpB->MID[i + 1];
IrpB->IRP[i] = IrpB->IRP[i + 1];
}
}
IrpB->Last--;
if ( IrpB->Last < 0 )
IrpB->Last = IRP_BUFFER_SIZE - 1;
}
//*****************************************************************************
void IrpB_DeleteAllByHID( PTIrpBuffer IrpB, int _HID )
{
int First = IrpB->First;
while ( IrpB->Last != First )
{
if ( IrpB->HID[First] == _HID )
{
IrpB_Delete( IrpB, First );
}
else
{
First++;
if ( First >= IRP_BUFFER_SIZE )
First = 0;
}
}
}
//*****************************************************************************
void IrpB_DeleteByIrp( PTIrpBuffer IrpB, PIRP _IRP )
{
int First = IrpB->First;
while ( IrpB->Last != First )
{
if ( IrpB->IRP[First] == _IRP )
{
IrpB_Delete( IrpB, First );
return;
}
First++;
if ( First >= IRP_BUFFER_SIZE )
First = 0;
}
}
//*****************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -