2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
9 /*********************************************************************************************/
14 #include <aros/debug.h>
16 #include <prefs/prefhdr.h>
17 #include <prefs/serial.h>
19 static BOOL
LoadSerialPrefs(STRPTR filename
, struct SerialPrefs
* serialprefs
);
21 static const ULONG buffersizes
[] =
32 /*********************************************************************************************/
34 void SerialPrefs_Handler(STRPTR filename
)
36 static struct SerialPrefs serialprefs
;
37 D(bug("In IPrefs:SerialPrefs_Handler\n"));
38 D(bug("filename=%s\n",filename
));
39 if (TRUE
== LoadSerialPrefs(filename
, &serialprefs
)) {
40 struct Preferences prefs
;
42 GetPrefs(&prefs
, sizeof(prefs
));
44 while (-1 != buffersizes
[index
]) {
45 if (buffersizes
[index
] == serialprefs
.sp_InputBuffer
)
50 if (-1 == buffersizes
[index
])
53 D(bug("Setting new serial prefs.\n"));
54 D(bug("Setting baudrate to %d\n",serialprefs
.sp_BaudRate
));
55 D(bug("Setting receive buffer size to %d\n",buffersizes
[index
]));
56 D(bug("Setting read bit len to %d\n",8-serialprefs
.sp_BitsPerChar
));
57 D(bug("Setting write bit len to %d\n",8-serialprefs
.sp_BitsPerChar
));
58 D(bug("Setting stop bits to %d\n",1+serialprefs
.sp_StopBits
));
60 prefs
.BaudRate
= serialprefs
.sp_BaudRate
;
61 prefs
.SerRWBits
= (serialprefs
.sp_BitsPerChar
<< 4) | serialprefs
.sp_BitsPerChar
;
62 prefs
.SerStopBuf
= (serialprefs
.sp_StopBits
<< 4) | index
;
63 prefs
.SerParShk
= (serialprefs
.sp_Parity
<< 4) | serialprefs
.sp_InputHandshake
;
65 SetPrefs(&prefs
, sizeof(prefs
), TRUE
);
68 /*********************************************************************************************/
70 static BOOL
LoadSerialPrefs(STRPTR filename
, struct SerialPrefs
* serialprefs
)
72 struct IFFHandle
*iff
;
75 D(bug("LoadPrefs: Trying to open \"%s\"\n", filename
));
77 if ((iff
= AllocIFF()))
79 if ((iff
->iff_Stream
= (IPTR
)Open(filename
, MODE_OLDFILE
)))
81 D(bug("LoadPrefs: stream opened.\n"));
85 if (!OpenIFF(iff
, IFFF_READ
))
87 D(bug("LoadPrefs: OpenIFF okay.\n"));
89 if (!StopChunk(iff
, ID_PREF
, ID_SERL
))
91 D(bug("LoadPrefs: StopChunk okay.\n"));
93 if (!ParseIFF(iff
, IFFPARSE_SCAN
))
95 struct ContextNode
*cn
;
97 D(bug("LoadPrefs: ParseIFF okay.\n"));
99 cn
= CurrentChunk(iff
);
101 if (cn
->cn_Size
== sizeof(struct SerialPrefs
))
103 D(bug("LoadPrefs: ID_SERL chunk size okay.\n"));
105 if (ReadChunkBytes(iff
, serialprefs
, sizeof(struct SerialPrefs
)) == sizeof(struct SerialPrefs
))
107 D(bug("LoadSerialPrefs: Reading chunk successful.\n"));
109 D(bug("LoadSerialPrefs: Everything okay :-)\n"));
115 } /* if (!ParseIFF(iff, IFFPARSE_SCAN)) */
117 } /* if (!StopChunk(iff, ID_PREF, ID_SERL)) */
121 } /* if (!OpenIFF(iff, IFFF_READ)) */
123 Close((BPTR
)iff
->iff_Stream
);
125 } /* if ((iff->iff_Stream = (IPTR)Open(filename, MODE_OLDFILE))) */
129 } /* if ((iff = AllocIFF())) */