linuxÏÂÉú²úÕßÏû·ÑÕßµÄʵÏÖ
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <semaphore.h>
#define M 10 // »º³åÊýÄ¿
int in = 0; // Éú²úÕß·ÅÖòúÆ·µÄλÖÃ
int out = 0; // Ïû·ÑÕßÈ¡²úÆ·µÄλÖÃ
int buff[M] = {0}; // »º³å³õʼ»¯Îª0£¬ ¿ªÊ¼Ê±Ã»ÓвúÆ·
sem_t empty_sem; // ͬ²½ÐźÅÁ¿£¬ µ±ÂúÁËʱ×èÖ¹Éú²úÕ߷ŲúÆ·
sem_t full_sem; // ͬ²½ÐźÅÁ¿£¬ µ±Ã»²úƷʱ×èÖ¹Ïû·ÑÕßÏû·Ñ
pthread_mutex_t mutex; // »¥³âÐźÅÁ¿£¬ Ò»´ÎÖ»ÓÐÒ»¸öÏ̷߳ÃÎÊ»º³å
int product_id = 0; //Éú²úÕßid
int prochase_id = 0; //Ïû·ÑÕßid
/* ´òÓ¡»º³åÇé¿ö */
void print()
{
int i;
for(i = 0; i < M; i++)
printf("%d ", buff[i]);
printf("\n");
}
/* Éú²úÕß·½·¨ */
void *product()
{
int id = ++product_id;
while(1)
{
// ÓÃsleepµÄÊýÁ¿¿ÉÒÔµ÷½ÚÉú²úºÍÏû·ÑµÄËÙ¶È£¬±ãÓÚ¹Û²ì
sleep(1);
//sleep(1);
sem_wait(&empty_sem);
pthread_mutex_lock(&mutex);
Õâ¶þ¾äÈç¹ûµßµ¹µÄ»°,¿ÉÄܳöÏÖÒ»ÖÖÒì³£Çé¿ö,
µ±½øÈëÁË»º³åÇøÎªÂúʱ,µßµ¹Ö®ºó»á¶Ô»º³åÇøÏȼÓËø,È»ºó,½ø³ÌÓÉÓÚ»º³åÇøÎªÂòû·¨Éú²ú²úÆ·,ÔÚÕâÀï±»×èÈû,¶øÏû·ÑÕßÓÖÎÞ·¨»ñµÃ»º³åÇøµÄËø½øÈ뻺³åÇø,Òò¶ø»á³öÏÖËÀËø
in = in % M;
printf("product%d in %d. like: \t", id, in);
buff[in] = 1;
print();
++in;
pthread_mutex_unlock(&mutex);
sem_post(&full_sem);
}
}
/* Ïû·ÑÕß·½·¨ */
void *prochase()
{
int id = ++prochase_id;
while(1)
{
// ÓÃsleepµÄÊýÁ¿¿ÉÒÔµ÷½ÚÉú²úºÍÏû·ÑµÄËÙ¶È£¬±ãÓÚ¹Û²ì
sleep(2);
sem_wait(&full_sem); // Õâ¶þ¾äÈç¹ûµßµ¹µÄ»°,¿ÉÄܳöÏÖÒ»ÖÖÒì³£Çé¿ö,
µ±½øÈëÁË»º³åÇøÎª¿Õʱ,µßµ¹Ö®ºó»á¶Ô»º³åÇøÏȼÓËø,È»ºó,½ø³ÌÓÉÓÚ»º³åÇøÎª¿Õû·¢Ïû·Ñ²úÆ·,ÔÚÕâÀï±»×èÈû,¶øÉú²úÕßÓÖÎÞ·¨»ñµÃ»º³åÇøµÄËø½øÈ뻺³åÇø,Òò¶ø»á³öÏÖËÀËø
pthread_mutex_lock(&mutex);
Ïà¹ØÎĵµ£º
ÀýÒ»£º·¢ËÍSignaling Packet£º
Signaling CommandÊÇ2¸öBluetoothʵÌåÖ®¼äµÄL2CAP²ãÃüÁî´«Êä¡£ËùÒÔµÃSignaling CommandʹÓÃCID 0x0001.
¶à¸öCommand¿ÉÒÔÔÚÒ»¸öC-frame£¨control frame£©Öз¢ËÍ¡£
Èç¹ûÒªÖ±½Ó·¢ËÍSignaling Command.ÐèÒª½¨Á¢SOCK_RAWÀàÐ͵ÄL2CAPÁ¬½ÓSocket¡£ÕâÑù²ÅÓлú»á×Ô¼ºÌî³äCommand Code£¬Identi ......
Service Discovery Protocol(SDP)ÌṩһÖÖÄÜÁ¦£¬ÈÃÓ¦ÓóÌÐòÓз½·¨·¢ÏÖÄÄÖÖ·þÎñ¿ÉÓÃÒÔ¼°ÕâÖÖ·þÎñµÄÌØÐÔ¡£
·þÎñ·¢ÏÖÐÒé(SDP»òBluetooth SDP)ÔÚÀ¶ÑÀÐÒéÕ»ÖжÔÀ¶ÑÀ»·¾³ÖеÄÓ¦ÓóÌÐòÓÐÌØÊâµÄº¬Ò⣬·¢ÏÖÄĸö·þÎñÊÇ¿ÉÓõĺÍÈ·¶¨ÕâЩ¿ÉÓ÷þÎñµÄÌØÕ÷¡£SDP¶¨ÒåÁËbluetooth client·¢ÏÖ¿ÉÓÃbluetooth server·þÎñºÍËüÃǵÄÌØÕ÷µÄ·½·¨¡£ ......
ÏÖÔںöàµÄÈË¿ªÊ¼½Ó´¥µçÄÔµÄʱºò£¬¼ûµ½µÄÓ¦¸ÃÊÇWindows98
˵ʵ»°£¬98
ÒѾÊÇÒ»¸öºÜÈËÐÔ»¯£¬·â×°µÄºÜºÃµÄÒ»¸öϵͳÁËÒ»¸ö¶ÔµçÄÔÒ»Çϲ»Í¨µÄÈ˶¼ÄܺܿìµÄʹÓÃËü¡£ÕâÑùºÜ¶àÈ˶Ô"
µçÄÔ"
µÄÓ¡ÏóºÍÄÇЩºÍÎÒÒ»ÑùÒ»¿ªÊ¼½Ó´¥µÄÊÇDOS
ÈËÊǾøÈ»²»Í¬µÄ¡£ÔÚDOS
ʱ´ú£¬Èç¹ûÄã¶ÔµçÄԵĻù´¡Ö ......
ÓÃsecureCRT»òÕ߯äËûһЩ¿Í»§¶Ë¹¤¾ßµÇ½µ½Linux¿ÉÒÔ¿´µ½ËüÏÔʾÁËһЩÑÕÉ«£¬ÕâÊÇÔõô×öµ½µÄÄØ£¿
linuxÎı¾ÖÕ¶Ë¿ÉÒÔÀûÓÃÒ»¸ö¼òµ¥¶øÌØÊâµÄÃüÁîÀ´¿ØÖÆÑÕÉ«µÄÏÔʾ£º\033[<command>m£¬ ÆäÖÐcommand¾ÍÊÇÒ»¸öÊý×Ö
Èç¹ûÊÇÓÃechoÀ´ÏÔʾµÄ»°£¬±ØÐëÖ¸¶¨-e²ÎÊý£¬Èç
echo -e "\033[32mtest\033[0m"
ÆäÖÐÊý×Ö0±íʾ»Ö¸´Ö®Ç° ......