Added multiple uBASIC program objects to stm32f4xx example port. (#995)
This commit is contained in:
@@ -942,6 +942,22 @@ bool Program_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the context used with load, unload, run, halt, and restart
|
||||
* @param object_instance [in] BACnet object instance number
|
||||
* @param context [in] pointer to the context
|
||||
*/
|
||||
void *Program_Context_Get(uint32_t object_instance)
|
||||
{
|
||||
struct object_data *pObject = Object_Data(object_instance);
|
||||
|
||||
if (pObject) {
|
||||
return pObject->Context;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the context used with load, unload, run, halt, and restart
|
||||
* @param object_instance [in] BACnet object instance number
|
||||
|
||||
@@ -114,6 +114,8 @@ void Program_Init(void);
|
||||
note: return value is 0 for success, non-zero for failure
|
||||
*/
|
||||
BACNET_STACK_EXPORT
|
||||
void *Program_Context_Get(uint32_t object_instance);
|
||||
BACNET_STACK_EXPORT
|
||||
void Program_Context_Set(uint32_t object_instance, void *context);
|
||||
BACNET_STACK_EXPORT
|
||||
void Program_Load_Set(uint32_t object_instance, int (*load)(void *context));
|
||||
|
||||
@@ -562,11 +562,15 @@ void ubasic_load_program(struct ubasic_data *data, const char *program)
|
||||
}
|
||||
data->status.byte = 0x00;
|
||||
if (program) {
|
||||
data->program_ptr = program;
|
||||
tokenizer_init(&data->tree, program);
|
||||
data->program = program;
|
||||
}
|
||||
if (data->program) {
|
||||
data->program_ptr = data->program;
|
||||
tokenizer_init(&data->tree, data->program_ptr);
|
||||
data->status.bit.isRunning = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
token_error_print(struct ubasic_data *data, UBASIC_VARIABLE_TYPE token)
|
||||
@@ -2809,7 +2813,7 @@ static void subsequent_statement(struct ubasic_data *data)
|
||||
return;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static bool ubasic_program_finished(struct ubasic_data *data)
|
||||
bool ubasic_program_finished(struct ubasic_data *data)
|
||||
{
|
||||
struct ubasic_tokenizer *tree = &data->tree;
|
||||
|
||||
@@ -3015,6 +3019,29 @@ uint8_t ubasic_finished(struct ubasic_data *data)
|
||||
return (ubasic_program_finished(data) || data->status.bit.isRunning == 0);
|
||||
}
|
||||
|
||||
void ubasic_halt_program(struct ubasic_data *data)
|
||||
{
|
||||
data->status.bit.isRunning = 0;
|
||||
}
|
||||
|
||||
const char *ubasic_program_location(struct ubasic_data *data)
|
||||
{
|
||||
struct ubasic_tokenizer *tree = &data->tree;
|
||||
char *statement_end;
|
||||
if (tree->ptr) {
|
||||
snprintf(data->location, sizeof(data->location), "%s", tree->ptr);
|
||||
/* only return the statement until end-of-line */
|
||||
statement_end = strpbrk(data->location, ";\n");
|
||||
if (statement_end) {
|
||||
*statement_end = 0;
|
||||
}
|
||||
} else {
|
||||
snprintf(data->location, sizeof(data->location), "end");
|
||||
}
|
||||
|
||||
return data->location;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
void ubasic_set_variable(
|
||||
|
||||
@@ -116,7 +116,12 @@ struct ubasic_data {
|
||||
int16_t free_arrayptr;
|
||||
int16_t arrayvariable[UBASIC_VARNUM_MAX];
|
||||
#endif
|
||||
/* entire program */
|
||||
const char *program;
|
||||
/* points to current statement */
|
||||
const char *program_ptr;
|
||||
/* copy of the current statement until end-of-line */
|
||||
char location[UBASIC_STATEMENT_SIZE];
|
||||
|
||||
uint16_t gosub_stack[UBASIC_GOSUB_STACK_DEPTH];
|
||||
uint8_t gosub_stack_ptr;
|
||||
@@ -220,7 +225,13 @@ int32_t ubasic_run_program(struct ubasic_data *data);
|
||||
BACNET_STACK_EXPORT
|
||||
uint8_t ubasic_execute_statement(struct ubasic_data *data, char *statement);
|
||||
BACNET_STACK_EXPORT
|
||||
void ubasic_halt_program(struct ubasic_data *data);
|
||||
BACNET_STACK_EXPORT
|
||||
bool ubasic_program_finished(struct ubasic_data *data);
|
||||
BACNET_STACK_EXPORT
|
||||
uint8_t ubasic_finished(struct ubasic_data *data);
|
||||
BACNET_STACK_EXPORT
|
||||
const char *ubasic_program_location(struct ubasic_data *data);
|
||||
|
||||
BACNET_STACK_EXPORT
|
||||
uint8_t ubasic_waiting_for_input(struct ubasic_data *data);
|
||||
|
||||
Reference in New Issue
Block a user