#include <exec/types.h>
#include <exec/io.h>
#include <exec/libraries.h>
#include <FastTrak.h>

int   SendSCSIcmd(int,UWORD *,ULONG,int);    /* Function prototype */

struct   MsgPort        *MyPort;
struct   IOStdReq       *Req;
int      Actual;

main(argc,argv)
int   argc;
char **argv;
{
int   j,unit;
char  *ptr;
UBYTE junk[2];

   if ((argc<2)||(argv[1][0]=='?')) {
      printf("Usage: %ls <unit>\n",argv[0]);
      exit(0);
   }

   j=0;
   ptr = argv[1];
   while (*ptr) {
      j *= 10;
      j += *ptr - 48;
      ptr++;
   }

   unit = j;

   printf("Testing for unit %ld...\n",unit);
   if (SendSCSIcmd(unit,(UWORD *)junk,0,CMD_TUR)) {
      printf("Test failed\n");
   }
   else {
      printf("OK\n");
   }
}


int SendSCSIcmd(unit,addr,len,cmd)
ULONG len;
int   unit,cmd;
UWORD *addr;
{
   int   status;
   int   OpenFlag = 1;

   status = -1;

   MyPort = (struct MsgPort *)CreatePort("ft_Tools",0);
   if (MyPort) {
      Req = (struct IOStdReq *)CreateStdIO(MyPort);
      if (Req) {
         OpenFlag = OpenDevice("harddisk.device",unit,Req,0);
         if (!OpenFlag) {

            Req->io_Command = cmd;
            Req->io_Length = len;
            Req->io_Data = (APTR)addr;
            DoIO(Req);
            status = Req->io_Error;
            Actual = Req->io_Actual;

            CloseDevice(Req);
         }
         DeleteStdIO(Req);
      }
      DeletePort(MyPort);
   }
   return(status);
}
