From 3d3d14263ab51bcf27658b2f6280209178004a33 Mon Sep 17 00:00:00 2001 From: follower Date: Sat, 8 Dec 2007 03:13:10 +0000 Subject: [PATCH] Use new 'readMatch' routine to match start of the request to simplify state machine. git-svn-id: svn+ssh://oldsvn/home/mlalondesvn/svn/cral@80 3ee9b42a-b53c-0410-a25e-f0b6218d5d5b --- .../wiz810mj/src/demo/WizDemo3/WizDemo3.pde | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/branches/follower/wiz810mj/src/demo/WizDemo3/WizDemo3.pde b/branches/follower/wiz810mj/src/demo/WizDemo3/WizDemo3.pde index 747d97d..7637177 100644 --- a/branches/follower/wiz810mj/src/demo/WizDemo3/WizDemo3.pde +++ b/branches/follower/wiz810mj/src/demo/WizDemo3/WizDemo3.pde @@ -277,34 +277,35 @@ void loop() { while (getSn_SR(testSocket) == SOCK_ESTABLISHED) { while (getSn_RX_RSR(testSocket) > 0) { - theByte = readByte(); - Serial.print(theByte, BYTE); - if ((state == STATE_G) && (theByte == 'G')) { - state = STATE_E; - } else if ((state == STATE_E) && (theByte == 'E')) { - state = STATE_T; - } else if ((state == STATE_T) && (theByte == 'T')) { - state = STATE_SPACE; - } else if ((state == STATE_SPACE) && (theByte == ' ')) { - state = STATE_SLASH; - } else if ((state == STATE_SLASH) && (theByte == '/')) { - state = STATE_READ; - } else if ((state == STATE_READ) && (theByte == '0')) { + + if (state == STATE_G) { + if (readMatch("GET /")) { + state = STATE_READ; + } else { + state = STATE_ERR; + } + } + + if (state == STATE_READ) { + + theByte = readByte(); + + if (theByte == '0') { digitalWrite(PIN_LED, LOW); ledState = 0; - //state = STATE_END; - delay(100); - } else if ((state == STATE_READ) && (theByte == '1')) { + delay(100); + } else if (theByte == '1') { digitalWrite(PIN_LED, HIGH); ledState = 1; - //state = STATE_END; delay(100); - } else if (state == STATE_READ) { + } else { // It's not a valid byte. state = STATE_END; - } else { - state = STATE_ERR; } + + } else { + state = STATE_ERR; + } if ((state == STATE_ERR) || (state == STATE_END)) { Serial.println("");