通过XML-RPC发送远程信号

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通过XML-RPC发送远程信号相关的知识,希望对你有一定的参考价值。

  1. use Linux::Input::Wiimote;
  2.  
  3. require RPC::XML;
  4. require RPC::XML::Client;
  5.  
  6.  
  7. print "remote control ... ";
  8.  
  9. my $cli = RPC::XML::Client->new("http://localhost:9191");
  10. my $wii = new Linux::Input::Wiimote;
  11.  
  12. ##############################
  13. sub get_device_id {
  14. my $dev = $wii->wiimote_discover();
  15. print $dev;
  16. if ($dev eq 0){
  17.  
  18. print "Not found device, exit now ";
  19. #exit(0);
  20. }else{ print "Found dev $dev"; }
  21. return $dev;
  22. }
  23.  
  24. ##############################
  25. my $dev = 0;
  26. while ($dev eq 0){
  27. print "Press 1+2 ... ";
  28. $dev = get_device_id();
  29. }
  30.  
  31. $wii->wiimote_connect("00:1$dev");
  32.  
  33. while (1){
  34. $wii->wiimote_update();
  35. my $keys = "RELEASE";
  36. if($wii->get_wiimote_keys_down && $wii->get_wiimote_keys_b){
  37. $keys = "B-DOWN";
  38. }elsif ($wii->get_wiimote_keys_up && $wii->get_wiimote_keys_b){
  39. $keys = "B-UP";
  40. }elsif ($wii->get_wiimote_keys_left && $wii->get_wiimote_keys_b){
  41. $keys = "B-LEFT";
  42. }elsif ($wii->get_wiimote_keys_right && $wii->get_wiimote_keys_b){
  43. $keys = "B-RIGHT";
  44. }elsif ($wii->get_wiimote_keys_a && $wii->get_wiimote_keys_b){
  45. $keys = "B-A";
  46. }elsif($wii->get_wiimote_keys_down()){
  47. $keys = "DOWN";
  48. }elsif ($wii->get_wiimote_keys_right()){
  49. $keys = "RIGHT";
  50. }elsif ($wii->get_wiimote_keys_up()){
  51. $keys = "UP";
  52. }elsif ($wii->get_wiimote_keys_left()){
  53. $keys = "LEFT";
  54. }elsif ($wii->get_wiimote_keys_a()){
  55. $keys = "A";
  56. }elsif ($wii->get_wiimote_keys_b()){
  57. $keys = "B";
  58. }elsif ($wii->get_wiimote_keys_1()){
  59. $keys = "1";
  60. }elsif ($wii->get_wiimote_keys_2()){
  61. $key = "2";
  62. }elsif ($wii->get_wiimote_keys_home()){
  63. $keys = "HOME";
  64. }elsif ($wii->get_wiimote_keys_minus()){
  65. $keys = "MINUS";
  66. }elsif ($wii->get_wiimote_keys_plus()){
  67. $keys = "PLUS";
  68. }else {
  69. $keys = "RELEASE";
  70. }
  71.  
  72. #print $keys;
  73. print "wearetherock ok $keys ";
  74. $cli->send_request("updateState", $keys);
  75. }

以上是关于通过XML-RPC发送远程信号的主要内容,如果未能解决你的问题,请参考以下文章

XML-RPC远程方法调用

XML-RPC笔记

XML-RPC(remote procedure call 远程过程调用远端程序呼叫)(一种通过XML将调用函数封装,并使用HTTP协议作为传送机制的分布式计算协议)

如何在 python 中发送 xml-rpc 请求?

如何从 PHP 访问 XML-RPC 数据?

Python:XML-RPC介绍