diff --git a/examples/wiegand/Kconfig b/examples/wiegand/Kconfig new file mode 100644 index 000000000..7617bda4a --- /dev/null +++ b/examples/wiegand/Kconfig @@ -0,0 +1,29 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config EXAMPLES_WIEGAND + tristate "Wiegand example" + default n + ---help--- + Enable the wiegand example + +if EXAMPLES_WIEGAND + +config EXAMPLES_WIEGAND_PROGNAME + string "Program name" + default "wiegand" + ---help--- + This is the name of the program that will be used when the NSH ELF + program is installed. + +config EXAMPLES_WIEGAND_PRIORITY + int "wiegand task priority" + default 100 + +config EXAMPLES_WIEGAND_STACKSIZE + int "wiegand stack size" + default DEFAULT_TASK_STACKSIZE + +endif diff --git a/examples/wiegand/Make.defs b/examples/wiegand/Make.defs new file mode 100644 index 000000000..d509235d2 --- /dev/null +++ b/examples/wiegand/Make.defs @@ -0,0 +1,23 @@ +############################################################################ +# apps/examples/wiegand/Make.defs +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you 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. +# +############################################################################ + +ifneq ($(CONFIG_EXAMPLES_WIEGAND),) +CONFIGURED_APPS += $(APPDIR)/examples/wiegand +endif diff --git a/examples/wiegand/Makefile b/examples/wiegand/Makefile new file mode 100644 index 000000000..b07019653 --- /dev/null +++ b/examples/wiegand/Makefile @@ -0,0 +1,34 @@ +############################################################################ +# apps/examples/wiegand/Make.defs +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you 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 $(APPDIR)/Make.defs + +# wiegand built-in application info + +PROGNAME = $(CONFIG_EXAMPLES_WIEGAND_PROGNAME) +PRIORITY = $(CONFIG_EXAMPLES_WIEGAND_PRIORITY) +STACKSIZE = $(CONFIG_EXAMPLES_WIEGAND_STACKSIZE) +MODULE = $(CONFIG_EXAMPLES_WIEGAND) + +# wiegand Example + +MAINSRC = wiegand.c + +include $(APPDIR)/Application.mk diff --git a/examples/wiegand/wiegand.c b/examples/wiegand/wiegand.c new file mode 100644 index 000000000..9c912f671 --- /dev/null +++ b/examples/wiegand/wiegand.c @@ -0,0 +1,77 @@ +/**************************************************************************** + * apps/examples/wiegand/wiegand.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Wiegand + ****************************************************************************/ + +int main(int argc, FAR char *argv[]) +{ + int fd; + int ret; + struct wiegand_data_s data; + + fd = open ("/dev/wiega0", O_RDONLY); + + if (fd < 0) + { + printf("Erro: Failed to open \n"); + return -1; + } + + printf("Wiegand app is running\n"); + + while (1) + { + ret = read(fd, &data, sizeof(data)); + if (ret > 0) + { + if (data.status == WIEGAND_SUCCESS) + { + printf("ABA Code: %d\n", data.aba_code); + printf("FC: %04x \n", data.facility_code); + printf("ID: %06x\n", data.id); + break; + } + } + + sleep(1); + } + + close (fd); + + return 0; +}