Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions include/wifi_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@ typedef enum {
wifi_app_inst_sta_mgr = wifi_app_inst_base << 17,
wifi_app_inst_memwraptool = wifi_app_inst_base << 18,
wifi_app_inst_csi_analytics = wifi_app_inst_base << 19,
wifi_app_inst_link_quality = wifi_app_inst_base << 20,
wifi_app_inst_max = wifi_app_inst_base << 21
wifi_app_inst_web_gui = wifi_app_inst_base << 20,
wifi_app_inst_link_quality = wifi_app_inst_base << 21,
wifi_app_inst_max = wifi_app_inst_base << 22
} wifi_app_inst_t;

typedef struct {
Expand Down
45 changes: 45 additions & 0 deletions source/apps/web_gui/common_web_gui.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifndef COMMON_WEB_GUI_H
#define COMMON_WEB_GUI_H

#include <cjson/cJSON.h>
#include "wifi_base.h"
#include "collection.h"
#include "wifi_hal.h"

#ifdef __cplusplus
extern "C" {
#endif

#define WEB_SERVER_PATH "/www/data"

typedef struct web_t web_t;
typedef struct csimgr_t csimgr_t;
typedef struct sounder_t sounder_t;

typedef struct web_event web_event_t;
typedef unsigned int gestures_t;

typedef struct web_gui_obj {
csimgr_t *gui_csi_mgr;
web_t *web_server;
cJSON *json_assoc_sta_list;
} web_gui_obj_t;

int init_web_server_param(web_gui_obj_t *p_web_mgr);
int init_gui_csi_mgr_param(web_gui_obj_t *p_web_mgr);
int motion_core_init(void);

web_gui_obj_t *get_web_gui_obj(void);
int save_json_to_file(const char *filename, cJSON *json);

sounder_t* get_or_create_sounder_from_map(hash_map_t *map,
const char *mac_str,
const uint8_t *sta_mac);

void process_csi_motion_data(sounder_t *sd, wifi_csi_dev_t *csi_dev, gestures_t gestures);

#ifdef __cplusplus
}
#endif

#endif // COMMON_WEB_GUI_H
10 changes: 10 additions & 0 deletions source/apps/web_gui/motion/datamotion.json

Large diffs are not rendered by default.

138 changes: 138 additions & 0 deletions source/apps/web_gui/motion/inc/csimgr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/**
* Copyright 2023 Comcast Cable Communications Management, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef CSIMGR_H
#define CSIMGR_H

#include <stdint.h>
#include <string.h>
#include <pthread.h>
#include "cJSON.h"
#include "bus.h"
#include "collection.h"
#include "common_web_gui.h"
#include "common_defs.h"
#include "vector.h"
#include "matrix.h"
#include "wifi_csi.h"
#include "wifi_hal.h"
#include "sounder.h"
#include "web.h"

#define CSI_MOTION_CORE_INTERVAL 100
#define MAX_STA_MACLIST_SIZE 512
#define MAX_STA_MAC_STR_SIZE 18

class csimgr_t {
bool m_exit;
pthread_mutex_t m_lock;
pthread_cond_t m_cond;
queue_t *m_queue;
hash_map_t *m_sounders_map;

unsigned int m_sampling;
motion_test_params_t m_test_params;

int m_remaining;
unsigned int m_iters;

char m_output_file[PATH_NAME_SZ];
char m_storage_dir[PATH_NAME_SZ];
cJSON *m_out_obj;

// ------------------------------------------------------------------
// Motion core (CSI bus / pipe reader) state – private
// ------------------------------------------------------------------
bus_handle_t m_handle;
uint32_t m_csi_session_index;
uint32_t m_motion_interval_in_ms;
int32_t m_pipe_read_fd;
bool m_pipe_thread_running;
bool m_motion_enabled;
char m_sta_mac_list[MAX_STA_MACLIST_SIZE];
mac_addr_str_t m_gw_mac_str;

// ------------------------------------------------------------------
// Motion core private methods
// ------------------------------------------------------------------
static void remove_mac_colon(char *mac_str);
void process_csi_raw_data(wifi_csi_dev_t *csi_dev_data);
bool decode_csi_pipe_msg_info(const uint8_t *data,
wifi_csi_dev_t &out_dev);
void deinit_motion_core();
void *pipe_read_loop();
bus_error_t trigger_bus_event_sub(bus_event_sub_t *bus_event,
uint32_t size);
bus_error_t set_sta_maclist(const char *mac_list);
bus_error_t set_bool_bus_value(const char *event_name, bool status);
bus_error_t set_csi_enable_status(bool status);
bus_error_t subscribe_csi_data(uint32_t csi_index,
uint32_t csi_interval);
bus_error_t init_bus();
int open_csi_conn();

// Static C-style callbacks (pthread / bus)
static void *pipe_thread_entry(void *arg);
static void do_nothing_handler(char *event_name, raw_data_t *p_data,
void *userData);

public:
// ------------------------------------------------------------------
// CSI manager public interface
// ------------------------------------------------------------------
int init();
void deinit();
int run();

void push(web_event_t *evt) {
pthread_mutex_lock(&m_lock);
queue_push(m_queue, evt);
pthread_cond_signal(&m_cond);
pthread_mutex_unlock(&m_lock);
}

int read_test_object(cJSON *obj);
int read_gesture_object(cJSON *obj);
int read_capture_object(cJSON *obj);
int handle_result_object(cJSON *obj);
struct timespec *get_periodicity(struct timespec *time_to_wait);
void periodicity_handler(struct timespec **t_wait);

void create_output_template();
void update_graph(sounder_t *sd);
void dump_json(cJSON *obj);

hash_map_t *get_sounders_map() const { return m_sounders_map; }

// ------------------------------------------------------------------
// Motion core public interface
// ------------------------------------------------------------------
int motion_init();
void set_cal_duration(uint32_t duration_sec);

// ------------------------------------------------------------------
// Utilities
// ------------------------------------------------------------------
static char *get_local_time(char *buff, unsigned int len);

explicit csimgr_t(const char *path);
csimgr_t();
~csimgr_t();
};

#endif // CSIMGR_H
94 changes: 94 additions & 0 deletions source/apps/web_gui/motion/inc/sounder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* Copyright 2023 Comcast Cable Communications Management, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef SOUNDER_H
#define SOUNDER_H

#include <stdint.h>
#include "vector.h"
#include "matrix.h"
#include "sequence.h"
#include "cJSON.h"
#include "wifi_hal.h"
#include "common_defs.h"


#define gesture_idle 0
#define gesture_finger 1
#define gesture_hand gesture_finger << 1

typedef unsigned int gestures_t;

class sounder_t {
mac_address_t m_mac;
mac_addr_str_t m_mac_str;

// test parameters
cJSON *m_input_obj;
unsigned int m_recs;
unsigned int m_current;

matrix_t m_samples;
sequence_t m_sequence[MAX_NR];
matrix_t m_antenna_variance;
sequence_t m_uber_variance;

motion_test_params_t m_test_params;

wifi_frame_info_t m_frame_info;

bool m_enable_status;
double m_last_motion_detected_time;
uint32_t m_cal_packets_cnt;

public:
//vector_t run_test();//@TODO TBD ANIKET
int update(cJSON *input_obj, wifi_frame_info_t *frame_info, motion_test_params_t *params);
vector_t process_csi_data(wifi_csi_data_t &csi, gestures_t gestures);

void reset();

void push(vector_t v) { m_samples.push(v); }
matrix_t *get_samples() { return &m_samples; }
float get_uber_variance() { return m_uber_variance.get_mean().m_re; }
void add_sequence(unsigned int rx_index, number_t num);
number_t get_mean(unsigned int rx_index) { return m_sequence[rx_index].m_mean; }
number_t get_variance(unsigned int rx_index) { return m_sequence[rx_index].m_variance; }
number_t get_kurtosis(unsigned int rx_index) { return m_sequence[rx_index].m_kurtosis; }
number_t get_mfilter(unsigned int rx_index) { return m_sequence[rx_index].m_mfilter; }
void reset_samples() { m_samples.reset(); }

unsigned char* get_mac_addr() { return m_mac; }
char *get_mac_str(){ return m_mac_str; }
unsigned int get_num_antennas() { return m_frame_info.Nr; }

void set_enable_status(bool status) { m_enable_status = status; }
bool get_enable_status() const { return m_enable_status; }
void set_last_motion_detected_time(double t) { m_last_motion_detected_time = t; }
double get_last_motion_detected_time() const { return m_last_motion_detected_time; }
void set_cal_packets_cnt(uint32_t cnt) { m_cal_packets_cnt = cnt; }
uint32_t get_cal_packets_cnt() const { return m_cal_packets_cnt; }

static char *get_local_time(char *buff, unsigned int len);
static void parse_frame_object(cJSON *frame_obj, wifi_frame_info_t *frame_info);

sounder_t(mac_address_t mac);
~sounder_t();
};

#endif
Loading
Loading