*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/* free a radio device from requesting client, power it off */
STATIC AFB_error releaseRadio (pluginHandleT *handle, radioCtxHandleT *ctx) {
/* free a radio device from requesting client, power it off */
STATIC AFB_error releaseRadio (pluginHandleT *handle, radioCtxHandleT *ctx) {
jresp = json_object_new_object();
json_object_object_add(jresp, "token", json_object_new_string (request->client->token));
jresp = json_object_new_object();
json_object_object_add(jresp, "token", json_object_new_string (request->client->token));
- /* "?value=" parameter is "1" or "on" */
- else if ( atoi(value) == 1 || !strcasecmp(value, "on") ) {
+ /* "?value=" parameter is "1" or "true" */
+ else if ( atoi(value) == 1 || !strcasecmp(value, "true") ) {
if (!ctx->radio) {
if (reserveRadio (handle, ctx) == AFB_FAIL) {
request->errcode = MHD_HTTP_SERVICE_UNAVAILABLE;
if (!ctx->radio) {
if (reserveRadio (handle, ctx) == AFB_FAIL) {
request->errcode = MHD_HTTP_SERVICE_UNAVAILABLE;
- /* "?value=" parameter is "0" or "off" */
- else if ( atoi(value) == 0 || !strcasecmp(value, "off") ) {
+ /* "?value=" parameter is "0" or "false" */
+ else if ( atoi(value) == 0 || !strcasecmp(value, "false") ) {
if (ctx->radio) {
if (releaseRadio (handle, ctx) == AFB_FAIL) {
request->errcode = MHD_HTTP_SERVICE_UNAVAILABLE;
if (ctx->radio) {
if (releaseRadio (handle, ctx) == AFB_FAIL) {
request->errcode = MHD_HTTP_SERVICE_UNAVAILABLE;
radioCtxHandleT *ctx = (radioCtxHandleT*)request->client->ctx;
const char *value = getQueryValue (request, "value");
radioCtxHandleT *ctx = (radioCtxHandleT*)request->client->ctx;
const char *value = getQueryValue (request, "value");
ctx->mode ?
json_object_object_add (jresp, "mode", json_object_new_string ("AM"))
: json_object_object_add (jresp, "mode", json_object_new_string ("FM"));
}
ctx->mode ?
json_object_object_add (jresp, "mode", json_object_new_string ("AM"))
: json_object_object_add (jresp, "mode", json_object_new_string ("FM"));
}
else if ( atoi(value) == 1 || !strcasecmp(value, "AM") ) {
ctx->mode = AM;
_radio_set_mode (ctx->idx, ctx->mode);
else if ( atoi(value) == 1 || !strcasecmp(value, "AM") ) {
ctx->mode = AM;
_radio_set_mode (ctx->idx, ctx->mode);
else if ( atoi(value) == 0 || !strcasecmp(value, "FM") ) {
ctx->mode = FM;
_radio_set_mode (ctx->idx, ctx->mode);
else if ( atoi(value) == 0 || !strcasecmp(value, "FM") ) {
ctx->mode = FM;
_radio_set_mode (ctx->idx, ctx->mode);
radioCtxHandleT *ctx = (radioCtxHandleT*)request->client->ctx;
const char *value = getQueryValue (request, "value");
json_object *jresp = json_object_new_object();
radioCtxHandleT *ctx = (radioCtxHandleT*)request->client->ctx;
const char *value = getQueryValue (request, "value");
json_object *jresp = json_object_new_object();
snprintf (freq_str, sizeof(freq_str), "%f", ctx->freq);
json_object_object_add (jresp, "freq", json_object_new_string (freq_str));
}
/* "?value=" parameter, set frequency */
else {
snprintf (freq_str, sizeof(freq_str), "%f", ctx->freq);
json_object_object_add (jresp, "freq", json_object_new_string (freq_str));
}
/* "?value=" parameter, set frequency */
else {
- ctx->freq = strtof (value, NULL);
- _radio_set_freq (ctx->idx, ctx->freq);
-
+ freq = strtod (value, NULL);
+ _radio_set_freq (ctx->idx, freq);
+ ctx->freq = (float)freq;
+
snprintf (freq_str, sizeof(freq_str), "%f", ctx->freq);
json_object_object_add (jresp, "freq", json_object_new_string (freq_str));
}
snprintf (freq_str, sizeof(freq_str), "%f", ctx->freq);
json_object_object_add (jresp, "freq", json_object_new_string (freq_str));
}
radioCtxHandleT *ctx = (radioCtxHandleT*)request->client->ctx;
const char *value = getQueryValue (request, "value");
radioCtxHandleT *ctx = (radioCtxHandleT*)request->client->ctx;
const char *value = getQueryValue (request, "value");
ctx->mute ?
json_object_object_add (jresp, "mute", json_object_new_string ("on"))
: json_object_object_add (jresp, "mute", json_object_new_string ("off"));
}
ctx->mute ?
json_object_object_add (jresp, "mute", json_object_new_string ("on"))
: json_object_object_add (jresp, "mute", json_object_new_string ("off"));
}
- /* "?value=" parameter is "1" or "on" */
- else if ( atoi(value) == 1 || !strcasecmp(value, "on") ) {
+ /* "?value=" parameter is "1" or "true" */
+ else if ( atoi(value) == 1 || !strcasecmp(value, "true") ) {
else if ( atoi(value) == 0 || !strcasecmp(value, "off") ) {
ctx->mute = 0;
_radio_set_mute (ctx->idx, ctx->mute);
else if ( atoi(value) == 0 || !strcasecmp(value, "off") ) {
ctx->mute = 0;
_radio_set_mute (ctx->idx, ctx->mute);
ctx->is_playing ?
json_object_object_add (jresp, "play", json_object_new_string ("on"))
: json_object_object_add (jresp, "play", json_object_new_string ("off"));
}
ctx->is_playing ?
json_object_object_add (jresp, "play", json_object_new_string ("on"))
: json_object_object_add (jresp, "play", json_object_new_string ("off"));
}
- /* "?value=" parameter is "1" or "on" */
- else if ( atoi(value) == 1 || !strcasecmp(value, "on") ) {
+ /* "?value=" parameter is "1" or "true" */
+ else if ( atoi(value) == 1 || !strcasecmp(value, "true") ) {
- /* "?value=" parameter is "0" or "off" */
- else if ( atoi(value) == 0 || !strcasecmp(value, "off") ) {
+ /* "?value=" parameter is "0" or "false" */
+ else if ( atoi(value) == 0 || !strcasecmp(value, "false") ) {
-STATIC json_object* status (AFB_request *request) {
- return NULL;
+STATIC json_object* refresh (AFB_request *request) { /* AFB_SESSION_RENEW */
+ json_object *jresp = json_object_new_object();
+ json_object_object_add(jresp, "token", json_object_new_string (request->client->token));
+ return jresp;
+}
+
+STATIC json_object* ping (AFB_request *request) { /* AFB_SESSION_NONE */
+ return jsonNewMessage(AFB_SUCCESS, "Ping Binder Daemon - Radio API");
{"freq" , AFB_SESSION_CHECK, (AFB_apiCB)freq , "Radio API - freq"},
{"mute" , AFB_SESSION_CHECK, (AFB_apiCB)mute , "Radio API - mute"},
{"play" , AFB_SESSION_CHECK, (AFB_apiCB)play , "Radio API - play"},
{"freq" , AFB_SESSION_CHECK, (AFB_apiCB)freq , "Radio API - freq"},
{"mute" , AFB_SESSION_CHECK, (AFB_apiCB)mute , "Radio API - mute"},
{"play" , AFB_SESSION_CHECK, (AFB_apiCB)play , "Radio API - play"},
- {"status" , AFB_SESSION_RENEW, (AFB_apiCB)status , "Radio API - status"},
+ {"refresh", AFB_SESSION_RENEW, (AFB_apiCB)refresh , "Radio API - refresh"},
+ {"ping" , AFB_SESSION_NONE, (AFB_apiCB)ping , "Radio API - ping"},