2 *----------------------------------------------------------------------------
3 * DRadio Tool for Poseidon
4 *----------------------------------------------------------------------------
5 * By Chris Hodges <chrisly@platon42.de>
10 #include <proto/dos.h>
11 #include <proto/exec.h>
12 #include <proto/poseidon.h>
14 #include "DRadioTool.h"
26 const char DRadioTool_prgname
[] = "DRadioTool";
27 static const char *template = "ON/S,OFF/S,FREQ/K/N,SCAN/S,AUTO/S,SIGNAL/S,UNIT/N/K";
28 const char DRadioTool_version
[] = "$VER: DRadioTool 1.1 (12.06.09) by Chris Hodges <chrisly@platon42.de>";
29 static IPTR ArgsArray
[ARGS_SIZEOF
];
30 static struct RDArgs
*ArgsHook
= NULL
;
34 AROS_UFP3(void, releasehook
,
35 AROS_UFPA(struct Hook
*, hook
, A0
),
36 AROS_UFPA(APTR
, pab
, A2
),
37 AROS_UFPA(struct NepClassDRadio
*, nch
, A1
));
39 struct NepClassDRadio
* SetupDRadio(void);
40 struct NepClassDRadio
* AllocDRadio(struct NepClassDRadio
*nch
);
41 void FreeDRadio(struct NepClassDRadio
*nch
);
43 AROS_UFH3(void, releasehook
,
44 AROS_UFHA(struct Hook
*, hook
, A0
),
45 AROS_UFHA(APTR
, pab
, A2
),
46 AROS_UFHA(struct NepClassDRadio
*, nch
, A1
))
49 /*psdAddErrorMsg(RETURN_WARN, (STRPTR) prgname,
51 Signal(nch
->nch_Task
, SIGBREAKF_CTRL_C
);
55 struct NepClassDRadio
* SetupDRadio(void)
57 struct NepClassDRadio
*nch
;
58 struct PsdDevice
*pd
= NULL
;
59 struct PsdAppBinding
*pab
;
62 if(ArgsArray
[ARGS_UNIT
])
64 unit
= *((ULONG
*) ArgsArray
[ARGS_UNIT
]);
72 pd
= psdFindDevice(pd
,
76 } while(pd
&& (unit
--));
80 PutStr("No D-Link/GemTek Radio found!\n");
83 if((nch
= psdAllocVec(sizeof(struct NepClassDRadio
))))
86 nch
->nch_ReleaseHook
.h_Entry
= (APTR
) releasehook
;
88 pab
= psdClaimAppBinding(ABA_Device
, pd
,
89 ABA_ReleaseHook
, &nch
->nch_ReleaseHook
,
98 PutStr("Couldn't allocate DRadio...\n");
100 psdReleaseAppBinding(pab
);
102 PutStr("Couldn't claim binding!\n");
106 PutStr("Hohum...\n");
111 struct NepClassDRadio
* AllocDRadio(struct NepClassDRadio
*nch
)
113 nch
->nch_Task
= FindTask(NULL
);
115 if((nch
->nch_TaskMsgPort
= CreateMsgPort()))
117 if((nch
->nch_EP0Pipe
= psdAllocPipe(nch
->nch_Device
, nch
->nch_TaskMsgPort
, NULL
)))
121 PutStr("Couldn't allocate default pipe\n");
123 DeleteMsgPort(nch
->nch_TaskMsgPort
);
129 void FreeDRadio(struct NepClassDRadio
*nch
)
133 psdGetAttrs(PGA_DEVICE
, nch
->nch_Device
,
136 psdReleaseAppBinding(pab
);
137 psdFreePipe(nch
->nch_EP0Pipe
);
138 DeleteMsgPort(nch
->nch_TaskMsgPort
);
142 void SetFreq(struct NepClassDRadio
*nch
, ULONG pll_div
)
145 psdPipeSetup(nch
->nch_EP0Pipe
, URTF_IN
|URTF_VENDOR
|URTF_DEVICE
, CMDID_SETFREQ
, (pll_div
>>8) & 0xff, pll_div
& 0xff);
146 ioerr
= psdDoPipe(nch
->nch_EP0Pipe
, nch
->nch_Buf
, 1);
149 Printf("Error sending set freq request: %s (%ld)\n",
150 psdNumToStr(NTS_IOERR
, ioerr
, "unknown"), ioerr
);
152 /*psdPipeSetup(nch->nch_EP0Pipe, URTF_IN|URTF_VENDOR|URTF_DEVICE, CMDID_CTRL, 0x9c, 0xb7);
153 ioerr = psdDoPipe(nch->nch_EP0Pipe, nch->nch_Buf, 1);
156 Printf("Error sending set freq request: %s (%ld)\n",
157 psdNumToStr(NTS_IOERR, ioerr, "unknown"), ioerr);
161 /**************************************************************************/
163 int main(int argc
, char *argv
[])
165 struct NepClassDRadio
*nch
;
167 ULONG pll_div
= (MIN_FREQ
*1000 + PLLFREQ
) / PLLSTEP
;
168 ULONG ret
= RETURN_OK
;
170 if(!(ArgsHook
= ReadArgs(template, ArgsArray
, NULL
)))
172 PutStr("Wrong arguments!\n");
175 ps
= OpenLibrary("poseidon.library", 1);
181 if(!(nch
= SetupDRadio()))
185 return(RETURN_ERROR
);
187 if(ArgsArray
[ARGS_ON
])
189 /*psdPipeSetup(nch->nch_EP0Pipe, URTF_IN|URTF_VENDOR|URTF_DEVICE, CMDID_GETSTEREO, 0x00, 0xC7);
190 ioerr = psdDoPipe(nch->nch_EP0Pipe, nch->nch_Buf, 1);
193 Printf("Error sending on request: %s (%ld)\n",
194 psdNumToStr(NTS_IOERR, ioerr, "unknown"), ioerr);
196 psdPipeSetup(nch
->nch_EP0Pipe
, URTF_IN
|URTF_VENDOR
|URTF_DEVICE
, CMDID_POWER
, 0x01, 0x00);
197 ioerr
= psdDoPipe(nch
->nch_EP0Pipe
, nch
->nch_Buf
, 1);
200 Printf("Error sending power on request: %s (%ld)\n",
201 psdNumToStr(NTS_IOERR
, ioerr
, "unknown"), ioerr
);
204 if(ArgsArray
[ARGS_OFF
])
206 /*psdPipeSetup(nch->nch_EP0Pipe, URTF_IN|URTF_VENDOR|URTF_DEVICE, CMDID_GETSTEREO, 0x16, 0x1C);
207 ioerr = psdDoPipe(nch->nch_EP0Pipe, nch->nch_Buf, 1);
210 Printf("Error sending off request: %s (%ld)\n",
211 psdNumToStr(NTS_IOERR, ioerr, "unknown"), ioerr);
213 psdPipeSetup(nch
->nch_EP0Pipe
, URTF_IN
|URTF_VENDOR
|URTF_DEVICE
, CMDID_POWER
, 0x00, 0x00);
214 ioerr
= psdDoPipe(nch
->nch_EP0Pipe
, nch
->nch_Buf
, 1);
217 Printf("Error sending mute request: %s (%ld)\n",
218 psdNumToStr(NTS_IOERR
, ioerr
, "unknown"), ioerr
);
221 if(ArgsArray
[ARGS_FREQ
])
224 freq
= *((ULONG
*) ArgsArray
[ARGS_FREQ
]);
225 if((freq
< MIN_FREQ
) || (freq
> MAX_FREQ
))
227 Printf("Value out of range. Must be between %ldKHz and %ldKHz.\n", MIN_FREQ
, MAX_FREQ
);
229 pll_div
= (freq
*1000 + PLLFREQ
) / PLLSTEP
;
230 SetFreq(nch
, pll_div
);
233 if(ArgsArray
[ARGS_SCAN
])
237 for(; pll_div
< (MAX_FREQ
*1000 + PLLFREQ
) / PLLSTEP
; pll_div
+= 16)
239 freq
= ((pll_div
* PLLSTEP
) - PLLFREQ
) / 1000;
240 SetFreq(nch
, pll_div
);
241 //Printf("Pll_Div: %ld\r", pll_div);
243 psdPipeSetup(nch
->nch_EP0Pipe
, URTF_IN
|URTF_VENDOR
|URTF_DEVICE
, CMDID_GETSTEREO
, 0x00, 0x00);
244 ioerr
= psdDoPipe(nch
->nch_EP0Pipe
, nch
->nch_Buf
, 1);
247 Printf("Error sending status request: %s (%ld)\n",
248 psdNumToStr(NTS_IOERR
, ioerr
, "unknown"), ioerr
);
251 if(!(nch
->nch_Buf
[0] & 0x01))
254 if(ArgsArray
[ARGS_AUTO
])
256 Printf("Found station at %ld.%ld MHz. Press Ctrl-C to keep.\n", freq
/1000, freq
% 1000);
259 Printf("%ld\n", freq
);
262 if(SetSignal(0,0) & SIGBREAKF_CTRL_C
)
269 SetFreq(nch
, last_pll
);
272 if(ArgsArray
[ARGS_SIGNAL
])
274 psdPipeSetup(nch
->nch_EP0Pipe
, URTF_IN
|URTF_VENDOR
|URTF_DEVICE
, CMDID_GETSTEREO
, 0x00, 0x00);
275 ioerr
= psdDoPipe(nch
->nch_EP0Pipe
, nch
->nch_Buf
, 1);
278 Printf("Error sending status request: %s (%ld)\n",
279 psdNumToStr(NTS_IOERR
, ioerr
, "unknown"), ioerr
);
281 if(nch
->nch_Buf
[0] & 0x01)