#include "MAIN.h"
#define port 444 //port number
//port = 18017;
typedef unsigned _int8 uint8;
typedef unsigned _int16 uint16;
typedef unsigned _int32 uint32;
uint32 measurements[18];
void XcpApp_IpTransmit(uint16, Xcp_StatePtr8, uint16);
void main(void)
{
#ifdef XCP_ENABLE
/*initialise the XCP Ecu Softwares */
Xcp_Initialize();
#endif
//initialize before start of the operating system
while(1)
{
Timer1();
Timer2();
Timer3();
}
}
/ 此行中的错误 / void XcpApp_IpTransmit(uint16 port,Xcp_StatePtr8 pBytes,uint16 numBytes)//此函数必须在端口标识的IP连接上传输指定的字节 {
pBytes = &measurements; // pBytes points to address of the memory
numBytes = 8; //number of bytes at pBytes.
struct sockaddr_in server; // creating a socket address structure: structure contains ip address and port number
WSADATA wsa;
SOCKET s;
int len;
//int bytes_recieved;
//char send_data[1024],recv_data[1024];
printf("Initializing Winsock\n");
if(WSAStartup(MAKEWORD(2,2), &wsa)!=0)
{
printf("Failed Error Code: %d", WSAGetLastError());
return 1;
}
printf("Initialised\n");
//CREATING a SOCKET
if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
printf("Could not Create Socket\n");
return 0;
}
printf("Socket Created\n");
server.sin_addr.s_addr = inet_addr("127.0.0.1");
server.sin_family = AF_INET;
server.sin_port = htons("port");
len = sizeof(server);
//SENDING a data
/* bzero(&(server_addr.sin_zero),8);
if (connect(sock, (struct sockaddr *)&server_addr,
sizeof(struct sockaddr)) == -1)
{
perror("Connect");
exit(1);
}*/
while(1)
{
//bytes_recieved=recv(s,recv_data,1024,0)
numBytes=recvfrom(s, pBytes, 8, 0, (struct sockaddr*)&server, &len);
pBytes[numBytes] = '\0';
if (strcmp(pBytes , "q") == 0 || strcmp(pBytes , "Q") == 0)
{
close(s);
break;
}
/* else
printf("\nreceived data = %s " , pBytes);*/
// XcpIp_RxCallback (chunkLen, pChunkData, port);
/*
printf("\nSEND (q or Q to quit) : ");
gets(send_data);
if (strcmp(send_data , "q") != 0 && strcmp(send_data , "Q") != 0)
send(s,send_data,strlen(send_data), 0); */
else
{
//after the data has ben transmitted
XcpIp_TxCallback (port, numTxBytes);
//send(s,send_data,strlen(send_data), 0);
closesocket(s);
WSACleanup();
break;
}
}
}
我创建了一个18 * 4字节的内存,指定了端口号,后来我调用了一个函数
void XcpApp_IpTransmit(uint16, Xcp_StatePtr8, uint16);
将数据从内存传输到指定的端口号。我在main函数中执行一些任务。稍后为被调用函数编写函数定义(创建套接字并通过端口号和IP地址发送数据)
我收到这样的错误:
error C2143: syntax error : missing ')' before 'constant'
error C2143: syntax error : missing '{' before 'constant'
error C2059: syntax error : '<Unknown>'
error C2059: syntax error : ')'
有没有人可以帮我解决这个错误(错误是在函数体中的空格XcpApp_IpTransmit(uint16,Xcp_StatePtr8,uint16))???????
答案 0 :(得分:0)
如果这是C
程序,我可以看到的第一个错误是函数XcpApp_IpTransmit()
中的变量声明不是它们范围的第一行。
换句话说,尝试将该函数的前几行更改为以下内容:
void XcpApp_IpTransmit(uint16 port, Xcp_StatePtr8 pBytes, uint16 numBytes) // this function must transmit the specified byte on IP connection identified by port
{
struct sockaddr_in server; // creating a socket address structure: structure contains ip address and port number
WSADATA wsa;
SOCKET s;
int len;
//int bytes_recieved;
//char send_data[1024],recv_data[1024];
pBytes = &measurements; // pBytes points to address of the memory
numBytes = 8; //number of bytes at pBytes.
printf("Initializing Winsock\n");
...
}
答案 1 :(得分:0)
由于行
#define port 444 //port number
声明
void XcpApp_IpTransmit(uint16 port, Xcp_StatePtr8 pBytes, uint16 numBytes)
变成了
void XcpApp_IpTransmit(uint16 444, Xcp_StatePtr8 pBytes, uint16 numBytes)
由预处理器。 444
是编译器抱怨的'constant'
。