# carbonwg-pic version history
#
# Versions ending in even numbers are stable releases.
#
# Versions ending in odd numbers are development snapshots
# and not guaranteed to be stable.
#
# generate short commit summary, for tag commit message
# git log --since=2021-06-01 --pretty="format: %h %n  %B" > commit-summary.txt
#
# Add tag summary to the commit summary
# Generate tag
# git tag -a -F commits-summary.txt <tag>
#
# Generate formatted tag summary (most recent first) 
# git tag -l -n99 --sort=-v:refname --format="%(taggerdate:iso) %(objecttype) %(refname:short)  %0a %(contents:lines=99) %0a" 
#
# add tag summary to HISTORY
# commit history and move tag to include updated history
# git add HISTORY
# git commit -m "update history for tag" HISTORY
# git tag -a --force -F commits-since-date.txt <tag>
#
# push tag to remote
# git push origin <tag>
#
# see also
# https://git-scm.com/docs/git-rev-list
# https://git-scm.com/docs/pretty-formats
# https://git-scm.com/docs/git-for-each-ref

2021-08-27 14:35:32 -0700 tag 6.3.0b0  
 Refactor I2C for bit-bang and/or MCC, Add SHT3X to build, add MDIO/MMEAS support to GUI, bug fixes,
    
     15a3ac1
      update project files
    
     34e7d76
      add call for SHT3X proto test
    
     e2991af
      disable I2C/SHT3X proto code
    
     e63eacf
      Merged in feature/i2c_uni-mixmatch (pull request #25)
    
    Feature/i2c uni mixmatch
     b1dafd0
      update project files
    
     6202bfe
      add scripts for v2 manifold (one outputs normally, the OR version streams output for the GUI)
    
     9f789bf
      rename vars, add hnd to sht3x args, fix typos
    
     a72d1c6
      merge GUI changes from master (rename from cwg to cview)
    
     2528106
      rename cwg GUI from cwg to cview (update imports)
    
     7b75d84
      rename cwg GUI from cwg to cview
    
     8f4044d
      refactor to allow concurrent use of bit-banged and MCC I2C resources
    
     2eaac4f
      refactor to allow concurrent use of bit-banged and MCC I2C resources, add/update comments
    
     f4735a3
      whitespace
    
     7ca39b8
      refactor MCC function mapping scheme to eliminate function tables and wrappers
    
     2e6936c
      add comments, update project files to include all i2c impl headers
    
     4fa40b5
      add support for I2C (may be configured to use bitbang or MCC), add driver for SHT3X RH/T and proto code (untested, pending HW)
    
     17eb649
      add support for I2C (may be configured to use bitbang or MCC), add driver for SHT3X RH/T and proto code (untested, pending HW)
    
     a39af28
      update project files - remove i2c,sht3x files from build
    
     aff234e
      update project files
    
     6325a7c
      Merged in feature/gui-mmeas (pull request #24)
    
    Feature/gui mmeas
    
     bccd514
      add status message w/ generated command string
    
     6ec79ff
      reorganize mmeas tm config options in tabs to accommodate separate options for console and host, add controls for mmeas CYC directive
    
     a968dd8
      WIP - add partial implementation of MMEAS GUI input processing
    
     0c79380
      WIP - add MMEAS controls to GUI (not fully implemented)
    
     607720d
      eliminate redundant MDIO sub-frames and reorganize, add macro/preset overrides
    
     b2332d1
      increase width of op spinbox
    
     865c4ce
      change LI_RAW_RECORD_STR_BYTES from 370 to 375 to address missing data tag errors (seems like licor strings were slightly longer, causing the last few bytes to be missed)
    
     0ff9c8c
      updated MDIO interface, replace comboboxes with spin boxes and radio buttons and improve error messages and logic to be robust for manual entries
    
     b3d4aea
      bugfix: missing h2odewpoint field output causes plots to fail; add to init
    
     feaf9c1
      add missing comma in preset list
    
     c537aa5
      update preset list, swap macro and preset layout
    
     55fb8f9 

2021-05-17 18:40:46 -0700 tag 6.2.1b0  
 6.2.1b0 fix log rollover bug and add log pre-open for streaming handlers 

2021-05-13 09:10:52 -0700 tag 6.2.0b0  
 Merge serial IO and debug update: replace cwglib C library with cwg_io.py, which uses pyserial and is fully cross-platform. Replace debugging print output with python logging. Make updates for native windows, minor bug fixes and improvements.(updated w/ GUI bug fixes) 

2021-04-30 22:16:53 -0700 tag 6.1.3b0  
 Summary:GUI updates, bug fixes
    - update GUI baud rate to new default (19200)
    - more reliable binary downloads
    - adding matlab loader for orecords (load_obin.m)
    - update matlab zrecord loader for new file structure, rename to load_zbin.m 

2021-04-29 10:22:03 -0700 tag 6.1.2b0  
 Summary:GUI updates, default baud, mmeas option parsing
    - enable GUI plots from manual console measurements:
      - enable output from console to host from mmeas, log utils
      - add plot passive mode to GUI: plot csv records from (host) port without initiating a plot cycle
    - consolidate option parsing in mmeas USR, LOAD/TM, and OUT contexts to separate functions
      for readability and to eliminate redundant code
    - change default console/host serial rate to 19200 bps 

2021-04-26 15:04:52 -0700 tag 6.1.1b0  
 add cron help 

2021-04-25 20:33:15 -0700 tag 6.1.0b0  
 Summary:
    - rename cycle log CBIN and use to mirror orecords from current cycle
    - create named buffer, CBIN.BUF, to mirror current orecords from current cycle
    - implement variable names that reference the current logs : $ZBIN, $OBIN, $RAW, $SYS, $CBUF
    - add support for parsing comment line options that contain quoted tokens (e.g. cron T: option)
    - add output TTY selection for SCR SCH
    - bug fixes, comment cleanup/improvement
    
    290d2ec
    add parsing support for tokens with embedded quotes, clean up cruft, improve comments
    
    e90126d
    add error checking in tab_set_path; restore changes on error
    
    b4e579c
    break on schedule parse errors
    
    45d80fe
    add otty value to script_show
    
    16ff518
    add support for SYS variable (syslog name)
    
    0f511c9
    add support for SYS variable (syslog name)
    
    db2b00a
    add tty option to SCR SCH, add TX drain to output to allow full output when called from scripts, catch error in cron parsing, remove cruft
    
    6080090
    add alias get/set DATE (TIME)
    
    2aecc00
    add CLI wrappers for file sys functions to enable variable substitution before fsys calls
    
    61ced84
    Summary: rename CYC log to CBIN, and use it to mirror the orecords for the current cycle. Add support for a cycle buffer, CBIN.BUF, which may be used to hold the last cycle's orecords for processing or telemetry. Implement config variables CBIN, OBIN, ZBIN and CBUF to reflect the names of the current segment of the cycle (updated when they change), orecord, zrecord, and cycle buffer files. The vars may be used with log utils or file cp, e.g.: lcat o l4 out:c $CBIN cp $CBIN $CBUF cli_api - add cli_cp (wrapper for fcopy) cli_impl - replace const (-1) with CYCLE_ID_INVALID - truncate LOG_CBIN at cycle start config - add string variables CBIN, CBUF, OBIN, ZBIN (name of current segment of cycle log, cycle buffer file, orecord log, zrecord log) iow_file - add iow_ftruncate (truncate file to zero length) licor - add parallel orecord…
    
    36f952d
    fix typo 

2021-04-21 15:03:38 -0700 tag 6.0.0b0  
 Summary:
    
    Add cycle ID  and meas seq number to orecord and zrecord structures to make it enable association between orecords and zrecords.
    Change meas and ensemble members from uint32_t to uint16_t.
    Eliminate padding from orecord struct.
    Add mmeas syntax to support cycle start/stop.
    Change field order for CSV output.
    Add cycle log (for cycle id seq file) and eliminate data queue logs.
    Add cycle and meas filter/search support for lless and lcat.
    Add shortcuts Ln SnCm to cat, +/-ul to mdio.
    Add state output to mmeas SHOWLog cal strings in syslog.
    Increase syslog buffer size (if memory available)Add generic log_printf (can write to other logs).
    Bug fixes.
    
    commit b367fd54581eef3f148ba41292237a338ef3eda7
    
        add quotes around syslogged cal strings
    
    commit e60797a03c671407e2e87cb433934843b05ef4a5
    
        use new mdio +/-ul syntax
    
    commit c5f5542626c03fd2884cdf9e96ff620aac0e664c
    
        add AIO_XCVR_LICOR_ON/OFF to enable mdio +/-ul option, add MX_CAL_TON_MSEC and use to increse licor power on delay (cals were failing b/c they were trying to get output too soon after power on) 3s seems to be OK.
    
    commit 67094b42e2b310574c6713fc0c85bb95138a6b5a
    
        in log_syslog and log_printf - add attempt to palloc large buffer (LOG_SYSLOG_ALLOC_BYTES=512) and use smaller existing buffer if alloc fails
    
    commit 8df28d2f405a8606bd94e5474ca366550819e261
    
        add LI_CAL_COUNT and cal type strings, export string array, add CALTYPE_STR macro, update comments/whitespace
    
    commit 9a1d4a17912e487fed3a5fd1d45e25787bffa3a6
    
        update debug info, whitespace
    
    commit 12af0824fbe3d96e931392f8360c40d6b18f5ec2
    
        add Ln and SnCm shortcuts to help
    
    commit 6bd2c75506e125ae33ccbb7f02b16ecb47791f0f
    
        remove XCVR_LICOR from IO_PROTECTED mask
    
    commit 54844d5fd323074bd44101da1b8cb93d4c2a318e
    
        add xcat shortcuts Ln SnCm (lastn, start/count), fix bug: zcal used MMID_SCAL
    
    commit be1f2c175ae86a401778ca0e5c1c912b2e8e1096
    
        add log_printf similar to log_syslog, but takes log handle so may add to any log
    
    commit 18f09e67fc6451c7c0344eac6cf93b0695be96e3
    
        add support for cycle log to LOG command, allow mdio to enable licor xcvr via IOH:ul
    
    commit 27095cd48d63f6efd1590161d575a00ffcbc1bf2
    
        add state info to mmeas SHOW/STAT and show in order specified, whitspace
    
    commit 996ac4bbb313f434c4778033b88d7e142b0b7643
    
        change spacing between key/val (2->1)
    
    commit f46d706f8fef202e4814d17664b21d19441a2062
    
        use short form RMS in cycle init
    
    commit c1165ec41fc759f456fd0890471d20198e6165fd
    
        update for mmeas syntax changes, add message at script end
    
    commit 1280dc5131db2c116cb9de751f7ea4fbe3bf2adb
    
        bugfix: RM_INVALID missed when mask/shift meas id; add byte wide invalid value (0xFF)
    
    commit 4dd12dde23d0c4533b61f64ae54e504d0d3dd46b
    Merge: 9250c5f f9f3175
    
        merge bugfix/lutils-multi
    
    commit f9f31750141a6debe22d6fbd641ca59579f061a8
    
        bugfix in sync: add fwd version of fix for sync start occurrence during sync sequence, clean some comments/whitespace
    
    commit 9250c5f00ceea294e6bcbff16d5708acecd03e5f
    
        change size of ens_n,ens_len and meas_n to uint16_t, eliminate b85 pad bytes, add cycle_id (cyc) and meas_n (msn) search to lless
    
    commit b5fa2fa7391acf6e6783d6e968df309debdfe7dd
    
        update CSV plot parsing to use new fields/order
    
    commit 4fa122eb8424d28212084393947b4e18e5b83314
    
        Add cycle ID to logging for the purpose of aligning zrecord summaries with associated observation records.
        Make sequence numbers specifically about log sequence 

2021-04-15 18:13:44 -0700 tag 5.0.0b0  
 commit 8791bedc83c66fd82f12891853b2b0591fb027b1 (HEAD -> master, origin/master, origin/HEAD)
    Merge: 21ec642 5131c25
    Date:   Fri Apr 16 01:02:37 2021 +0000
    
        Merged in feature/cli-util-apr21 (pull request #13)
    
        Feature/cli util apr21
    
    commit 5131c25c2abf2eaafb59ec358d624bd72a1e06fb (origin/feature/cli-util-apr21, feature/cli-util-apr21)
    Date:   Thu Apr 15 17:58:52 2021 -0700
    
        update project files
    
    commit 8ff5c27c835f692f0ad499e13ddea2174b2da28f
    Date:   Thu Apr 15 17:56:01 2021 -0700
    
        fix bugs: nshow and show return values and end of file handling causing error return value, also segfault occuring when invalid type passed
    
    commit 707c04d10f828738c4c7f68c70e88aba46739ab0
    Date:   Thu Apr 15 17:52:29 2021 -0700
    
        provide default file when unspecified (current log) for lutils (lcat, lless, linspect)
    
    commit f288552ba6abbb602b933f09ad016360c139687d
    Date:   Thu Apr 15 17:50:14 2021 -0700
    
        change error to warning gated by g_xprint
    
    commit d1530944a0db4509c3937aae172caee2c8177bfa
    Date:   Thu Apr 15 17:48:42 2021 -0700
    
        fix orecord sequence number bug (log_get_seq order caused double bumps)
    
    commit 33361e5a5a6532dc5b77141871d149309d706f33
    Date:   Thu Apr 15 17:47:48 2021 -0700
    
        add XTEST macro returns true if mask&global!=1
    
    commit 32db6bcb806977e3e6b06df826c489a45a4a68a0
    Date:   Thu Apr 15 17:46:18 2021 -0700
    
        change outr to outc for consistency w queue utils, fix orecord sequence number bug (log_get_seq order caused double bumps), use hexdump-like format for binary output in cat for readbility
    
    commit 21ec642307cb74c36aa1d7f0d89448d985dd0847
    Date:   Wed Mar 31 14:31:45 2021 -0700
    
        add demo crontabs to sdc 


# Tag 4.0.1b0 20210303-1020


    set default debug mask to 0, update dbg mask option parsing to accept operators +/-/=

    update field indexing and streaming commands to match refactored log utils

    update with latest commits (LS wildcard)

    add simple wildcard capability to LS|DIR (name contains string)


# Tag 4.0.0b0 20210228-1700
refactored log utilities
- eliminated CSV log
- added OBIN log (binary orecord, i.e. parsed XML)
- renamed DAT log ZBIN (binary zrecord)
- partitioned log utils to use content-independent front end API, and content-dependent back-end 
implementations, minimizing redundant code and enabling the log utils (lless, lcat, etc) to 
work the same for different log types. 
- log utility semantics are updated to reflect content-sensitive use
- mmeas semantics are updated with options for logging orecord/raw data, handler selection, and 
streaming console output formatting.
- a file-based queue API (dqutil) is designed (front end implemented), intended to implement a download queue.
The dqutil API is intended to provide a download queue capability, i.e. log records could be 
formatted as B85, CSV etc. and moved to a download queue file.
Doing so would be redundant (and so not implemented), but would provide a safe and flexible
space for telemetry that would not require host systems to directly manipulate the binary logs.

# Tag 3.5.0b1 20210228-1640
Pre-merge tag (before feature/log-refactor pull request)

# Tag 3.5.0b0 20210205-2040
Updates for Python GUI and CSV streaming/logging

CSV logging
    add API functions to retrieve CSV log records

    remove trailing delimiter from CSV log output

    add CSV log support and mmeas output options for streaming handler to output to CSV log/console/both

Python GUI
    fix bug: invalid names in host file list: validate host file names before adding to combobox control, use print instead of message box for debug output.

Serial IO refactor
    Merged in feature/serio-refactor (pull request #11)
    Feature/serio refactor
    Merged master into feature/serio-refactor

Bug fixes
    fix bug: IO_PROTECTED covers ADC bits, causing mdio operations with ADC bits to fail (correct IO_PROTECTED mask)
    fix bug: passing id instead of pointer to handler causes licor_streamx to fail (merge from master)
    fix bug: passing id instead of pointer to handler causes licor_streamx to fail

Python GUI
    add options for mingw build
    add win stubs
    add support for win DLL builds
    add windows.h for DWORD def on winXX build
    cast offset to fix warnings in winXX build
    add gmtime_s for WIN32/64
    fix signal handling and printf flags for win32/mingw
    update for mingw build; use wser_read in drain_rx_base
    mods for mingw build
    add dirent.h for WIN32,WIN64
    add win/mingw signal handling conditional defs
    adjusting included headers for mingw build
    fix warnings on Cygwin build
    add warning with platform for debugging builds
    refactor cwglib, break out serial IO into iowserial with platform-specific definitions; ultimate aim is to support windows w/o cygwin

    minor changes to debug output
    remove unused code, fix plot bug (sharex causes old x-value to stick when invalid channel given)
    remove example code, (WIP):add PlotControl class and refactor to use array of these for plot output
    remove example code
    remove cruft, add debug and mode_test model data members
    move file validation from controller to model
    add support for multiple plots (WIP)
    remove cruft
    initial checkin of model/view/controller implementation of cwg GUI (refactored cwgfx.py)
    replace cwg file label/entry with button combobox that reads directory on CWG, rename widget styles for readability
    fix bug: read end condition hangs in upload_file (use >= instead of >)
    add support for full(verbose)/quiet option
    add dir function prototype
    add Q and F options (quiet,full) to dir/ls; Q outputs only file names
    add additional plot controls (period), licor power, and cygwin support
    Merged in feature/restream_fn (pull request #10)
    Feature/restream fn
    add prototype strip chart using new orecord streamer in cwglib
    add ostream licor streamer handler (streams orecords to console)
    add linkage to lib lutils for lout
    WIP: add implementations for cwg_fget_lastn, cwg_mget_lastn, cwg_fget_n, cwg_mget_n
    WIP: add test support for cwg_fget_lastn, cwg_mget_lastn, cwg_fget_n, cwg_mget_n
    add line and CRLF to error output
    put condition on error message to limit invocation, add range checks too read_len too detect/prevent errors in lu_lcat, add info to debug statements
    don't use OUT_CTTY in licor_zrecord_outr b/c it doesn't output null characters
    fix bug: segfault due to insufficient dest range checking in iow_fread; add explicit casts for conversions
    change bgcolor for Entry widgets from gray to white
    WIP: add platform-dependent filter for devices, style
    WIP: fix download, refactor device/filebrowser, add device refresh
    add prototype file transfer GUI using python/tk on top of libcwg
    replace quotes with brackets for system headers
    add cwg_ser_set_device method to replace serial device
    rename test file
    add cwg_download_file impl, in upload_file implement option for text file, add prompt/echo disable, use macro sizes for IO buf
    add shared cwglib target
    fix raw mode output leaks in cli_upload
    WIP: add cwg_upload_file, cwg_download_file

cwglib:
add cwg_break function (interrupt loops)

cli_impl:
add binary modes to upload and cat, add FSIZE command (returns file size of specified file(s))

help.md:
update from carbonwg-doc repo

main:
fix bug: g_ctty unset in main before boot banner (doesn't show)


# Tag 3.4.0b0 20201118-0950
WIP update and fix bugs in cwglib (client C library)

fix timing and logic issues (serial read/drain exit too early or late), document API functions

remove cwg_mkcmd..., add macros for building commands, rename several functions for consistency and readability

add licor_parse_csv function (CSV to zrecord), add XM_SDEV_TO_S (invert XM_SDEV)

use SER_ERR for TRACE, add FMT_X16 print format

extend cron disable to optionally suspend and resume after a timeout (e.g. to resume if coonnetion is lost while suspended)

add SCR STAT directive (return script state)

move cwg_test function to cwglib-test, make minor updates to output formatting, rename script in upload test and remove after test.

update signature and logic of z85 decode to enable decoding one of multiple messages in the same buffer

rename functions and data types for consistency, move main from cwglib to cwglib-test (new file)

rename cwgcli* to cwglib

change use of CRLF (command macros exclude them), change read_until to also behave as skip_until (i.e. more flexible control of exit conditions)

add support for directing script output to host or console

WIP: refactor for reuse, improve logic for reliability, add and rearrange functions

increase delay after CR detection to enable CRLF seq to be completed in a timely way. It was causing issues in a client when the newline was missed, resulting in a failed data read command

disable g_ctty=SER_CONS - TODO: direct script output at runtime

add quiet option to upload for m2m

add rstat member variable to script ctx, stores return value of last command

add CX (store output), Q (suppress output) options to GET ERR

eliminate cwgcli, add cwg_mkcmd_sample, updates to test code

add support for GET ERR (set error code), clean some indents/blocks

use OUT_CTTY instead of OUT_CONS, clean up whitespace and cruft

add cross-platform FMT_D32 print specifier

use OUT_CTTY instead of OUT_CONS, add GET ERR directive to return status of last command (e.g. as 0)

WIP: consolidate and generalize write/read functions, add cwg_rx_drain, add command/constant macros, add test code

use current log file by default if unspecified

WIP: add CWG reference client; currently roughed in, developing test code first

switch ECHO config var to flag enum, add PROMPT flag enum; prompt and echo flags may be set independently for host/console/all/none, enabling independent machine/machine interface that doesn't echo or emit prompt if needed

consolidate log_get_seq_number and log_read_seq_number into single function (changes signature). now optionally returns value in argument and returns 0/-1 on success/error, and adds increment argument to optionally update seq no

add (binary) log stats structure, optionally pass to linfo to return stats

move tokenize from cwgsys to cwgsys-shared and update macro names for cross-platform build compatibility

add doxygen comments to variables/functions, rename some variables/macros (e.g. SCR_ to CFG_)

move licor model enum from licor8xx to licor8xx-shared to fix compile error in boot version (somehow not a problem in non-boot)

# Tag 3.3.0b0 20201106-2055
Add  LI-COR 830 support, eliminate cwgconf (use config.c,h)
add LI MODEL directive (get/set model)
consolidate licor model config variables into config.h, licor8xx*.h

# Tag 3.2.0b0 20201105-1830

bugfix/cron-dropouts

cron scheduling update to address fix task firing dropouts and timer update to fix intermittent late task firing

Synopsis:

cron scheduling : change cron task updates and next event computation to use hardware timers in conjunction w/ schedule next event.
Perform next event computation only when task run timer is reset, and use it to set run timer

bug fix: cron tasks intermittently fire (~11s) late

Refactor tkDoIdle:
- eliminate several error prone time/tick conversions
- changed idle loop to compare TMR ticks instead of time
- simplified a number of computations to tighten up the loop timing
- fix potential over/underflow issues
- improved timer setup
- add flagging for exit/error conditions

bug fix: cron tasks intermittently fire (~11s) late
- occassionally, TMR1 reads 1 after completing a cycle (instead of the PR1 value)
- when that happens, the idle mode loop would go an extra cycle, causing the the next event
to be late by 1 idle period (PR1*PS/RTCFREQ
- To fix it: when idle is interrupted by an interrupt (e.g. keyboard), add the value of TMR1 (which could be wrong, but usually not)
When a short cycle occurs (TMR1<PR1) add the nominal ticks for a full cycle (PR1).
Also,
- moved the clearing of the T1 interrupt flag and TON disable to the TMR1 interrupt handler
- reduced T1 period PR1 from A000 (10s) to 5000 (5s); this is a trade between longer sleep and potentially greater error
- added a number of flags and checks for debugging various conditions
- It is not clear why TMR1 reads 1 sometimes
- It is not clear how this will behave for over very long (hours) sleep intervals
- added some code to cuont system tick "crumbs" i.e. ticks that pass making computation during idle.
turns out these are very small (maybe 1 T1 tick per cycle, there are 4096 T1 ticks per system tick)

Could consider scaling the idle timer period (i.e. PR1) and/or prescale value depending on the sleep duration

main:
Rename TASK_TIME_OUT SYS_MIN_SLEEP_MSEC
Add, reformat debug sleep info

micron:
add timer_t run_timer to task
initialize task state to TSK_INVALID
use TSK_LIST_END state to mark list end
rewrite micron_update_task state machine to use cleaner design (switch to set state/action(s), if action)
use task timers instead of sched_next to update micron_next_event; account for task state
eliminate unused TSK_ state variables (only need INVALID, PENDING, RUNNING)

pic24:
eliminate unused macros TMR1PRD TMR2PRD
add PR1 macros P24_SET_PR1(x)   P24_PR1_DFL

timers:
export uint16_t tk_sflags=0x0000;
fix uninitialized var and ambiguous syntax in tkTmrUpdate
refactor tkDoIdle

cli_impl:
update uptime computation and include msec

add cron reset,suspend task, rename timer and tasks global flags for consistency, add TSK_SUSPENDED state


# Tag 3.1.0b0 20201028-1530

fix pin mux bug, integrate cron scheduler, update show functions for consistency

fix pin mux for RG9 (pump2:output), change SV0 to be included in V*, remove sv* support as pumps 4,5
update _show functions to use new clean format style (no brackets)

move next event time calc to sys_next_event function, use sys_next_event in main and cli_sleep, add MOD_SYS id

update project files

fix bugs: adjustments for month lengths and leap years, clean up s_next_x search function, make wday and mday independent

rename MOD_PROTO to MOD_PRO, add MOD_AUX, MPRINT use OUT_CTTY instead of serPrint CONS_SER

add SCH_IS_LEAPYEAR macro

fix bug: rollover issue in carry (use L for consts and use longs for sums, make wday/mday independent and support '-' for
no matching schedule specifiers to set all field bits to zero

Merged in feature/cron-integrate (pull request #7)

Feature/cron integrate

fix various bugs in sched next, clean up, remove cruft, add cron X option (returns time to next event), add new debug modules to sli_debug

add MOD_SCH debug module ID, MMOD_IS_EN macro (true if module ID mask & debug flags !=0)

integrate new cron implementation, move from proto to module micron - WIP: debugging micron_next (get next scheduled event)

update project files (boot config didn't work until new files excluded and re-included)

change symantics of scr kill/sch/sync to take multiple ids (use options P,D e.g. to disambiguate tokens)

# Tag 3.0.0b0 20201022-0840

Tag includes a number of bug fixes, API changes and new features developed during documentation; it is being released to a beta-tester.

add additional CREG operators (bitwise), add support for some output formatting control for creg, dreg, consolidate some redundant output code in *reg, add hex value parsing for creg

add 4 general purpose string vars S0:3

add support for parsing mask in CX reg (extends to set/clr bits, mdio)

fix bug: cursor escape sequences not processing '[' correctly

terminate buffer in ui_unescape

fix bug: *reg indent in wrong place, use OUT_CTTY in cli_print, indentation

fix bug: quoted strings with whitespace don't print correctly from script - add preserve_quote flag to ui_tokenize (script sets true, ui sets false)

restore RCON status to startup message

add C,M options to specify queue ID in QUEUE API

change IO_PUMP* masks to reflect new manifold

fix indent for *REG

add timeout option to upload command

add sleep command to UI

use CAT for both implementations, add C|H mnemonics for CON, use cron show for s:*, add test to proto cron test (sch using mnemonic weekdays)

rewrite get ser, adding port mnemonics, new termination conditions and user interrupt detection

change *reg syntax to support chained operations on one line, add rate alternative to or licor cmd, add default output for cli_get_print

support 'li rate' as alternative to 'li or' command

WIP cron: fix bugs, API updates/additions e.g. task scheduling

fix bug overwrite error ignored in script load, add script_run_excl function to API (similar to bootstrap, but with overwrite option

in cli_get_time, use rtc_mktime for GMT instead of local

rtc_mktime returns GMT instead of local time

WIP cron proto: debugging, change task req_n to signed int

WIP: update cron state machine, initialization, task/tab init, etc.

WIP start concurrent/cooperative multitasking cron state machine implementation

rename state update functions for consistency

fix bugs, change cli_impl parsing to accept clustered args


WIP: add cron functions (partially debugged) including cli_impl proto interface, change API to support multiple cron instances using handles

clean up cron parsing/eval function

add proto code for cron feature core API functions

update retval logic in sched_parse, update debug statements in sched_match_tm

add proto feature macro for cron test, add SYS_ISQUOTE, SYS_ISSPACE macros to help w trimming lines

move proto schedule to source module.

update w/ proto cron commits


WIP: cron matching appears to work, add various output methods, helper functions/macros, add mnemonic support for month/weekday

WIP: adding proto schedule capabilities; debug show functions (not working yet), though parse and match appear to work

add proto code for cron-syntax parser

rename sequence related macros, functions and constants and arguments to align with underlying concepts; add doc/comments for various macros, functions and variables.

remap IO per latest manifold doc

rename macros for consistency, made del arg required (non-NULL) in licor*_out*, document macros/functions, cleanup cruft

fix typos, add comments, delete empty lines

rename Licor zrecord macros for brevity and consistency

fix bug: file errors indicated in lless caused by extra record delimiter byte.Added appropriate output flag to mmeas OUT log output. Updated error messages, removed cruft

add ECHO value typedef and use in config and elsewhere

bug-fix: add buffer overflow protection in uiGetLine; pass cursors into uiGetLine instead of internal character counters, add other pointer and overflow checks


# Tag 2.0.0b0 20200929-1800

## Updates

merge with feature/mmeas-refactor

Refactoring mmeas and modifying syntax for mmeas, mmio to augment macro coverage.
The new syntax is more intuitive (and minimal), and the underlying concepts and implementation are cleaner.
Rather than implement a generic (and memory hungry) macro composer, it's now easier to compose IO and measurement operations.
Internally, mmeas parsing uses read-only measurement profile data tables (stored in program memory) for presets, and supports
several r/w user-defined profiles. Parsing is more efficient and has cleaner state management and data persistence between calls.
Multi-step IO macros can be easily built with just a line or two of scripting.

The highlights include:

* new MDIO commands for writing general custom IO operations not covered by macros
* new MMEAS command syntax : mmeas <cmd>:[option,...]
* user-defined measurement profiles
* automatic line-end conversion for file upload
* aliases (mnemonics) for many key numeric parameters (IO bit sets, presets, macros)

cli_impl:
  add automatic line end translation (to CRLF) and end-of-file CRLF to file upload (default): use option no-eol to disable

script:
  fix redundant EOF warning

proto:
    add proto code to explore macro table feature memory requirements

project:
    update project settings (version/tag)

# Tag 1.0.1b1 20200929-1800

## Issues

```
fix bug [cli_impl.c]: qpop faults (resets) when given invalid argument (e.g. "qpop 1"). 
  Root cause was weak argument validation in UI handler.

fix bug [licor8xx.c]: mmeas fails to store measurements correctly. 
  Root cause is in handler function, which incorrectly indexed mdata.
```

## Updates

```
sequence:
  add/extend sequence API for new manifold design

cli_impl:
  cli_mmeas - Add MBR for MBRESET

cwg-shared:
  add FMT_D16 printf format

licor8xx,script:
  change debug output for silent operation when debug disabled

HISTORY:
  use markdown for new entries.
```

1.0.0b0
use new sequence API for mdio, renamed IO presets, before updates for manifold changes
Data and definitions are in sequence.[ch].
Relevant macros moved from api_impl.h to sequence.h.
using new version major.minor.patch[abrc]number, to be consistent w/ best practices
IO preset names have changed, using convention +/-<name>
  +/-AIR
  +/-SEA
  +/-LI
  +/-IOPURGE
  +/-IOFILL
  SAMPLE_PUMP
  ACID_PUMP
  +/-IOZERO
  +/-IOZVENT
  +/-IOZCAL
  +/-IOSZERO
  +/-IOSZVENT
  +/-IOSAMPLE
  +/-IOAIR
  +/-IOSTD
  +/-IOSTDFILL
  +/-IOREST


0.0.2beta1      fix 16-bit bootloader bug, with pending issue in Universal Host. Tech Support case pending with Microchip. 

0.0.1beta2      tag relase 0.0.1beta2

0.0.1beta1      rearrange proto functions for readability

v0.0.98 [20200324-1950]
add port of disk_use util and convert to iow_ API (all file utils now cross platform), add missing boilerplate to source/headers

iofile:
- add port of disk_use util and convert to iow_ API (all file utils now cross platform)

iow_file:
- add iow_fstat

licor, cli_impl
- rename log utils from licor_* to lu_*

cwg-shared:
- add macros FINFO_T (file info) FSYS_T (file sys)

v0.0.96 [20200323-1000]
add functions to file IO wrapper API and use in file utils, rename file util functions.

iowfile:
- add functions : iow_opendir,iow_readdir,iow_closedir,iow_frename,iow_unlink,iow_fstrerror
- allow multiple arguments for ls, du

cli_api, cli_impl, config, iofile:
- rename fcList:dlist, fcRename:frename, fcCopy:fcopy, fcShowS:du (use du instead of stats), fcUnlink:fdelete
- replace FatFS calls w/ iowfile API calls
- remove obsolete code and platform specific ifdefs

cwg-shared
- add DIRENT_T (directory/file info)
- use OUT_CTTY for debug macros
- Add FRESULT

iowfile:
- add functions : iow_opendir, iow_closedir, iow_readdir, iow_fputs
iow_frename, iow_unlink, iow_fstrerror, iow_get_line, iow_get_char, iow_delay_msec
[get_line, get_char, delay_msec formerly in logutils; not strictly file IO, but related]
- replace constant 1024 using G_FILEBUF_LEN macro in header
- modified file open/create mode flags to fit new cases

iofile:
- rewrote PutRC more efficiently and renamed s_fr_perror
- renamed fc* functions and made static
- made most file utils cross-platorm: dlist, fcat, frename, fdelete, fcopy, fless, next_dir

cwgsys:
- rename LC_CHUNK_BYTES -> SYS_LC_CHUNK_BYTES and move to header

various:
- remove CRLF from EPRINT/EMSG calls (EPRINT/EMSG already include CRLF)
- where practical, replace macro types (DWORD, INT, e.g) using system types (uint32_t, int16_t, etc.)
- where practical, replace FILINFO with DIRENT_T

help.md : doc updates

futil: test wrapper for (non-PIC) file utility implementations

v0.0.94 [20200320-2140]
bug fix (script loops on unterminated end line/file), replace deprecated file macros with iowfile API

iowfile:
- add DIR_T (directory type) and iow_closedir
- add iow_fputs
- add iow_f

sdc: add noeol.scr to test unterminated file bug

v0.0.92 [20200320-1400]
bug fixes, convert of selected file macros to iowfile API, add set print command

cli_impl, help.md:
- add commands - SET/GET PRINT
- add support for header, data, verbose content flags in cli_qpeek, cli_qpop, cli_mmeas
- doc updates

cwgsys, cwg-shared:
- move debug flags, module debug from cwgsys to cwgshared

iowfile:
- add iow_fgets

log:
- update queue entry sizes using macros instead of consts (size changes w/ removal of mdata pointer)

various modules:
- remove deprecated debug print macros to reduce number of macros
- deprecate file macros, replace with iowfile API calls (in progress)
- expand use of OUT_* macros
- add conditional to DPRINT (set at run time using set print d[0|1])
- add verbose output usign VPRINT, VLPRINT, VLEPRINT with optional verbosity level
  (set at run time using set print v<n>)

logutils:
- linfo: add seq number info to output
- linfo: enable user interrupt (CR or CTRL-D)

bug fixes:
- console output for PRETTY format doesn't work (bad IO flag processing, uint16_t being used for 32 bit flags in cli_mmeas)
- linfo: shows last time 0 for log file with single entry
- linfo: seq range 0 fix seq info initialization

v0.0.90 [20200319-1530]
bug fixes, add proto mkblog args, misc.

bug fixes: logutils (related to data typing sign/overflows, missed type changes for a couple of variables)
- k jump hangs
- j,k jumps don't stop at right place at end/start of file
- index search infinite loops on PIC
- restore iso8601 timestamp display for record header
- misc output formatting updates (use OUT_* and FMT_* macros)

various - replace CWG_HW_PIC with built-in __PIC24...__ macros
proto - add file name and record count args to PROTO_MKBLOG

v0.0.88 [20200318-2310]
Add lless implementation, bug fixes

- add lless implementation based on iowfile, licor8xx-shared, cwg-shared
- add  character (blocking/non-blocking) and line reads for terminals
- add delay functions (for terminal IO)

Bug fixes :
- data typing changes for consistency across POSIX and FatFS.
- related debug output changes

v0.0.86 [20200318-1340]
Remove mdata pointer from log record struct, bug fixes (consistent data typing)

v0.0.84 [20200317-2100]
Refactor shared cross-platform code, add cross-platform file IO wrapper API

- add iowfile, a file IO wrapper API with cross platform implementations
- split modules into shared and platform-specific code:
  licor8xx + licor-shared
  cwgsys + cwg-shared
-  convert log utility file IO to iowfile and move logic from licor8xx to logutils
- util files are now C wrappers for logutils, which run on PIC, mac, linux etc.
- cross-platform port of lless pending

v0.0.82 [20200313-1100]
Bug fixes, improved search algorithm, syntax and doc updates

cli_impl, licor8xxx:
- add faster search algorithm functions s_log_fast_find_rel, s_jump_n
  (still needs sync error handling), use where appropriate
- add/expand output flags for lless, lcat
- make syntax consistent across mmeas, log utils, etc.
- test and validate oflags before applying in mmeas
- change licor_zrecord_outs to handle data/header content flags
- run log util output through licor_zrecord_outs

utils: add ttest (test code for timestamp overflow)

bug fix (lless): timestamps and sequence numbers wrong in search (add initial FSEEK, fix timestamp in test file generator); note: discovered that struct tm overflows after 2038, since all members are int, which are 16-bit on pic24
bug fix (licor_logrechdr_show) : invalid data type (build, make pointer)

v0.0.80 [20200311-1430]
Add log utilities: lless, lcat, linfo, lseq.
Add utils

lless: interactive log inspection w/ search
lcat : output selected log records using specified formats
linfo: output log summary
lseq : read next sequence number (log sequence data file)

Enable/disable build using WITH_LOG_UTILS in cwgsys.h

utils : shore side utility code

licor8xx :
- add content flags to queue output flags (QOF_HEADER,_DATA,VERBOSE,_CONTENT_FLAGS)
- add LF_NORDEL to log_flags_t (disable record delimiter, i.e. for binary logs)
- add iso8601 timestamp formatting to output

bug-fixes
- sequence numbers not updating
- ZMBLINE macros using invalid variables, change from zrec pointer to mdata pointer
- logged records 2 bytes short - incorrect QUEUE_CYCLE_ENTRY_BYTES
- incorrect size calculation in macro LICOR_ZRECORD_SIZE(p)

cwgsys:
add macro BOOLCHAR(b)  (boolean to character)
add macro U64_TIMESTAMP_SEC(ts) (seconds portion of uint64 time)
add macro U64_TIMESTAMP_MSEC(ts) (msec portion of uint64 time)
add macro TIMESTAMP_STR_MIN_BYTES (minimum iso8601 time string len, bytes)
add macro FEOF(fp) file pointer position
add implementation for 2k buffer to pool (zero configured)

cli_impl: add indent for cli_mdio::show

v0.0.78 [20200303-1300]
Updates to output functions, doc

cli_impl:
- rename MEASX to MTERM in cli_mdio
- add X* option (both hex and prettyhex)
- make hex output upper case
- add XFMT_LCASE to sys_hexfmt_flag
- rearrange show functions to output in structure member order
- fix LICOR_ZRECORD_SIZE to use sizeof(log_rec_header_t) instead of sizeof(p->hdr)
- update comments

v0.0.76 [20200302-2000]
Bug fixes

project files: updated
cli_impl:
- fixed cli_qpeek:  qc, data_sz not set correctly (deferred until after hnd set)
- updated/fixed mmeas use notes
- set mbuf RTID to default during initialization
- use UL consts in to_msec calcs in cli_mmeas
- fixed parsing bug for cli_mmeas out<n> (ignored zero)
- add statv command to cli_mmeas (verbose/non-verbose output)
- fixed bug: mmeas timeout sticking, causing sample to under sample. (invalidate to_msec every cycle)
licor8xx:
- fixed bug: qpeek/pop show wrong data (current contents of xfer mbuf). Must reset
  record mdata pointer when reading back from memory (e.g. queues, files, etc.) the mdata
pointer must be updated any time the record/mdata is moved. Also, we're invalidating the mdata
pointer (NULL) when it's transferred *to* the queue for good bookkeeping - the pointer
should always be valid or NULL.
- fixed incorrect hdr.len in licor_meas_out (should NOT include hdr length)
- fixed incorrect mdata size (256)
- fixed extra fields, duplicate output lines, stray chars in licor_mbuf_show
- removed unnecessary mdata==NULL checks in binary, csv, raw output
- use meas_count>=0 instead of >0 in LICOR_ZRECORD_SIZE (returns header size if empty)
- fixed QUEUE_MEAS_ENTRY_BYTES changed from 280 to 284
- fixed QUEUE_CYCLE_ENTRY_BYTES from 1540 to 1562

log:
- fixed typo: LOG_HDN_COUNT to LOG_HND_COUNT

v0.0.74 [20200229-1055]
Major update of sampling and logging to return more data, improve memory/storage efficiency, simplify sampling architecture, simplify post-processing.

cli_api, cli_impl:
- change output symantics to support new output formats
- support record/measurement type changes
- support multiple queues
- update mmeas states, stickiness for record/meas typing
- mmeas uses licor_stream_x instead of cli_nmeas
- mmeas operations are stateless, but the measurement buffer has state
- deprecate li_tm, li_nmeas
- deprecate cli_impl functions: s_qextract (replace with licor_queue_out and licor_mmeas_out),

cwgsys:
- return number of bytes
- add hex format flags (pretty, offset, ucase)

licor8xx:
- single binary record format and processing handler
- all measurements have the same structure (zrecord), using different parameters
- all measurements include min/max/mean/sdev of all (13) licor parameters
- all measurements include CO2 area and trendline parameters
- deprecate/replace x,v,b,avg records/handlers with single zrecord, handler_z
- zrecord is a variable length binary record
- tighten up record typing to make it better defined
- log in binary format
- add output formats (pretty, prettyhex, base85, hex, csv, raw)
- change buffering scheme:
  - 2 queues:
   - cycle (1x1540) holds last cycle record
   - measurement (2x280) may hold individual records [optional, mostly for test/debug]
  - 2 measurement buffers (mbuf)
   - sample: working buffer for mmeas; holds complete cycle record and state,
   - xfer: scratch buffer for transferring records to queues

- output functions return number of bytes written, eliminate bracket cruft
- licor_parse_measurement: remove record type arg
- licor_stream_x: remove record type arg, replace vrecord w/ orecord

- deprecate functions
    licor_x_logrec_show
    licor_xrecord_show
    licor_xrecord_str
    licor_brecord_show
    licor_brecord_str
    licor_vrecord_show
    licor_vrecord_str
    licor_avg_handler
    licor_bline_handler
    licor_last_record
    licor_publish
    licor_parse_pub_flags

- add functions:
    licor_xrecord_show
    licor_mbuf_reset
    licor_mbuf_instance
    licor_mbuf_record_size
    licor_mbuf_set_rtime
    licor_mbuf_set_rtid
    licor_mbuf_set_rmid
    licor_mbuf_set_mperiodn
    licor_mbuf_set_mperiod
    licor_mbuf_record
    licor_mbuf_depth
    licor_mbuf_mcount
    licor_mbuf_show
    licor_mmeas_out
    licor_queue_out
    licor_logrechdr_show
    licor_zrecord_outb
    licor_zmdata_show
    licor_zmdata_outc
    licor_zrecord_outr
    licor_zrecord_outl
    licor_zrecord_outs
    licor_zrecord_outx
    licor_zrecord_show
    licor_orecord_show
    licor_orecord_str
- add record type flags (deprecate previous)
    licor_rtype_id
    licor_rmeas_id
    licor_mmeas_id
    licor_zrec_field_id
    licor_zrec_extra_id
    licor_mbuf_handle_t
    queue_output_flag

- new types:
    z_meas_buffer_t
    mdata_Z_t
    sdata_Z_t
    licor_zrecord_t

- update/ bline macros (ZBLINE...) w/ new record types
- deprecate macros related to old record types and processing

- rename functions for consistency:
  - licor_get_orate->licor_orate
licor_show_status->licor_status_show

z85.[c,h]: new files, z85 (ZMQ variant of base85 encoding, with encoding char set that is more compatible with transferring source code (e.g. no '/','*' etc) )

log:
- add cycle queue (QUEUE_CYCLE, 1x1540); holds 1 complete record cycle. Intended to store last measurement
for retrieval by host controller
- measurement queue configured to hold single measurement records. Not sure if/how we'll use
this...may prefer to use memory for a second cycle entry so that we can hold 1 cal cycle and one sample cycle
- rename queues (QUEUE_DATA->QUEUE_MEAS)
- support for multiple queues
- add function: log_queue_entry_size

proto: add test code for Z85 codec



v0.0.72 [20191212-1300]
Updates and scripting bug fixes for deployment opportunity.
Using pic24 carbon wg controller for octopus garden time lapse camera.

cli_api:
- rename scr_debug function cli_scr_sdebug

cli_impl:
- support CX registers for delay arg in mdio (d$CXn) and pulse bits ($CXn)
- remove unused/duplicate line from scr_show
bug fix (scr_load):
- files starting with 'o' to be ignored on load when overwrite option used
- if(!overwrite) ignored? use if(overwrite==false) just to be safe

script:
- bug fix (script_step) : comment lines register as error

v0.0.70 [20191209-1015]
bug fix: use correct pin mux for PUMPDC_2 (RG9), PUMP3 (RB1) [previously analog and/or input].

v0.0.68 [20191206-1700]
add support for new board pump (DC) IO, add test command group and bit test, updates and bug fixes in expression parsing.

cli_api, cli_impl, commands.h, csgsys, help.md:
- add test command group, test bits command [store current IO, mask, masked state in CX vars]
- show ADC2 (always 0) in cli_get_bits
- bug-fix(cli_reg) : add scan for %lX instead of %X to get chg value
- remapped IO constants to accommodated added pump IO
- document

iodigital:
- update dio_parse_bits for remapped IO

config:
- add config_int_val to return config values as ints (int64); companion to config_double_val()

script:
- bug-fix(expression parsing): fixed incorrect parse/comparison/conversion between double and int types
- distinguish between floating point and integer token types in expressions - TT_NUM -> TT_INT, TT_FLT
- token parsers now get double and int values, and use appropriate comparison

sdc:
- add bittest.scr: tests IO and expressions, demonstrates test bits command.
- update help.md
- bug fix(goto.scr): update for debug command syntax change

previous commits:
f68385a
change li cal syntax and doc to eliminate extra argument, disambiguate cal types; add some general syntax notes and valve preset reference doc
2019‑11‑07
4501b50
simplify crlf fixup (was taking too long and dropping characters)
2019‑10‑10
ef301da
remove tabs, adjust whitespace
2019‑10‑10
356428c
add serPutPrettyString, auto CRLF for upload, less, cat so unix files display correctly; allow tabs in upload files
2019‑10‑09
653ffde
add scr reset|kill doc
2019‑10‑09
26ef300
alias scr reset to scr kill
2019‑10‑09
64cacbe
doc updates
2019‑10‑09
2aa45ed
fix LI_WR_DATETAG macro
2019‑10‑07
94fef33
add WITH_MDIO_SHOW feature compilation switch
2019‑10‑07
f2c6f86
fix pump logic in cli_mdio,add show and verbose options,use config span concentration default and delay extension option in licor cal
2019‑10‑07
1127a8f
doc updates
2019‑10‑07
ef108a9
fix data tag (cal cals not accepted) use span concentration from config as dfl, add post cal delay extension, disable output before running cal
2019‑10‑07
b0097f8
add support for showing status subsets in licor_stat
2019‑09‑19
710235f
add LI STAT command (print licor status to console)
2019‑09‑19
8c1d02f
add pre-sample blank interval support in licor_stream_x, change debug API (no space between args) for consistency, doc updates (+REF, -SET DEBUG, etc.)
2019‑09‑19
058cb6b
fix bug: qpeek fails when single queue entry (index error in cli_qpeek)
2019‑09‑18
8456645
add script_parst_hnd (used in previous cli_impl checkin), fix segfault when unload non-existent script (script_init NULL check)
2019‑09‑18
4ea2b11
add goto test script
2019‑09‑18
4a73fa3
add print doc, remove deprecated command doc
2019‑09‑18
9795456
add debug output for MOD_LIC debug bit, fix swapped peak/area labels for xrecord_show, fix co2 peak initialization (incorrect peak output), deprecate m* macros, deprecate scr macro
2019‑09‑18
400fd7a
change name of scr debug to scr sdebug
2019‑09‑17
aa48d73
fix bugs: scr delay ignores args due to bad hnd parsing, debug doesn't work from script context due to name conflict (rename scr debug scr sdebug)
2019‑09‑17
5a01e4a
add debug (MOD_ACT) to mdio macros
2019‑09‑17

v0.0.66 [20190814-1740]
Add support to enable/disable calibration writes for MMEAS

v0.0.64 [20190813-1620]
Reformat help text using Markdown

v0.0.62 [20190813-1445]
Bug fixes (scr load/unload), deprecating M<op> macros using MDIO and MMEAS.

cli_impl:
MDIO and MMEAS separate IO manipulation from measurement processing.
MDIO may be used to set up valves and pumps with specified delays.
MMEAS is used to process a set of licor measurements, using specified parameters.
They provide fine-grained control of cycle operations, as well as simple presets (macros)
that encapsulate several IO operations and timing, with minimal parameter overrides.

The use of M<op> macros are deprecated, but available for testing.
MDIO, MMEAS should be used for production scripts

M<op> equivalents are implemented using mdio and mmeas:

	PURGE: mdio purge
	FILL: mdio fill
	ACID: mdio acid
	ZERO: mdio zero
	MEAS: mdio sample
		  mmeas prebl sample postbl
		  mdio measx
	AIR: mdio air
		 mmeas air
		 mdio measx
	STD: mid std
	  	 mmeas std
		 mdio measx
	SZERO: mdio szero
	REST:mdio rest
- removed cli_mpow
- fix bug - (cli_scr_load) o option ignored. Change symantics o<+/->
may be inserted anywhere in file list to enable/disable overwrite for
files that follow.
- fix bug (cli_scr_unload) : handles list incorrectly
- simplified cal parsing

licor8xx:
- simplify parsing

v0.0.60 [20190812-1255]
Macro updates/additions

cli_impl, cli_api:
- streamline code for calling licor measurement
- add optional baseline measurements in mmeas
- add macro mpow (power licor, pumps w/ pre/post delay)
- add macro mxmeas (take one or more licor measurements)

v0.0.59 [20190801-1515]
Add command history

ui, cli_impl, cli_api, cwgsys:
- add command history feature
- up/down arrows recall queued commands
- add hist command (alias "!")
  hist [v] [id]
	default: shows command history
	v : verbose output
	id: execute history command id

- may be compiled out, configured in cwgsys.h using
WITH_UI_HISTORY, UI_HIST_QUEUE_LEN


v0.0.57 [20190731-1515]
Eliminate duplicate code, bug fix (arg index in pulse nbits), help doc updates

cli_impl.c, :
- eliminate duplicate code (cli_pulse_bits wraps call to cli_pulse_nbits)
- bug fix: cli_pulse_nbits uses wrong arg index to start processing bit set
cwgsys.h: add macros for pump IO bits

iodigital:
- add mnemonics to CLI for specific pumps, and new pump combinations

v0.0.55 [20190731-1145]
Update help text file, HISTORY corrections

help.txt: updated bit numbers to reflect previously added IO bits, added help for pulse nbits
HISTORY: fix duplicate version number (0.0.51 -> 0.0.53) and time

v0.0.53 [20190731-1100]
Add command to pulse bits multiple cycles (specify duty cycle), bug fixes

cli_impl, cli_api:
- add pulse nbits command (pulse nbits <dir> <ta> <tb> <n> <bits>...)
- bug fix: macro arguments ignored; fix logical sscanf eval (sscanf... instead of !sscanf...)

v0.0.51 [20190729-1300]
Add macros that wrap cycle sub-operations, add support for valve, pump IO

cli_impl: add macro implementations to CLI:
MACID, MAIR, MFILL, MMEAS, MPURGE, MREST, MSTD, MSZERO, MZERO

cwgsys.h:
- add macro (MBIT) to map bit index to bit mask
- add support for new valve, pump IO bits

v0.0.50 [20190619-1630]
Add support for additional valve IO (SV9)

cwgsys, cli_impl, iodigital:
- add IO to enumeration
- adjust IO constants

v0.0.49 [20190613-1330]
bug fix (iospi) : SPI BRG configuration (too slow), resulting in sampling errors.
Fast/RTC:1 MHz (FCY/1)  Slow:62.5 kHZ (FCY/16)

v0.0.48 [20190612-1700]
Bug fix (set var w/o SDC installed hangs)

bug fix (main): set var w/o SDC installed hangs; initialize log memory even when SDC init fails

v0.0.47 [20190604-1200]
Add print/println UI cmd, Add script pause/resume, deprecate UI echo cmd

cli_api:
- add PRINT, PRINTLN commands: case-insensitive,
- println wraps print, automatically adds CRLF
- use
	print|println <fmt> [var...]
	fmt: quoted format string (e.g. printf)
	var: variable names (w/o $ prefix)

	Example:
	>> creg cx0 = 1
	>> print "counter[0] %ld\r\n" CX0
	COUNTER[0] 1
	>>
- deprecate ECHO (use PRINT; may still compile ECHO support using WITH_UI_ECHO)
- use CAT|FSHOW instead of CAT|PRINT

config:
- add alt_fmt arg in config_str_val(), implementing alternative output format (used in print, e.g.)

cwgsys:
- add ISQUOTE(c) macro (return true if c is single or double quote)

script, ui:
- change delay semantics; delay time <0: pause ==0: resume >0:delay
- add script PAUSE/RESUME (wraps scr delay)
- add NULL check to various script macros, invalid value returned if NULL passed
- return value type changed from void to return_code_t for script_set_event, script_set_mode, script_clr_mode

ui:
- add \b, \f support to ui_unescape
- update ui_tokenize to expand variable names in place, e.g.
	>> print "S/N hex/dec $serial_n/%d\r\n" serial_n
	is expanded by ui_tokenize to
		{ "S/N HEX/DEC X4C02/%D\R\N", "SERIAL_N"}

	which, when passed to print becomes
		S/N HEX/DEC X4C02/19458

v0.0.45 [20190530-1400]
Add log segmentation, change log naming scheme, main boot sequence, bug fixes

log:
- add log segmentation: files may be segmented or monolithic.
 - new log naming scheme: XXXYYMM.NNN
   - XXX: name
   -  YY: year
   -  MM: month
   - NNN: segment
   - e.g RAW1905.000 : raw data log, first segment of May 2019

 - seg_size=0 indicates monotolithic (single segment)
 - segmented files may have up to 1000 segments.
 - segments are monotonic (deleted files are not replaced)
 - segments are not overwritten when the max segment is full
 - segments increment automatically on open
 - file size = seg_size+last_write
 - segment resets to 0 for new month
- add log_t members seg_size, segment
- remove log_t member suffix
- add log API functions:
   uint32_t log_err_flags();
   return_code_t log_set_segsize(log_handle_t hnd, uint32_t val);
   return_code_t log_segsize(log_handle_t hnd, uint32_t *ss);
   return_code_t log_close(log_handle_t hnd);
   uint32_t log_max_seg(log_handle_t hnd);
   void log_show(log_handle_t hnd, bool verbose, int indent);
- add LOG_SEG_SUFFIX_DFL "000", LOG_MAX_SEG_N 999

cli_impl, cli_api:
- add ui command lshow: show log summary information
  use: lshow [0:2|*]

- add ui command lseg: get/set log segment maximum
  use: lseg <hnd> [<val>[K|M|G]]
  e.g. set log 2 (raw log) segment size to 20 MB:
       lseg 2 20M

iofile :
- add function fc_dir_next: directory item iterator. Pass non-NULL directory path ("/") on
initial call, NULL path on subsequent calls; each call returns next directory item, or NULL when
there are no more.

licor8xx:
- add logging flag LF_NOCLOSE
- pass LF_NOCLOSE on raw logging calls in log_stream_x to lazy-open raw data file and hold it open
until processing is complete to reduce overhead. log_close called after processing complete.

main:
- move log init until after SDC init is complete
- add test variables
- reorder some boot sequence dependencies for clarity, consistency
- add more detailed boot messages

proto:
- add some test code for directory read (find max file segment)

script:
- set g_ctty to SER_CONS instead of SER_SCR so that errors are sent to console in script context

bug-fix (config): load_config returns incorrect error code
bug-fix (script): script_bootstrap returns incorrect error code
bug-fix (log): use ul suffix for KBYTE, MBYTE, GBYTE constants

v0.0.43 [20190523-1830]
Add regression params to baseline record, add tests for fseek time issue

cli_impl, licor8xx:
- Dialed back nmeas timeout to 1.2*nominal, removed pre-check for data tag

ISSUE: samples fail due to incomplete sample count:
- after sampling continuously for some time (hours?), licor_streamx returns ERR_FAILURE b/c
it failed to read the requested number of samples. There are also errors indicating that
set_outrate fails frequently. Calling li nmeas from command line also produces
errors.
Root cause: as raw data file grows, seek time starts at ~40-60 ms to EOF increases ~10 ms/MB.
At ~20-25MB, the seek time exceeds the nominal sampling period, resulting in sampling errors.
Resolution TBD; options: file segmentation?

licor8xx:
- add calculation of trend line slope, offset, correlation (m, b, r^2) to bline handler,
together with associated macros
- add required fields to bline record, state structs
- rename bline record, state/struct members and macros for clarity
- add m,b,r^2 fields to bline record output format in licor_brecord_str, licor_brecord_show
- set outrate to 0 then flush serial input in licor_streamx before setting output to improve
reliability of set_outrate return.

config:
- add config item LOG_RAW (bool, log raw licor records if true)

proto:
- add fseek test (see issue this commit)

ui:
- do not preserve quotes in echo

cwgsys:
- add prototype system state struct (for tracking state between power cycles); not currently used

v0.0.41 [20190517-1630]
Update/fix sequence number logic

licor8xx, cli_impl:
- set sequence number only when logging
- fix oflags set/lookup for sequence number
- set in cli instead of licor_parse_measurement

various:
- rename iso1806->iso8601 (standard name incorrect)

v0.0.39 [20150517-1130]
Add text file pager with basic search, update help file, change uiGetLine semantics

cli_api, cli_impl, iofile, cwgsys
- add LESS command (text file pager)
- help command uses pager
- less feature may be compiled out using -DWITHOUT_IOF_LESS
- fsys utils (e.g. ls, cat, rm, etc) use XPRINT so that they will work from host or console

iofile, ui :
- change uiGetLine semantics to accept buffer length and flags arguments for controlling
input echoing and case-sensitivity

help.txt :
- update format for readability
- add

proto, cwgsys:
- add less test (see PROTO_* options in cwgsys.h)

v0.0.37 [20190514-1015]
Update output direction scheme, routing output to calling terminal

Until now, most commands issued from host port direct output to the console.
This prevents hosts from using output and detecting error conditions, and
may not be what users expect. The new scheme generally directs output to the terminal
that issued the input, though in some cases, output may be explicitly directed to one
or more endpoints.

cli_impl, cwg_sys, io_file, main, script, ui:
- add global system variable (g_ctty in cwg_sys)
- g_ctty is set by ui, script when input lines are read, indicating which terminal issued a command
- define XPRINT macro and use g_ctty in some existing macros (e.g. E*, W*) to direct output to the calling terminal.
- add macros to direct output to host (HPRINT, HEMSG, HEPRINT, HWMSG, HWPRINT); default macros use calling terminal
- selected commands (e.g. echo, li nmeas) include arguments to explicitly control the output endpoint(s)
- add SER_SCR constant to indicate that caller is script (output generally suppressed, except as explicitly configured)

cli_impl :
- (cli_debug) : add assigment option ('=') to set module debug flags
- (cli_set/get ser, baud) : support H|C|L options in addition to port numbers

v0.0.35 [20190509-1740]
Bug fix (qpeek, qpop records truncated), qpeek/qpop symantics changes

qpeek:
- change symantics, now start index is relative (to peek pointer), not absolute queue index
- add optional count argument (number of entries)
- add '*' argument to indicate all entries

qpop:
- add optional count argument (number of entries)
- add '*' argument to indicate all entries
- add 'Q' option to suppress output (i.e. just delete the entries indicated)

bug fix: (qpeek, qpop records created from cmd line using li nmeas are truncated)
- caused by default record type being applied after push to queue

v0.0.33 [20190509-1200]
Bug fix (qpop causes addr exception), add sys_hex_show function, add qclear command

log, cli_impl, cli_api:
- add qclear command to CLI; deletes all queue entries
- add log_queue_clear function

- bug fix (cli_qpop) : qpop causes fatal exception (code 3: addr error). argc not checked before reading argv argument to set verbose option.
The stack was apparently corrupted by this access, causing the failure in subsequent function calls, even though the data was valid. Checking
argc to prevent invalid argv access resolves the issue.

cwgsys :
- add sys_hex_show function for formatted memory console output. Optionally set number of columns (default 16), indent and/or output of offsets.

licor8xx :
- add context byte to default output flags

v0.0.31 [20190507-1320]
Bug fix: delay during cal config write causes subsequent sample measurement to fail

licor8xx :
- add read of cal write output with timeout (~8-10s needed). The cal write responds with ACK
and then suspends output while the cal is written(?). Reading the licor after the ACK
e.g. via li nmeas command, may fail since output is suspended while the cal write takes place.

v0.0.29 [20190424-1930]
Bug fix (resets on licor serial interruptions), trap code updates and tests

- new feature: add addrtrap.s, implements trap prologue that unwinds stack
to report approximate error line on address trap. (currently used for debug only)

- new feature (traps.c): add blinky LED codes to indicate trap values

- proto: add test for forcing trap conditions to test trap code.

- cwgsys: reinstated pmem command

- ioserial, licor8xx: fix unitialized vars and added pointer checks.

licor8xx:
- remove pack pragma and add ctx byte field (maybe already added) to ensure proper
alignment to prevent pointer mishaps.


- bug-fix (licor8xx): reset when powering on licor while cyc.scr script is running. Unchecked NULL pointer (pmalloc return), combined with pfree inside a block of code (should have been outside). If serial IO was interrupted during licor_streamx, sometimes the buffer would fail to free. Eventually, pmalloc would run out of buffers and return NULL, which went unchecked. The NULL pointer access resulted in a reset (not an addr trap).

cwgsys, main:
- capture/clear RCON (reset control reg) state at start-up and report to console, syslog

v0.0.27 [18apr19-1430]
Add arglist concatenation, add syslog error reporting, bug fixes

ISSUES:
- entered potential sdcard corruption when programming while script is running

cwgsys:
- add pargcat, function to concatenate arglist (argc,argv) into single string.

cli_impl:
- use pargcat in echo and for some syslog calls
- li_tm, li_nmeas, li_or: make logic consistent and add syslog for errors
- scr_delay: adjust logic to allow hdn to be passed on command line, enabling scripts to be paused from CLI or other scripts.
iofile:
- csShowS_orig: changed fail logic to proceed as far as possible
- fcUnlink: add syslog entry when deleting files

ioserial:
- changed some DPRINT to MPRINT

licor8xxx:
- bug-fix (licor_publish): always returns failure. now returns error only on failure.

v0.0.25 [17apr19-1410]
Logging bug fix (again)
log:
- bug-fix (log_addx): improved logic (remove else) s.t. no empty line is written when file is created.

v0.0.23 [17apr19-1300]
Logging bug fix
log:
- bug-fix (log_addx): log not written when file created. Nothing is written, so len always zero,
causing it to follow the zero len path forever. Fixed logic; writes empty line at start of file.

v0.0.21 [17apr19-1215]
Logging bug fixes

log:
- bug-fix (log_queue_show): reported entry, push/pop pointers incorrect
- bug fix (log_addx) : raw records not logging. fseek offset specifed as size_t but should be DWORD (ulong).

licor8xx, config:
- moved mnemonic parsing routines from licor8xx to config and renamed (config_...).

licor8xx, log:
- change pad byte in record structs to context field (byte). Add support in oflags so
that it may be enabled/disabled.

- bug-fix (licor_publish): records failing to log b/c data len 0 (previous impl used 0 len differently, must handle binary). Add len field
- bug-fix (licor_streamx): li nmeas, tmrecord timestamps incorrect. Type alignement from rtc_mktime; call mktime directly and use intermediate variable to get result. Seems intermittent?
- bug-fix (licor_brecord_str): bline record fields (li nmeas b...) change each cycle. output flags referenced a miscast data member. Added oflags member far and set in bline handler.

v0.0.19 [16apr19-0800]
Add Support for configuration mnemonics (inbound only), add support for general purpose double registers, register function naming consistency, bug fixes

cli_api:
- Add DREG command to get/set double registers
- rename CTR, FLAG commands to CREG, FREG.

cli_impl:
- feature (CREG): add decimal and hex output for display
- feature (CREG, FREG, DREG): specify '*' instead of register name to show all
- feature (cli_get_analog, cli_get_bits) : store result to register
- cli_scr_macro: zero IO bits before executing macro
- bug-fix (cli_creg): fix parsing to accept decimal or hex

config:
- function and macro renaming to make more consistent:  config_parse_counter, config_parse_flag to config_parse_cx,config_parse_fx. Add config_parse_dx. Register validation macros (FX_ISVALID, CX_ISVALID).
- add configuration variables: LI_OFLAGS (record field configuration), LI_CFLAGS (instrument output configuration).
- feature: add alt_parse function member to licor_config_item_t to support mnemonic parsing. The basic architecture is that user application code (e.g. licor) may provide an alternative configuration parser. If not set to NULL, the alternative is invoked first when the values are parsed. If it fails, the default parser is invoked (e.g. SET VAR). This applies whenever CLI functions invoke parsing as well. For now, mnemonic support is inbound only, i.e. reads, but config exports use the default format. In the future, this may be extended to support outbound.
- add direct accessor methods for register values: config_get_fx/cx/dx
- bug-fix: now skip comment lines when parsing configuration files
- bug-fix: config_get

config, licor_8xx:
- feature: add mnemonic support for LI_OFLAGS, LI_CFLAGS
- increase config line length limit to accommodate li_cflags, etc.
- bug fix: config_set() crashes in assign function when passed pointer to vrecord->oflags, but not a pointer to a uint32_t, though both are the same type. Apparently this is a structure alignment issue related to structure type member (single byte), not fixed by pack pragma. Adding pad byte (or moving type field to end of struct) seems to resolve issue.
proto:
- some test code for debugging issue: config_set() crashes in assign function when passed pointer to vrecord->oflags, but not a pointer to a uint32_t, though both are the same type. see bug fix above.

ISSUES:
- updated, reorganized list

v0.0.17 [11apr19-1830]
Major revision of UI and CLI to eliminate redundant parsing code and implement limited variable substitution and escape character support

command, action, ui, iofile, iodigital, script, config, proto, log:
- change command -> cli_api
- change actions -> cli_impl (function names cli_)
- change CmdFunc signature from (char *) to (int argc, char **argv)
- command line processing does tokenization ( w/ variable substition),
then passes token array to command functions. This eliminates much cut/paste
tokenization code from action functions. For quoted strings, space is preserved,
and variable sub is performed, but escape character processing is deferred to
downstream processes.
- add dispatch functions that accept token lists (supports functions that previously called uiParse again)

- add support for escape characters
- IO parsing formats for unsigned types require X prefix for hex numbers

cwgsys:
- add sys_show_tokens to dump token lists
- add DSHOW_TOKENS(argc,argv) macro to call sys_show_tokens; allows calls to be compiled out or controlled via module ID x2000
- add pstralloc(char*b, char *e): allocates buffer and creates NULL terminated string that
includes characters between the begin and end pointers. This is used to extract substrings
without affecting the original.
- add several 16- and 32-bit buffers to the pool for processing tokens.

script:
- scr sync behavior changed to run script after specified delay
- changed EPRINT to SERR

.gitignore:
- add sandbox

v0.0.15 [09apr19-1315]
Rename RT_X to RT_SAMPLE, deprecate pulse bit (use pulse bits), add proto tokenizer

licor, actions:
- renamed RT_X to RT_SAMPLE

actions, commands:
- deprecated pulse bit (use pulse bits)

ui,proto:
- add ui_tokenizer; divides lines into tokens, including quoted strings, and does variable substitution. If input line contain variables, new strings are created using palloc. Callers must call ui_release_toks on token array returned.

config:
- switch output from EPRINT to SERR macro


v0.0.13 [08apr19-1740]
Replace set/clr power and set/clr bit with set/clr bits, implement reference record variant of licor_xrecord_t

action, commands, iodigital:
- deprecate commands: set/clr power, set/clr bit (use set/clr bits)
- add dio_parse_bits function to iodigital; implements CLI mnemonics for specifying
  one or more IO bits.

licor8xx:
- implement reference record variant of licor_xrecord_t; both use licor_xrecord_t, but use
record type to gate output of area, peak fields (reference record vs sample record).

script:
- rename MACRO_STD_STR MACRO_SPAN_STR
- add ZIO macro (turns off all valves and pumps) (redundant w/ clr bits)

v0.0.11 [08apr19]
Improve log API, generalize queue API, add doxygen comments for licor, log

log, action:
- bug fix (fcPrint): variable type mismatches caused cat to quit early for some files
- generalized queue functions (take queue handles), enables support for multiple queues
- improved log add functions: data type/length requirements were ambiguous; now has
adds (add string), addb (arbitrary binary data), addx(general functions wrapped by adds, addb).
addb, addx require length argument, and addx uses fwrite instead of puts (which assumes NULL
terminated string). Added flags argument to support options like adding data size field
to data. Overall, made log_add functions more clear and consistent.
cwgsys:
- added SOUT and SERR print macros (distinct from DPRINT, which may be commented out, and EPRINT, which also prints function, line)

licor, action:
- rename bline_record_t licor_brecord_t
- rename avg_record_t licor_xrecord_t
- deprecate licor_last_record (use qpeek)

v0.0.9 [05apr19]
Fix SPI configuration bug (slow SD Card writes), refactor record types, misc features/cleanup

bug fix - spi1_driver.c (mcc), iospi.c:
spi modes bits were misconfigured, manifesting as slow SD Card writes.
The root cause was coding error when replacing legacy implementation with MCC code. There were several issues:
SPI fast mode clock divisor configuration same as slow mode.
The CKE bit for fast mode was incorrectly set.
The variable CardFast in iospi had been commented out for fast mode.
Now RTC works, and SDCard writes are 4x faster (fast enough to capture raw data at 2 Hz).
To fix:
- change MODE_FAST SPI1CON1 configuration from 0x1D 1:16 divisor (125khz) to 0x1F 1:1 (2Mhz).
- added MODE_RTC (like slow sdc mode, but CKE bit set).
- reordered the configs: MODE_SLOW(0x013F) MODE_FAST(0x013D) MODE_RTC(0x003D)

licor, action:
- refactor record types for simplicity:
	Replace licor_parsed_data_t w/ licor_vrecord_t (value record),
	with an array of double fields indexed using FID_<field>
	incorporate area and peak into fields.
    use field indices to define oflag values
	Eliminate frecord
- add licor_brecord_show function
- refactored record stream handler, str and show functions to iterate over fields (more compact)
- rename records and fields more consistently
- add sdev to avg_record_t
- change LI_RECORD_STR_BYTES from 512 to 370 (speeds up processing if bytes are dropped,
  since timeout/overflow happens more quickly)

log:
- increase LOG_QUEUE_DATA_BYTES from 100 to 200
- remove unimplemented log_queue functions

actions, iofile :
	- rm now accepts file list
	- qpeek, qpop accept V (verbose) option (calls show methods in addition to dumping record string)


v0.0.7 [02apr19]
Add data record queue feature

commands, actions:
- add ver command
- see also: log changes

licor8xx:
- Change data records to separate binary record data from state information,
  i.e. package record data separately from intermediate computation products.
  This makes it easy to buffer the binary record (e.g. in a queue).

log:
- Implement a FIFO sample queue for binary records. Currently, it is allocated to
  hold the largest binary record w/ a depth of 10 (~1kb), or 3-4 sample cycles
  assuming records per cycle. The licor nmeas CLI function uses log_queue_push()
  to put binary records in the queue. Hosts may manipulate the queue using
  CLI functions:
    QSHOW: show a summary of the queue
    QPEEK <n>: print the contents of the nth queue entry (a data record).
    QPOP: print the contents of the next queue entry and delete it.
    QCOUNT: return the number of entries in the queue

proto:
- add queue unit test to the proto suite.


v0.0.5 [01apr19]
Move counter and flag variable implementations from script to config
script, config, actions, commands:
- move counter and flag variable implementations from script to config.
- rename varsave to excfg
cwgsys:
- add NULL pointer check in RTRIM macro
- add null '\0' check in TRIM macro

v0.0.3 [28mar19]
Enable parsing characters to integer, byte types, deprecate cwgconf.[ch]
replace with config.[[ch]]

- cwgsys.h : ETRACE, EMSG macros - ETRACE allows format, args, EMSG is string message only

- SET VAR : enable parsing for characters e.g. 'M' into for int, byte config values

- deprecate cwgconf.c,h (replace w/ config.c,h)

v0.0.1 [27mar19]
- Add script control constructs, licor multi-sample, counter/flag variables

new features:
- counters (uint32_t, CXn)
- flags (bool, FXn)
- script control features:
	- GOTO label|var
	- IF[expr] statement
	- labels
- counter, flag set/show ommands:
	- CTR CXn [=|++|--|*=|/=|%=]
	- FLAG FXn [=|!]
	- ECHO [text|var...] 
- licor commands:
	- LI NMEAS: take multiple samples, process using specified function
	- LI CAL: licor_cal(): perform specified calibrarion  using specified function

updates:
- get/set var: support for typed variables, counters, flags
- scr load: accept file list
- config: add config_double_val(), change signatures of _val() functions for consistency
- licor: add brecord, frecord types 
 log: add support for raw data log (experimental). add wrapper for addf with optional payload
length output and better timestamp handling

- bug fixes
- clean up failed scr load 
- error handling for invalid GOTO destination

