Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Commit

Permalink
Nodes registration Complete (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnsAnns authored Jul 4, 2024
2 parents e75701f + d10d132 commit 039a555
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 69 deletions.
2 changes: 1 addition & 1 deletion node/code/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ ifndef CONFIG_LWM2M_SERVER_URI

endif
##### /LWM2M #####

CFLAGS += -DCONFIG_LWM2M_DEVICE_NAME=\""urn:t8i:dev:1"\"

include $(RIOTBASE)/Makefile.include

Expand Down
3 changes: 3 additions & 0 deletions node/code/modules/display_handler/display_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ handler_result_t displayHandler_handleEvent(EVENT_T event){
break;
case READY:
init_registered_pet();
char text[50];
get_pet_short_info((char*) &text);
change_top_bar_text((char*) &text);
break;
case INFO_PRESSED:
get_pet_stats((char*)&buf);
Expand Down
1 change: 1 addition & 0 deletions node/code/modules/display_handler/include/init_lvgl.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void left_released(void);
void right_pressed(void);
void right_released(void);
void init_not_registered_code(char* code);
void change_top_bar_text(char* top_bar_text);
void init_registered_no_pet(void);
void init_registered_pet(void);
void init_pet_stats(char* stats);
Expand Down
108 changes: 55 additions & 53 deletions node/code/modules/display_handler/init_lvgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
* @}
*/
#include "lvgl/src/widgets/lv_img.h"
#include "lvgl/src/widgets/lv_roller.h"
//#include "lvgl/src/widgets/lv_label.h"

#include <string.h>

Expand All @@ -34,10 +32,6 @@
#include "events.h"
#include "debug.h"

#define CPU_LABEL_COLOR "FF0000"
#define MEM_LABEL_COLOR "0000FF"
#define CHART_POINT_NUM 100

lv_obj_t * roller1;


Expand Down Expand Up @@ -164,6 +158,60 @@ static uint32_t keypad_get_key(void)
return 0;
}

void enter_pressed(void){
buttons[0].state = true;
}

void enter_released(void){
buttons[0].state = false;
}

void up_pressed(void){
buttons[1].state = true;
}

void up_released(void){
buttons[1].state = false;
}

void down_pressed(void){
buttons[2].state = true;
}

void down_released(void){
buttons[2].state = false;
}

void left_pressed(void){
buttons[3].state = true;
}

void left_released(void){
buttons[3].state = false;
}

void right_pressed(void){
buttons[4].state = true;
}

void right_released(void){
buttons[4].state = false;
}

static void timer_cb(lv_timer_t *param){
(void) param;
lvgl_wakeup();
}

void change_top_bar_text(char* top_bar_text){
lv_obj_clean(top_bar);
// Add a label to the top bar
lv_obj_t * pet_label = lv_label_create(top_bar);
lv_label_set_text(pet_label, top_bar_text);
lv_obj_set_style_text_color(pet_label, lv_color_hex(0xFFFFFF), LV_PART_MAIN);

}

void init_default_screen(char* top_bar_text){
lv_obj_clean(lv_scr_act());
static lv_style_t style_base;
Expand Down Expand Up @@ -232,54 +280,8 @@ void init_default_screen(char* top_bar_text){

}

void enter_pressed(void){
buttons[0].state = true;
}

void enter_released(void){
buttons[0].state = false;
}

void up_pressed(void){
buttons[1].state = true;
}

void up_released(void){
buttons[1].state = false;
}

void down_pressed(void){
buttons[2].state = true;
}

void down_released(void){
buttons[2].state = false;
}

void left_pressed(void){
buttons[3].state = true;
}

void left_released(void){
buttons[3].state = false;
}

void right_pressed(void){
buttons[4].state = true;
}

void right_released(void){
buttons[4].state = false;
}

static void timer_cb(lv_timer_t *param){
(void) param;
lvgl_wakeup();
}


void init_not_registered(void){

lv_obj_clean(center);
/* Style of the align bar*/
static lv_style_t style_align;
lv_style_init(&style_align);
Expand Down
4 changes: 4 additions & 0 deletions node/code/modules/fsm/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ void get_pet_stats(char *buf){
pet_stats.happiness, pet_stats.wellbeing, pet_stats.health, pet_stats.xp,pet_stats.hunger, pet_stats.cleanliness, pet_stats.fun);
}

void get_pet_short_info(char *buf){
sprintf(buf,"%s XP: %ld%%",pet_stats.name, pet_stats.xp);
}

char* get_register_code(void){
printf("code in get: %s\n",register_code.code);
return register_code.code;
Expand Down
2 changes: 2 additions & 0 deletions node/code/modules/fsm/fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ void off_entry(void) {
}

handler_result_t unregistered_handler(EVENT_T event) {
printf("[FSM:unregistered_state_handler]: event: %d \n",event);
switch (event) {

case REGISTER_CODE:
DEBUG("[FSM:unregistered_state_handler]: REGISTER_CODE\n");
displayHandler_handleEvent(REGISTERED); //is that right?
Expand Down
15 changes: 11 additions & 4 deletions node/code/modules/fsm/include/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ typedef enum {

typedef struct{
int32_t id; /**< id of pet */
char name[10]; /**< name of pet */
char name[20]; /**< name of pet */
int32_t color; /**< color of the pet */
int32_t happiness; /**< happiness of the pet*/
int32_t wellbeing; /**< wellbeing of the pet*/
Expand Down Expand Up @@ -108,17 +108,24 @@ typedef enum
/**
* @brief Writes the actual pet stats into the parameter pointer
*
* @param[out] buf Buffer in which the stats get written
*/
void get_pet_stats(char *buf);

/**
* @brief Writes the register code into the parameter pointer
*
* @brief Writes the actual pet stats into the parameter pointer short version for top row
*
* @param[in] stats The pointer to an pet_stats_t object in which the that gets copied.
* @param[out] buf Buffer in which the stats get written
*/
void get_pet_short_info(char *buf);

/**
* @brief Writes the register code into the parameter pointer
* @return char pointer to the register code
*/
char* get_register_code(void);


/**
* @brief Triggers an Event for the FSM
*
Expand Down
11 changes: 5 additions & 6 deletions node/code/modules/lwm2m_handler/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
USEMODULE += xtimer
USEPKG += wakaama
# Include packages that pull up and auto-init the link layer.
# NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present
Expand All @@ -12,8 +11,8 @@ USEMODULE += gnrc_icmpv6_echo
USEMODULE += shell
USEMODULE += shell_cmds_default
USEMODULE += ps
USEMODULE += wakaama_client_dtls
# Specify sock DTLS implementation
USEPKG += tinydtls
# tinydtls needs crypto secure PRNG
USEMODULE += prng_sha1prng
# USEMODULE += wakaama_client_dtls
# # Specify sock DTLS implementation
# USEPKG += tinydtls
# # tinydtls needs crypto secure PRNG
# USEMODULE += prng_sha1prng
63 changes: 63 additions & 0 deletions node/code/modules/lwm2m_handler/include/lwm2m_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* @brief Device name used to register at the LwM2M server
*/
#ifndef CONFIG_LWM2M_DEVICE_NAME
#define CONFIG_LWM2M_DEVICE_NAME "urn:t8i:dev:<SOMETHING>"
#endif

/**
* @brief Device object manufacturer string
*/
#ifndef CONFIG_LWM2M_DEVICE_MANUFACTURER
#define CONFIG_LWM2M_DEVICE_MANUFACTURER "Sose 2024"
#endif

/**
* @brief Device object model.
*
* @note Defaults to the board name
*/
#ifndef CONFIG_LWM2M_DEVICE_MODEL
#define CONFIG_LWM2M_DEVICE_MODEL RIOT_BOARD
#endif

/**
* @brief Device object serial number
*/
#ifndef CONFIG_LWM2M_DEVICE_SERIAL
#define CONFIG_LWM2M_DEVICE_SERIAL "000000"
#endif

/**
* @brief Device object firmware version
*
* @note Defaults to the running RIOT version
*/
#ifndef CONFIG_LWM2M_DEVICE_FW_VERSION
#define CONFIG_LWM2M_DEVICE_FW_VERSION RIOT_VERSION
#endif

/**
* @brief Device object device type
*/
#ifndef CONFIG_LWM2M_DEVICE_TYPE
#define CONFIG_LWM2M_DEVICE_TYPE "Teamagotchi"
#endif

/**
* @brief Device object hardware version
*
* @note Defaults to the board name
*/
#ifndef CONFIG_LWM2M_DEVICE_HW_VERSION
#define CONFIG_LWM2M_DEVICE_HW_VERSION RIOT_BOARD
#endif

/**
* @brief Device object software version
*
* @note Defaults to the running RIOT version
*/
#ifndef CONFIG_LWM2M_DEVICE_SW_VERSION
#define CONFIG_LWM2M_DEVICE_SW_VERSION RIOT_VERSION
#endif
12 changes: 7 additions & 5 deletions node/code/modules/lwm2m_handler/lwm2m_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "objects/device.h"
#include "objects/security.h"
#include "credentials.h"

#include "liblwm2m.h"

#define ENABLE_DEBUG 1
Expand Down Expand Up @@ -90,17 +91,18 @@ static void lwm2m_write_callback(uint16_t event_id, callback_value value){
static void lwm2m_pet_device_write_callback(uint16_t event_id, char* value){
switch (event_id) {
case LWM2M_DEVICE_STATUS_ID:
if (strcmp(value,"INIT")){
if (strcmp(value,"INIT") == 0){
DEBUG("[Lwm2mHandler:write_callback]: init\n");
trigger_event(INIT);
}else if(strcmp(value,"REGISTER")){
}else if(strcmp(value,"REGISTERED")){
}else if(strcmp(value,"REGISTERED") == 0){
DEBUG("[Lwm2mHandler:write_callback]: registered\n");
trigger_event(REGISTERED);
}else if(strcmp(value,"READY")){
}else if(strcmp(value,"READY") == 0){
DEBUG("[Lwm2mHandler:write_callback]: ready\n");
trigger_event(READY);
}
break;
case LWM2M_DEVICE_REGISTER_ID:
printf("Value of device cb: %s\n",value);
trigger_event_string(REGISTER_CODE,value);
break;
case LW2M_DEVICE_TIME_ID:
Expand Down

0 comments on commit 039a555

Please sign in to comment.