work in progress -> rf settings shell

This commit is contained in:
Harald Pichler 2017-09-05 16:38:55 +02:00
parent 3f6cb4e795
commit 8c5b66d715
7 changed files with 520 additions and 19 deletions

View file

@ -12,7 +12,7 @@ CONTIKI_WITH_IPV6 = 1
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\" CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
CFLAGS += -DCONTIKI_CONF_SETTINGS_MANAGER=1 CFLAGS += -DCONTIKI_CONF_SETTINGS_MANAGER=1
PROJECT_SOURCEFILES += ${SKETCH}.cpp PROJECT_SOURCEFILES += ${SKETCH}.cpp extended-rf-api.c
# automatically build RESTful resources # automatically build RESTful resources
REST_RESOURCES_DIR = ./resources REST_RESOURCES_DIR = ./resources

View file

@ -14,7 +14,7 @@ indent_mode=2
[project] [project]
name=arduino-merkurbaord name=arduino-merkurbaord
base_path=/home/harald/install/osd-contiki/examples/osd/arduino-merkurboard/ base_path=/home/harald/install/osd-contiki/examples/osd/arduino-settingsmanager/
description= description=
file_patterns= file_patterns=
@ -23,19 +23,9 @@ long_line_behaviour=1
long_line_column=72 long_line_column=72
[files] [files]
current_page=11 current_page=0
FILE_NAME_0=2281;None;0;EUTF-8;1;1;0;%2Fhome%2Fharald%2Finstall%2Fosd-contiki%2Fexamples%2Fosd%2Farduino-soil-moisture%2Fsketch.pde;0;4 FILE_NAME_0=1838;C++;0;EUTF-8;1;1;0;%2Fhome%2Fharald%2Finstall%2Fosd-contiki%2Fexamples%2Fosd%2Farduino-settingsmanager%2Fsketch.pde;0;4
FILE_NAME_1=2895;C;0;EUTF-8;1;1;0;%2Fhome%2Fharald%2Finstall%2Fosd-contiki%2Fexamples%2Fosd%2Farduino-soil-moisture%2Fresources%2Fres-soillight.c;0;4 FILE_NAME_1=1824;C;0;EUTF-8;1;1;0;%2Fhome%2Fharald%2Finstall%2Fosd-contiki%2Fcore%2Fdev%2Fserial-line.c;0;4
FILE_NAME_2=2893;C;0;EUTF-8;1;1;0;%2Fhome%2Fharald%2Finstall%2Fosd-contiki%2Fexamples%2Fosd%2Farduino-soil-moisture%2Fresources%2Fres-soiltemp.c;0;4
FILE_NAME_3=2177;C;0;EUTF-8;1;1;0;%2Fhome%2Fharald%2Finstall%2Fosd-contiki%2Fexamples%2Fosd%2Farduino-soil-moisture%2Fproject-conf.h;0;4
FILE_NAME_4=5823;C++;0;EUTF-8;1;1;0;%2Fhome%2Fharald%2Finstall%2Fosd-contiki%2Fexamples%2Fosd%2Farduino-soil-moisture%2FI2CSoilMoistureSensor.cpp;0;4
FILE_NAME_5=1931;C;0;EUTF-8;1;1;0;%2Fhome%2Fharald%2Finstall%2Fosd-contiki%2Fexamples%2Fosd%2Farduino-soil-moisture%2FI2CSoilMoistureSensor.h;0;4
FILE_NAME_6=0;None;0;EUTF-8;1;1;0;%2Fhome%2Fharald%2Finstall%2Fsunrise%2FPCTools%2Fpowerconsumption%2FPICOTEST%2Ftemplate%2Fvob-ok%2Faverage2.awk;0;4
FILE_NAME_7=0;XML;0;EUTF-8;1;1;0;%2Fhome%2Fharald%2Fprojekte%2Fairkey-ez2092%2FEZ2092.sch;0;4
FILE_NAME_8=0;HTML;0;EUTF-8;1;1;0;%2Fhome%2Fharald%2FDownloads%2FSemesterplan.html;0;4
FILE_NAME_9=1273;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fharald%2Finstall%2Fpensi%2Fpensi.sh;0;4
FILE_NAME_10=600;None;0;EUTF-8;1;1;0;%2Fhome%2Fharald%2Fprojekte%2Fairkey-commissioningtest%2FREADME;0;4
FILE_NAME_11=451;None;0;EUTF-8;1;1;0;%2Fhome%2Fharald%2Fprojekte%2Fairkey-energieverbrauch%2Fpowerconsumption%2FPICOTEST%2Fez2092b%2Fez2092b-fw4.54%2Fstartup%2Fsperrung-vob-ok.gpl;0;4
[VTE] [VTE]
last_dir=/home/harald last_dir=/home/harald

View file

@ -0,0 +1,194 @@
/*
* Copyright (c) 2014, George Oikonomou (george@contiki-os.org)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Example project demonstrating the extended RF API functionality
*/
#include "contiki.h"
#include "net/netstack.h"
#include "dev/radio.h"
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "extended-rf-api.h"
/*---------------------------------------------------------------------------*/
struct rf_consts {
radio_value_t channel_min;
radio_value_t channel_max;
radio_value_t txpower_min;
radio_value_t txpower_max;
};
static struct rf_consts consts;
void
print_64bit_addr(const uint8_t *addr)
{
unsigned int i;
for(i = 0; i < 7; i++) {
printf("%02x:", addr[i]);
}
printf("%02x (network order)\n", addr[7]);
}
/*---------------------------------------------------------------------------*/
radio_result_t
get_object(radio_param_t param, void *dest, size_t size)
{
radio_result_t rv;
rv = NETSTACK_RADIO.get_object(param, dest, size);
switch(rv) {
case RADIO_RESULT_ERROR:
printf("Radio returned an error\n");
break;
case RADIO_RESULT_INVALID_VALUE:
printf("Value is invalid\n");
break;
case RADIO_RESULT_NOT_SUPPORTED:
printf("Param %u not supported\n", param);
break;
case RADIO_RESULT_OK:
break;
default:
printf("Unknown return value\n");
break;
}
return rv;
}
/*---------------------------------------------------------------------------*/
radio_result_t
set_object(radio_param_t param, void *src, size_t size)
{
radio_result_t rv;
rv = NETSTACK_RADIO.set_object(param, src, size);
switch(rv) {
case RADIO_RESULT_ERROR:
printf("Radio returned an error\n");
break;
case RADIO_RESULT_INVALID_VALUE:
printf("Value is invalid\n");
break;
case RADIO_RESULT_NOT_SUPPORTED:
printf("Param %u not supported\n", param);
break;
case RADIO_RESULT_OK:
break;
default:
printf("Unknown return value\n");
break;
}
return rv;
}
/*---------------------------------------------------------------------------*/
radio_result_t
get_param(radio_param_t param, radio_value_t *value)
{
radio_result_t rv;
rv = NETSTACK_RADIO.get_value(param, value);
switch(rv) {
case RADIO_RESULT_ERROR:
printf("Radio returned an error\n");
break;
case RADIO_RESULT_INVALID_VALUE:
printf("Value %d is invalid\n", *value);
break;
case RADIO_RESULT_NOT_SUPPORTED:
printf("Param %u not supported\n", param);
break;
case RADIO_RESULT_OK:
break;
default:
printf("Unknown return value\n");
break;
}
return rv;
}
/*---------------------------------------------------------------------------*/
radio_result_t
set_param(radio_param_t param, radio_value_t value)
{
radio_result_t rv;
rv = NETSTACK_RADIO.set_value(param, value);
switch(rv) {
case RADIO_RESULT_ERROR:
printf("Radio returned an error\n");
break;
case RADIO_RESULT_INVALID_VALUE:
printf("Value %d is invalid\n", value);
break;
case RADIO_RESULT_NOT_SUPPORTED:
printf("Param %u not supported\n", param);
break;
case RADIO_RESULT_OK:
break;
default:
printf("Unknown return value\n");
break;
}
return rv;
}
/*---------------------------------------------------------------------------*/
void
get_rf_consts(void)
{
printf("====================================\n");
printf("RF Constants\n");
printf("Min Channel : ");
if(get_param(RADIO_CONST_CHANNEL_MIN, &consts.channel_min) == RADIO_RESULT_OK) {
printf("%3d\n", consts.channel_min);
}
printf("Max Channel : ");
if(get_param(RADIO_CONST_CHANNEL_MAX, &consts.channel_max) == RADIO_RESULT_OK) {
printf("%3d\n", consts.channel_max);
}
printf("Min TX Power: ");
if(get_param(RADIO_CONST_TXPOWER_MIN, &consts.txpower_min) == RADIO_RESULT_OK) {
printf("%3d dBm\n", consts.txpower_min);
}
printf("Max TX Power: ");
if(get_param(RADIO_CONST_TXPOWER_MAX, &consts.txpower_max) == RADIO_RESULT_OK) {
printf("%3d dBm\n", consts.txpower_max);
}
}

View file

@ -0,0 +1,53 @@
/*
* Copyright (c) 2014, George Oikonomou (george@contiki-os.org)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Example project demonstrating the extended RF API functionality
*/
#ifndef EXTENDED_RF_API_H_
#define EXTENDED_RF_API_H_
#include "contiki.h"
#include "net/netstack.h"
#include "dev/radio.h"
#include <stdio.h>
#include <stdint.h>
#include <string.h>
void print_64bit_addr(const uint8_t *addr);
radio_result_t get_object(radio_param_t param, void *dest, size_t size);
radio_result_t set_object(radio_param_t param, void *src, size_t size);
radio_result_t get_param(radio_param_t param, radio_value_t *value);
radio_result_t set_param(radio_param_t param, radio_value_t value);
void get_rf_consts(void);
#endif /* EXTENDED_RF_API_H_ */

View file

@ -0,0 +1,126 @@
/*
* Copyright (c) 2008, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
/**
* \file
* Tmote Sky-specific Contiki shell commands
* \author
* Adam Dunkels <adam@sics.se>
*/
#include "contiki.h"
#include "sys/cc.h"
#include "shell-sky.h"
#include "dev/watchdog.h"
#include "net/rime/rime.h"
#include "net/netstack.h"
#include "net/rime/timesynch.h"
#include "dev/radio.h"
#include "sys/node-id.h"
#include <stdio.h>
#include <string.h>
/*---------------------------------------------------------------------------*/
PROCESS(shell_txpower_process, "txpower");
SHELL_COMMAND(txpower_command,
"txpower",
"txpower <power>: change CC2420 transmission power (0 - 31)",
&shell_txpower_process);
PROCESS(shell_rfchannel_process, "rfchannel");
SHELL_COMMAND(rfchannel_command,
"rfchannel",
"rfchannel <channel>: change CC2420 radio channel (11 - 26)",
&shell_rfchannel_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_txpower_process, ev, data)
{
struct {
uint16_t len;
uint16_t txpower;
} msg;
const char *newptr;
PROCESS_BEGIN();
msg.txpower = shell_strtolong(data, &newptr);
/* If no transmission power was given on the command line, we print
out the current txpower. */
if(newptr == data) {
msg.txpower = rf230_get_txpower();
} else {
rf230_set_txpower(msg.txpower);
}
msg.len = 1;
shell_output(&txpower_command, &msg, sizeof(msg), "", 0);
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_rfchannel_process, ev, data)
{
struct {
uint16_t len;
uint16_t channel;
} msg;
const char *newptr;
PROCESS_BEGIN();
msg.channel = shell_strtolong(data, &newptr);
/* If no channel was given on the command line, we print out the
current channel. */
if(newptr == data) {
msg.channel = rf230_get_channel();
} else {
rf230__set_channel(msg.channel);
}
msg.len = 1;
shell_output(&rfchannel_command, &msg, sizeof(msg), "", 0);
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
void
shell_sky_init(void)
{
shell_register_command(&txpower_command);
shell_register_command(&rfchannel_command);
}
/*---------------------------------------------------------------------------*/

View file

@ -0,0 +1,47 @@
/*
* Copyright (c) 2008, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
/**
* \file
* Header file for Tmote Sky-specific Contiki shell commands
* \author
* harald pichler <harald@the-develop.net>
*/
#ifndef SHELL_MERKUR_H_
#define SHELL_MERKUR_H_
#include "shell.h"
void shell_merkur_init(void);
#endif /* SHELL_MERKUR_H_ */

View file

@ -17,6 +17,9 @@ extern "C" {
#include "lib/settings.h" #include "lib/settings.h"
#include "shell.h" #include "shell.h"
#include "serial-shell.h" #include "serial-shell.h"
#include "shell-merkur.h"
#include "dev/radio.h"
#include "extended-rf-api.h"
extern resource_t res_led, res_battery, res_cputemp; extern resource_t res_led, res_battery, res_cputemp;
@ -29,6 +32,93 @@ uint16_t panid;
char hostname[30]; char hostname[30];
uint16_t channel; uint16_t channel;
struct rf_consts {
radio_value_t channel_min;
radio_value_t channel_max;
radio_value_t txpower_min;
radio_value_t txpower_max;
};
//static struct rf_consts consts;
static radio_value_t value;
static uint8_t ext_addr[8];
/*---------------------------------------------------------------------------*/
static void
print_rf_values(void)
{
printf("====================================\n");
printf("RF Values\n");
printf("Power: ");
if(get_param(RADIO_PARAM_POWER_MODE, &value) == RADIO_RESULT_OK) {
if(value == RADIO_POWER_MODE_ON) {
printf("On\n");
} else if(value == RADIO_POWER_MODE_OFF) {
printf("Off\n");
}
}
printf("Channel: ");
if(get_param(RADIO_PARAM_CHANNEL, &value) == RADIO_RESULT_OK) {
printf("%d\n", value);
}
printf("PAN ID: ");
if(get_param(RADIO_PARAM_PAN_ID, &value) == RADIO_RESULT_OK) {
printf("0x%02x%02x\n", (value >> 8) & 0xFF, value & 0xFF);
}
printf("16-bit Address: ");
if(get_param(RADIO_PARAM_16BIT_ADDR, &value) == RADIO_RESULT_OK) {
printf("0x%02x%02x\n", (value >> 8) & 0xFF, value & 0xFF);
}
printf("64-bit Address: ");
if(get_object(RADIO_PARAM_64BIT_ADDR, ext_addr, 8) == RADIO_RESULT_OK) {
print_64bit_addr(ext_addr);
}
printf("RX Mode: ");
if(get_param(RADIO_PARAM_RX_MODE, &value) == RADIO_RESULT_OK) {
printf("Address Filtering is ");
if(value & RADIO_RX_MODE_ADDRESS_FILTER) {
printf("On, ");
} else {
printf("Off, ");
}
printf("Auto ACK is ");
if(value & RADIO_RX_MODE_AUTOACK) {
printf("On, ");
} else {
printf("Off, ");
}
printf("(value=%d)\n", value);
}
printf("TX Mode: ");
if(get_param(RADIO_PARAM_TX_MODE, &value) == RADIO_RESULT_OK) {
printf("%d\n", value);
}
printf("TX Power: ");
if(get_param(RADIO_PARAM_TXPOWER, &value) == RADIO_RESULT_OK) {
printf("%d dBm [0x%04x]\n", value, (uint16_t)value);
}
printf("CCA Threshold: ");
if(get_param(RADIO_PARAM_CCA_THRESHOLD, &value) == RADIO_RESULT_OK) {
printf("%d dBm [0x%04x]\n", value, (uint16_t)value);
}
printf("RSSI: ");
if(get_param(RADIO_PARAM_RSSI, &value) == RADIO_RESULT_OK) {
printf("%d dBm [0x%04x]\n", value, (uint16_t)value);
}
}
void setup (void) void setup (void)
{ {
@ -120,18 +210,19 @@ void setup (void)
printf("settings-example: Done.\n"); printf("settings-example: Done.\n");
// Seriell Shell // Seriell Shell
serial_shell_init(); serial_shell_init();
shell_blink_init(); // shell_blink_init();
shell_ps_init(); shell_ps_init();
shell_reboot_init(); shell_reboot_init();
shell_text_init(); // shell_text_init();
shell_time_init(); // shell_time_init();
// shell_merkur_init();
#if COFFEE #if COFFEE
shell_coffee_init(); shell_coffee_init();
shell_file_init(); shell_file_init();
#endif #endif
print_rf_values();
// init coap resourcen // init coap resourcen
rest_init_engine (); rest_init_engine ();
#pragma GCC diagnostic ignored "-Wwrite-strings" #pragma GCC diagnostic ignored "-Wwrite-strings"