【发布时间】:2013-12-02 08:31:22
【问题描述】:
#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();
}
}
/ERROR IN THIS LINE/ 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); 将数据从内存传输到指定的端口号。我正在主要功能中执行一些任务。稍后为被调用函数编写函数定义(创建一个套接字并通过端口号和IP地址发送数据)
我收到这样的错误:
error C2143: syntax error : missing ')' before 'constant'
error C2143: syntax error : missing '{' before 'constant'
error C2059: syntax error : '<Unknown>'
error C2059: syntax error : ')'
谁能帮我解决这个错误(错误在函数体 void XcpApp_IpTransmit(uint16, Xcp_StatePtr8, uint16))???????
【问题讨论】:
-
检查导致语法错误的最佳方法是注释部分程序并验证错误是否消失。这样做直到找到有问题的地方。你可以自己做。
-
你能把代码贴在 MAIN.h 里吗?
-
发布 MAIN.h,也许有帮助
-
#pragma once #pragma comment (lib, "ws2_32.lib") typedef unsigned _int16 uint16; typedef 无符号 _int32 uint32; typedef _int32 int32; typedef 无符号 _int8 uint8; typedef unsigned long uint32; #include
#include #include #include "xcp.h" #include "LocatedVars.h" #include #include "Task2ms.h" #包括 "Task10ms.h" #include "Task100ms.h" #include "TIMER1.h" #include "TIMER2.h" #include "TIMER3.h" #include "xcp_pub.h" #include "xcpip_pub.h" #include "stopwatch.h" #include "xcp_common.h" #include "xcp_auto_conf.h"#include "xcp_auto_confpriv.h" -
请将相关信息添加到问题本身,但将其压缩到 cmets 中,很难阅读。谢谢。