pitt-rnel / pyrtma

A Python client for RTMA/Dragonfly

Home Page:https://pyrtma.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compiler ignores float constants

jmw182 opened this issue · comments

The message compiler currently ignores constants that include float values, e.g. #define PI 3.14 or (more practical) #define SAMPLE_LENGTH 0.02. Such constants are ignored whether they involve calculations or not.

This can be fixed by updating the regex statement in the line below to include \. in the expression character set.

macros = re.findall(
r"#define\s*(?P<name>\w+)\s+(?P<expression>[\(\)\[\]\w \*/\+-]+)\n", text
)

This simple fix should allow constant literals to be defined, but will not fix errors from performing arithmetic on a mixture of float and int constants. If this is difficult to fix we could choose not to support this. This affects one definition in the current climber_config.h, but this could potentially be phased out of climber:

#define RAW_COUNTS_PER_SAMPLE 2 // MAJOR CHANGE FROM HST1: CHANGING FROM 3 TO 2 TO INCREASE SAMPLE FREQ FROM 33Hz TO 50 Hz
#define SAMPLE_LENGTH (0.01 * RAW_COUNTS_PER_SAMPLE) // seconds

I updated the regex in compile.py in fe8d708 to allow macros with decimal points. This should work for constant literals but will still result in errors for arithmetic expressions such as #define SAMPLE_LENGTH (0.01 * RAW_COUNTS_PER_SAMPLE).

Also, the regex skips string constants that include special characters. For example this constant is skipped by the compiler due to special characters " and :

#define DEFAULT_MM_IP "localhost:7111"

These issues have been resolved in compiler V2