julian C / VarStore
Embed: (wiki syntax)

« Back to documentation index

VarStore Class Reference

VarStore Class beta !!!!!!! Used for reading/modifying program variables from the console at runtime. More...

#include <VarStore.h>

Public Member Functions

int Load (char *Name, void *VarPtr, VarTypes VarType)
 Load a variable on VarStore.
int Load (char *Name, void *VarPtr, VarTypes VarType, int Size)
 Load an array on VarStore.

Static Public Member Functions

static void Worker (void const *args)
 Thread that will manage the console interaction.

Detailed Description

VarStore Class beta !!!!!!! Used for reading/modifying program variables from the console at runtime.

Helpful for debugging It has a facility as well to reset the mbed from the serial console without pressing any button. It does not block the serial/input channel in case it is needed for other stuff

From the console ( be aware that if you do not have local echo activated you wil not see what you tye. Commands are triggered at CR

s:var:value -> sets the value of var to value at runtime d:var -> dump content of var s:arr:val1,val2,val3 -> set first three values of arr to val1,val2,val3 r -> reset mbed... and reload program w:milisecs -> (beta) release the console input for your program for a period of time7

I do have in a note pad sets of commands, e.g. dumps of variables I want to check and then I just copy and paste in to the terminal so see all of them at once or repeteadly show them.

hope it helps.

Example:

 #include "mbed.h"
 #include "rtos.h"
 #include "VarStore.h"

 #include <RawSerial.h>

 RawSerial  pc(USBTX,USBRX);  // Be aware !!!! need rawserial. No printf for you anymore !! 
                              // no malloc nither as this works in ISR

 VarStore Store(&pc,20);      // create storage for 20 variables/arrays attach to serial pc
 
 DigitalOut led1(LED1);
 DigitalOut led2(LED2);
 
 void led2_thread(void const *args) {
    
    int wait2=1000;
    Store.Load("wait2",&wait2,T_int);   // load variable wait2 in Store
    
    while (true) {
        led2 = !led2;
        Thread::wait(wait2);  // remember, no WAIT, STOPS CPU FROM RUNNING WHOLE PROGRAM.
                               // use Thread::wait to stop just your path of execution.
    }
 }
 
 int main() {
    
    int wait1=500;
    Store.Load("wait1",&wait1,T_int);  // Load variable wait1 in Store
    Thread VS_thread(VarStore::Worker,&Store,osPriorityNormal,DEFAULT_STACK_SIZE,NULL); // launch VarStore Thread
    
    Thread thread(led2_thread);
    
    while (true) {
        led1 = !led1;
        Thread::wait(wait1); // remember, no WAIT, STOPS CPU FROM RUNNING WHOLE PROGRAM.
                              // use Thread::wait to stop just your path of execution.
    }
 }

Definition at line 81 of file VarStore.h.


Member Function Documentation

int Load ( char *  Name,
void *  VarPtr,
VarTypes  VarType,
int  Size 
)

Load an array on VarStore.

Parameters:
Namestring that will be used to query/set the value of the variable/array
VarPtrpointer to base of array
VarTypeenumerated type indicating int/float ( only supported currently) enum VarTypes {T_int,T_float};
Sizenumber of elements in the array
Returns:
ERR on error / NULL on success

Definition at line 62 of file VarStore.cpp.

int Load ( char *  Name,
void *  VarPtr,
VarTypes  VarType 
)

Load a variable on VarStore.

Parameters:
Namestring that will be used to query/set the value of the variable/array
VarPtrpointer to variable
VarTypeenumerated type indicating int/float ( only supported currently) enum VarTypes {T_int,T_float};
Returns:
ERR on error / NULL on success

Definition at line 54 of file VarStore.cpp.

void Worker ( void const *  args ) [static]

Thread that will manage the console interaction.

Main role is to remain sleeping and only awakening to fire worker2 to deal with console input

Parameters:
argspointer to the VarStore Object that will be managing.
Returns:
ERR on error / NULL on success

Definition at line 151 of file VarStore.cpp.