123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- #define BUILDING_OPENDOORS
- #include <string.h>
- #include <ctype.h>
- #include "OpenDoor.h"
- #include "ODStr.h"
- #include "ODTypes.h"
- #include "ODGen.h"
- #include "ODPlat.h"
- #include "ODCore.h"
- #include "ODKrnl.h"
- static char ODWaitNoCase(char *pszWaitFor, tODMilliSec WaitTime);
- #define ANSI_TRIES 1
- #define ANSI_WAIT 660
- #define RIP_TRIES 1
- #define RIP_WAIT 660
- #define ANSI_QUERY "\x1b[6n\r \r"
- #define ANSI_RESPONSE "\x1b["
- #define RIP_QUERY "\r\x1b[!\r \r"
- #define RIP_RESPONSE "RIP"
- #define MATCH_LEN 3
- ODAPIDEF void ODCALL od_autodetect(INT nFlags)
- {
- INT nCount;
-
- TRACE(TRACE_API, "od_autodetect()");
-
- if(!bODInitialized) od_init();
- OD_API_ENTRY();
-
-
- (void)nFlags;
-
- if(od_control.baud == 0)
- {
- od_control.user_ansi = TRUE;
- OD_API_EXIT();
- return;
- }
-
- if(!od_control.user_ansi)
- {
-
- od_clear_keybuffer();
-
- for(nCount = 0; nCount < ANSI_TRIES; ++nCount)
- {
-
-
- od_disp(ANSI_QUERY, strlen(ANSI_QUERY), FALSE);
-
-
- if(ODWaitNoCase(ANSI_RESPONSE, ANSI_WAIT))
- {
-
-
- od_control.user_ansi = TRUE;
- break;
- }
- }
- od_clear_keybuffer();
- }
-
- if(!od_control.user_rip)
- {
-
- od_clear_keybuffer();
-
- for(nCount = 0; nCount < RIP_TRIES; ++nCount)
- {
-
-
- od_disp(RIP_QUERY, strlen(RIP_QUERY), FALSE);
-
- if(ODWaitNoCase(RIP_RESPONSE, RIP_WAIT))
- {
-
-
- od_control.user_rip = TRUE;
- break;
- }
- }
- od_clear_keybuffer();
- }
- OD_API_EXIT();
- }
- static char ODWaitNoCase(char *pszWaitFor, tODMilliSec WaitTime)
- {
- tODTimer Timer;
- char szReceived[MATCH_LEN + 1];
- int nCount;
- char chReceived;
- int nMatchChars = MIN(MATCH_LEN, strlen(pszWaitFor));
- ASSERT(pszWaitFor != NULL);
- ASSERT(strlen(pszWaitFor) != 0);
- ASSERT(WaitTime >= 0);
- ODTimerStart(&Timer, WaitTime);
- for(nCount = 0; nCount <= MATCH_LEN; ++nCount)
- {
- szReceived[nCount] = '\0';
- }
- do
- {
- if((chReceived = od_get_key(FALSE)) != 0)
- {
- for(nCount = 0; nCount < MATCH_LEN - 1; ++ nCount)
- {
- szReceived[nCount] = szReceived[nCount + 1];
- }
- szReceived[MATCH_LEN - 1] = chReceived;
- if(strnicmp(szReceived + (MATCH_LEN - nMatchChars), pszWaitFor,
- nMatchChars) == 0)
- {
- return(TRUE);
- }
- }
- } while(!ODTimerElapsed(&Timer));
- return(FALSE);
- }
|