Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * runRemote.c:
  3. * Run the remote commands passed over the network link.
  4. *
  5. * Copyright (c) 2012-2017 Gordon Henderson
  6. ***********************************************************************
  7. * This file is part of wiringPi:
  8. * https://github.com/WiringPi/WiringPi/
  9. *
  10. * wiringPi is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Lesser General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * wiringPi is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public License
  21. * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
  22. ***********************************************************************
  23. */
  24. #include <arpa/inet.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <stdint.h>
  28. #include <unistd.h>
  29. #include <string.h>
  30. #include <errno.h>
  31. //#include <stdarg.h>
  32. #include <wiringPi.h>
  33. #include <wpiExtensions.h>
  34. #include "drcNetCmd.h"
  35. #include "network.h"
  36. #include "runRemote.h"
  37. int noLocalPins = FALSE ;
  38. void runRemoteCommands (int fd)
  39. {
  40. register uint32_t pin ;
  41. int len ;
  42. struct drcNetComStruct cmd ;
  43. len = sizeof (struct drcNetComStruct) ;
  44. if (setsockopt (fd, SOL_SOCKET, SO_RCVLOWAT, (void *)&len, sizeof (len)) < 0)
  45. return ;
  46. for (;;)
  47. {
  48. if (recv (fd, &cmd, sizeof (cmd), 0) != sizeof (cmd)) // Probably remote hangup
  49. return ;
  50. pin = cmd.pin ;
  51. if (noLocalPins && ((pin & PI_GPIO_MASK) == 0))
  52. {
  53. if (send (fd, &cmd, sizeof (cmd), 0) != sizeof (cmd))
  54. return ;
  55. continue ;
  56. }
  57. switch (cmd.cmd)
  58. {
  59. case DRCN_PIN_MODE:
  60. pinMode (pin, cmd.data) ;
  61. if (send (fd, &cmd, sizeof (cmd), 0) != sizeof (cmd))
  62. return ;
  63. break ;
  64. case DRCN_PULL_UP_DN:
  65. pullUpDnControl (pin, cmd.data) ;
  66. break ;
  67. case DRCN_PWM_WRITE:
  68. pwmWrite (pin, cmd.data) ;
  69. if (send (fd, &cmd, sizeof (cmd), 0) != sizeof (cmd))
  70. return ;
  71. break ;
  72. case DRCN_DIGITAL_WRITE:
  73. digitalWrite (pin, cmd.data) ;
  74. if (send (fd, &cmd, sizeof (cmd), 0) != sizeof (cmd))
  75. return ;
  76. break ;
  77. case DRCN_DIGITAL_WRITE8:
  78. //digitalWrite8 (pin, cmd.data) ;
  79. if (send (fd, &cmd, sizeof (cmd), 0) != sizeof (cmd))
  80. return ;
  81. break ;
  82. case DRCN_DIGITAL_READ:
  83. cmd.data = digitalRead (pin) ;
  84. if (send (fd, &cmd, sizeof (cmd), 0) != sizeof (cmd))
  85. return ;
  86. break ;
  87. case DRCN_DIGITAL_READ8:
  88. //cmd.data = digitalRead8 (pin) ;
  89. if (send (fd, &cmd, sizeof (cmd), 0) != sizeof (cmd))
  90. return ;
  91. break ;
  92. case DRCN_ANALOG_WRITE:
  93. analogWrite (pin, cmd.data) ;
  94. if (send (fd, &cmd, sizeof (cmd), 0) != sizeof (cmd))
  95. return ;
  96. break ;
  97. case DRCN_ANALOG_READ:
  98. cmd.data = analogRead (pin) ;
  99. if (send (fd, &cmd, sizeof (cmd), 0) != sizeof (cmd))
  100. return ;
  101. break ;
  102. }
  103. }
  104. }