ibClr.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /***************************************************************************
  2. lib/ibClr.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 ibclr( int ud )
  18. {
  19. uint8_t cmd[ 16 ];
  20. ibConf_t *conf;
  21. ibBoard_t *board;
  22. ssize_t count;
  23. int i;
  24. conf = enter_library( ud );
  25. if( conf == NULL )
  26. return exit_library( ud, 1 );
  27. board = interfaceBoard( conf );
  28. if( conf->is_interface )
  29. {
  30. setIberr( EARG );
  31. return exit_library( ud, 1 );
  32. }
  33. i = send_setup_string( conf, cmd );
  34. cmd[ i++ ] = SDC;
  35. //XXX detect no listeners (EBUS) error
  36. count = my_ibcmd( conf, cmd, i );
  37. if(count != i)
  38. {
  39. return exit_library( ud, 1 );
  40. }
  41. return exit_library( ud, 0 );
  42. }
  43. int InternalDevClearList( ibConf_t *conf, const Addr4882_t addressList[] )
  44. {
  45. int i;
  46. ibBoard_t *board;
  47. uint8_t *cmd;
  48. int count;
  49. if( addressListIsValid( addressList ) == 0 )
  50. {
  51. return -1;
  52. }
  53. if( conf->is_interface == 0 )
  54. {
  55. setIberr( EDVR );
  56. return -1;
  57. }
  58. board = interfaceBoard( conf );
  59. if( is_cic( board ) == 0 )
  60. {
  61. setIberr( ECIC );
  62. return -1;
  63. }
  64. cmd = malloc( 16 + 2 * numAddresses( addressList ) );
  65. if( cmd == NULL )
  66. {
  67. setIberr( EDVR );
  68. setIbcnt( ENOMEM );
  69. return -1;
  70. }
  71. i = 0;
  72. if( numAddresses( addressList ) )
  73. {
  74. i += create_send_setup( board, addressList, cmd );
  75. cmd[ i++ ] = SDC;
  76. }
  77. else
  78. {
  79. cmd[ i++ ] = DCL;
  80. }
  81. //XXX detect no listeners (EBUS) error
  82. count = my_ibcmd( conf, cmd, i );
  83. free( cmd );
  84. cmd = NULL;
  85. if(count != i)
  86. {
  87. return -1;
  88. }
  89. return 0;
  90. }
  91. void DevClearList( int boardID, const Addr4882_t addressList[] )
  92. {
  93. int retval;
  94. ibConf_t *conf;
  95. conf = enter_library( boardID );
  96. if( conf == NULL )
  97. {
  98. exit_library( boardID, 1 );
  99. return;
  100. }
  101. retval = InternalDevClearList( conf, addressList );
  102. if( retval < 0 )
  103. exit_library( boardID, 1 );
  104. exit_library( boardID, 0 );
  105. }
  106. void DevClear( int boardID, Addr4882_t address )
  107. {
  108. Addr4882_t addressList[2];
  109. addressList[0] = address;
  110. addressList[1] = NOADDR;
  111. DevClearList( boardID, addressList );
  112. }