socket.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #ifndef __SOCKET_H_
  2. #define __SOCKET_H_
  3. #include "pt.h"
  4. #define SOCKET_NUM_MAX 2 //与模块相关,可以根据实际使用增减,ps:如果只使用一个,则定义为1即可
  5. typedef struct{
  6. unsigned char machine;
  7. unsigned char status;
  8. unsigned char tcpStatus;
  9. unsigned short port;
  10. char Ip[20];
  11. void (*UserHandle)(unsigned char );
  12. void (*RxCallBack)(unsigned char *, unsigned int);
  13. void (*SockeShutDown)(unsigned char );
  14. }__attribute__ ((packed)) SOCKET_INFO;
  15. typedef struct{
  16. unsigned char index;
  17. SOCKET_INFO socketList[SOCKET_NUM_MAX];
  18. }__attribute__ ((packed)) SOCKET_DEF;
  19. extern SOCKET_DEF gSocket;
  20. PT_THREAD (ptSocketTask(struct pt *pt));
  21. void tcpSocketInit(void);
  22. short tcpSocketAdd(void (*UserHandle)(unsigned char socketID),void (*RxCallBack)(unsigned char *data , unsigned int),void (*SockeShutDown)(unsigned char socketID),char *ipAddr, unsigned short port);
  23. void tcpSocketDel(short socketID);
  24. char tcpSocketSendData(unsigned char socketID,unsigned char *data, unsigned int length);
  25. void tcpSocketStatusUpdate(char socketID, char status,char type);
  26. char tcpSocketGetStatus(char socketID);
  27. void SocketParaUpdate(unsigned char socketID,char *ipAddr, unsigned short port);
  28. #endif