Skip to content

Commit

Permalink
adapt to new layout
Browse files Browse the repository at this point in the history
  • Loading branch information
t-8ch committed May 31, 2016
1 parent 284a4c5 commit 9db2db2
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 139 deletions.
39 changes: 23 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,20 @@ install(TARGETS ffffm
ARCHIVE DESTINATION lib/static)

if(RESPONDD)
add_library(ffffm-respondd SHARED ffffm-respondd.c) # FIXME make this a module
target_link_libraries(ffffm-respondd ffffm)
target_link_libraries(ffffm-respondd ffffm ${JSON_LIBRARIES})
target_include_directories(ffffm-respondd PUBLIC ${JSON_INCLUDE_DIRS})
# install(FILES $<TARGET_FILE:ffffm-respondd>
install(FILES libffffm-respondd.so
RENAME ffffm.so
add_library(respondd-nexthop SHARED respondd-nexthop.c) # FIXME make this a module
target_link_libraries(respondd-nexthop ffffm ${JSON_LIBRARIES})
target_include_directories(respondd-nexthop PUBLIC ${JSON_INCLUDE_DIRS})
# install(FILES $<TARGET_FILE:respondd-nexthop>
install(FILES librespondd-nexthop.so
RENAME nexthop.so
DESTINATION lib/gluon/respondd/)

add_library(respondd-wireless SHARED respondd-wireless.c) # FIXME make this a module
target_link_libraries(respondd-wireless ffffm ${JSON_LIBRARIES})
target_include_directories(respondd-wireless PUBLIC ${JSON_INCLUDE_DIRS})
# install(FILES $<TARGET_FILE:respondd-wireless>
install(FILES librespondd-wireless.so
RENAME wireless.so
DESTINATION lib/gluon/respondd/)
endif()

Expand Down Expand Up @@ -83,15 +90,15 @@ if(INSTALL_TESTS)
RUNTIME DESTINATION bin)
endif()

if(RESPONDD)
add_executable(ffffm-respondd-test ffffm-respondd-test.c)
target_link_libraries(ffffm-respondd-test ffffm-respondd)
add_test(NAME ffffm-respondd-test COMMAND ffffm-respondd-test)
if(INSTALL_TESTS)
install(TARGETS ffffm-respondd-test
RUNTIME DESTINATION bin)
endif()
endif()
#if(RESPONDD)
# add_executable(ffffm-respondd-test ffffm-respondd-test.c)
# target_link_libraries(ffffm-respondd-test ffffm-respondd)
# add_test(NAME ffffm-respondd-test COMMAND ffffm-respondd-test)
# if(INSTALL_TESTS)
# install(TARGETS ffffm-respondd-test
# RUNTIME DESTINATION bin)
# endif()
#endif()

if(LUA)
add_test(NAME ffffm-lua-test COMMAND ffffm-lua-test)
Expand Down
12 changes: 6 additions & 6 deletions ffffm-lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ static int get_wifi_info(lua_State *L) {

lua_newtable(L);

if (i->channel_24) {
lua_pushstring(L, "channel_24");
lua_pushinteger(L, i->channel_24);
if (i->c24) {
lua_pushstring(L, "chan2");
lua_pushinteger(L, i->c24);
lua_settable(L,-3);
}
if (i->channel_50) {
lua_pushstring(L, "channel_50");
lua_pushinteger(L, i->channel_50);
if (i->c50) {
lua_pushstring(L, "chan5");
lua_pushinteger(L, i->c50);
lua_settable(L, -3);
}

Expand Down
107 changes: 0 additions & 107 deletions ffffm-respondd.c

This file was deleted.

2 changes: 1 addition & 1 deletion ffffm-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

int main() {
struct ffffm_wifi_info *i = ffffm_get_wifi_info();
printf("24: %u, 50: %u\n", i->channel_24, i->channel_50);
printf("24: %u, 50: %u\n", i->c24, i->c50);
}
7 changes: 4 additions & 3 deletions ffffm.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ extern const unsigned int FFFFM_INVALID_CHANNEL;
extern const double FFFFM_INVALID_AIRTIME;

struct ffffm_wifi_info {
unsigned char channel_24;
unsigned char channel_50;
unsigned char c24;
unsigned char c50;
unsigned char t24;
unsigned char t50;
};

char *ffffm_get_nexthop(void);
struct ffffm_wifi_info *ffffm_get_wifi_info(void);
void ffffm_free_wifi_info(struct ffffm_wifi_info *i);
double ffffm_get_airtime(void);
38 changes: 38 additions & 0 deletions respondd-nexthop.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <json-c/json.h>

#include <respondd.h>

#include "ffffm.h"

static struct json_object *get_nexthop(void) {
struct json_object *ret;
char *nexthop_s;

nexthop_s = ffffm_get_nexthop();
if (!nexthop_s)
return NULL;

ret = json_object_new_string(nexthop_s);
free(nexthop_s);
return ret;
}

static struct json_object *respondd_provider_statistics(void) {
struct json_object *ret = json_object_new_object();

if (!ret)
return NULL;

struct json_object *nexthop;

nexthop = get_nexthop();
if (nexthop)
json_object_object_add(ret, "nexthop", nexthop);

return ret;
}

const struct respondd_provider_info respondd_providers[] = {
{"statistics", respondd_provider_statistics},
{0},
};
77 changes: 77 additions & 0 deletions respondd-wireless.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include <string.h>

#include <json-c/json.h>

#include <respondd.h>

#include "ffffm.h"

static struct json_object *get_airtime(void) {
double airtime = ffffm_get_airtime();
if (FFFFM_INVALID_AIRTIME == airtime)
return NULL;

return json_object_new_double(airtime);
}

static struct json_object *respondd_provider_statistics(void) {
struct json_object *ret = json_object_new_object();

if (!ret)
return NULL;

struct json_object *airtime;

airtime = get_airtime();
if (airtime)
json_object_object_add(ret, "airtime2", airtime);

return ret;
}

static struct json_object *respondd_provider_nodeinfo(void) {
struct ffffm_wifi_info *i = ffffm_get_wifi_info();
if (!i)
goto end;

struct json_object *ret = json_object_new_object();
struct json_object *v;
if (!ret)
goto end;

if (i->c24) {
v = json_object_new_int64(i->c24);
if (!v)
goto end;
json_object_object_add(ret, "chan2", v);
}
if (i->c50) {
v = json_object_new_int64(i->c50);
if (!v)
goto end;
json_object_object_add(ret, "chan5", v);
}
if (i->t24) {
v = json_object_new_int64(i->t24);
if (!v)
goto end;
json_object_object_add(ret, "txpower2", v);
}
if (i->t50) {
v = json_object_new_int64(i->t50);
if (!v)
goto end;
json_object_object_add(ret, "txpower5", v);
}
end:
free(i);
return ret;

}


const struct respondd_provider_info respondd_providers[] = {
{"statistics", respondd_provider_statistics},
{"nodeinfo", respondd_provider_nodeinfo},
{0},
};
16 changes: 10 additions & 6 deletions wifi_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ static inline unsigned char parse_channel(const char *s) {
return (unsigned char)(result % UCHAR_MAX);
}

static inline unsigned char parse_txpower(const char *s) {
return parse_channel(s);
}

struct ffffm_wifi_info *ffffm_get_wifi_info(void) {
struct uci_context *ctx = uci_alloc_context();
ctx->flags &= ~UCI_FLAG_STRICT;
Expand All @@ -57,9 +61,13 @@ struct ffffm_wifi_info *ffffm_get_wifi_info(void) {

const char *c24 = lookup_option_value(ctx, p, wifi_24_dev, "channel");
const char *c50 = lookup_option_value(ctx, p, wifi_50_dev, "channel");
const char *t24 = lookup_option_value(ctx, p, wifi_24_dev, "txpower");
const char *t50 = lookup_option_value(ctx, p, wifi_50_dev, "txpower");

ret->channel_24 = parse_channel(c24);
ret->channel_50 = parse_channel(c50);
ret->c24 = parse_channel(c24);
ret->c50 = parse_channel(c50);
ret->t24 = parse_txpower(t24);
ret->t50 = parse_txpower(t50);
end:
if (ctx)
uci_free_context(ctx);
Expand All @@ -70,7 +78,3 @@ struct ffffm_wifi_info *ffffm_get_wifi_info(void) {
ret = NULL;
goto end;
}

void ffffm_free_wifi_info(struct ffffm_wifi_info *i) {
free(i);
}

0 comments on commit 9db2db2

Please sign in to comment.