2017-01-08 14:17:13 -04:00
|
|
|
#ifndef BUZZ_UPDATE_H
|
|
|
|
#define BUZZ_UPDATE_H
|
2017-12-07 22:49:27 -04:00
|
|
|
/*Simulation or robot check*/
|
2017-12-08 19:52:35 -04:00
|
|
|
//#define SIMULATION 1 // set in CMAKELIST
|
2017-12-07 22:49:27 -04:00
|
|
|
|
2017-01-08 14:17:13 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <buzz/buzztype.h>
|
|
|
|
#include <buzz/buzzdict.h>
|
|
|
|
#include <buzz/buzzdarray.h>
|
|
|
|
#include <buzz/buzzvstig.h>
|
2017-05-17 14:54:32 -03:00
|
|
|
#include <fstream>
|
2017-01-08 14:17:13 -04:00
|
|
|
#define delete_p(p) do { free(p); p = NULL; } while(0)
|
|
|
|
|
2017-12-07 22:49:27 -04:00
|
|
|
static const uint16_t CODE_REQUEST_PADDING=250;
|
|
|
|
static const uint16_t MIN_UPDATE_PACKET=251;
|
|
|
|
static const uint16_t UPDATE_CODE_HEADER_SIZE=5;
|
|
|
|
static const uint16_t TIMEOUT_FOR_ROLLBACK=50;
|
2017-01-08 14:17:13 -04:00
|
|
|
/*********************/
|
|
|
|
/* Updater states */
|
|
|
|
/********************/
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
CODE_RUNNING = 0, // Code executing
|
|
|
|
CODE_STANDBY, // Standing by for others to update
|
|
|
|
} code_states_e;
|
|
|
|
|
|
|
|
/*********************/
|
|
|
|
/*Message types */
|
|
|
|
/********************/
|
|
|
|
|
|
|
|
typedef enum {
|
2017-12-07 22:49:27 -04:00
|
|
|
SENT_CODE = 0, // Broadcast code
|
|
|
|
RESEND_CODE, // ReBroadcast request
|
2017-01-08 14:17:13 -04:00
|
|
|
} code_message_e;
|
|
|
|
|
|
|
|
/*************************/
|
|
|
|
/*Updater message queue */
|
|
|
|
/*************************/
|
|
|
|
|
|
|
|
struct updater_msgqueue_s {
|
|
|
|
uint8_t* queue;
|
|
|
|
uint8_t* size;
|
|
|
|
} ;
|
|
|
|
typedef struct updater_msgqueue_s* updater_msgqueue_t;
|
|
|
|
|
2017-12-07 22:49:27 -04:00
|
|
|
struct updater_code_s {
|
|
|
|
uint8_t* bcode;
|
|
|
|
uint8_t* bcode_size;
|
|
|
|
} ;
|
|
|
|
typedef struct updater_code_s* updater_code_t;
|
|
|
|
|
2017-01-08 14:17:13 -04:00
|
|
|
/**************************/
|
|
|
|
/*Updater data*/
|
|
|
|
/**************************/
|
|
|
|
|
|
|
|
struct buzz_updater_elem_s {
|
|
|
|
/* robot id */
|
2017-01-27 11:03:55 -04:00
|
|
|
//uint16_t robotid;
|
2017-01-27 09:10:27 -04:00
|
|
|
/*current Bytecode content */
|
2017-01-08 14:17:13 -04:00
|
|
|
uint8_t* bcode;
|
2017-12-07 22:49:27 -04:00
|
|
|
/*old Bytecode name */
|
|
|
|
const char* old_bcode;
|
2017-01-08 14:17:13 -04:00
|
|
|
/*current bcode size*/
|
2017-01-27 09:10:27 -04:00
|
|
|
size_t* bcode_size;
|
2017-12-07 22:49:27 -04:00
|
|
|
/*Update patch*/
|
|
|
|
uint8_t* patch;
|
|
|
|
/* Update patch size*/
|
|
|
|
size_t* patch_size;
|
2017-01-27 09:10:27 -04:00
|
|
|
/*current Bytecode content */
|
|
|
|
uint8_t* standby_bcode;
|
|
|
|
/*current bcode size*/
|
|
|
|
size_t* standby_bcode_size;
|
2017-01-08 14:17:13 -04:00
|
|
|
/*updater out msg queue */
|
|
|
|
updater_msgqueue_t outmsg_queue;
|
|
|
|
/*updater in msg queue*/
|
|
|
|
updater_msgqueue_t inmsg_queue;
|
|
|
|
/*Current state of the updater one in code_states_e ENUM*/
|
2017-01-27 09:10:27 -04:00
|
|
|
int* mode;
|
|
|
|
uint8_t* update_no;
|
2017-12-07 22:49:27 -04:00
|
|
|
};
|
2017-01-08 14:17:13 -04:00
|
|
|
typedef struct buzz_updater_elem_s* buzz_updater_elem_t;
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
/*Updater routine from msg processing to file checks to be called from main*/
|
|
|
|
/**************************************************************************/
|
2017-12-07 22:49:27 -04:00
|
|
|
void update_routine();
|
2017-01-08 14:17:13 -04:00
|
|
|
|
|
|
|
/************************************************/
|
|
|
|
/*Initalizes the updater */
|
|
|
|
/************************************************/
|
2017-12-07 22:49:27 -04:00
|
|
|
void init_update_monitor(const char* bo_filename,const char* stand_by_script,
|
|
|
|
const char* dbgfname, int robot_id);
|
2017-01-08 14:17:13 -04:00
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************/
|
|
|
|
/*Appends buffer of given size to in msg queue of updater*/
|
|
|
|
/*********************************************************/
|
|
|
|
|
|
|
|
void code_message_inqueue_append(uint8_t* msg,uint16_t size);
|
|
|
|
|
|
|
|
/*********************************************************/
|
|
|
|
/*Processes messages inside the queue of the updater*/
|
|
|
|
/*********************************************************/
|
|
|
|
|
|
|
|
void code_message_inqueue_process();
|
|
|
|
|
|
|
|
/*****************************************************/
|
|
|
|
/* obtains messages from out msgs queue of the updater*/
|
|
|
|
/*******************************************************/
|
|
|
|
uint8_t* getupdater_out_msg();
|
|
|
|
|
|
|
|
/******************************************************/
|
|
|
|
/*obtains out msg queue size*/
|
|
|
|
/*****************************************************/
|
|
|
|
uint8_t* getupdate_out_msg_size();
|
|
|
|
|
|
|
|
/**************************************************/
|
|
|
|
/*destroys the out msg queue*/
|
|
|
|
/*************************************************/
|
|
|
|
void destroy_out_msg_queue();
|
|
|
|
|
|
|
|
/***************************************************/
|
|
|
|
/*obatins updater state*/
|
|
|
|
/***************************************************/
|
|
|
|
int get_update_mode();
|
|
|
|
|
2017-01-31 02:11:59 -04:00
|
|
|
|
|
|
|
buzz_updater_elem_t get_updater();
|
2017-01-08 14:17:13 -04:00
|
|
|
/***************************************************/
|
|
|
|
/*sets bzz file name*/
|
|
|
|
/***************************************************/
|
|
|
|
void set_bzz_file(const char* in_bzz_file);
|
|
|
|
|
2017-01-27 09:10:27 -04:00
|
|
|
int test_set_code(uint8_t* BO_BUF, const char* dbgfname,size_t bcode_size);
|
|
|
|
|
2017-01-08 14:17:13 -04:00
|
|
|
/****************************************************/
|
|
|
|
/*Destroys the updater*/
|
|
|
|
/***************************************************/
|
|
|
|
|
|
|
|
void destroy_updater();
|
|
|
|
|
2017-01-27 10:09:42 -04:00
|
|
|
int is_msg_present();
|
|
|
|
|
2017-01-29 04:03:29 -04:00
|
|
|
int get_update_status();
|
|
|
|
|
|
|
|
void set_read_update_status();
|
|
|
|
|
2017-12-07 22:49:27 -04:00
|
|
|
int compile_bzz(std::string bzz_file);
|
2017-05-11 23:12:59 -03:00
|
|
|
|
2017-04-02 16:06:36 -03:00
|
|
|
void updates_set_robots(int robots);
|
|
|
|
|
2017-12-07 22:49:27 -04:00
|
|
|
void set_packet_id(int packet_id);
|
|
|
|
|
2017-05-17 14:54:32 -03:00
|
|
|
void collect_data(std::ofstream &logger);
|
2017-01-08 14:17:13 -04:00
|
|
|
#endif
|