Permalink
Browse files

Initial trigger support (#74)

This commit adds the possibility to trigger a pin (PB3) when a certain
string has been sniffed on the corresponding protocol.
  • Loading branch information...
Baldanos authored and bvernoux committed Mar 13, 2017
1 parent 06aba46 commit a982d6b2bc575f65d741c0e4a767f016577d2431
Showing with 188 additions and 0 deletions.
  1. +49 −0 hydrabus/commands.c
  2. +1 −0 hydrabus/commands.h
  3. +1 −0 hydrabus/hydrabus.mk
  4. +5 −0 hydrabus/hydrabus_mode_uart.c
  5. +110 −0 hydrabus/hydrabus_trigger.c
  6. +22 −0 hydrabus/hydrabus_trigger.h
View
@@ -143,6 +143,7 @@ t_token_dict tl_dict[] = {
{ T_FILE, "filename" },
{ T_ONEWIRE, "1-wire" },
{ T_FLASH, "flash" },
{ T_TRIGGER, "trigger" },
{ T_LEFT_SQ, "[" },
{ T_RIGHT_SQ, "]" },
@@ -299,6 +300,24 @@ t_token tokens_mode_nfc_sniff[] = {
{ }
};
t_token tokens_mode_trigger[] = {
{
T_SHOW,
.subtokens = tokens_mode_show,
.help = "Show trigger parameters"
},
{
T_FILTER,
.arg_type = T_ARG_STRING,
.help = "Trigger data"
},
{
T_START,
.help = "Arm the trigger"
},
{ }
};
#define NFC_PARAMETERS \
{\
T_TYPEA,\
@@ -410,6 +429,11 @@ t_token tokens_mode_uart[] = {
.subtokens = tokens_mode_show,
.help = "Show UART parameters"
},
{
T_TRIGGER,
.subtokens = tokens_mode_trigger,
.help = "Setup UART trigger"
},
UART_PARAMETERS
/* UART-specific commands */
{
@@ -559,6 +583,11 @@ t_token tokens_mode_i2c[] = {
.subtokens = tokens_mode_show,
.help = "Show I2C parameters"
},
{
T_TRIGGER,
.subtokens = tokens_mode_trigger,
.help = "Setup I2C trigger"
},
I2C_PARAMETERS
/* I2C-specific commands */
{
@@ -665,6 +694,11 @@ t_token tokens_mode_spi[] = {
.subtokens = tokens_mode_show,
.help = "Show SPI parameters"
},
{
T_TRIGGER,
.subtokens = tokens_mode_trigger,
.help = "Setup SPI trigger"
},
SPI_PARAMETERS
/* SPI-specific commands */
{
@@ -900,6 +934,11 @@ t_token tokens_mode_onewire[] = {
.subtokens = tokens_mode_show,
.help = "Show 1-wire parameters"
},
{
T_TRIGGER,
.subtokens = tokens_mode_trigger,
.help = "Setup 1-wire trigger"
},
ONEWIRE_PARAMETERS
/* 1-wire-specific commands */
{
@@ -993,6 +1032,11 @@ t_token tokens_mode_twowire[] = {
.subtokens = tokens_mode_show,
.help = "Show 2-wire parameters"
},
{
T_TRIGGER,
.subtokens = tokens_mode_trigger,
.help = "Setup 2-wire trigger"
},
TWOWIRE_PARAMETERS
/* 2-wire-specific commands */
{
@@ -1099,6 +1143,11 @@ t_token tokens_mode_threewire[] = {
.subtokens = tokens_mode_show,
.help = "Show 3-wire parameters"
},
{
T_TRIGGER,
.subtokens = tokens_mode_trigger,
.help = "Setup 3-wire trigger"
},
THREEWIRE_PARAMETERS
/* 3-wire-specific commands */
{
View
@@ -136,6 +136,7 @@ enum {
T_FILE,
T_ONEWIRE,
T_FLASH,
T_TRIGGER,
/* BP-compatible commands */
T_LEFT_SQ,
View
@@ -28,6 +28,7 @@ HYDRABUSSRC = hydrabus/hydrabus.c \
hydrabus/hydrabus_bbio_onewire.c \
hydrabus/hydrabus_bbio_flash.c \
hydrabus/hydrabus_sd.c \
hydrabus/hydrabus_trigger.c \
# Required include directories
HYDRABUSINC = ./hydrabus
@@ -19,6 +19,7 @@
#include "common.h"
#include "hydrabus_mode_uart.h"
#include "bsp_uart.h"
#include "hydrabus_trigger.h"
#include <string.h>
#define UART_DEFAULT_SPEED (9600)
@@ -223,6 +224,10 @@ static int exec(t_hydra_console *con, t_tokenline_parsed *p, int token_pos)
case T_BRIDGE:
bridge(con);
break;
case T_TRIGGER:
t++;
t += cmd_trigger(con, p, t);
break;
default:
return t - token_pos;
}
View
@@ -0,0 +1,110 @@
/*
* HydraBus/HydraNFC
*
* Copyright (C) 2014-2017 Benjamin VERNOUX
* Copyright (C) 2017 Nicolas OBERLI
*
* 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.
*/
#include "common.h"
#include "tokenline.h"
#include "hydrabus.h"
#include "bsp.h"
#include "bsp_gpio.h"
#include "hydrabus_mode.h"
#include "hydrabus_trigger.h"
#include <string.h>
static uint8_t trigger_data[256];
static uint32_t trigger_length;
static void show_params(t_hydra_console *con)
{
cprintf(con, "Current trigger data :\r\n");
print_hex(con, trigger_data, trigger_length);
}
static int show(t_hydra_console *con, t_tokenline_parsed *p, int token_pos)
{
int tokens_used;
tokens_used = 0;
switch (p->tokens[++token_pos]) {
case T_PINS:
tokens_used++;
cprintf(con, "Trigger pin : PB%d\r\n", TRIGGER_PIN);
break;
default:
show_params(con);
break;
}
return tokens_used;
}
static int trigger_run(t_hydra_console *con)
{
uint32_t i=0;
uint8_t rx_data;
bsp_gpio_init(TRIGGER_PORT, TRIGGER_PIN, MODE_CONFIG_DEV_GPIO_OUT_PUSHPULL,
MODE_CONFIG_DEV_GPIO_NOPULL);
bsp_gpio_clr(TRIGGER_PORT, TRIGGER_PIN);
while(!USER_BUTTON) {
if(con->mode->exec->read) {
con->mode->exec->dump(con,&rx_data,1);
}
if(rx_data == trigger_data[i]) {
i++;
} else {
i=0;
}
if(i==trigger_length) {
bsp_gpio_set(TRIGGER_PORT, TRIGGER_PIN);
return 1;
}
}
return 0;
}
int cmd_trigger(t_hydra_console *con, t_tokenline_parsed *p, int token_pos)
{
int t;
uint32_t length;
for (t = token_pos; p->tokens[t]; t++) {
switch (p->tokens[t]) {
case T_FILTER:
t += 2;
trigger_length = strlen(p->buf + p->tokens[t]);
if(length<=255) {
memcpy(trigger_data, p->buf + p->tokens[t], trigger_length);
}
show_params(con);
break;
case T_START:
cprintf(con, "Interrupt by pressing user button.\r\n");
cprint(con, "\r\n", 2);
trigger_run(con);
break;
case T_SHOW:
t += show(con, p, t);
default:
return t - token_pos;
}
}
return t - token_pos;
}
@@ -0,0 +1,22 @@
/*
* HydraBus/HydraNFC
*
* Copyright (C) 2017 Nicolas OBERLI
*
* 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.
*/
#define TRIGGER_PORT BSP_GPIO_PORTB
#define TRIGGER_PIN 3
int cmd_trigger(t_hydra_console *con, t_tokenline_parsed *p, int token_pos);

0 comments on commit a982d6b

Please sign in to comment.