o
    jj&                  	   @  s	  U d Z ddlmZ i dddddddd	d
d	dddddddddddddddddddddd d!d"i d#d$d%d&d'dd(dd)d*d+d,d-d.d/d0d1d2d3d4d5d d6dd7d&d8d9d:d;d<d&d=d>i d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMd,dNdOdPdQdRdSdTdUdVdWdXddYdZd[d\d]d^i d_d`dadbdcd,ddddedfdgdhdidjdkdZdldmdnddodpdqddrdsdtdudvddwddxdyi dzdQd{d|d}d~dddddddddddddd"ddddddsdddddddd"i dddddddd	ddddddddddddddddddZddddddddi ddddddddddddddddddddddddddddÓddÓddddi ddZdddddddd̓dddddddd^ddғddԓdd֓dd`ddٓddۓddddi dd$dddd$ddddddWdddddddd ddddddddddddddi ddddddddddddd ddddddddd	d
ddddd̓dddddd~i ddddddddddddddd d!d"dOd#d$d%d.d&d'd(d)d*d+d,d$d-dd.d/i d0d/d1d4d2d4d3dd4d0d5d0d6dd7dd8d2d9d2d:d;d<dud=d>d?d@dAddBdOdCdi dDdEdFdEdGddHddIdJdKddLddMdNdOdQdPddQd/dRdSdTdUdVdWdXd dYddZdi d[d$d\dd]d^d_d*d`dEdadEdbdcddddeddfdٓdgddhdidjddkdÓdlddmdidndoi dpd$dqddrdidsddtdudvdsdwddxd$dydzd{dd|d&d}d"d~d"dddd	ddddi ddddZddddddQddddddddddddddddddddddddi ddddddddmdddddddddddddddd	dddddddddd i dddddddddddddddddd,dd,dɐdʓdːdcd̐dcd͐dodΐddddddѐdddӐdԐdՐdd֜Zded< d&ddddڜZded< G dݐdބ deZddddZdS (  a  Numeric codes for Roboteq serial command constants (the `_XXX` names
used as the first argument to GetValue/SetCommand/GetConfig/SetConfig).

Two tiers of confidence here:

1. **Bytecode-confirmed** (the highest bar): decoded directly from real
   RoborunPlus-compiled `.hex` output.

       _VAR      = 6   (batch 4, GetValue and SetCommand)
       _ALIM     = 42 (0x2A)  (batch 4, GetConfig/SetConfig)
       _MS       = 16 (0x10)  (batch 6, SetCommand)
       _GO       = 0          (batch 6, SetCommand)
       _ESTOP    = 14 (0x0E)  (batch 6, SetCommand)
       _AI       = 16 (0x10)  (batch 6, GetValue)
       _BATAMPS  = 12 (0x0C)  (batch 6, GetValue)
       _MOTAMPS  = 0           (batch 6, GetValue)
       _MOTPWR   = 2           (batch 6, GetValue)
       _V        = 13 (0x0D)  (batch 6, GetValue)
       _D0       = 11 (0x0B)  (onoff.mbs, 2026-07-29, SetCommand -- corrects
                                the manual-sourced guess of 9 below, which
                                was apparently confused with _DOUT's own
                                code. _D1 = 10 (0x0A) was independently
                                confirmed correct by the same diff.)

2. **Manual-sourced** (everything else below): read directly from the
   "HexCode:" field documented for each command/query/config parameter in
   *Roboteq Controllers User Manual*, V2.1. All 10 bytecode-confirmed values
   above also appear in the manual and match exactly -- strong evidence the
   manual's HexCode field is what actually goes on the wire, so the other
   ~300 values it documents are trusted here even though they haven't each
   been individually diffed against a compiled `.hex` file.

Extraction notes (see `docs/reverse_engineering.md` for the full writeup):

- A handful of aliases were dropped because the manual itself has
  copy-paste errors: some later sections reuse an earlier section's
  `Syntax Scripting` example without updating the `_XXX` name to match that
  section's own declared alias (e.g. the `CU` command's example says
  `setcommand(_CS, ...)` -- copied from the preceding `CS` section and never
  fixed). Where a section's own alias doesn't match the `_XXX` name in its
  own example, that example was discarded rather than trusted.
- The DS402 (CANopen motion-profile) command/query sections were excluded
  entirely. That's a separate operating profile from plain serial
  MicroBasic scripting and several of its aliases collide with unrelated
  classic-mode codes for the same short name (e.g. a DS402-only `MOTVEL`
  variant using a different HexCode than the classic `S` command's
  `_MOTVEL`) -- since a MicroBasic script on this hardware isn't running in
  DS402 mode, the classic definition is what applies, and the DS402
  duplicate would just be wrong here.
- `_BRUN` and `_CSS` (and only these two, once the above two rules are
  applied) turned out to genuinely mean different things depending on the
  verb: `_BRUN` is HexCode `0x0C` as a `SetCommand` (start/stop/restart the
  running script) but `0x48` as a `SetConfig` (enable auto-start on power
  up) -- two unrelated parameters that happen to share an alias. `_CSS` is
  `0x6C` to `SetCommand` (load an SSI counter) and `0x6E` to `GetValue`
  (read it back) -- related but still separately numbered. These are
  handled by `VERB_SPECIFIC_CODES` below and checked before the flat table.

Command names are matched case-insensitively, without the leading
underscore (the parser strips it before lookup).
    )annotationsaabcntr   abspeed   ac   accelacs   actr   adb   ai   aic#   aina   alim*   alin   amax   amaxa   amin   amina   amod   ams   anainanaincangB   apol   asi3   atga,   atgd-   atrig+   axbbabadj`   badva   batampsbdt   becc   beed   bfbkc   bhl>   bhla@   bhome<   bhv   bindbkd   blcntr   blfb;   bll=   blla?   blrspeedblspeed
   blstd:   bmcL   bmfM   bmod_   bndboolbpol9   bpr   brv   bsbscP   bsrbzpwb   ccalive&   can'   cangocansendcasZ   cbcbrX   cd   cenV   cf(   cgchbY   chla   chs   ciacipcisclclerd8   clin   clsn[   cmdanacmdplscmdsercnodW   cpricr   cscsrm   csrt\   ctps]   cttp   d   d0d1dcddt   deceldfcdhcpo   di   digindigoutdindinadinldmod   dodoa   dol   dout	   dpan   dr"   dreacheddresdsdsetdxeechofedec   eeeeseesavehlehlaN   ehomeO   ellK   ellaemodI   epprJ   estopexffcG   feedbkfffid   finfltflagflw{   fm0   fsfsa   ggidgiqz   gogwai   hhomehpo   hs1   hsat   hsensehsm   icap2   iclF   illr   ilm   ipah   ippk   irr   ismk!   kdg   kifkig   kpf   kpg   ld   lk   lockedlperrlq   mma%   macmdal   mdec4   mdirw   memsmgmgd)   mgdetmgmmgmrkrmgomgsmgstatusmgtmgtrackmgymgyromlx   mmodmnod   mnrpm   motampsmotcmdmotflagmotpos   motpwrmotvelmposrelmpw   msmstopmvel5   mxmdmxpfmxprmxrpm6   mxs   mxtrn7   nxtaccnxtdecnxtposnxtposrnxtvelotl   ovhovlppctr    pdbpdnsphapipic$   pinaplinplsinplsincpmax   pmaxapminpminapmodpms   ppolprprxpsa   pxrrcrcoutrelcntrrelspeedrfc   rs   rs485   rsbrrwdssblcntrsbmj   sccE   scpr   sdnssecsed   sencntrshl   shla   shome   skctrS   skdbT   sklinU   skmaxR   skminQ   skuseslH   sll   slla   smod   snay   spektrumspolA   srsro^   ssssf   ssrstflagsto   sttsvt   swd   sxttemptidtimetmtnm   trtracktrnuiduvlv         g      )varvkvoltsvphwmodzsmazsmczdict[str, int]COMMAND_CODESl   ))brun
setcommand)r  	setconfig)cssr  )r  getvaluezdict[tuple[str, str], int]VERB_SPECIFIC_CODESc                      s   e Zd Zd fddZ  ZS )UnknownCommandErrornamestrc                   s(   t  d| dtt d || _d S )Nz#Unknown Roboteq command constant '_z'. See commands.py (z& known constants) for how to add more.)super__init__lenr  r  )selfr  	__class__ P/sessions/funny-vibrant-bardeen/mnt/compiler/src/microbasic_compiler/commands.pyr    s   
zUnknownCommandError.__init__)r  r  )__name__
__module____qualname__r  __classcell__r  r  r  r  r    s    r  Nr  r  verb
str | Nonereturnintc                 C  sF   |  d }|dur||ftv rt||f S |tvrt|t| S )aB  name includes the leading underscore, e.g. '_ALIM'.

    verb, when given, is the lowercase device-I/O function name the
    constant is being passed to ('getvalue', 'setcommand', 'getconfig',
    'setconfig') -- only relevant for the handful of aliases in
    VERB_SPECIFIC_CODES that mean different things per verb.
    _N)lstriplowerr  r  r  )r  r  keyr  r  r  resolve_command_code  s   r  )N)r  r  r  r  r  r  )	__doc__
__future__r   r  __annotations__r  	Exceptionr  r  r  r  r  r  <module>   s   >	
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~                 	  
                                               !  "  #  $  %  &  '  (  )  *  +  ,  -  .  /  0  1  2  3  4  5  6  7  8  9  :  ;  <  =  >  ?  @  A  B  C  D  E  F  G  H  I  J  K  L  M  N  O  P  Q  R  S  T  U  V  W  X  Y  Z  [  \  ]  ^  _  `  a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u  v  w  x  y  z  {  |  }  ~                                     	    
                                                                                             !    "    #    $    %    &    '    (    )    *    +    ,    -    .    /    0    1    2    3    4    5    C	