5 Ekim 2017 Perşembe

Time Division Multiple Access - TDMA

Giriş
Time Division Multiple Access - TDMA ile ilgili notlarım şöyle.

Zaman Kaynağı
TDMA tüm kullanıcıların saatlerini eşitlemesi için referans zaman kaynağına ihtiyaç duyar. Bu kaynak GPS veya periyodik olarak yayınlanan "time referance" paketleri olabilir.

Zaman Slot'lara Bölünür
Zaman slot'lara yani dilimlere bölünür. Açıklaması şöyle
At a high level, TDMA (Time Division Multiple Access) simply means that multiple users share a communications channel by taking turns transmitting and receiving. This channel is usually considered to be a mobile radio channel, but it can just as easily be something wired like Ethernet.

Time is divided into slots, and certain terminals can only transmit in certain slots.
As for the specifics of how those slots are assigned, that is largely dependent on application, and that's where things can get really tricky.
Farklı Hızlar
TDMA kullanırken kaynakların farklı hızlara sahip olması bir problem. Bunun çözümleri var ama ben bilmiyorum.

MySQL String Metodları

Giriş
MySQL String metodlarının listesi burada

Cast
Cast tam olarak bir string metodu sayılmaz ancak string'i sayıya çevirdiği için yazıya dahil ettim. Şöyle yaparız.
update <table> set new_column = CAST(ColumnName AS UNSIGNED);
Field metodu
Açıklaması şöyle
MySQL FIELD() returns the index position of the searching string from a list of strings. If search string is not found, it returns a 0(zero). If search string is NULL, the return value is 0 because NULL fails equality comparison with any value.
Şöyle yaparız.
SELECT * FROM `students` WHERE `id` IN (83, 84)
ORDER BY FIELD(`id`, 83, 84);
Convert - Expression + Type
Elimizde char tipi olan DOB sütunu olsun. String'den Integer'a çevirmek için şöyle yaparız.
SELECT * 
FROM employees
WHERE CONVERT(DOB, INTEGER) >= 1960
   AND CONVERT(DOB, INTEGER) <= 1969
Find_In_Set metodu
Açıklaması şöyle
MySQL FIND_IN_SET() returns the position of a string if it is present (as a substring) within a list of strings. The string list itself is a string contains substrings separated by ‘,’ (comma) character.

This function returns 0 when search string does not exist in the string list and returns NULL if either of the arguments is NULL.
Söz dizimi şöyle
FIND_IN_SET (search string, string list)
Parametreler şöyle
search string   A string which is to be looked for in following list of arguments.
string list     List of strings to be searched if they contain the search string.
Şöyle yaparız
SELECT * FROM `students` WHERE `id` IN (83,84)
ORDER BY FIND_IN_SET(id,'83,84')
Like
SQL dünyasında "%xx%" şeklinde kullanıma "un-anchored search pattern" deniliyor. Şöyle yaparız.
foo LIKE '%bar%'
Eğer "like%" şeklinde kullanırsak anchored search pattern deniliyor. Açıklaması şöyle
If you lack a % on either side, it is said that the search pattern anchors to the start or end of the string respectively. This lingo comes from the regex world.
Şöyle yaparız.
foo like 'bar%'
Bazen de like ta belirtilen örüntü "needle" olarak adlandırılıyor. "Haystack" ise needle'dan daha uzun veri. Yani "samanlıkta iğne aramak" :) Şöyle yaparız.
SET @hayStack := 'www.example.com';
SET @needle := 'www.example.com/test';

SELECT 

IF(LENGTH(@hayStack) > LENGTH(@needle), 
    @hayStack LIKE CONCAT('%',@needle,'%'),
    @needle LIKE CONCAT('%',@hayStack,'%')
)
Like ve Concat
Eğer sütun verisi örüntümüz olacaksa şöyle yaparız.
SELECT * FROM db WHERE 'www.example.com/test' LIKE CONCAT('%',urlColumn,'%');
Like ve Group By
Örüntüyü belirtip sütun içinde arama yapacaksak şöyle yaparız.
SELECT country,COUNT(*)  
FROM Table1
WHERE aut_name LIKE "%a%"
GROUP BY country;

Substring metodu
İlk iki karakter ayırmak için şöyle yaparız
select * from yourtable order by CONVERT(INT, SUBSTRING(title, 1 , 2)) ASC
Substring_Index metodu
Boşluğun solundaki ilk token ve sağındaki ilk token'ı almak için şöyle yaparız
select * from yourtable order by CONVERT(INT, SUBSTRING_INDEX(title, ' ', 1)) ASC,
SUBSTRING_INDEX(title, ' ', -1) ASC




4 Ekim 2017 Çarşamba

Internet Protocol Security - IPSec

Giriş
Internet Protocol Security - IPSec ile ilgili notlarım şöyle.

Authentication Header
Açıklaması şöyle
Authentication Header adds a cryptographic signature to each packet, which ensures nothing has modified it and it came from the correct source. AH is, obviously, not compatible with NAT.
Encapsulating Security Payload
Integrity Check Value alanının açıklaması şöyle
ESP's ICV is just a checksum to ensure the packet hasn't been damaged. It does not ensure the packet has not been altered, or authenticate who sent it.

3 Ekim 2017 Salı

termios yapısı

termios yapısı
POSIX seri port API'sinde (örneğin RS232) herşey termios yapısı etrafında döner. Yapı şöyle
struct termios {
  tcflag_t    c_iflag;    /* input flags */
  tcflag_t    c_oflag;    /* output flags */
  tcflag_t    c_cflag;    /* control flags */
  tcflag_t    c_lflag;    /* local flags */
  cc_t        c_cc[NCCS]; /* control chars */
  speed_t     c_ispeed;   /* input speed */
  speed_t     c_ospeed;   /* output speed */
};
Linux'ta Posix standardından daha fazla bir çok bayrak var.

canonical kullanım
Şöyle yaparız.
newtio.c_cflag |= CLOCAL | CREAD;
newtio.c_cflag &= ~CSIZE;
newtio.c_cflag |= CS8;         /* 8-bit characters */
newtio.c_cflag &= ~PARENB;     /* no parity bit */
newtio.c_cflag &= ~CSTOPB;     /* only need 1 stop bit */
newtio.c_cflag &= ~CRTSCTS;    /* no hardware flowcontrol */

newtio.c_lflag |= ICANON | ISIG;  /* canonical input */
newtio.c_lflag &= ~(ECHO | ECHOE | ECHONL | IEXTEN);

newtio.c_iflag &= ~INPCK;
newtio.c_iflag |= ICRNL;
newtio.c_iflag &= ~(INLCR | IGNCR | IUCLC | IMAXBEL);
newtio.c_iflag &= ~(IXON | IXOFF | IXANY);   /* no SW flowcontrol */

newtio.c_oflag &= ~OPOST;

c_cflag Alanı
Kontrol bayrakları içindir. Posix şu bayrakları tanımlar.

CSIZE Bayrağı: Bir karakter büyüklüğünü tanımlar. 5,6,7,8 bit olabilir. 5 ve 6 bit veri büyüklükleri çok eskiden kullanılırdı.
CSTOPB Bayrağı: İki veya bir stop biti kullanır. Açıklaması şöyle. Tüm veri alındıktan sonra start bit'in tekrar gözlemlenmesi için ne kadar süre geçmesi gerektiğini belirtir.
With this kind of communication, both the sender and receiver have to agree ahead of time on a few parameters. The two key parameters here are the baud rate and the number of data bits.

The line starts out in the idle level. The transmitter first sends the start bit, which is at the opposite level. It then sends the data bits, followed by the stop bit.

Unlike what others have said, the stop bit is not a checksum. It is required so that there is always a transition at the leading edge of the start bit. Otherwise, if the last data bit ov the previous character happened to be of the same polarity as a start bit, the receiver wouldn't be able to see the start bit if a new character was sent immediately. The stop bit is essentially enforced line idle time between characters. That time is also used to absorb some clock mismatch between the sender and receiver.

When idle, the receiver monitors the line looking for it to change to the non-idle state. When that happens, it starts a stopwatch. Since it is configured for the same bit rate as the transmitter, it knows when each data bit is sent, whether it differs from a previous bit or not. The middle of the first data bit is at 1½ bit times from the leading edge of the start bit. The second at 2½ bit times, etc.

After the last data bit is received, the receiver waits for the line to go back to the idle state, then waits for the next start bit again.
Start Bit Gelince
1.5 cycle beklenir ve sonra okuma işlemi başlar. Açıklaması şöyle
The start bit is used to trigger the read cycle in the receiver. The receiver synchronises itself on the start bit and then waits 1.5 cycles to start sampling bits. Thereafter the bits are sampled at the baud rate. This initial delay means that even with a 5% clock error the receiver should still be within the bit timing for the last bit.

CREAD : Açıklama yaz
PARENB : Parity kontrolünü etkinleştirir.
PARODD : Parity etkinse odd veya even olabilir.
HUPCL : Açıklama yaz
CLOCAL : Açıklama yaz

8N1 8 bit data, No Parity, 1 Stop bit anlamına gelir.

c_oflag alanları
Raw Output
Açıklaması şöyle. Text Editor tarzı işlerde kullanılır
Up next is understanding how to set your terminal into "raw mode." By default, your terminal processes text line-by-line, echoing every character that we type and much more. We don't want all of that. However, to enter raw mode, we'll need to learn about native Unix APIs and how to access them with Java.

One such API is the Termios API. It effectively lets you set your terminal into raw mode; hence, I'll show you how to use JNA to access the Termios API — and do a fair amount of bit-wise ANDs to get your terminal into the right mode.

With ANSI escape codes and terminal raw mode knowledge under our belts, we can finally create our terminal editor skeleton. When we start the editor, we want to see a clear screen. In addition, all empty rows should start with a "~" sign, and we should also have a nice little status bar at the bottom of the screen — time for implementation!
Şöyle yaparız
port_settings.c_oflag &= ~OPOST; //enable raw output 
cfmakeraw yazısına da bakılabilir.

OpenCV Image Smoothing

Giriş
OpenCV image smoothing (blurring) için 4 tane yöntem sunuyor. Bunlar Averaging, Gaussian Blurring, Median Blurring ve Bileteral Filtering metodları. Bir resmin blurry olduğu şöyle anlaşılabilir.
Compute the fft and analyse the result. The Fourier transform tells you which frequencies are present in the image. If there is a low amount of high frequencies, then the image is blurry.
Resmin blur işleminden geçmesi yani bulanıklaştırılması normalde lossy yani kayıplı bir işlem. Bulanıklaştırma resmin bir kısmını gizlemek (örneğin insan yüzü) veya detayları azaltmak için (yumuşatma) için kullanılır. Bazı yazılımlar bir şekilde bulanıklaştırma işlemini geri alabiliyorlar.

Convolution
Açıklaması şöyle
The process for (trying) to deblur a blurry image is called convolution. This is not the same or the reverse of focusing on a sharp scene to produce a sharp image. They work differently.
Kernel
Image matristen daha küçük bir matristir. Bazen image filter olarak ta isimlendirilir. Genellikle işlem şöyledir
- kernel  image matris üzerinde bir alana yerleştirilir.
- kernel ve üzerine yerleştiği image matris elemanları çarpılır ve tüm çarpımların toplamı alınır. Bu toplam da image matris'te kernel'in tam ortasındaki konuma atanır.

1. GaussianBlur metodu
Gaussian Blur aynı zamanda Gaussian Smoothing olarak ta bilinir. Gaussian Blur her türlü resime uygun olmayabilir. Açıklaması şöyle
The Gaussian kernel corresponds to very smooth functions, and when that kernel is chosen the assumption is being made that smooth functions will provide a decent model. That's not always the case, and there are tons of other kernels that encode different assumptions about what you want your function class to look like. There are kernels for modeling periodic functions, non-stationary kernels, and a whole host of other things. For example, the smoothness assumption encoded by the Gaussian kernel is not appropriate for text classification...

Gaussian Noise Nedir
Rastgele dağılmış gürültüyü ifade eder. Gürültüyü gidermek için smoothing yapılabilir. Salt & Pepper koyu alanlarda beyaz, beyaz alanlarda koyu noktaları ifade eder.

Metod 6 tane parametre alır.
src image
kaynak resim
out image
sonuç resim
kernel
tek sayı kare matris. Size matrisinin 33x33 gibi büyük bir değer ile kullanılmaması daha iyi sonuç verebilir.
sigma x
double tipinde. Resmin ne kadar blur edileceğini belirtir. Ne olduğunu anlamadım
sigma y
double tipinde. Ne olduğunu anlamadım
border type
int tipinde. Ne olduğunu anlamadım 

Örnek
Çıktıyı aynı resime yazmak için şöyle yaparız.
Mat mat = ...;
GaussianBlur(mat, mat, Size(7,7), 1.5, 1.5);
Örnek
Çıktıyı farklı resime yazmak Şöyle yaparız.
 cv::GaussianBlur(crop,// input image
        imgBlurred,    // output image
        cv::Size(5, 5),// smoothing window width and height in pixels
        5);        // sigma value, determines how much the image will be blurred
Python ile şöyle yaparız.
# Blurring to get rid of some noise
self.img = cv2.GaussianBlur(self.img, (9, 9), 0)
2. medianBlur metodu
Açıklaması şöyle
Median filtering is common in reduction of certain types of noise in image processing. Especially salt and pepper noise. It works by picking out the median value in each color channel in each local neighbourhood of the image and replacing it with it. How large these neighbourhoods are can vary. Popular filter sizes (neighbourhoods) are for example 3x3 and 5x5 pixels
Şöyle yaparız. Genelde 3x3 veya 5x5 kernel kullanılır.
Mat image = ...

// blur will enhance edge detection
Mat blurred(image);
cv::medianBlur(image, blurred, 9);