LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 673|回复: 1

求助:消息队列的收发函数不能使用而创建函数能为什么?

[复制链接]
发表于 2006-5-7 19:52:42 | 显示全部楼层 |阅读模式
错误提示:
b.c: In function `send_message':
b.c:73: incompatible type for argument 2 of `msgsnd'
b.c: In function `read_message':
b.c:85: incompatible type for argument 2 of `msgrcv'

源程序:

#include <errno.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>

#define refextcon (*(volatile unsigned *)0x03FF303c)
#define extacon1  (*(volatile unsigned *)0x03FF300c)
#define extacon0  (*(volatile unsigned *)0x03FF3008)
#define extdbwth  (*(volatile unsigned *)0x03FF3010)
#define iopmod    (*(volatile unsigned *)0x03FF5000)          /*iop mode register*/
#define iopdata   (*(volatile unsigned *)0x03FF5008)         /*iop data register*/

#define ADC_CH0                (*(volatile unsigned char *)0x03F00060) /*ADC Channel 0*/
#define ADC_CH1                (*(volatile unsigned char *)0x03F00061) /*ADC Channel 1*/
#define ADC_CH2                (*(volatile unsigned char *)0x03F00062) /*ADC Channel 2*/
#define ADC_CH3                (*(volatile unsigned char *)0x03F00063) /*ADC Channel 3*/
#define ADC_CH4                (*(volatile unsigned char *)0x03F00064) /*ADC Channel 4*/
#define ADC_CH5                (*(volatile unsigned char *)0x03F00065) /*ADC Channel 5*/
#define ADC_CH6                (*(volatile unsigned char *)0x03F00066) /*ADC Channel 6*/
#define ADC_CH7                (*(volatile unsigned char *)0x03F00067) /*ADC Channel 7*/

#define LED1                  (*(volatile unsigned char*)0x03F00000) /*DS4*/
#define LED2                  (*(volatile unsigned char*)0x03F00010) /*DS3*/
#define LED3                  (*(volatile unsigned char*)0x03F00020) /*DS2*/
#define LED4                  (*(volatile unsigned char*)0x03F00030) /*DS1*/

#define maxline 5

#define ordernum (long)('o')
#define presentnum (long)('p')

extern int errno;

unsigned char led[11]={0xb7,0x06,0x73,0x57,0xc6,0xd5,0xf5,0x07,0xf7,0xd7,0x0};

char show[11]={'0','1','2','3','4','5','6','7','8','9','10'};

key_t key=12345;

struct mymesg{
        long mtype;
char mtext[10];
}

/*error*/
report_error(char *s)                    
{
printf("receiver:error in %s,errno=%d\n",s,errno);
perror("error type");
exit(1);
}

/*open or creat a queue(error:-1;true:qid)*/
int open_queue(key_t keyval)
{
int qid;
if((qid=msgget(keyval,IPC_CREAT|0760))==-1)
{return(-1);}
return(qid);
}

/*send message to an opened queue(error:-1;true:0)*/
int send_message(int qid,char sbuf[maxline],long type)
{
struct mymesg qbuf;
int result,length;
qbuf.mtype = type;
strcpy(qbuf.mtext,sbuf);
length=sizeof(struct mymesg)-sizeof(long);
if((result=msgsnd(qid,qbuf,length,0))==-1)
  {return(-1);}
return(result);
}

/* Read a message from the queue(true:the read message size;have no message:0)*/
int read_message(int qid,char sbuf[maxline],long type)
{
struct mymesg qbuf;
int result,length;
qbuf.mtype = type;
length=sizeof(struct mymesg)-sizeof(long);
if((result=msgrcv(qid,qbuf,length,type,IPC_NOWAIT))==-1)
return(0);
else {
       strcpy(sbuf,qbuf.mtext);
        return(result);
     }
}

void Delay(unsigned int x)
{
        unsigned int i,j,k;
        for(i=0;i<=x;i++)
                for(j=0;j<255;j++)
                        for(k=0;k<255;k++);
}

/*change the binary to char*/
disp(char adc,char charnum[5])
{
        unsigned char temp;
        temp=adc;
        adc=adc/1000;
        LED1=led[adc];
        charnum[0]=show[adc];
        temp=temp-1000*adc;
        adc=temp;
        adc=adc/100;
        LED2=led[adc];
        charnum[1]=show[adc];
        temp=temp-100*adc;
        adc=temp;
        adc=adc/10;
        LED3=led[adc];
        charnum[2]=show[adc];
        temp=temp-10*adc;
        LED4=led[temp];
        charnum[3]=show[temp];
        charnum[4]='\0';
}

int compare(char onum[5],char pnum)
{
int flag=0,onumber=0;
onumber=(onum[0]-48)*1000+(onum[1]-48)*100+(onum[2]-48)*10+onum[3]-48;
flag=onumber-pnum;
return(flag);
}


main()
{       
        unsigned char adc,cpe;
        char snum[maxline]="",gnum[maxline]="";
        int flag=0,qidx;
        refextcon=0xce2783f0;
        extacon1=0x0fffffff;
        extacon0=0x0fffffff;
        extdbwth=0x05503002;
        iopmod=0xff;
        iopdata=0xff;
/*establish or open a message queue*/
        if((qidx=open_queue(key))==-1)
                    report_error("establish or open a message queue");
        for(;;){
                 ADC_CH0=0x0;        /*启动ADC,延时等待,并读取转换结果*/
                 Delay(5);
                 if(read_message(qidx,NULL,presentnum)==0)
                            printf("read no message/n");
                 if(send_message(qidx,snum,presentnum)==-1)
                        report_error("send message");
                 if(read_message(qidx,gnum,ordernum)==0)
                        printf("read no message/n");
                 flag=compare(gnum,cpe);
                 if(flag==0)           /*the present num equal the order's num*/
                         iopdata=0x00;
                 else if(flag<0)    /*the present num big than the order's num*/
                        iopdata=0x10;
                 else             /*the present num small than the order's num*/
                        iopdata=0x20;
                 adc=cpe=ADC_CH0;       
                 disp(adc,snum);        /*在LED显示器上显示ADC结果*/
                }
}
 楼主| 发表于 2006-5-8 13:22:35 | 显示全部楼层
我知道了,是参数的类型不对。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表