Sunday, December 30, 2018

Change Arduino Editor Tab size. 아두이노 에디터 탭 크기 변경


C:\Users\사용자이름\AppData\Local\Arduino15\preferences.txt

파일을 열어서
editor.tabs.size 항목을 변경하세요.

반드시 아두이노 개발툴을 끈 상태에서 편집하고 저장한 후

아두이노 개발툴을 실행하세요.

그리고 자동 포멧시 탭 크기도 변경하세요.

아두이노 IDE가 설치된 폴더의 lib폴더 안의 formatter.conf 파일을 열어

indent=spaces=2  항목의 숫자를 수정하고 저장하세요.

보통 위치는 C:\Program Files (x86)\Arduino\lib\formatter.conf 입니다.

편집 후 저장할 때 저장이 안되면 메모장을 관리자 권한으로 실행하여 파일 열기로 들어가서 직접 열면 편집 가능합니다.

Friday, July 13, 2018

STM8S PB4 PB5 output not works 출력 안되는 문제

STM8S 의

PB4, PB5 는 OD 출력만된다.


STM8S
PB4, PB5  have no Push-Pull output.  have only Open drain output


Wednesday, July 11, 2018

3G SMS PDU DECODER SOURCE CODE




int HexToInt(const char* p)
{
char temp[3];
temp[0] = p[0];
temp[1] = p[1];
temp[2] = '\0';
return strtol(temp, NULL, 16);


}

void HexToString(unsigned char* dest, unsigned char* src)
{
char temp[3];
char* p = (char*)src;
int len = strlen(p);


temp[2] = '\0';

for(int i=0; i <len; i+=2)
{
temp[0] = *p;
p++;
temp[1] = *p;
p++;

unsigned char ch = (unsigned char)strtol(temp, NULL, 16 );

dest[ i/2 ] = ch;

}

}


void cat_hex(unsigned char *dest, unsigned char val)
{
static unsigned char hex_table[]="0123456789ABCDEF";

dest[0] = hex_table[ (val >> 4) & 0x0f ];

dest[1] = hex_table[ (val ) & 0x0f ];
}


int DecodePDU(unsigned char* result, unsigned char* pDataPDU)
{
bool fUDHI;
unsigned char DataSMSDecode[255];
unsigned char *pDataSMSDecode = DataSMSDecode;
int nIndex = 0;
int nLengthUDH =0;
int nLength = 0;
unsigned char nHex=0;
unsigned char nBitMask = 0;
int nDCS;
unsigned char nShift;
unsigned char nChar1;
unsigned char nChar2;

memset( DataSMSDecode, 0, sizeof(DataSMSDecode));

// 07
nLength =  HexToInt( &pDataPDU[nIndex]);

nIndex = nIndex + 2;

//# 91280102194105
//# Type-of-address of the SMSC. (91 means international format of the phone number)
//# Service center number (+821020911450)

nIndex = nIndex + nLength * 2;

//# 44
//# Check TP-UDHI bit (40)
if (0x40 == (HexToInt( &pDataPDU[nIndex]) & 0x40))
{
fUDHI = true;
}
else
{
fUDHI = false;
nLengthUDH = 0;
}

nIndex = nIndex + 2;


//# 0BA11020903746F0
nLength = HexToInt( &pDataPDU[nIndex] );

if ( nLength % 2)
{
nLength = (nLength + 1) / 2;
}

nIndex = nIndex + (nLength + 2) * 2;

//# 00 : TP-PID
nIndex = nIndex + 2;
//# 00 : TP-DCS

nDCS = HexToInt( &pDataPDU[nIndex] );

nIndex = nIndex + 2;

//    # 21505251708263
//    # Time stamp
nIndex = nIndex + 14;

//# 0E
nIndex = nIndex + 2;

if( fUDHI )
{
//# 0A
nLengthUDH = HexToInt( &pDataPDU[nIndex] );
nIndex = nIndex + 2;

//# 22
nIndex = nIndex + 2;

//# 080B811020903746F0
nLength = HexToInt( &pDataPDU[nIndex] );
nIndex = nIndex + (nLength + 1) * 2;
}

if (0x00 == nDCS)
{
//# 8001
//# decode

pDataPDU = &pDataPDU[nIndex];
strcat( pDataPDU, "00");


if ( 0 != nLengthUDH )
{

nShift = 7 - ((nLengthUDH + 1) % 7);
nBitMask = (0xFF >> nShift) << nShift;

nLength = strlen(pDataPDU);
if(nLength > 250)
nLength = 250;



for(nIndex=0; nIndex <= nLength; nIndex+=2)
{

if (nLength - 2 == nIndex)
{
break;
}

if (7 == nShift)
{
nChar1 = HexToInt( &pDataPDU[nIndex] );
nHex = nChar1 & 0x7F;


cat_hex( pDataSMSDecode, nHex);
pDataSMSDecode++;
pDataSMSDecode++;


// szDataSMSDecode = szDataSMSDecode + hex(nHex);
}

nChar1 = HexToInt( &pDataPDU[nIndex]);
nChar2 = HexToInt( &pDataPDU[nIndex+2]);

nHex = (nChar1 & nBitMask) >> nShift;

nShift = nShift - 1;

nBitMask = (0xFF >> nShift) << nShift;

nHex = nHex | ((nChar2 & (~nBitMask)) << (7 - nShift));

cat_hex( pDataSMSDecode, nHex);
pDataSMSDecode++;
pDataSMSDecode++;

if (0 == nShift)
nShift = 7;
}

HexToString( DataSMSDecode, DataSMSDecode );
}
}
else
{
HexToString( DataSMSDecode, &pDataPDU[nIndex] );

}

strcpy( result, DataSMSDecode);
return strlen(result);
}



//  --- 아래는 테스트 예제 ---
void __fastcall TForm1::Button1Click(TObject *Sender)
{
String a ;

AnsiString t = "0791280102195140440BA11030917583F30000216051908591635D0A22080B811030917583F3088BC7E4B2F98C0E8BC7E4B2F98C0E8BC7E4B2F98C0E8BC7E4B2F98C0E8BC7E4B2F98C0E8BC7E4B2F98C0E8BC7E4B2F98C0E8BC7E4B2F98C0E8BC7E4B2F98C0E8BC7E4B2F98C06";

//t = "0791280102194189440BA11080554992F7008451805000727463110A22080B811080554992F7C7D1B1B9B8BB";

unsigned char temp[1000];

DecodePDU(temp,   t.c_str());
Memo1->Lines->Text = AnsiString((char*)temp);
}