rcsys.pwp


//-------------------------------------------------------------------------
//
// PicoWeb Project File for RCS HVAC Temperature Controller
//
//-------------------------------------------------------------------------
//
// application-specific preprocessor definitions
//
#define BANNER "\r\nPicoWeb RCS\r\n" /* only if debugger is in! */
#define EEPROM_IP                    /* use file "ip" for IP address */
#define ENABLE_WATCHDOG              /* use Atmel watchdog timer hardware */
#undef DEBUGGER                      /* no debugger firmware */
#define SERIAL_BAUD_DIVISOR 51       /* serial port speed: 9600 baud @ 8 MHz */

//
// application-specific HTML and image file names
//
rcsys.htm          // ii00  (default Web page)
delay1.htm         // ii01

//
// application-specific CGI routines
//
rcs_form.cgi       // iu00
rcs_dump.cgi       // iu01
rcs_stat.cgi       // iu02
rcs_get_temp.cgi   // iu03
rcs_setpt.cgi      // iu04
rcs_mode_O.cgi     // iu05
rcs_mode_H.cgi     // iu06
rcs_mode_C.cgi     // iu07
rcs_mode_A.cgi     // iu08
rcs_fan_0.cgi      // iu09
rcs_fan_1.cgi      // iu0a
rcs_dump.cgi       // iu0b

//
// application-specific assmbly language files
//
// <none>

//
// included application-specific pcode and/or AVR assembly language follows
//
#avr_reset
;--------------------------------------------------------------------------
; this code is executed each time microcontroller is reset
;--------------------------------------------------------------------------
;
    sbi     ddrd,LED_BIT      ; make LED driver pin an output

#avr_slow
;--------------------------------------------------------------------------
; this code is executed each trip through "slow idle" loop (~1 sec period)
;--------------------------------------------------------------------------
;

#avr_fast
;--------------------------------------------------------------------------
; this code is executed each trip through "fast idle" loop
;--------------------------------------------------------------------------
;

#avr_asm
;--------------------------------------------------------------------------
; application-specific CGI pcode and AVR assembly routines go here
;--------------------------------------------------------------------------
;
.eseg

#define putchar_serial pmovbi putc_b,0
#define putchar_net    pmovbi putc_b,1
#define serial_binary  pser_mode 1
#define serial_normal  pser_mode 0
#define SER_TMO        800

.dseg
#define RCSLEN  64
rcs_mode: .byte   1
rcs_fan:  .byte   1
rcs_ptr:  .byte   2
rcs_buf:  .byte   RCSLEN

old_putcok: .byte 1                     ; save state of putcok here

.eseg
rcs_stat:
    pcall rcs_status                    ; get device status into buffer
    pret

.eseg
rcs_form:
    pcall rcs_form_check                ; check for FORM URL
    pret

;
; process a FORM by converting the GET command (copied into buf by
; the PicoWeb server's URL processor) into a legal RCS thermo
; unit command, mostly by turning &'s into ,'s.  This way the HTML
; form can be tailored to make custom RCS commands without the need for
; CGI coding.
;
.cseg
rcs_form_check:
    pwdr                                ; reset watchdog timer
    pmovwi rcs_ptr,buf+2                ; process GET command in buf
rcs_form_check_more:
    pcmpwi rcs_ptr,buf+buf_len-1
    pjumpeq rcs_form_check_done

    pmovb buf,[byte rcs_ptr]            ; get next URL character
    pcmpbi buf,' '                      ; stop at first ' '
    pjumpeq rcs_form_check_done

    pcmpbi buf,'U'                      ; look for 'U'
    pjumpne rcs_form_check_noU
    pcall rcs_form_set                  ; found! process form
    pjumpeq rcs_form_check_done

rcs_form_check_noU:
    paddwi rcs_ptr,1
    pjump rcs_form_check_more

rcs_form_check_done:
    pret

;
; this routine processes the FORM data if a 'U' is found in the GET data
;
rcs_form_set:
    pmovb old_putcok,putcok             ; save putchar enable state
    pmovbi putcok,0xff                  ; enable output to serial port
    serial_binary                       ; put serial port in binary mode
    putchar_serial                      ; switch output to serial port

    pmovwi rcs_ptr,buf+2                ; convert GET to RCS SET command
rcs_form_set_more:
    pwdr                                ; reset watchdog timer
    pcmpwi rcs_ptr,buf+buf_len-1
    pjumpeq rcs_form_set_done

    pmovb buf,[byte rcs_ptr]            ; get next URL character
    pcmpbi buf,' '                      ; stop at first ' '
    pjumpeq rcs_form_set_done

    pcmpbi buf,'X'                      ; stop at first 'X'
    pjumpeq rcs_form_set_done

    pcmpbi buf,'U'                      ; stop at first 'U'
    pjumpeq rcs_form_set_done

    pcmpbi buf,'='                      ; special processing after '='
    pjumpne rcs_form_set_noeq
    paddwi rcs_ptr,1
    pmovb buf,[byte rcs_ptr]            ; get next URL character after '='
    pcmpbi buf,'O'                      ; map 'O" to '0'
    pjumpne rcs_form_set_noO
    pmovbi [byte rcs_ptr],'0'
rcs_form_set_noO:
    pcmpbi buf,'H'                      ; map 'H" to '1'
    pjumpne rcs_form_set_noH
    pmovbi [byte rcs_ptr],'1'
rcs_form_set_noH:
    pcmpbi buf,'C'                      ; map 'C" to '2'
    pjumpne rcs_form_set_noC
    pmovbi [byte rcs_ptr],'2'
rcs_form_set_noC:
    pcmpbi buf,'A'                      ; map 'A" to '3'
    pjumpne rcs_form_set_noA
    pmovbi [byte rcs_ptr],'3'
rcs_form_set_noA:
    paddwi rcs_ptr,-1                   ; restore URL pointer
    pmovb buf,[byte rcs_ptr]            ; restore next URL character

rcs_form_set_noeq:
    pcmpbi buf,'&'                      ; map '&" to ','
    pjumpne rcs_form_set_noamp
    pmovbi [byte rcs_ptr],','

rcs_form_set_noamp:
    pputcb [byte rcs_ptr]
    paddwi rcs_ptr,1
    pjump rcs_form_set_more

rcs_form_set_done:
    pmovbi [byte rcs_ptr],0x0d          ; trailing CR
    pputcb [byte rcs_ptr]
    putchar_net                         ; switch putchar back to 'net
    pmovb putcok,old_putcok             ; restore putcok
    pret

;
; output the current temperature from the SRAM status buffer which
; was filled in by the CGI routine rcs_status
;
.eseg
rcs_get_temp:
    putchar_net                         ; redirect output to 'net
    pmovwi rcs_ptr,rcs_buf              ; point to start of status buffer
    paddwi rcs_ptr,15                   ; "A=00 O=1 Z=1 T=74 SP=80 M=O FM=0\n"
    pputcb [rcs_ptr]                    ;  012345678901234^ <- send this digit
    paddwi rcs_ptr,1                    ; advance pointer
    pputcb [rcs_ptr]                    ; send second temperature digit
    pret

.eseg
rcs_mode_O:
    pmovwi rcs_mode,'O'
    pcall rcs_mode_X
    pret

rcs_mode_H:
    pmovwi rcs_mode,'H'
    pcall rcs_mode_X
    pret

rcs_mode_C:
    pmovwi rcs_mode,'C'
    pcall rcs_mode_X
    pret

rcs_mode_A:
    pmovwi rcs_mode,'A'
    pcall rcs_mode_X
    pret

;
; output <input type="radio" value="{rcs_mode}"[ checked] name="M">
;
.cseg
rcs_mode_X:
    putchar_net                        ; redirect output to 'net
    pprint eseg "<input type=\"radio\" value=\""
    pputcb rcs_mode
    pprint eseg "\""

    pmovwi buf,[rcs_mode]              ; target value?
    pcmpbi buf,[byte rcs_buf+26]       ; "A=00 O=1 Z=1 T=74 SP=80 M=O FM=0\n"
    pjumpne rcs_mode_nochk             ;  01234567890123456789012345^
    pprint eseg " checked"

rcs_mode_nochk:
    pprint eseg " name=\"M\">"
    pret

.eseg
rcs_fan_0:
    pmovwi rcs_fan,'0'
    pcall rcs_fan_X
    pret

rcs_fan_1:
    pmovwi rcs_fan,'1'
    pcall rcs_fan_X
    pret

;
; output <input type="radio" value="{rcs_fan}"[ checked] name="F">
;
.cseg
rcs_fan_X:
    putchar_net                         ; redirect output to 'net
    pprint eseg "<input type=\"radio\" value=\""
    pputcb rcs_fan
    pprint eseg "\""

    pmovwi buf,[rcs_fan]                ; target value?
    pcmpbi buf,[byte rcs_buf+31]        ; "A=00 O=1 Z=1 T=74 SP=80 M=O FM=0\n"
    pjumpne rcs_fan_nochk               ;  0123456789012345678901234567890^
    pprint eseg " checked"

rcs_fan_nochk:
    pprint eseg " name=\"F\">"
    pret

;
; output the current setpoint from the SRAM status buffer which
; was filled in by the CGI routine rcs_status
;
.eseg
rcs_setpt:
    putchar_net                         ; redirect output to 'net
    pmovwi rcs_ptr,rcs_buf              ; point to start of status buffer
    paddwi rcs_ptr,21                   ; "A=00 O=1 Z=1 T=74 SP=80 M=O FM=0\n"
    pputcb [rcs_ptr]                    ;  012345678901234567890^ <- our digit
    paddwi rcs_ptr,1                    ; advance pointer
    pputcb [rcs_ptr]                    ; output second digit
    pret

.eseg
rcs_dump:
    pcall rcs_status                   ; get device status
    pmovwi buf,rcs_buf                 ; dump entire response buffer to 'net
rcsnext:
    pcmpwi buf,[rcs_ptr]
    pjumpeq rcsshow_done
    pputcb [buf]
    paddwi buf,1
    pjump rcsnext
rcsshow_done:
    pret

;
; send RCS temp unit command to read status, then fill in the
; SRAM rcs_buf with the response for other CGI routines to use
;
.cseg
rcs_status:                            ; get status of RCS temp unit
    pmovbi com_lost,0                  ; zero out lost char counter
    pmovb old_putcok,putcok            ; save putchar enable state
    pmovbi putcok,0xff                 ; enable output to serial port
    serial_binary                      ; put serial port in binary mode
    putchar_serial                     ; switch output to serial port
    pwdr                               ; reset watchdog timer
    pprint eseg "A=1,R=1\r"
    putchar_net                        ; redirect output back to 'net
    pmovb putcok,old_putcok            ; restore putcok
    pcall rcsin                        ; get response from external device
    pret
;
; read characters from serial port into rcs_buf until first CR (or timeout)
;
rcsin:
    pmovwi buf+2,SER_TMO               ; reset timeout counter
    pwdr                               ; reset watchdog timer
    pmovwi rcs_ptr,rcs_buf             ; point to start of buffer
rcsnextchar:
    pser_getc buf                      ; get a char into buf
    pjumpeq rcsempty                   ; no more chars!
    pcmpbi buf,0x0d                    ; exit on first CR
    pjumpeq rcsdone
    pmovbi [rcs_ptr],[byte buf]        ; save next byte
    paddwi rcs_ptr,1                   ; advance pointer
    pcmpwi rcs_ptr,rcs_buf+RCSLEN      ; check if reached limit
    pjumpeq rcsdone                    ; sorry - ran out of space
    pmovwi buf+2,SER_TMO               ; reset timeout counter
    pwdr                               ; reset watchdog timer
    pjump rcsnextchar                  ; go get another one
rcsempty:
    psubwi buf+2,1                     ; decrement timeout
    pjumpne rcsnextchar                ; not yet timed out
rcsdone:
    pret


Back