ibTrg.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /***************************************************************************
  2. lib/ibTrg.c
  3. -------------------
  4. copyright : (C) 2001,2002 by Frank Mori Hess
  5. email : fmhess@users.sourceforge.net
  6. ***************************************************************************/
  7. /***************************************************************************
  8. * *
  9. * This program is free software; you can redistribute it and/or modify *
  10. * it under the terms of the GNU General Public License as published by *
  11. * the Free Software Foundation; either version 2 of the License, or *
  12. * (at your option) any later version. *
  13. * *
  14. ***************************************************************************/
  15. #include "ib_internal.h"
  16. #include <stdlib.h>
  17. int my_trigger( ibConf_t *conf, const Addr4882_t addressList[] )
  18. {
  19. int i, retval;
  20. uint8_t *cmd;
  21. if( addressListIsValid( addressList ) == 0 )
  22. {
  23. setIberr( EARG );
  24. return -1;
  25. }
  26. cmd = malloc( 16 + 2 * numAddresses( addressList ) );
  27. if( cmd == NULL )
  28. {
  29. setIberr( EDVR );
  30. setIbcnt( ENOMEM );
  31. return -1;
  32. }
  33. i = create_send_setup( interfaceBoard( conf ), addressList, cmd );
  34. cmd[ i++ ] = GET;
  35. retval = my_ibcmd( conf, cmd, i );
  36. free( cmd );
  37. cmd = NULL;
  38. if( retval != i )
  39. {
  40. return -1;
  41. }
  42. return 0;
  43. }
  44. int ibtrg( int ud )
  45. {
  46. ibConf_t *conf;
  47. int retval;
  48. Addr4882_t addressList[ 2 ];
  49. conf = enter_library( ud );
  50. if( conf == NULL )
  51. return exit_library( ud, 1 );
  52. if( conf->is_interface )
  53. {
  54. setIberr( EARG );
  55. return exit_library( ud, 1 );
  56. }
  57. addressList[ 0 ] = packAddress( conf->settings.pad, conf->settings.sad );
  58. addressList[ 1 ] = NOADDR;
  59. retval = my_trigger( conf, addressList );
  60. if( retval < 0 )
  61. {
  62. return exit_library( ud, 1 );
  63. }
  64. return exit_library( ud, 0 );
  65. }
  66. void TriggerList( int boardID, const Addr4882_t addressList[] )
  67. {
  68. ibConf_t *conf;
  69. int retval;
  70. conf = enter_library( boardID );
  71. if( conf == NULL )
  72. {
  73. exit_library( boardID, 1 );
  74. return;
  75. }
  76. if( conf->is_interface == 0 )
  77. {
  78. setIberr( EDVR );
  79. exit_library( boardID, 1 );
  80. return;
  81. }
  82. retval = my_trigger( conf, addressList );
  83. if( retval < 0 )
  84. {
  85. exit_library( boardID, 1 );
  86. return;
  87. }
  88. exit_library( boardID, 0 );
  89. }
  90. void Trigger( int boardID, Addr4882_t address )
  91. {
  92. Addr4882_t addressList[ 2 ];
  93. addressList[ 0 ] = address;
  94. addressList[ 1 ] = NOADDR;
  95. TriggerList( boardID, addressList );
  96. }