LinuxÏÂc¿ª·¢ Ö® Ïß³ÌͨÐÅ
1.Linux“Ï߳̔
½ø³ÌÓëÏß³ÌÖ®¼äÊÇÓÐÇø±ðµÄ£¬²»¹ýLinuxÄÚºËÖ»ÌṩÁËÇáÁ¿½ø³ÌµÄÖ§³Ö£¬Î´ÊµÏÖÏß³ÌÄ£ÐÍ¡£LinuxÊÇÒ»ÖÖ“¶à½ø³Ìµ¥Ï߳̔µÄ²Ù×÷ϵͳ¡£Linux±¾ÉíÖ»Óнø³ÌµÄ¸ÅÄ¶øÆäËùνµÄ“Ï߳̔±¾ÖÊÉÏÔÚÄÚºËÀïÈÔÈ»Êǽø³Ì¡£
´ó¼ÒÖªµÀ£¬½ø³ÌÊÇ×ÊÔ´·ÖÅäµÄµ¥Î»£¬Í¬Ò»½ø³ÌÖеĶà¸öÏ̹߳²Ïí¸Ã½ø³ÌµÄ×ÊÔ´£¨Èç×÷Ϊ¹²ÏíÄÚ´æµÄÈ«¾Ö±äÁ¿£©¡£LinuxÖÐËùνµÄ“Ïֻ߳̔ÊÇÔÚ±»´´½¨Ê±cloneÁ˸¸½ø³ÌµÄ×ÊÔ´£¬Òò´Ëclone³öÀ´µÄ½ø³Ì±íÏÖΪ“Ï߳̔£¬ÕâÒ»µãÒ»¶¨ÒªÅªÇå³þ¡£Òò´Ë£¬Linux“Ï߳̔Õâ¸ö¸ÅÄîÖ»ÓÐÔÚ´òðºÅµÄÇé¿öϲÅÊÇ×î׼ȷµÄ¡£
Ä¿Ç°LinuxÖÐ×îÁ÷ÐеÄÏ̻߳úÖÆΪLinuxThreads£¬Ëù²ÉÓõľÍÊÇỊ̈߳½ø³Ì“Ò»¶ÔÒ»”Ä£ÐÍ£¬µ÷¶È½»¸øºËÐÄ£¬¶øÔÚÓû§¼¶ÊµÏÖÒ»¸ö°üÀ¨ÐźŴ¦ÀíÔÚÄÚµÄÏ̹߳ÜÀí»úÖÆ¡£LinuxThreadsÓÉXavier Leroy (Xavier.Leroy@inria.fr)¸ºÔ𿪷¢Íê³É£¬²¢ÒÑ°ó¶¨ÔÚGLIBCÖз¢ÐУ¬ËüʵÏÖÁËÒ»ÖÖBiCapitalizedÃæÏòLinuxµÄPosix 1003.1c “pthread”±ê×¼½Ó¿Ú¡£Linuxthread¿ÉÒÔÖ§³ÖIntel¡¢Alpha¡¢MIPSµÈƽ̨ÉϵĶദÀíÆ÷ϵͳ¡£
¡¡¡¡°´ÕÕPOSIX 1003.1c ±ê×¼±àдµÄ³ÌÐòÓëLinuxthread ¿âÏàÁ´½Ó¼´¿ÉÖ§³ÖLinuxƽ̨ÉϵĶàỊ̈߳¬ÔÚ³ÌÐòÖÐÐè°üº¬Í·Îļþpthread. h£¬ÔÚ±àÒëÁ´½ÓʱʹÓÃÃüÁ
gcc -D -REENTRANT -lpthread xxx. c
¡¡¡¡ÆäÖÐ-REENTRANTºêʹµÃÏà¹Ø¿âº¯Êý(Èçstdio.h¡¢errno.hÖк¯Êý) ÊÇ¿ÉÖØÈëµÄ¡¢Ḭ̈߳²È«µÄ(thread-safe)£¬-lpthreadÔòÒâζ×ÅÁ´½Ó¿âĿ¼ÏµÄlibpthread.a»òlibpthread.soÎļþ¡£Ê¹ÓÃLinuxthread¿âÐèÒª2.0ÒÔÉÏ°æ±¾µÄLinuxÄں˼°ÏàÓ¦°æ±¾µÄC¿â(libc 5.2.18¡¢libc 5.4.12¡¢libc 6)¡£
2.“Ï߳̔¿ØÖÆ
¡¡¡¡Ï̴߳´½¨
¡¡¡¡½ø³Ì±»´´½¨Ê±£¬ÏµÍ³»áΪÆä´´½¨Ò»¸öÖ÷Ị̈߳¬¶øÒªÔÚ½ø³ÌÖд´½¨ÐµÄỊ̈߳¬Ôò¿ÉÒÔµ÷ÓÃpthread_create£º
pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *
(start_routine)(void*), void *arg);
¡¡¡¡start_routineΪÐÂÏ̵߳ÄÈë¿Úº¯Êý£¬argΪ´«µÝ¸østart_routineµÄ²ÎÊý¡£
¡¡¡¡Ã¿¸öÏ̶߳¼ÓÐ×Ô¼ºµÄÏß³ÌID£¬ÒÔ±ãÔÚ½ø³ÌÄÚÇø·Ö¡£Ïß³ÌIDÔÚpthread_createµ÷ÓÃʱ»Ø·µ¸ø´´½¨Ï̵߳ĵ÷ÓÃÕߣ»Ò»¸öÏß³ÌÒ²¿ÉÒÔÔÚ´´½¨ºóʹÓÃpthread_self()µ÷ÓûñÈ¡×Ô¼ºµÄÏß³ÌID£º
pthread_self (void) ;
¡¡¡¡Ïß³ÌÍ˳ö
¡¡
Ïà¹ØÎĵµ£º
¼ÆËãÏß³ÌÖ´ÐÐijÏîÈÎÎñÏûºÄµÄʱ¼äʱ£¬Ðí¶à¿ª·¢ÈËÔ±»áµ÷ÓÃGetTickCount/GetTickCount64±àдÈçϵĴúÂ룺
// Get the current time (start time)
ULONGLONG qwStartTime = GetTickCount64();
// Perform complex algorithm here
// Subtract start time from current time to get duration
ULONGLONG dwElapsedTime = Get ......
Ç°Ãæ½²ÁËʹÓà ioctl·¢ËÍHCI CommandµÄ·½·¨¡£µ«HCI protocol»¹ÓÐһЩCommand£¬±ÈÈçInquiryµÈ£¬ËûÃÇÔò²»ÐèҪʹÓÃioctlÀ´·¢ËÍ¡£blueZ Ö±½ÓÌṩÁËÖ§³Ö£¬ËäÈ»ËûÃǵÄ×îÖÕ¶¼ÊÇÓÃͬÑù°ì·¨ÊµÏֵġ£
ÔÚÓ¦ÓóÌÐòÖУº
hci_inquiry(dev_id, length, num_rsp, NULL, &info, flags);
ÕâÑùÐèÒª°üº¬blueZ Í·ÎļþÈçÏ£º
#include //BT ......
SamÒ»ÄêÇ°ÔÚLinuxÏÂдÁËÒ»¸öÀàËÆWindowsÏÂBTWµÄ¿â--BTX¡£ÏÖÔÚÐèÒªÌí¼Óй¦ÄÜʱ·¢Ïֺܶà֪ʶµã¶¼Íü¼ÇÁË¡£ËùÒÔ¾ö¶¨ÔÚÕâ´ÎѧϰÖУ¬°ÑһЩbluez API¼Ç¼ÏÂÀ´¡£Õ⼸ÌìÓÖÏ룬ÕâÑù»¹²»¹»£¬²»Èç°ÑLinuxϵÄBluetooth±à³Ì»ù´¡¸ø¼Ç¼ÏÂÀ´°É¡£
Ç°ÑÔ£ºËæ×ÅǶÈëʽϵͳµÄ·ÉËÙ·¢Õ¹£¬ºÜ¶àǶÈëʽƽ̨ÉÏÐèÒªBluetoothÉ豸ºÍÓ¦Óᣵ«ÔÚLinuxÏ ......
LinuxÏÂBluetoothÐÒéÕ»µÄʵÏÖ. LinuxÏ¿ª·ÅµÄÀ¶ÑÀÐÒéÕ»Ö÷Òª°üÀ¨IBM¹«Ë¾µÄBlueDrekar£¬Nokia¹«Ë¾µÄAffix, Axis¹«Ë¾µÄOpenBTºÍ¹Ù·½ÐÒéÕ»BlueZ¡£ÎÒÃÇÖ÷ÒªÃæ¶ÔBluezÀ´Ì½ÌÖ¡£
BlueZ»ù´¡´úÂë¾ùÊÇÓÉMaxim KrasnyanskyÍê³ÉµÄ¡£°üÀ¨£ºHCI£¬L2CAP£¬RFCOMMºÍ»ù±¾socketµÄʵÏÖ¡£Ëû¾ÍÖ°ÓÚQualcomm(¸ßͨ)¡£Marcel Holtmann¿ª·¢²ãµÄÐÒ ......
1. HCI²ãÐÒé¸ÅÊö£º
HCIÌṩһÌ×ͳһµÄ·½·¨À´·ÃÎÊBluetoothµ×²ã¡£ÈçͼËùʾ£º
´ÓͼÉÏ¿ÉÒÔ¿´³ö£¬Host Controller Interface(HCI) ¾ÍÊÇÓÃÀ´¹µÍ¨HostºÍModule¡£Hostͨ³£¾ÍÊÇPC£¬ ModuleÔòÊÇÒÔ¸÷ÖÖÎïÀíÁ¬½ÓÐÎʽ£¨USB,serial,pc-cardµÈ£©Á¬½Óµ½PCÉϵÄbluetooth Dongle¡£
ÔÚHostÕâÒ»¶Ë£ºapplication,SDP,L2capµÈÐÒé ......