[an error occurred while processing this directive]
Если кому не влом скоректируйте трансляцию из С в дельфи
(«Телесистемы»: Конференция «Микроконтроллеры и их применение»)

миниатюрный аудио-видеорекордер mAVR

Отправлено TamTam 1 10 января 2006 г. 01:33

////////////////// DELPHI /////////////////////////

function RxFrame (Timeout:cardinal; ADD: integer; CMD: integer; N: integer; DATA: integer):boolean; stdcall;
var
i: integer;
b: integer;
begin
crc:=crc_init;
cComTo.ReadTotalTimeoutConstant:=Timeout;
if not SetCommTimeouts(hCommFile,cComTo) then result:=false;
i:=0;
while (i < 512) and (b <> FEND) do
begin
if not RxByteCom(b) then break;
Inc(i);
end;
if b <> FEND then result:= false;
DowCRC(b,crc);
N:=0;
ADD:=0;
for i:=-3 to i<=N do
begin
if not RxByteCom(b) then break;
if b = FESC
then
if not RxByteCom(b) then break;
else begin
if b = TFEND
then
b:=FEND;
else
if b=TFESC
then
b=FESC;
else
break;
end;
DowCRC(b,crc);
if i=-3
then
if (b and $80) = 0
then begin
CMD := b;
inc(i);
end
else
ADD:=d and $7f;
else
if i=-2
then
if b and $80 <> 0
then
break;
else
CMD:=b;
else
if i=-1
then
N:=b;
else
if i <> N+1
then
Data[i]=b;
end;
result:= ((i:=N+1) AND not CRC);
end; ///


//////////////////// C ///////////////////////////

bool WINAPI RxFrame(DWORD To, unsigned char &ADD, unsigned char &CMD,
unsigned char &N, unsigned char *Data)
{ int i;
unsigned char b = 0, crc = CRC_Init; //init CRC
ComTo.ReadTotalTimeoutConstant = To; //set timeout
if (!SetCommTimeouts(hCom, &ComTo)) return 0; //set timeouts error
for (i = 0; i < 512 && b != FEND; i++)
if (!RxByteCOM(b)) break; //frame synchronzation
if (b != FEND) return 0; //timeout or sync error
DowCRC(b, crc); //update CRC
N = 0; ADD = 0;
for (i = -3; i<=N; i++)
{
if (!RxByteCOM(b)) break; //timeout error
if (b == FESC)
if (!RxByteCOM(b)) break; //timeout error
else
{ if (b == TFEND) b = FEND; //TFEND <- FEND
else
if (b == TFESC) b = FESC; //TFESC <- FESC
else break;
}
DowCRC(b, crc); //update CRC
if (i == -3)
if ((b & 0x80) == 0) { CMD = b; i++; } //CMD (b.7=0)
else ADD = b & 0x7F; //ADD (b.7=1)
else
if (i == -2)
if ((b & 0x80) != 0) break; //CMD error (b.7=1)
else CMD = b; //CMD
else
if (i == -1)
N = b; //N
else
if (i != N) Data[i] = b; //data
}
return ((i==N+1) && !crc); //RX or CRC error
}

Составить ответ  |||  Конференция  |||  Архив

Ответы


Отправка ответа

Имя (обязательно): 
Пароль: 
E-mail: 
NoIX ключ Запомнить

Тема (обязательно):
Сообщение:

Ссылка на URL: 
Название ссылки: 

URL изображения: 


Rambler's Top100 Рейтинг@Mail.ru
Перейти к списку ответов  |||  Конференция  |||  Архив  |||  Главная страница  |||  Содержание

E-mail: info@telesys.ru