25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

105 lines
2.2 KiB

  1. #include "define.h"
  2. #include "PrintfServer.h"
  3. #ifdef USE_WINC1500
  4. #else
  5. #include "TCPIP_Stack/TCPIP.h"
  6. #endif
  7. #include <stdio.h>
  8. //BYTE vTelnetSession;
  9. WORD w, w2;
  10. #ifdef USE_WINC1500
  11. #else
  12. TCP_SOCKET MyPrintfSocket;
  13. #endif
  14. char mPrintfString[1024]; //Make shure this string is at least as big as the heap
  15. BOOL mPrintfAvailable;
  16. int OpenPrintfServer()
  17. {
  18. memset(mPrintfString,'\0',1024);
  19. #ifdef USE_WINC1500
  20. return 0;
  21. #else
  22. MyPrintfSocket = TCPOpen(0, TCP_OPEN_SERVER, 6463, TCP_PURPOSE_GENERIC_TCP_SERVER);
  23. if (MyPrintfSocket == INVALID_SOCKET)
  24. {
  25. return 0;
  26. }
  27. mPrintfAvailable = FALSE;
  28. return 1;
  29. #endif
  30. }
  31. void TickPrintfServer()
  32. {
  33. int length;
  34. static int PrintfServerTickState = PRINTF_SERVER_INIT_STATE;
  35. switch(PrintfServerTickState)
  36. {
  37. case PRINTF_SERVER_INIT_STATE:
  38. {
  39. if(OpenPrintfServer() == 1)
  40. {
  41. PrintfServerTickState = PRINTF_SERVER_RUN_STATE;
  42. }
  43. break;
  44. }
  45. case PRINTF_SERVER_RUN_STATE:
  46. {
  47. #ifdef USE_WINC1500
  48. #else
  49. if(TCPIsConnected(MyPrintfSocket) == FALSE)
  50. {
  51. mPrintfAvailable = FALSE;
  52. return;
  53. }
  54. else
  55. {
  56. if(mPrintfAvailable == FALSE)
  57. {
  58. mPrintfAvailable = TRUE;
  59. TCPPutString(MyPrintfSocket,"Sprinkler printf console\n");
  60. }
  61. }
  62. length = (int)strlen(mPrintfString);
  63. if(length > 0 /*&& TCPIsPutReady(MySocket) > length*/)
  64. {
  65. TCPPutString(MyPrintfSocket,mPrintfString);
  66. memset(mPrintfString,'\0',1024);
  67. }
  68. #endif
  69. break;
  70. }
  71. }
  72. }
  73. void TelnetPutPrintf(char c)
  74. {
  75. if(mPrintfAvailable == FALSE)
  76. return;
  77. // if(strlen(mPrintfString) >= 1000)
  78. // return;
  79. //
  80. // strncat(mPrintfString,&c,1);
  81. #ifdef USE_WINC1500
  82. #else
  83. TCPPut(MyPrintfSocket,c);
  84. #endif
  85. // TCPFlush(MyPrintfSocket);
  86. }