Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .devcontainer/activate-venv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
# Auto-activate Python virtual environment for devcontainer
# This script is idempotent and safe to source multiple times
VENV_PATH="/workspaces/python-mercuryapi/.venv"

# Only activate if venv exists and not already activated
if [ -d "$VENV_PATH" ] && [ -f "$VENV_PATH/bin/activate" ]; then
if [ -z "$VIRTUAL_ENV" ] || [ "$VIRTUAL_ENV" != "$VENV_PATH" ]; then
source "$VENV_PATH/bin/activate"
fi
fi

10 changes: 10 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "Python Mercury API",
"image": "mcr.microsoft.com/devcontainers/python:3.12",
"postCreateCommand": "chmod +x .devcontainer/activate-venv.sh && python3 -m venv /workspaces/python-mercuryapi/.venv && /workspaces/python-mercuryapi/.venv/bin/pip install --upgrade pip && if [ -f requirements.txt ]; then /workspaces/python-mercuryapi/.venv/bin/pip install -r requirements.txt; fi && echo 'source /workspaces/python-mercuryapi/.devcontainer/activate-venv.sh' >> ~/.bashrc && echo 'source /workspaces/python-mercuryapi/.devcontainer/activate-venv.sh' >> ~/.profile",
"remoteEnv": {
"VIRTUAL_ENV": "/workspaces/python-mercuryapi/.venv",
"PATH": "/workspaces/python-mercuryapi/.venv/bin:${containerEnv:PATH}"
},
"remoteUser": "vscode"
}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.vs
build
dist
mercuryapi-*/
!_vendor/
*.egg-info
mercuryapi-*
Examples/
Tests/
.venv/
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ include mercuryapi_osx.patch
include README.md
include long_description.txt
include LICENSE
recursive-include _vendor *
11 changes: 4 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
APIZIP ?= mercuryapi-AHAB-1.35.2.72-1.zip
APIVER ?= 1.35.2.72
APIZIP ?= _vendor/mercuryapi-$(APIVER).zip
APIVER ?= 1.37.4.8
PYTHON ?= $(shell { command -v python3 || command -v python; } 2>/dev/null)

.PHONY: all mercuryapi install
Expand All @@ -11,7 +11,7 @@ install: mercuryapi
$(PYTHON) setup.py install

mercuryapi: mercuryapi-$(APIVER)/.done
make -C mercuryapi-$(APIVER)/c/src/api
make -C mercuryapi-$(APIVER)/c/src/api SKIP_SAMPLES=1

mkdir -p build/mercuryapi/include
find mercuryapi-*/c/src/api -type f -name '*.h' ! -name '*_imp.h' ! -path '*ltkc_win32*' -exec cp {} build/mercuryapi/include/ \;
Expand All @@ -20,9 +20,6 @@ mercuryapi: mercuryapi-$(APIVER)/.done
find mercuryapi-*/c/src/api -type f \( -name '*.a' -or -name '*.so.1' \) -exec cp {} build/mercuryapi/lib/ \;

mercuryapi-$(APIVER)/.done: $(APIZIP)
unzip $(APIZIP)
unzip -o $(APIZIP) -x "*/cs/*" "*/java/*"
patch -p0 -d mercuryapi-$(APIVER) < mercuryapi.patch
touch mercuryapi-$(APIVER)/.done

$(APIZIP):
curl https://www.jadaktech.com/wp-content/uploads/2022/08/$(APIZIP) -o $(APIZIP)
Binary file added _vendor/mercuryapi-1.37.4.8.zip
Binary file not shown.
6 changes: 4 additions & 2 deletions mercury.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ parse_gen2filter(TMR_TagFilter *tag_filter, PyObject *arg, TMR_GEN2_Select_actio
{
if (obj == Py_None)
tag_filter->u.gen2Select.action = defaction;
else if ((tag_filter->u.gen2Select.action = str2action(object2str(obj))) == -1)
else if ((tag_filter->u.gen2Select.action = str2action(object2str(obj))) == (TMR_GEN2_Select_action)-1)
return 0;
}
else
Expand Down Expand Up @@ -1004,7 +1004,7 @@ Reader_write_tag_mem(Reader *self, PyObject *args, PyObject *kwds)
if(!parse_multifilter(&tag_filter, epc_target))
return NULL;

ret = TMR_writeTagMemBytes(&self->reader, tag_filter, bank, address, PyByteArray_Size(data), (uint8_t *)PyByteArray_AsString(data));
ret = TMR_writeTagMemBytes(&self->reader, tag_filter, bank, address, PyByteArray_Size(data), (uint8_t *)PyByteArray_AsString(data), NULL);
reset_filter(&tag_filter);
if (ret == TMR_ERROR_NO_TAGS_FOUND)
Py_RETURN_FALSE;
Expand Down Expand Up @@ -2360,7 +2360,9 @@ initmercury(void)
{
#endif
PyObject* m;
#if PY_VERSION_HEX < 0x03070000
PyEval_InitThreads();
#endif

if (PyType_Ready(&ReaderType) < 0
|| PyType_Ready(&TagDataType) < 0
Expand Down
80 changes: 79 additions & 1 deletion mercuryapi.patch
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,88 @@
+++ c/src/api/Makefile 2016-07-30 02:44:13.854834003 -0700
@@ -68,7 +68,7 @@
HEADERS += tmr_utils.h

DBG ?= -g
-CWARN = -Werror -Wall
+CWARN = -Wall
# Add -Wextra to chase down warnings that might appear on build server, but not dev machines
#CWARN += -Wextra
ifneq ($(TMR_ENABLE_SERIAL_READER_ONLY), 1)
diff -auNr mercuryapi-1.31.2.orig/c/src/api/Makefile mercuryapi-1.31.2/c/src/api/Makefile
--- c/src/api/Makefile 2018-10-02 18:53:16.000000000 +1000
+++ c/src/api/Makefile 2019-07-23 23:24:44.000000000 +1000
@@ -138,7 +138,7 @@
endif

ifneq ($(SERIAL_READER_ONLY), 1)
-all: $(LTKC_LIB) $(STATIC_LIB) $(SHARED_LIB) $(PROGS)
+all: $(LTKC_LIB) $(STATIC_LIB) $(PROGS)

$(OBJS): $(LTKC_LIB) $(LTKC_TM_IB)

@@ -153,7 +153,7 @@
find lib/LTK/LTKC/Library -name '*.h' -exec cp -p {} ltkc_win32/inc/ \;
find lib/LTK/LTKC/Library -name '*.c' -exec cp -p {} ltkc_win32/src/ \;
else
-all: $(STATIC_LIB) $(SHARED_LIB) $(PROGS)
+all: $(STATIC_LIB) $(PROGS)

$(OBJS):
endif
diff -auNr mercuryapi-1.31.2.orig/c/src/api/lib/install_LTKC.sh mercuryapi-1.31.2/c/src/api/lib/install_LTKC.sh
--- c/src/api/lib/install_LTKC.sh 2018-11-21 19:39:14.000000000 +1000
+++ c/src/api/lib/install_LTKC.sh 2019-07-23 23:23:53.000000000 +1000
@@ -45,6 +45,7 @@
patch -p0 -d ${INSTALL_DIR} < ${PATCH_DIR}/llrp_ltk_shared_libs.patch
#Apply patch that provides specific error messages related to read function. This doesnt cover any additional functionality.
#patch -p0 -d ${INSTALL_DIR} < ${PATCH_DIR}/llrp_ltkc_read_specific_errors.patch
+patch -p0 -l -d ${INSTALL_DIR} < ${PATCH_DIR}/llrp_ltk_osx.patch

#This is to avoid multiple includes of out_ltkc_ header files.
echo '#ifndef __OUT_LTKC_WRAPPER_H' > ${INSTALL_DIR}/LTK/LTKC/Library/out_ltkc_wrapper.h
diff -auNr mercuryapi-1.31.2.orig/c/src/api/lib/llrp_ltk_osx.patch mercuryapi-1.31.2/c/src/api/lib/llrp_ltk_osx.patch
--- c/src/api/lib/llrp_ltk_osx.patch 1970-01-01 10:00:00.000000000 +1000
+++ c/src/api/lib/llrp_ltk_osx.patch 2019-07-23 23:22:53.000000000 +1000
@@ -0,0 +1,42 @@
+diff -auNr LTK.orig/LTKC/Library/LLRP.org/Makefile LTK/LTKC/Library/LLRP.org/Makefile
+--- LTK.orig/LTKC/Library/LLRP.org/Makefile 2019-07-23 23:17:20.000000000 +1000
++++ LTK/LTKC/Library/LLRP.org/Makefile 2019-07-23 23:20:17.000000000 +1000
+@@ -49,7 +49,7 @@
+ TM_LTKC_SONAME = $(TM_LTKC_LIB:.a=.so.1)
+ TM_LTKC_SHARED_LIB = $(TM_LTKC_SONAME)
+
+-all: $(TM_LTKC_LIB) $(TM_LTKC_SHARED_LIB)
++all: $(TM_LTKC_LIB)
+
+ $(TM_LTKC_LIB) : $(TM_LTKC_OBJS)
+ $(AR) crv $(TM_LTKC_LIB) $(TM_LTKC_OBJS)
+diff -auNr LTK.orig/LTKC/Library/Makefile LTK/LTKC/Library/Makefile
+--- LTK.orig/LTKC/Library/Makefile 2019-07-23 23:17:20.000000000 +1000
++++ LTK/LTKC/Library/Makefile 2019-07-23 23:19:45.000000000 +1000
+@@ -60,7 +60,7 @@
+ LTKC_SONAME = $(LTKC_LIB:.a=.so.1)
+ LTKC_SHARED_LIB = libltkc.so.1
+
+-all: $(LTKC_LIB) $(LTKC_SHARED_LIB)
++all: $(LTKC_LIB)
+ cd LLRP.org; make all
+
+ everything:
+diff -auNr LTK.orig/LTKC/Library/ltkc_platform.h LTK/LTKC/Library/ltkc_platform.h
+--- LTK.orig/LTKC/Library/ltkc_platform.h 2011-03-04 16:56:16.000000000 +1000
++++ LTK/LTKC/Library/ltkc_platform.h 2019-07-23 23:18:30.000000000 +1000
+@@ -39,8 +39,6 @@
+ * good to go.
+ */
+
+-#ifdef _STDINT_H
+-
+ typedef uint8_t llrp_u8_t;
+ typedef int8_t llrp_s8_t;
+ typedef uint16_t llrp_u16_t;
+@@ -54,5 +52,3 @@
+ typedef uint8_t llrp_utf8_t;
+ typedef int llrp_bool_t;
+ typedef uint8_t llrp_byte_t;
+-
+-#endif /* _STDINT_H */
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Build dependencies for python-mercuryapi
setuptools>=65.0.0
wheel>=0.38.0