Picproje Elektronik Sitesi

SERBEST BÖLGE => Programlama ve Algoritma => Konuyu başlatan: armsistem - 05 Ağustos 2014, 18:01:07

Başlık: Consistent Overhead Byte Stuffing—Reduced (COBS/R)
Gönderen: armsistem - 05 Ağustos 2014, 18:01:07
Arkadaşlar , merhaba ;

aşağıdaki kodu çalıştıramadım , çıkan sonuçlar bir tuhaf 'Consistent Overhead Byte Stuffing—Reduced (COBS/R)' anlamaya çalışıyorum , şimdiden teşekkür ederim.


#include <iostream>

#define FinishBlock(X) (*code_ptr = (X), code_ptr = dst++, code = 0x01)


using namespace std;
char ch[5];
int tg=1234567890;




void UnStuffData(const unsigned char *ptr,
unsigned long length, unsigned char *dst)
{
  const unsigned char *end = ptr + length;
  while (ptr < end)
  {
    int i, code = *ptr++;
    for (i=1; i<code; i++)
      *dst++ = *ptr++;
    if (code < 0xFF)
      *dst++ = 0;
  }
}

void StuffData(const unsigned char *ptr,
unsigned long length, unsigned char *dst)
{
  const unsigned char *end = ptr + length;
  unsigned char *code_ptr = dst++;
  unsigned char code = 0x01;

  while (ptr < end)
  {
    if (*ptr == 0)
      FinishBlock(code);
    else
    {
      *dst++ = *ptr;
      code++;
      if (code == 0xFF)
        FinishBlock(code);
    }
    ptr++;
  }

  FinishBlock(code);
}

int main()
{
const unsigned char text[] = {0x11,0x22,0x00,0x33};
unsigned char codify[4];

StuffData(text, (sizeof(text)/sizeof(text[0])), codify);
UnStuffData
//0x03 0x11 0x22 0x02 0x33
printf("%d", codify);
// printf("%c", codify);
// printf("%d", codify);
// printf("%l", codify);

// cout <<  codify ;

return 0;
}