├── utils ├── luci-app-ipcam2 │ ├── docs │ │ └── img │ │ │ ├── ipcam2_services.jpg │ │ │ ├── ipcam2_settings.jpg │ │ │ ├── ipcam2_filebrowser.jpg │ │ │ ├── ipcam2_minisnmpd.jpg │ │ │ └── ipcam2_sdcardsettings.jpg │ ├── luasrc │ │ ├── controller │ │ │ └── admin │ │ │ │ ├── settings.lua │ │ │ │ ├── snmpd.lua │ │ │ │ ├── service.lua │ │ │ │ ├── ipcam.lua │ │ │ │ └── filebrowser2.lua │ │ ├── view │ │ │ └── admin_ipcam │ │ │ │ ├── sdcard_status.htm │ │ │ │ ├── sdcard_format_f2fs.htm │ │ │ │ ├── sdcard_format_vfat.htm │ │ │ │ ├── range.htm │ │ │ │ ├── service.htm │ │ │ │ └── filebrowser.htm │ │ ├── model │ │ │ └── cbi │ │ │ │ └── admin_ipcam │ │ │ │ ├── sdcard_settings.lua │ │ │ │ ├── mini_snmpd.lua │ │ │ │ └── settings.lua │ │ └── LIP.lua │ ├── Makefile │ └── README.md ├── xmdp │ ├── src │ │ ├── netip.h │ │ ├── Makefile │ │ ├── utils.h │ │ ├── utils.c │ │ ├── netip.c │ │ ├── xmdp.c │ │ └── cjson │ │ │ └── cJSON.h │ ├── README.md │ ├── LICENSE │ └── Makefile ├── memdump │ ├── README.md │ ├── LICENSE │ ├── Makefile │ └── src │ │ └── memdump.c ├── hisi_gpio_scanner │ ├── README.md │ ├── LICENSE │ ├── Makefile │ └── src │ │ ├── hisi_gpio_scanner.c.bak │ │ └── hisi_gpio_scanner.c ├── hisi_gpio_watcher │ ├── README.md │ ├── LICENSE │ ├── Makefile │ └── src │ │ └── hisi_gpio_watcher.c └── ipctool │ └── Makefile ├── LICENSE └── README.md /utils/luci-app-ipcam2/docs/img/ipcam2_services.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIPC/packages/main/utils/luci-app-ipcam2/docs/img/ipcam2_services.jpg -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/docs/img/ipcam2_settings.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIPC/packages/main/utils/luci-app-ipcam2/docs/img/ipcam2_settings.jpg -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/docs/img/ipcam2_filebrowser.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIPC/packages/main/utils/luci-app-ipcam2/docs/img/ipcam2_filebrowser.jpg -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/docs/img/ipcam2_minisnmpd.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIPC/packages/main/utils/luci-app-ipcam2/docs/img/ipcam2_minisnmpd.jpg -------------------------------------------------------------------------------- /utils/xmdp/src/netip.h: -------------------------------------------------------------------------------- 1 | #ifndef NETIP_H 2 | #define NETIP_H 3 | 4 | bool netip_connect(const char* addr, uint16_t port); 5 | 6 | #endif /* NETIP_H */ 7 | -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/docs/img/ipcam2_sdcardsettings.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIPC/packages/main/utils/luci-app-ipcam2/docs/img/ipcam2_sdcardsettings.jpg -------------------------------------------------------------------------------- /utils/xmdp/src/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-Wall -Wpedantic 2 | LDFLAGS=-lm 3 | 4 | all: xmdp 5 | 6 | xmdp: xmdp.o netip.o utils.o cjson/cJSON.c 7 | $(CC) -o $@ $^ $(LDFLAGS) 8 | 9 | clean: 10 | -rm xmdp *.o 11 | -------------------------------------------------------------------------------- /utils/xmdp/README.md: -------------------------------------------------------------------------------- 1 | # XMDP 2 | 3 | Utility for finding devices that support the NETIP protocol 4 | 5 | ### Example compilation in OpenIPC root dir 6 | 7 | ```make -j1 V=s package/feeds/futurum/xmdp/{clean,compile,install}``` 8 | -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/controller/admin/settings.lua: -------------------------------------------------------------------------------- 1 | module("luci.controller.admin.settings", package.seeall) 2 | 3 | function index() 4 | entry({"admin", "ipcam", "settings"}, cbi("admin_ipcam/settings"), _("Settings")) 5 | end -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/controller/admin/snmpd.lua: -------------------------------------------------------------------------------- 1 | module("luci.controller.admin.snmpd", package.seeall) 2 | 3 | function index() 4 | entry({"admin", "ipcam", "mini_snmpd"}, cbi("admin_ipcam/mini_snmpd"), _("Mini SNMPd")) 5 | end -------------------------------------------------------------------------------- /utils/memdump/README.md: -------------------------------------------------------------------------------- 1 | # MEMDUMP 2 | 3 | An alternative simple utility for getting dumps from memory 4 | 5 | ### Example compilation in OpenIPC root dir 6 | 7 | ```make -j1 V=s package/feeds/futurum/memdump/{clean,compile,install}``` 8 | -------------------------------------------------------------------------------- /utils/hisi_gpio_scanner/README.md: -------------------------------------------------------------------------------- 1 | # HISI_GPIO_SCANNER 2 | 3 | Utility for diagnosing and displaying GPIO statuses 4 | 5 | ### Example compilation in OpenIPC root dir 6 | 7 | ```make -j1 V=s package/feeds/futurum/hisi_gpio_scanner/{clean,compile,install}``` 8 | -------------------------------------------------------------------------------- /utils/hisi_gpio_watcher/README.md: -------------------------------------------------------------------------------- 1 | # HISI_GPIO_WATCHER 2 | 3 | Utility for run commands when changing GPIO statuses 4 | 5 | ### Example compilation in OpenIPC root dir 6 | 7 | ```make -j1 V=s package/feeds/futurum/hisi_gpio_watcher/{clean,compile,install}``` 8 | -------------------------------------------------------------------------------- /utils/xmdp/src/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILS_H 2 | #define UTILS_H 3 | 4 | const char *get_json_strval(const cJSON *json, const char *key, 5 | const char *def_val); 6 | int get_json_intval(const cJSON *json, const char *key, 7 | int def_val); 8 | 9 | #endif /* UTILS_H */ 10 | -------------------------------------------------------------------------------- /utils/xmdp/src/utils.c: -------------------------------------------------------------------------------- 1 | #include "cjson/cJSON.h" 2 | #include "utils.h" 3 | 4 | const char *get_json_strval(const cJSON *json, const char *key, 5 | const char *def_val) { 6 | const cJSON *jval = cJSON_GetObjectItemCaseSensitive(json, key); 7 | if (cJSON_IsString(jval) && (jval->valuestring != NULL)) { 8 | return jval->valuestring; 9 | } else { 10 | return def_val; 11 | } 12 | } 13 | 14 | int get_json_intval(const cJSON *json, const char *key, 15 | int def_val) { 16 | const cJSON *jval = cJSON_GetObjectItemCaseSensitive(json, key); 17 | if (cJSON_IsNumber(jval) && (jval->valueint)) { 18 | return jval->valueint; 19 | } else { 20 | return def_val; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/view/admin_ipcam/sdcard_status.htm: -------------------------------------------------------------------------------- 1 | <%+cbi/valueheader%> 2 | 3 | 21 | 22 | 23 | <%+cbi/valuefooter%> 24 | 25 | -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/controller/admin/service.lua: -------------------------------------------------------------------------------- 1 | module("luci.controller.admin.service", package.seeall) 2 | 3 | function index() 4 | entry({"admin", "ipcam", "service"}, template("admin_ipcam/service"), _("Service"), 1) 5 | entry({"admin", "ipcam", "service", "control"}, call("svc_control")).leaf = true 6 | end 7 | 8 | function svc_control() 9 | if luci.http.formvalue("action") == "Restart" then 10 | luci.sys.call("killall -sigint majestic") 11 | luci.sys.call("export SENSOR=`fw_printenv -n sensor`; majestic 2>&1 | logger -p daemon.info -t majestic &") 12 | end 13 | if luci.http.formvalue("action") == "Stop" then 14 | luci.sys.call("killall -sigint majestic") 15 | end 16 | if luci.http.formvalue("action") == "Start" then 17 | luci.sys.call("killall -sigint majestic") 18 | luci.sys.call("export SENSOR=`fw_printenv -n sensor`; majestic 2>&1 | logger -p daemon.info -t majestic &") 19 | end 20 | luci.http.redirect(luci.dispatcher.build_url("admin/ipcam/service")) 21 | end -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 OpenIPC.org 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /utils/xmdp/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 OpenIPC.org 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /utils/memdump/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 OpenIPC.org 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /utils/hisi_gpio_scanner/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 OpenIPC.org 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /utils/hisi_gpio_watcher/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 OpenIPC.org 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2011-2014 OpenWrt.org 3 | # 4 | # This is free software, licensed under the GNU General Public License v2. 5 | # See /LICENSE for more information. 6 | # 7 | 8 | include $(TOPDIR)/rules.mk 9 | 10 | PKG_NAME:=luci-app-ipcam2 11 | PKG_VERSION:=2021-04-21 12 | PKG_RELEASE:=2.0 13 | PKG_MAINTAINER:=Randy 14 | 15 | include $(INCLUDE_DIR)/package.mk 16 | 17 | PKG_LICENSE:=GPL-2.0 18 | PKG_LICENSE_FILES:=LICENSE 19 | 20 | define Package/$(PKG_NAME) 21 | SECTION:=openipc 22 | CATEGORY:=OpenIPC 23 | SUBMENU:=Other 24 | TITLE:=OpenIPC luci extension 25 | MAINTAINER:=Randy D. 26 | URL:=http://openipc.org 27 | endef 28 | 29 | define Package/$(PKG_NAME)/description 30 | Original concept from luci-app-config by Igor Zalatov (ZFT Lab.) . Modified to configure OpenIPC settings and monitor services. 31 | endef 32 | 33 | define Build/Prepare 34 | endef 35 | 36 | define Build/Compile 37 | endef 38 | 39 | define Package/$(PKG_NAME)/install 40 | $(INSTALL_DIR) $(1)/usr/lib/lua/luci 41 | $(CP) ./luasrc/* $(1)/usr/lib/lua/luci/ 42 | $(CP) ./htdocs/ $(1)/www/ 43 | endef 44 | 45 | $(eval $(call BuildPackage,$(PKG_NAME))) 46 | -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/model/cbi/admin_ipcam/sdcard_settings.lua: -------------------------------------------------------------------------------- 1 | local os = require "os"; 2 | local fs = require "nixio.fs"; 3 | local config = 'ipcam'; 4 | 5 | local m, d, a, s, dm, t; 6 | 7 | if fs.stat('/etc/config/'..config, "type") ~= "reg" then 8 | os.execute('touch /etc/config/'..config) 9 | end 10 | 11 | m = Map(config, translate("SD Card Settings"), translate("Here you can configure sd card settings.")); 12 | 13 | s = "sdcard"; 14 | 15 | dm = m:section(NamedSection, "sdcard", ""); 16 | 17 | t = dm:option(DummyValue, "_capacity", translate("Capacity")) 18 | t.template = "admin_ipcam/sdcard_status" 19 | 20 | a = dm:option(Flag, "photo", "Save event photo to SD card"); 21 | a.optional = false; a.rmempty = false; 22 | 23 | a = dm:option(Flag, "video", "Save event video to SD card"); 24 | a.optional = false; a.rmempty = false; 25 | 26 | a = dm:option(Flag, "overwrite", "Over-write when full"); 27 | a.optional = false; a.rmempty = false; 28 | 29 | t = dm:option(DummyValue, "_format_sd_card_f2fs", "Format SD Card") 30 | t.template = "admin_ipcam/sdcard_format_f2fs" 31 | 32 | t = dm:option(DummyValue, "_format_sd_card_vfat", "Format SD Card") 33 | t.template = "admin_ipcam/sdcard_format_vfat" 34 | 35 | return m 36 | -------------------------------------------------------------------------------- /utils/hisi_gpio_scanner/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2013-2021 OpenIPC.org 3 | # 4 | # This is free software, licensed under the MIT License. 5 | # See /LICENSE for more information. 6 | # 7 | 8 | include $(TOPDIR)/rules.mk 9 | 10 | PKG_NAME:=hisi_gpio_scanner 11 | PKG_VERSION:=0.1 12 | PKG_RELEASE:=latest 13 | PKG_MAINTAINER:=Andrew_kmr 14 | 15 | include $(INCLUDE_DIR)/package.mk 16 | 17 | PKG_LICENSE:=MIT 18 | PKG_LICENSE_FILES:=LICENSE 19 | 20 | define Package/$(PKG_NAME) 21 | SECTION:=openipc 22 | CATEGORY:=OpenIPC 23 | SUBMENU:=Utils 24 | TITLE:=Utility for diagnosing and displaying GPIO statuses 25 | MAINTAINER:=Andrew_kmr 26 | endef 27 | 28 | define Package/$(PKG_NAME)/description 29 | Utility for diagnosing and displaying GPIO statuses 30 | endef 31 | 32 | define Build/Prepare 33 | $(INSTALL_DIR) $(PKG_BUILD_DIR) 34 | $(CP) ./src/* $(PKG_BUILD_DIR)/ 35 | endef 36 | 37 | define Build/Compile 38 | $(TARGET_CC) $(TARGET_CFLAGS) $(TARGET_LDFLAGS) -o $(PKG_BUILD_DIR)/$(PKG_NAME) $(PKG_BUILD_DIR)/hisi_gpio_scanner.c 39 | endef 40 | 41 | define Package/$(PKG_NAME)/install 42 | $(INSTALL_DIR) $(1)/usr/bin 43 | $(INSTALL_BIN) $(PKG_BUILD_DIR)/$(PKG_NAME) $(1)/usr/bin/ 44 | endef 45 | 46 | $(eval $(call BuildPackage,$(PKG_NAME))) 47 | -------------------------------------------------------------------------------- /utils/memdump/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2013-2021 OpenIPC.org 3 | # 4 | # This is free software, licensed under the MIT License. 5 | # See /LICENSE for more information. 6 | # 7 | 8 | include $(TOPDIR)/rules.mk 9 | 10 | PKG_NAME:=memdump 11 | PKG_VERSION:=0.1 12 | PKG_RELEASE:=latest 13 | PKG_MAINTAINER:=Maksim Patrushev <330379404icq@gmail.com> 14 | 15 | include $(INCLUDE_DIR)/package.mk 16 | 17 | PKG_LICENSE:=MIT 18 | PKG_LICENSE_FILES:=LICENSE 19 | 20 | define Package/$(PKG_NAME) 21 | SECTION:=openipc 22 | CATEGORY:=OpenIPC 23 | SUBMENU:=Utils 24 | TITLE:=An alternative simple utility for getting dumps from memory 25 | MAINTAINER:=Maksim Patrushev <330379404icq@gmail.com> 26 | endef 27 | 28 | define Package/$(PKG_NAME)/description 29 | An alternative simple utility for getting dumps from memory 30 | endef 31 | 32 | define Build/Prepare 33 | $(INSTALL_DIR) $(PKG_BUILD_DIR) 34 | $(CP) ./src/* $(PKG_BUILD_DIR)/ 35 | endef 36 | 37 | define Build/Compile 38 | $(TARGET_CC) $(TARGET_CFLAGS) $(TARGET_LDFLAGS) -o $(PKG_BUILD_DIR)/$(PKG_NAME) $(PKG_BUILD_DIR)/memdump.c 39 | endef 40 | 41 | define Package/$(PKG_NAME)/install 42 | $(INSTALL_DIR) $(1)/usr/bin 43 | $(INSTALL_BIN) $(PKG_BUILD_DIR)/$(PKG_NAME) $(1)/usr/bin/ 44 | endef 45 | 46 | $(eval $(call BuildPackage,$(PKG_NAME))) 47 | -------------------------------------------------------------------------------- /utils/hisi_gpio_watcher/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2013-2021 OpenIPC.org 3 | # 4 | # This is free software, licensed under the MIT License. 5 | # See /LICENSE for more information. 6 | # 7 | 8 | include $(TOPDIR)/rules.mk 9 | 10 | PKG_NAME:=hisi_gpio_watcher 11 | PKG_VERSION:=0.1 12 | PKG_RELEASE:=latest 13 | PKG_MAINTAINER:=Maksim Patrushev <330379404icq@gmail.com> 14 | 15 | include $(INCLUDE_DIR)/package.mk 16 | 17 | PKG_LICENSE:=MIT 18 | PKG_LICENSE_FILES:=LICENSE 19 | 20 | define Package/$(PKG_NAME) 21 | SECTION:=openipc 22 | CATEGORY:=OpenIPC 23 | SUBMENU:=Utils 24 | TITLE:=Utility for run commands when changing GPIO statuses 25 | MAINTAINER:=Maksim Patrushev <330379404icq@gmail.com> 26 | endef 27 | 28 | define Package/$(PKG_NAME)/description 29 | Utility for run commands when changing GPIO statuses 30 | endef 31 | 32 | define Build/Prepare 33 | $(INSTALL_DIR) $(PKG_BUILD_DIR) 34 | $(CP) ./src/* $(PKG_BUILD_DIR)/ 35 | endef 36 | 37 | define Build/Compile 38 | $(TARGET_CC) $(TARGET_CFLAGS) $(TARGET_LDFLAGS) -o $(PKG_BUILD_DIR)/$(PKG_NAME) $(PKG_BUILD_DIR)/hisi_gpio_watcher.c 39 | endef 40 | 41 | define Package/$(PKG_NAME)/install 42 | $(INSTALL_DIR) $(1)/usr/bin 43 | $(INSTALL_BIN) $(PKG_BUILD_DIR)/$(PKG_NAME) $(1)/usr/bin/ 44 | endef 45 | 46 | $(eval $(call BuildPackage,$(PKG_NAME))) 47 | -------------------------------------------------------------------------------- /utils/xmdp/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2013-2021 OpenIPC.org 3 | # 4 | # This is free software, licensed under the MIT License. 5 | # See /LICENSE for more information. 6 | # 7 | 8 | include $(TOPDIR)/rules.mk 9 | 10 | PKG_NAME:=xmdp 11 | PKG_VERSION:=0.1 12 | PKG_RELEASE:=latest 13 | PKG_MAINTAINER:=Dmitry Ilyin 14 | 15 | include $(INCLUDE_DIR)/package.mk 16 | 17 | PKG_LICENSE:=MIT 18 | PKG_LICENSE_FILES:=LICENSE 19 | 20 | define Package/$(PKG_NAME) 21 | SECTION:=openipc 22 | CATEGORY:=OpenIPC 23 | SUBMENU:=Utils 24 | TITLE:=Utility for finding devices that support the NETIP protocol 25 | MAINTAINER:=Dmitry Ilyin 26 | endef 27 | 28 | define Package/$(PKG_NAME)/description 29 | Utility for finding devices that support the NETIP protocol 30 | endef 31 | 32 | define Build/Prepare 33 | $(INSTALL_DIR) $(PKG_BUILD_DIR) 34 | $(CP) ./src/* $(PKG_BUILD_DIR)/ 35 | endef 36 | 37 | define Build/Compile 38 | $(TARGET_CC) $(TARGET_CFLAGS) $(TARGET_LDFLAGS) -O -g -D LINUX -std=c99 -Wall -Wpedantic -lm -o $(PKG_BUILD_DIR)/$(PKG_NAME) \ 39 | $(PKG_BUILD_DIR)/xmdp.c $(PKG_BUILD_DIR)/netip.c $(PKG_BUILD_DIR)/utils.c $(PKG_BUILD_DIR)/cjson/cJSON.c 40 | endef 41 | 42 | define Package/$(PKG_NAME)/install 43 | $(INSTALL_DIR) $(1)/usr/bin 44 | $(INSTALL_BIN) $(PKG_BUILD_DIR)/$(PKG_NAME) $(1)/usr/bin/ 45 | endef 46 | 47 | $(eval $(call BuildPackage,$(PKG_NAME))) 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## OpenIPC packages 2 | 3 | New packages feed **futurum** for IP cameras and NVRs based on the HiSilicon (and other) SoC's 4 | 5 | More information about project on our website [https://openipc.org](https://openipc.org) 6 | 7 |  8 |  9 |  10 | [](https://opensource.org/licenses/MIT) 11 | 12 | ----- 13 | 14 | ### Supporting 15 | 16 | If you like our work, please consider supporting us on [Open Collective](https://opencollective.com/openipc/contribute/backer-14335/checkout). 17 | 18 | [](https://opencollective.com/openipc) 19 | [](https://opencollective.com/openipc) 20 | 21 | [](https://opencollective.com/openipc#support) 22 | 23 | ### Thanks a lot !!! 24 | 25 | 26 | 27 | 28 | 29 | ----- 30 | -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/model/cbi/admin_ipcam/mini_snmpd.lua: -------------------------------------------------------------------------------- 1 | local fs = require "nixio.fs" 2 | local sys = require "luci.sys" 3 | 4 | m = Map("snmpd", translate("Mini_snmpd"), 5 | translate("Mini_snmpd offers a SNMP server. You can configure the settings for it here.")) 6 | 7 | s = m:section(TypedSection, "snmpd", "") 8 | s.anonymous = true 9 | s.addremove = false 10 | s.reset = false 11 | 12 | t = s:option(Flag, "enable", translate("Enable"), 13 | translate("Specifies if the SNMP server is enabled or disabled")) 14 | t.enabled = "1" 15 | t.disabled = "0" 16 | t.default = t.enabled 17 | t.rmempty = false 18 | 19 | l = s:option(Value, "location", translate("Location"), 20 | translate("Specifies the SNMP server location reply")) 21 | l.default = "World" 22 | 23 | d = s:option(Value, "disk", translate("Disk"), 24 | translate("Specifies the location to store SNMP temporary files")) 25 | d.default = "/overlay,/tmp" 26 | 27 | 28 | t = s:option(Value, "timeout", translate("Timeout"), 29 | translate("Specifies the timeout for SNMP queries to the server")) 30 | t.default = "1" 31 | 32 | c = s:option(Value, "community", translate("Community"), 33 | translate("Specifies the SNMP server read/write community")) 34 | c.default = "public" 35 | 36 | c2 = s:option(Value, "contact", translate("Contact"), 37 | translate("Specifies the SNMP server contact reply")) 38 | c2.default = "OpenIPC" 39 | 40 | i = s:option(Value, "interface", translate("Interface"), 41 | translate("Specifies the SNMP server listening interface, eth0 by default")) 42 | i.widget = "radio" 43 | i.template = "cbi/network_ifacelist" 44 | 45 | return m -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/view/admin_ipcam/sdcard_format_f2fs.htm: -------------------------------------------------------------------------------- 1 | <%+cbi/valueheader%> 2 | 3 | 51 | 52 | 53 | <%+cbi/valuefooter%> 54 | -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/view/admin_ipcam/sdcard_format_vfat.htm: -------------------------------------------------------------------------------- 1 | <%+cbi/valueheader%> 2 | 3 | 51 | 52 | 53 | <%+cbi/valuefooter%> 54 | -------------------------------------------------------------------------------- /utils/ipctool/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2013-2021 OpenIPC.org 3 | # 4 | # This is free software, licensed under the MIT License. 5 | # See /LICENSE for more information. 6 | # 7 | 8 | include $(TOPDIR)/rules.mk 9 | 10 | PKG_NAME:=ipctool 11 | PKG_VERSION:=master 12 | PKG_RELEASE:=latest 13 | PKG_MAINTAINER:=Dmitry Ilyin 14 | 15 | PKG_LICENSE:=MIT 16 | PKG_LICENSE_FILES:=LICENSE 17 | 18 | PKG_SOURCE_PROTO:=git 19 | PKG_SOURCE_URL:=https://github.com/OpenIPC/ipctool.git 20 | PKG_SOURCE_VERSION:=3c21f3c914b5f55fee9243a517f22b47ee3eeb24 21 | #PKG_SOURCE_VERSION:=360ba07038af31d3f9c64fee44d88086c92e6676 22 | #PKG_SOURCE_VERSION:=04b2eec1f6d2cbb053548257836e6a7bbebf9d93 23 | #PKG_SOURCE_VERSION:=84b48c5035795de5233b354e843d30f58a1e8bc4 24 | #PKG_SOURCE_VERSION:=7e523a84b054a122245039b7b32e67bf0995ba8f 25 | 26 | PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) 27 | PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) 28 | PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz 29 | 30 | include $(INCLUDE_DIR)/package.mk 31 | include $(INCLUDE_DIR)/cmake.mk 32 | 33 | define Package/$(PKG_NAME) 34 | SECTION:=openipc 35 | CATEGORY:=OpenIPC 36 | SUBMENU:=Utils 37 | TITLE:=New util for get info from IPCamera SoCs 38 | MAINTAINER:=Dmitry Ilyin 39 | DEPENDS:=@(TARGET_hi35xx) 40 | endef 41 | 42 | define Package/$(PKG_NAME)/description 43 | New util for get info from IPCamera (Hisi) SoCs 44 | endef 45 | 46 | CMAKE_OPTIONS += -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -DSKIP_VERSION=ON 47 | 48 | define Build/Prepare 49 | (cd $(PKG_BUILD_DIR) && tar --strip-components 1 -xvzf $(DL_DIR)/$(PKG_SOURCE)) 50 | endef 51 | 52 | define Package/$(PKG_NAME)/install 53 | $(INSTALL_DIR) $(1)/usr/bin 54 | $(INSTALL_BIN) $(PKG_BUILD_DIR)/$(PKG_NAME) $(1)/usr/bin/ 55 | $(INSTALL_BIN) $(PKG_BUILD_DIR)/ipcinfo $(1)/usr/bin/ 56 | 57 | endef 58 | 59 | $(eval $(call BuildPackage,$(PKG_NAME))) 60 | -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/README.md: -------------------------------------------------------------------------------- 1 | # luci-app-ipcam2 2 | ### About: 3 | 4 | Original package from [luci-app-config](https://github.com/ZigFisher/Glutinium/tree/master/luci-app-ipcam) by @ZigFisher. Modified to configure OpenIPC settings, view OpenIPC service information, etc. 5 | 6 | This should be considered a beta extension! 7 | 8 | ### Download 9 | 10 | Download the luci-app-ipcam2_2021-04-21-2.0_hi35xx.ipk release [here](https://github.com/randysbytes/luci-app-ipcam2/releases/download/v2.0/luci-app-ipcam2_2021-04-21-2.0_hi35xx.ipk) or clone this repository to your OpenIPC source code directory. 11 | 12 | ### Installation 13 | 14 | First download the ipk package or build it from source and transfer it to the /tmp/ directoy of your OpenIPC camera using scp. 15 | 16 | `# scp luci-app-ipcam2_2021-04-21-2.0_hi35xx.ipk root@OpenIPC_CAMERAIP:/tmp/luci-app-ipcam2_2021-04-21-2.0_hi35xx.ipk` 17 | 18 | If the package luci-app-ipcam is installed on OpenIPC, remove it by running this command on your camera. 19 | 20 | `# opkg remove luci-app-ipcam` 21 | 22 | Now run the opkg install process on your camera. 23 | 24 | `# opkg install /tmp/luci-app-ipcam2_2021-04-21-2.0_hi35xx.ipk` 25 | 26 | Now from your OpenIPC camera you can use the IPCam menu in luci. 27 | 28 | ### Configuration 29 | 30 | Due to the default configuration having comments in it and the way the configuration is parsed in lua, some settings with the default /etc/majestic.yaml configuration may have comments in them or white space's, if you wish to get rid of this, it is suggested you restore the configuration on the Reset/Edit tab of the settings page, you will lose any configuration changes you have made to your majestic.yaml configuration and a "cleaned" configuration will be written. 31 | 32 | If for some reason you need to remove this application and want to restore the the default majestic configuration yaml, run the following command. 33 | 34 | `# cp /rom/etc/majestic.yaml /etc/majestic.yaml` 35 | 36 | ### Screenshots 37 | 38 | **** 39 | 40 | **** 41 | 42 | **** 43 | 44 | **** 45 | 46 | **** 47 | -------------------------------------------------------------------------------- /utils/xmdp/src/netip.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "cjson/cJSON.h" 11 | #include "netip.h" 12 | #include "utils.h" 13 | 14 | #define PACKED __attribute__((packed)) 15 | 16 | #define OP_LOGIN 1000 17 | #define OP_SYSINFO 1020 18 | 19 | #define RESULT_OK 100 20 | #define RESULT_UNKNOWN_ERROR 101 21 | #define RESULT_INCORRECT_PWD 203 22 | 23 | typedef struct netip_preabmle { 24 | uint8_t head; 25 | uint8_t version; 26 | uint16_t unused; 27 | uint32_t session; 28 | uint32_t sequence; 29 | uint8_t total; 30 | uint8_t cur; 31 | uint16_t msgid; 32 | uint32_t len_data; 33 | char data[]; 34 | } PACKED netip_preabmle_t; 35 | 36 | #define MAX_UDP_PACKET_SIZE 0xFFFF 37 | 38 | typedef union netip_pkt { 39 | char buf[MAX_UDP_PACKET_SIZE]; 40 | netip_preabmle_t header; 41 | } netip_pkt_t; 42 | 43 | #define NETIP_HSIZE sizeof(netip_preabmle_t) 44 | #define NETIP_MAX_JSON sizeof(resp) - NETIP_HSIZE - 1 45 | 46 | bool netip_connect(const char *addr, uint16_t port) { 47 | bool res = true; 48 | 49 | int s = socket(AF_INET, SOCK_STREAM, 0); 50 | if (s == -1) 51 | return false; 52 | 53 | struct sockaddr_in srv; 54 | srv.sin_addr.s_addr = inet_addr(addr); 55 | srv.sin_family = AF_INET; 56 | srv.sin_port = htons(port); 57 | 58 | if (connect(s, (struct sockaddr *)&srv, sizeof(srv)) < 0) 59 | return false; 60 | 61 | netip_pkt_t msg; 62 | memset(&msg.header, 0, sizeof(msg.header)); 63 | msg.header.head = 0xff; 64 | msg.header.msgid = OP_LOGIN; 65 | const char default_login[] = 66 | "{\"EncryptType\": \"MD5\", \"LoginType\": \"DVRIP-Web\", \"PassWord\": " 67 | "\"tlJwpbo6\", \"UserName\": \"admin\"}\n\0"; 68 | strcpy(msg.header.data, default_login); 69 | msg.header.len_data = sizeof(default_login); 70 | 71 | if (send(s, &msg, sizeof(default_login) + NETIP_HSIZE, 0) < 0) { 72 | puts("Send failed"); 73 | return false; 74 | } 75 | 76 | if (recv(s, &msg, sizeof(msg), 0) <= NETIP_HSIZE) { 77 | puts("recv failed"); 78 | } 79 | 80 | cJSON *json = cJSON_Parse(msg.header.data); 81 | if (!json) { 82 | const char *error_ptr = cJSON_GetErrorPtr(); 83 | if (error_ptr != NULL) { 84 | fprintf(stderr, "Error before: %s\n", error_ptr); 85 | } 86 | res = false; 87 | goto skip_loop; 88 | } 89 | const int retval = get_json_intval(json, "Ret", 0); 90 | if (retval != RESULT_OK) 91 | return false; 92 | 93 | skip_loop: 94 | cJSON_Delete(json); 95 | 96 | return res; 97 | } 98 | -------------------------------------------------------------------------------- /utils/memdump/src/memdump.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | unsigned long parse_int (char *str); 12 | 13 | void dumphex(const void* data, size_t size) { 14 | char ascii[17]; 15 | size_t i, j; 16 | ascii[16] = '\0'; 17 | for (i = 0; i < size; ++i) { 18 | printf("%02X ", ((unsigned char*)data)[i]); 19 | if (((unsigned char*)data)[i] >= ' ' && ((unsigned char*)data)[i] <= '~') { 20 | ascii[i % 16] = ((unsigned char*)data)[i]; 21 | } else { 22 | ascii[i % 16] = '.'; 23 | } 24 | if ((i+1) % 8 == 0 || i+1 == size) { 25 | printf(" "); 26 | if ((i+1) % 16 == 0) { 27 | printf("| %s \n", ascii); 28 | } else if (i+1 == size) { 29 | ascii[(i+1) % 16] = '\0'; 30 | if ((i+1) % 16 <= 8) { 31 | printf(" "); 32 | } 33 | for (j = (i+1) % 16; j < 16; ++j) { 34 | printf(" "); 35 | } 36 | printf("| %s \n", ascii); 37 | } 38 | } 39 | } 40 | } 41 | 42 | int main (int argc, char *argv[]) { 43 | unsigned long addr, length; 44 | 45 | int devmem; 46 | void *mapping; 47 | 48 | long page_size; 49 | off_t map_base, extra_bytes; 50 | 51 | char *buf; 52 | ssize_t ret; 53 | 54 | if (argc != 3) { 55 | fprintf(stderr, "Usage: %s ADDR LENGTH\n", argv[0]); 56 | exit(EXIT_FAILURE); 57 | } 58 | 59 | addr = parse_int(argv[1]); 60 | length = parse_int(argv[2]); 61 | 62 | devmem = open("/dev/mem", O_RDONLY); 63 | if (devmem == -1) { 64 | perror("Could not open /dev/mem"); 65 | goto open_fail; 66 | } 67 | 68 | page_size = sysconf(_SC_PAGE_SIZE); 69 | map_base = addr & ~(page_size - 1); 70 | extra_bytes = addr - map_base; 71 | 72 | mapping = mmap(NULL, length + extra_bytes, PROT_READ, MAP_SHARED, 73 | devmem, map_base); 74 | if (mapping == MAP_FAILED) { 75 | perror("Could not map memory"); 76 | goto map_fail; 77 | } 78 | 79 | buf = malloc(length); 80 | if (buf == NULL) { 81 | fprintf(stderr, "Failed to allocate memory\n"); 82 | goto alloc_fail; 83 | } 84 | 85 | memcpy(buf, (char *)mapping + extra_bytes, length); 86 | 87 | dumphex(buf,length); 88 | 89 | free(buf); 90 | 91 | alloc_fail: 92 | munmap(mapping, length + extra_bytes); 93 | 94 | map_fail: 95 | close(devmem); 96 | 97 | open_fail: 98 | return EXIT_SUCCESS; 99 | } 100 | 101 | unsigned long parse_int (char *str) { 102 | long long result; 103 | char *endptr; 104 | 105 | result = strtoll(str, &endptr, 0); 106 | if (str == '\0' || *endptr != '\0') { 107 | fprintf(stderr, "\"%s\" is not a valid number\n", str); 108 | exit(EXIT_FAILURE); 109 | } 110 | 111 | return (unsigned long)result; 112 | } 113 | -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/controller/admin/ipcam.lua: -------------------------------------------------------------------------------- 1 | module("luci.controller.admin.ipcam", package.seeall) 2 | 3 | util = require "luci.util" 4 | 5 | 6 | function index() 7 | 8 | entry({"admin", "ipcam"}, alias("admin", "ipcam", "settings"), _("IPCam"), 55).index = true 9 | 10 | entry({"admin", "ipcam", "sdcard_settings"}, cbi("admin_ipcam/sdcard_settings"), _("SD Card Settings"), 11) 11 | 12 | entry({"admin", "ipcam", "sdcard_status"}, call("action_sdcard_status")) 13 | 14 | entry({"admin", "ipcam", "sdcard_format_f2fs"}, call("action_sdcard_format_f2fs")) 15 | 16 | entry({"admin", "ipcam", "sdcard_format_vfat"}, call("action_sdcard_format_vfat")) 17 | 18 | entry({"admin", "ipcam", "test_mail"}, call("action_send_mail")) 19 | 20 | end 21 | 22 | 23 | function sdcard_present() 24 | return (os.execute("mount |grep mmcblk0") == 0) 25 | end 26 | 27 | 28 | function action_sdcard_status() 29 | local sd_status = "detecting..." 30 | if( sdcard_present() == true ) then 31 | sd_status = util.exec("df -h /dev/mmcblk0|awk '/mmc/ {print $4}'") 32 | end 33 | luci.http.prepare_content("application/json") 34 | luci.http.write_json({ sdstring = sd_status }) 35 | 36 | end 37 | 38 | 39 | function action_sdcard_format_f2fs() 40 | if( sdcard_present() == true ) then 41 | os.execute("echo dd if=/dev/zero of=/dev/mmcblk0 bs=4M count=1 ; mkfs.f2fs -l IPCam /dev/mmcblk0") 42 | luci.http.status(200, "Formated") 43 | end 44 | end 45 | 46 | function action_sdcard_format_vfat() 47 | if( sdcard_present() == true ) then 48 | os.execute("echo dd if=/dev/zero of=/dev/mmcblk0 bs=4M count=1 ; mkfs.vfat -v -n IPCam /dev/mmcblk0") 49 | luci.http.status(200, "Formated") 50 | end 51 | end 52 | 53 | 54 | function create_temp_file(from, rcpt, subject) 55 | local jiji = os.tmpname() 56 | local f = io.open(jiji, "w+") 57 | 58 | f:write("From: "..from.."\nTo: "..rcpt.."\nSubject: "..subject.."\n\n Hello from IPCam!\n") 59 | f:close() 60 | return jiji 61 | end 62 | 63 | 64 | function action_send_mail() 65 | local server = (luci.http.formvalue("server")) 66 | local sender = (luci.http.formvalue("sender")) 67 | local password = (luci.http.formvalue("password")) 68 | local rcpt = (luci.http.formvalue("rcpt")) 69 | local subject = (luci.http.formvalue("subject")) 70 | local port = tonumber(luci.http.formvalue("port")) 71 | local auth = (luci.http.formvalue("auth")) 72 | 73 | temp_file = create_temp_file(sender, rcpt, subject) 74 | if( auth == "true") then 75 | os.execute("curl --url \'"..server..":"..port.."\' --ssl-reqd --mail-from \'"..sender.."\' --mail-rcpt \'"..rcpt.."\' --upload-file "..temp_file.." --user \'"..sender..":"..password.."\' --insecure"); 76 | else 77 | os.execute("curl --url \'"..server..":"..port.."\' --ssl-reqd --mail-from \'"..sender.."\' --mail-rcpt \'"..rcpt.."\' --upload-file "..temp_file.." --insecure"); 78 | end 79 | os.execute("rm "..temp_file.."") 80 | 81 | end 82 | -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/LIP.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Copyright (c) 2012 Carreras Nicolas 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | --]] 22 | --- Lua INI Parser. 23 | -- It has never been that simple to use INI files with Lua. 24 | --@author Dynodzzo 25 | 26 | local LIP = {}; 27 | 28 | --- Returns a table containing all the data from the INI file. 29 | --@param fileName The name of the INI file to parse. [string] 30 | --@return The table containing all data from the INI file. [table] 31 | function LIP.load(fileName) 32 | assert(type(fileName) == 'string', 'Parameter "fileName" must be a string.'); 33 | local file = assert(io.open(fileName, 'r'), 'Error loading file : ' .. fileName); 34 | local data = {}; 35 | local section; 36 | for line in file:lines() do 37 | local tempSection = line:match('^%[([^%[%]]+)%]$'); 38 | if(tempSection)then 39 | section = tonumber(tempSection) and tonumber(tempSection) or tempSection; 40 | data[section] = data[section] or {}; 41 | end 42 | line = line:gsub("^[;]", "", 1) 43 | local param, value = line:match('^([%w|_]+)%s-=%s-(.+)$'); 44 | if(param and value ~= nil)then 45 | if(tonumber(value))then 46 | value = tonumber(value); 47 | elseif(value == 'true')then 48 | value = true; 49 | elseif(value == 'false')then 50 | value = false; 51 | end 52 | if(tonumber(param))then 53 | param = tonumber(param); 54 | end 55 | data[section][param] = value; 56 | end 57 | end 58 | file:close(); 59 | return data; 60 | end 61 | 62 | --- Saves all the data from a table to an INI file. 63 | --@param fileName The name of the INI file to fill. [string] 64 | --@param data The table containing all the data to store. [table] 65 | function LIP.save(fileName, data) 66 | assert(type(fileName) == 'string', 'Parameter "fileName" must be a string.'); 67 | assert(type(data) == 'table', 'Parameter "data" must be a table.'); 68 | local file = assert(io.open(fileName, 'w+b'), 'Error loading file :' .. fileName); 69 | local contents = ''; 70 | for section, param in pairs(data) do 71 | contents = contents .. ('[%s]\n'):format(section); 72 | for key, value in pairs(param) do 73 | contents = contents .. ('%s=%s\n'):format(key, tostring(value)); 74 | end 75 | contents = contents .. '\n'; 76 | end 77 | file:write(contents); 78 | file:close(); 79 | end 80 | 81 | return LIP; -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/view/admin_ipcam/range.htm: -------------------------------------------------------------------------------- 1 | <%+cbi/valueheader%> 2 | 97 | 98 | > 99 | 0 100 | 101 | 102 | 123 | 124 | <%+cbi/valuefooter%> 125 | -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/view/admin_ipcam/service.htm: -------------------------------------------------------------------------------- 1 | <% 2 | local util = require "luci.util" 3 | local ntm = require "luci.model.network".init() 4 | local LIP = require 'luci.LIP' 5 | local wan = ntm:get_wannet() 6 | 7 | local ps = luci.util.exec("/bin/busybox pgrep majestic") 8 | local pstext 9 | if ps == "" then 10 | pstext = "/usr/bin/majestic not running" 11 | else 12 | pstext = "/usr/bin/majestic running as pid "..ps 13 | end 14 | 15 | if wan then 16 | host_ipaddr = wan:ipaddr() 17 | end 18 | 19 | tbl = LIP.load('/etc/majestic.yaml') 20 | host_webport = tbl['system']['web_port'] 21 | host_rtspport = tbl['rtsp']['port'] 22 | 23 | ns = luci.util.exec("netstat -p |grep majestic | tr ':' ' ' | awk -F ' ' '{print $5,$6}'") 24 | nstbl = {} 25 | nstbl_i = 1 26 | for line in ns:gmatch '[^\n]+' do 27 | fstbl = {} 28 | fstbl_i = 1 29 | for fs in line:gmatch '%S+' do 30 | fstbl[fstbl_i] = fs 31 | fstbl_i = fstbl_i + 1 32 | end 33 | nstbl[nstbl_i] = {clientip = fstbl[2], port = fstbl[1]} 34 | nstbl_i = nstbl_i + 1 35 | end 36 | 37 | %> 38 | 39 | <%+header%> 40 | 41 | Majestic Service 42 | 43 | 44 | Service Status 45 | This shows you the status of the Majestic service and provides control over starting, stopping, restarting the service. 46 | 47 | 48 | Process 49 | Control 50 | 51 | 52 | <%=pstext%> 53 | 54 | "> 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | Access URL's 67 | You access Majestic's services via the URLs provided below. 68 | 69 | MJPEG & MP3 streamhttp://<%=host_ipaddr%>:<%=host_webport%> 70 | JPEGhttp://<%=host_ipaddr%>:<%=host_webport%>/image.jpg 71 | JPEG Optionshttp://<%=host_ipaddr%>:<%=host_webport%>/image.jpg?width=640&height=360&qfactor=73&color2gray=1 72 | RAW (only for 16cv300/16ev100 and better processor)http://<%=host_ipaddr%>:<%=host_webport%>/image.dng 73 | MJPEG Embeddedhttp://<%=host_ipaddr%>:<%=host_webport%>/mjpeg.html 74 | H264 Embeddedhttp://<%=host_ipaddr%>:<%=host_webport%>/video.html 75 | MJPEGhttp://<%=host_ipaddr%>:<%=host_webport%>/mjpeg 76 | H264http://<%=host_ipaddr%>:<%=host_webport%>/video.mp4 77 | MP3http://<%=host_ipaddr%>:<%=host_webport%>/stream.mp3 78 | 79 | RTSP Demortsp://<%=host_ipaddr%>:<%=host_rtspport%>/demo 80 | RTSP Stream 9rtsp://<%=host_ipaddr%>:<%=host_rtspport%>/stream=0 81 | RTSP Stream 1rtsp://<%=host_ipaddr%>:<%=host_rtspport%>/stream=1 82 | 83 | 84 | 85 | 86 | Activate Connections 87 | This shows active clients connected to Majestic. 88 | 89 | 90 | 91 | Service/Port 92 | Client IP 93 | 94 | <% for index, data in pairs(nstbl) do %> 95 | 96 | <% for value, value2 in pairs(data) do %> 97 | 98 | <%=value2%> 99 | 100 | <% end %> 101 | <% end %> 102 | 103 | 104 | 105 | 106 | <%+footer%> -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/controller/admin/filebrowser2.lua: -------------------------------------------------------------------------------- 1 | module("luci.controller.admin.filebrowser2", package.seeall) 2 | 3 | local root_path = "/mnt" 4 | 5 | function index() 6 | 7 | page = entry({"admin", "ipcam", "filebrowser"}, template("admin_ipcam/filebrowser"), _("File Browser"), 1) 8 | page.i18n = "base" 9 | page.dependent = true 10 | 11 | page = entry({"admin", "ipcam", "filebrowser_list"}, call("filebrowser_list"), nil) 12 | page.leaf = true 13 | 14 | page = entry({"admin", "ipcam", "filebrowser_open"}, call("filebrowser_open"), nil) 15 | page.leaf = true 16 | 17 | page = entry({"admin", "ipcam", "filebrowser_delete"}, call("filebrowser_delete"), nil) 18 | page.leaf = true 19 | 20 | page = entry({"admin", "ipcam", "filebrowser_rename"}, call("filebrowser_rename"), nil) 21 | page.leaf = true 22 | 23 | page = entry({"admin", "ipcam", "filebrowser_upload"}, call("filebrowser_upload"), nil) 24 | page.leaf = true 25 | 26 | end 27 | 28 | function filebrowser_list() 29 | local rv = { } 30 | local path = root_path..luci.http.formvalue("path"):gsub("%.%.", "") 31 | 32 | rv = scandir(path) 33 | 34 | if #rv > 0 then 35 | luci.http.prepare_content("application/json") 36 | luci.http.write_json(rv) 37 | return 38 | end 39 | 40 | end 41 | 42 | function filebrowser_open(file, filename) 43 | filename = filename:gsub("%.%.", "") 44 | file = root_path..file:gsub("%.%.", ""):gsub("<>", "/") 45 | 46 | local io = require "io" 47 | local mime = to_mime(filename) 48 | 49 | local download_fpi = io.open(file, "r") 50 | luci.http.header('Content-Disposition', 'inline; filename="'..filename..'"' ) 51 | luci.http.prepare_content(mime or "application/octet-stream") 52 | luci.ltn12.pump.all(luci.ltn12.source.file(download_fpi), luci.http.write) 53 | end 54 | 55 | function filebrowser_delete() 56 | local path = root_path..luci.http.formvalue("path"):gsub("%.%.", "") 57 | local isdir = luci.http.formvalue("isdir") 58 | path = path:gsub("<>", "/") 59 | path = path:gsub(" ", "\ ") 60 | if isdir then 61 | local success = os.execute('rm -r "'..path..'"') 62 | else 63 | local success = os.remove(path) 64 | end 65 | return success 66 | end 67 | 68 | function filebrowser_rename() 69 | local filepath = root_path..luci.http.formvalue("filepath"):gsub("%.%.", "") 70 | local newpath = root_path..luci.http.formvalue("newpath"):gsub("%.%.", "") 71 | local success = os.execute('mv "'..filepath..'" "'..newpath..'"') 72 | return success 73 | end 74 | 75 | function filebrowser_upload() 76 | local filecontent = luci.http.formvalue("upload-file") 77 | local filename = luci.http.formvalue("upload-filename") 78 | local uploaddir = root_path..luci.http.formvalue("upload-dir"):gsub("%.%.", "") 79 | local filepath = uploaddir..filename 80 | local url = luci.dispatcher.build_url('admin', 'ipcam', 'filebrowser') 81 | 82 | --[[ 83 | local fp 84 | fp = io.open(filepath, "w") 85 | fp:write(filecontent) 86 | fp:close() 87 | ]] 88 | 89 | luci.http.redirect(url..'?path='..luci.http.formvalue("upload-dir")) 90 | 91 | --[[luci.http.setfilehandler( 92 | function(meta, chunk, eof) 93 | uci.http.write('open '..filepath) 94 | if not fp then 95 | if meta and meta.name == 'upload-file' then 96 | --luci.http.write('open file '..filepath) 97 | fp = io.open(filepath, "w") 98 | end 99 | end 100 | if fp and chunk then 101 | --luci.http.write(chunk) 102 | fp:write(chunk) 103 | end 104 | if fp and eof then 105 | --luci.http.write('close') 106 | fp:close() 107 | luci.http.redirect(url..'?path='..uploaddir) 108 | end 109 | end 110 | )]]-- 111 | end 112 | 113 | function scandir(directory) 114 | local i, t, popen = 0, {}, io.popen 115 | 116 | local ls_cmd = "ls -l \""..directory.."\" | egrep '^d' ; ls -lh \""..directory.."\" | egrep -v '^d'" 117 | 118 | local pfile = popen(ls_cmd) 119 | for filename in pfile:lines() do 120 | i = i + 1 121 | t[i] = filename 122 | end 123 | pfile:close() 124 | return t 125 | end 126 | 127 | MIME_TYPES = { 128 | ["txt"] = "text/plain"; 129 | ["js"] = "text/javascript"; 130 | ["css"] = "text/css"; 131 | ["htm"] = "text/html"; 132 | ["html"] = "text/html"; 133 | ["patch"] = "text/x-patch"; 134 | ["c"] = "text/x-csrc"; 135 | ["h"] = "text/x-chdr"; 136 | ["o"] = "text/x-object"; 137 | ["ko"] = "text/x-object"; 138 | 139 | ["bmp"] = "image/bmp"; 140 | ["gif"] = "image/gif"; 141 | ["png"] = "image/png"; 142 | ["jpg"] = "image/jpeg"; 143 | ["jpeg"] = "image/jpeg"; 144 | ["svg"] = "image/svg+xml"; 145 | 146 | ["zip"] = "application/zip"; 147 | ["pdf"] = "application/pdf"; 148 | ["xml"] = "application/xml"; 149 | ["xsl"] = "application/xml"; 150 | ["doc"] = "application/msword"; 151 | ["ppt"] = "application/vnd.ms-powerpoint"; 152 | ["xls"] = "application/vnd.ms-excel"; 153 | ["odt"] = "application/vnd.oasis.opendocument.text"; 154 | ["odp"] = "application/vnd.oasis.opendocument.presentation"; 155 | ["pl"] = "application/x-perl"; 156 | ["sh"] = "application/x-shellscript"; 157 | ["php"] = "application/x-php"; 158 | ["deb"] = "application/x-deb"; 159 | ["iso"] = "application/x-cd-image"; 160 | ["tgz"] = "application/x-compressed-tar"; 161 | 162 | ["mp3"] = "audio/mpeg"; 163 | ["ogg"] = "audio/x-vorbis+ogg"; 164 | ["wav"] = "audio/x-wav"; 165 | 166 | ["mpg"] = "video/mpeg"; 167 | ["mpeg"] = "video/mpeg"; 168 | ["avi"] = "video/x-msvideo"; 169 | } 170 | 171 | function to_mime(filename) 172 | if type(filename) == "string" then 173 | local ext = filename:match("[^%.]+$") 174 | 175 | if ext and MIME_TYPES[ext:lower()] then 176 | return MIME_TYPES[ext:lower()] 177 | end 178 | end 179 | 180 | return "application/octet-stream" 181 | end 182 | -------------------------------------------------------------------------------- /utils/xmdp/src/xmdp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "cjson/cJSON.h" 15 | #include "netip.h" 16 | #include "utils.h" 17 | 18 | #define SERVERPORT 34569 19 | // send broadcast packets periodically 20 | #define TIMEOUT 5 // seconds 21 | 22 | #define MIN(x, y) ((x) < (y) ? (x) : (y)) 23 | 24 | const char brpkt[] = 25 | "\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfa\x05" 26 | "\x00\x00\x00\x00"; 27 | static const char *Reset = "\x1b[0m"; 28 | static const char *FgRed = "\x1b[31m"; 29 | 30 | // get sockaddr, IPv4 or IPv6: 31 | void *get_in_addr(struct sockaddr *sa) { 32 | if (sa->sa_family == AF_INET) { 33 | return &(((struct sockaddr_in *)sa)->sin_addr); 34 | } 35 | 36 | return &(((struct sockaddr_in6 *)sa)->sin6_addr); 37 | } 38 | 39 | int ipaddr_from32bit(char *dst, size_t dlen, const char *coded) { 40 | if (strlen(coded) != 10) 41 | return -1; 42 | 43 | unsigned char octet[4]; 44 | char cnvt[5] = "0x01"; 45 | for (int i = 0; i < sizeof(octet); i++) { 46 | cnvt[2] = coded[i * 2 + 2]; 47 | cnvt[3] = coded[i * 2 + 3]; 48 | sscanf(cnvt, "%hhx", &octet[i]); 49 | } 50 | 51 | snprintf(dst, dlen, "%d.%d.%d.%d", octet[3], octet[2], octet[1], octet[0]); 52 | 53 | return 0; 54 | } 55 | 56 | int bsock; 57 | 58 | void send_netip_broadcast() { 59 | struct sockaddr_in sa; 60 | memset(sa.sin_zero, '\0', sizeof sa.sin_zero); 61 | 62 | sa.sin_family = AF_INET; 63 | sa.sin_addr.s_addr = 0xffffffff; 64 | sa.sin_port = htons(SERVERPORT); 65 | 66 | int rcvbts; 67 | if ((rcvbts = sendto(bsock, brpkt, sizeof(brpkt) - 1, 0, 68 | (struct sockaddr *)&sa, sizeof(struct sockaddr_in))) == 69 | -1) { 70 | perror("sendto"); 71 | exit(1); 72 | } 73 | } 74 | 75 | void sigalarm(int sig) { 76 | if (sig == SIGALRM) { 77 | send_netip_broadcast(); 78 | alarm(TIMEOUT); 79 | } 80 | } 81 | 82 | int main() { 83 | bsock = socket(AF_INET, SOCK_DGRAM, 0); 84 | if (bsock == -1) { 85 | perror("socket"); 86 | exit(1); 87 | } 88 | 89 | struct sockaddr_in name; 90 | name.sin_family = AF_INET; 91 | name.sin_port = htons(SERVERPORT); 92 | name.sin_addr.s_addr = htonl(INADDR_ANY); 93 | if (bind(bsock, (struct sockaddr *)&name, sizeof(name)) < 0) { 94 | perror("bind"); 95 | exit(EXIT_FAILURE); 96 | } 97 | 98 | // this call is what allows broadcast packets to be sent: 99 | int broadcast = 1; 100 | if (setsockopt(bsock, SOL_SOCKET, SO_BROADCAST, &broadcast, 101 | sizeof broadcast) == -1) { 102 | perror("setsockopt (SO_BROADCAST)"); 103 | exit(1); 104 | } 105 | 106 | send_netip_broadcast(); 107 | 108 | printf("Searching for XM cameras... Abort with CTRL+C.\n\n" 109 | "IP\t\tMAC-Address\t\tIdentity\n"); 110 | 111 | signal(SIGALRM, sigalarm); 112 | alarm(TIMEOUT); 113 | 114 | size_t seen_len = 0; 115 | size_t seen_cap = 1; 116 | uint32_t *seen_vec = malloc(seen_cap * sizeof(*seen_vec)); 117 | 118 | while (1) { 119 | char buf[1024]; 120 | struct sockaddr_in their_addr; 121 | socklen_t addr_len = sizeof their_addr; 122 | int rcvbts; 123 | if ((rcvbts = recvfrom(bsock, buf, sizeof buf - 1, 0, 124 | (struct sockaddr *)&their_addr, &addr_len)) == -1) { 125 | perror("recvfrom"); 126 | exit(1); 127 | } 128 | if (rcvbts <= sizeof brpkt) 129 | continue; 130 | 131 | buf[rcvbts] = '\0'; 132 | 133 | cJSON *json = cJSON_Parse(buf + 20); 134 | if (!json) { 135 | const char *error_ptr = cJSON_GetErrorPtr(); 136 | if (error_ptr != NULL) { 137 | fprintf(stderr, "Error before: %s\n", error_ptr); 138 | } 139 | goto skip_loop; 140 | } 141 | #if 0 142 | char *str = cJSON_Print(json); 143 | if (str) { 144 | puts(str); 145 | } 146 | free(str); 147 | #endif 148 | 149 | const cJSON *netcommon = 150 | cJSON_GetObjectItemCaseSensitive(json, "NetWork.NetCommon"); 151 | const char *hostname = get_json_strval(netcommon, "HostName", ""); 152 | const char *mac = get_json_strval(netcommon, "MAC", ""); 153 | const char *host_ip = get_json_strval(netcommon, "HostIP", ""); 154 | const int netip_port = get_json_intval(netcommon, "TCPPort", 0); 155 | const int chan_num = get_json_intval(netcommon, "ChannelNum", 0); 156 | const char *sn = get_json_strval(netcommon, "SN", ""); 157 | const char *version = get_json_strval(netcommon, "Version", ""); 158 | const char *builddt = get_json_strval(netcommon, "BuildDate", ""); 159 | 160 | uint32_t numipv4; 161 | if (sscanf(host_ip, "0x%x", &numipv4) == 1) { 162 | // find occurence 163 | for (int i = 0; i < seen_len; i++) 164 | if (seen_vec[i] == numipv4) 165 | goto skip_loop; 166 | if (seen_len == seen_cap) { 167 | seen_cap *= 2; 168 | seen_vec = realloc(seen_vec, seen_cap * sizeof(*seen_vec)); 169 | } 170 | seen_vec[seen_len++] = numipv4; 171 | } 172 | 173 | char abuf[50] = {0}; 174 | if (strlen(host_ip)) { 175 | ipaddr_from32bit(abuf, sizeof abuf, host_ip); 176 | host_ip = abuf; 177 | } 178 | bool netip_ok = netip_connect(host_ip, netip_port); 179 | 180 | char verstr[128] = {0}; 181 | if (strlen(version)) { 182 | int n_dot = 0, i = 0; 183 | while (*version) { 184 | if (*version == '.') { 185 | n_dot++; 186 | if (n_dot == 4) 187 | break; 188 | } else if (n_dot == 3) { 189 | verstr[i++] = *version; 190 | } 191 | version++; 192 | } 193 | 194 | if (strlen(builddt)) { 195 | const char *end; 196 | if ((end = strchr(builddt, ' '))) { 197 | strcat(verstr + strlen(verstr), " ("); 198 | snprintf(verstr + strlen(verstr), 199 | MIN(sizeof(verstr) - strlen(verstr), end - builddt + 1), 200 | "%s", builddt); 201 | strcat(verstr + strlen(verstr), ")"); 202 | } 203 | } 204 | } 205 | 206 | printf("%s%s\t%s\t%s %s, %s", netip_ok ? FgRed : "", host_ip, mac, 207 | chan_num > 1 ? "DVR" : "IPC", sn, hostname); 208 | if (strlen(verstr)) 209 | printf("\t%s", verstr); 210 | printf("%s\n", netip_ok ? Reset : ""); 211 | 212 | skip_loop: 213 | 214 | cJSON_Delete(json); 215 | } 216 | 217 | free(seen_vec); 218 | } 219 | -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/view/admin_ipcam/filebrowser.htm: -------------------------------------------------------------------------------- 1 | <%+header%> 2 | 3 | 150 | 151 | 208 | 209 | File browser 210 | 211 | 212 | Files list: 213 | 214 | 215 | 227 | <%+footer%> 228 | -------------------------------------------------------------------------------- /utils/hisi_gpio_scanner/src/hisi_gpio_scanner.c.bak: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | typedef struct tag_MMAP_Node { 10 | unsigned int Start_P; 11 | unsigned int Start_V; 12 | unsigned int length; 13 | unsigned int refcount; 14 | struct tag_MMAP_Node *next; 15 | } TMMAP_Node_t; 16 | 17 | TMMAP_Node_t *pTMMAPNode = NULL; 18 | #define PAGE_SIZE 0x1000 19 | #define PAGE_SIZE_MASK 0xfffff000 20 | 21 | static int fd = -1; 22 | static const char dev[] = "/dev/mem"; 23 | jmp_buf *sigbus_jmp; 24 | 25 | //************************************************************ 26 | void *memmap(unsigned long phy_addr, unsigned long size) { 27 | unsigned long phy_addr_in_page; 28 | unsigned long page_diff; 29 | unsigned long size_in_page; 30 | unsigned long value = 0; 31 | TMMAP_Node_t *pTmp; 32 | TMMAP_Node_t *pNew; 33 | void *addr = NULL; 34 | if (size == 0) { 35 | printf("memmap():size can't be zero!\n"); 36 | return NULL; 37 | } 38 | /* проверить, было ли преобразовано пространство физической памяти */ 39 | pTmp = pTMMAPNode; 40 | while (pTmp != NULL) { 41 | if ((phy_addr >= pTmp->Start_P) && 42 | ((phy_addr + size) <= (pTmp->Start_P + pTmp->length))) { 43 | pTmp->refcount++; /* referrence count increase by 1 */ 44 | return (void *)(pTmp->Start_V + phy_addr - pTmp->Start_P); 45 | } 46 | pTmp = pTmp->next; 47 | } 48 | /* not mmaped yet */ 49 | if (fd < 0) { 50 | /* dev not opened yet, so open it */ 51 | fd = open(dev, O_RDWR | O_SYNC); 52 | if (fd < 0) { 53 | printf("memmap():open %s error!\n", dev); 54 | return NULL; 55 | } 56 | } 57 | /* addr align in page_size(4K) */ 58 | phy_addr_in_page = phy_addr & PAGE_SIZE_MASK; 59 | page_diff = phy_addr - phy_addr_in_page; 60 | /* size in page_size */ 61 | size_in_page = ((size + page_diff - 1) & PAGE_SIZE_MASK) + PAGE_SIZE; 62 | addr = mmap((void *)0, size_in_page, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 63 | phy_addr_in_page); 64 | if (addr == MAP_FAILED) { 65 | printf("memmap():mmap @ 0x%lx error!\n", phy_addr_in_page); 66 | return NULL; 67 | } 68 | /* add this mmap to MMAP Node */ 69 | pNew = (TMMAP_Node_t *)malloc(sizeof(TMMAP_Node_t)); 70 | if (NULL == pNew) { 71 | printf("memmap():malloc new node failed!\n"); 72 | return NULL; 73 | } 74 | pNew->Start_P = phy_addr_in_page; 75 | pNew->Start_V = (unsigned long)addr; 76 | pNew->length = size_in_page; 77 | pNew->refcount = 1; 78 | pNew->next = NULL; 79 | if (pTMMAPNode == NULL) { 80 | pTMMAPNode = pNew; 81 | } else { 82 | pTmp = pTMMAPNode; 83 | while (pTmp->next != NULL) { 84 | pTmp = pTmp->next; 85 | } 86 | pTmp->next = pNew; 87 | } 88 | return (void *)(addr + page_diff); 89 | } 90 | 91 | #define DEFAULT_MD_LEN 256 92 | //************************************************************ 93 | unsigned long GetValueRegister(unsigned long adress) { 94 | void *pMem = NULL; 95 | unsigned long value = -1; 96 | jmp_buf sigbus_jmpbuf; 97 | sigbus_jmp = &sigbus_jmpbuf; 98 | if (sigsetjmp(sigbus_jmpbuf, 1) == 0) { 99 | pMem = memmap(adress, DEFAULT_MD_LEN); 100 | if (pMem == NULL) { 101 | printf("memmap failed!\n"); 102 | return -1; 103 | } 104 | value = *(unsigned int *)pMem; //читаем региср 105 | } 106 | return value; 107 | } 108 | 109 | //************************************************************ 110 | int SetValueRegister(unsigned long adress, unsigned long value) { 111 | void *pMem = NULL; 112 | pMem = memmap(adress, DEFAULT_MD_LEN); 113 | if (pMem == NULL) { 114 | printf("memmap failed!\n"); 115 | return -1; 116 | } 117 | *(unsigned int *)pMem = value; //пишем в регистр 118 | return 0; 119 | } 120 | 121 | //************************************************************ 122 | void print_bin(unsigned long data) { 123 | int i; 124 | unsigned long ulbit; 125 | for (i = 7; i >= 0; i--) { 126 | ulbit = data >> i; 127 | if (ulbit & 1) 128 | printf("1"); 129 | else 130 | printf("0"); 131 | } 132 | } 133 | 134 | //************************************************************ 135 | void get_gpio_adress(unsigned long *Chip_Id, unsigned long *GPIO_Groups, 136 | unsigned long *GPIO_Base, unsigned long *GPIO_Offset) { 137 | switch (*Chip_Id) { 138 | //------------------------------------------- 139 | // Hi3516Av100 A7 @600 MHz 140 | case 0x3516A100: 141 | *GPIO_Groups = 17; //пропустить G15 142 | *GPIO_Base = 0x20140000; 143 | *GPIO_Offset = 0x10000; 144 | break; 145 | //------------------------------------------- 146 | // Hi3516Cv100 ARM926 @440 MHz 147 | case 0x3516C100: 148 | *GPIO_Groups = 12; 149 | *GPIO_Base = 0x20140000; 150 | *GPIO_Offset = 0x10000; 151 | break; 152 | //------------------------------------------- 153 | // Hi3516Cv200 ARM926 @540 MHz 154 | case 0x3516C200: 155 | *GPIO_Groups = 9; 156 | *GPIO_Base = 0x20140000; 157 | *GPIO_Offset = 0x10000; 158 | break; 159 | //------------------------------------------- 160 | // Hi3516Cv300 ARM926 @800 161 | case 0x3516C300: 162 | *GPIO_Groups = 9; 163 | *GPIO_Base = 0x12140000; 164 | *GPIO_Offset = 0x1000; 165 | break; 166 | //------------------------------------------- 167 | // Hi3516Dv100 A7 @600 MHz 168 | case 0x3516D100: 169 | *GPIO_Groups = 15; 170 | *GPIO_Base = 0x20140000; 171 | *GPIO_Offset = 0x10000; 172 | break; 173 | //------------------------------------------- 174 | // Hi3516Ev200 A7 @900MHz 175 | case 0x3516E200: 176 | *GPIO_Groups = 9; 177 | *GPIO_Base = 0x120B0000; 178 | *GPIO_Offset = 0x1000; 179 | break; 180 | //------------------------------------------- 181 | // Hi3516Ev300 A7 @900MHz 182 | case 0x3516E300: 183 | *GPIO_Groups = 10; 184 | *GPIO_Base = 0x120B0000; 185 | *GPIO_Offset = 0x1000; 186 | break; 187 | //------------------------------------------- 188 | // Hi3518Ev100 ARM926 @440 MHz 189 | case 0x35180100: 190 | *GPIO_Groups = 12; 191 | *GPIO_Base = 0x20140000; 192 | *GPIO_Offset = 0x10000; 193 | break; 194 | //------------------------------------------- 195 | // Hi3518Ev200 ARM926 @540 MHz 196 | case 0x3518E200: 197 | *GPIO_Groups = 9; 198 | *GPIO_Base = 0x20140000; 199 | *GPIO_Offset = 0x10000; 200 | break; 201 | //------------------------------------------- 202 | // Hi3518Ev201 ARM926 @540 MHz 203 | case 0x3518E201: 204 | *GPIO_Groups = 9; 205 | *GPIO_Base = 0x20140000; 206 | *GPIO_Offset = 0x10000; 207 | break; 208 | //------------------------------------------- 209 | default: 210 | *GPIO_Groups = 0; 211 | *GPIO_Base = 0; 212 | *GPIO_Offset = 0; 213 | break; 214 | //--------------------------------- 215 | } 216 | } 217 | //************************************************************ 218 | int main() { 219 | unsigned long Chip_Id; 220 | unsigned long GPIO_Groups, GPIO_Base, GPIO_Offset; 221 | unsigned long address = 0; 222 | unsigned long direct = 0; 223 | unsigned long value = 0; 224 | unsigned long OldValue[20]; 225 | int bit, old_bit, new_bit; 226 | int i, group, mask; 227 | //--------------------------------------------------------------- 228 | Chip_Id = 0x3516E200; 229 | printf("========== Hisilicon GPIO Scaner (2020) Andrew_kmr - OpenIPC.org " 230 | "collective ==========\n"); 231 | printf("Chip_Id: 0x%08lX\n", Chip_Id); 232 | printf("---------------------------------------------------------------------" 233 | "-----------------\n"); 234 | get_gpio_adress(&Chip_Id, &GPIO_Groups, &GPIO_Base, &GPIO_Offset); 235 | if (GPIO_Base == 0) { 236 | printf("This CPU is not supported!\n"); 237 | return 0; 238 | } 239 | for (group = 0; group < GPIO_Groups; group++) { 240 | address = GPIO_Base + (group * GPIO_Offset) + 0x3fc; //регистр данных портов 241 | value = GetValueRegister(address); //регистр данных портов 242 | OldValue[group] = value; //запоминаем в массив значение 243 | printf("Gr:%2d, Addr:0x%08lX, Data:0x%02lX = 0b", group, address, value); 244 | print_bin(value); //выводим бинарный вид 245 | address = 246 | GPIO_Base + (group * GPIO_Offset) + 0x400; //регистр направления портов 247 | direct = GetValueRegister(address); 248 | printf(", Addr:0x%08lX, Dir:0x%02lX = 0b", address, direct); 249 | print_bin(direct); 250 | printf("\n"); 251 | } 252 | printf("While change value...\n"); 253 | while (1) { 254 | for (group = 0; group < GPIO_Groups; group++) { 255 | address = 256 | GPIO_Base + (group * GPIO_Offset) + 0x3fc; //регистр данных портов 257 | value = GetValueRegister(address); 258 | if (OldValue[group] != value) //старый и новый байты не равны 259 | { 260 | printf("---------------------------------------------------------------" 261 | "-----------------------\n"); 262 | printf("Gr:%d, Addr:0x%08lX, Data:0x%02lX = 0b", group, address, 263 | OldValue[group]); 264 | print_bin(OldValue[group]); 265 | printf(" --> 0x%02lX = 0b", value); 266 | print_bin(value); 267 | printf("\n"); 268 | for (bit = 7; bit >= 0; bit--) //цикл побитного сравнения 269 | { 270 | old_bit = (OldValue[group] >> bit) & 1; 271 | new_bit = (value >> bit) & 1; 272 | if (old_bit != new_bit) { 273 | address = GPIO_Base + (group * GPIO_Offset) + 274 | 0x400; //регистр направления портов 275 | direct = GetValueRegister(address); 276 | direct = (direct >> bit) & 277 | 1; //получили бит направления порта 0-вход 1-выход 278 | address = GPIO_Base + (group * GPIO_Offset) + (1 << (bit + 2)); 279 | if (direct == 1) { 280 | mask = value & 1 << bit; 281 | printf("Mask: \"himm 0x%08lX 0x%02X\", GPIO%d_%d, GPIO%d, " 282 | "Dir:Output, Level:%d\n", 283 | address, mask, group, bit, (group * 8) + bit, new_bit); 284 | } else { 285 | mask = value & 1 << bit; 286 | printf("Mask: \"himm 0x%08lX 0x%02X\", GPIO%d_%d, GPIO%d, " 287 | "Dir:Input, Level:%d\n", 288 | address, mask, group, bit, (group * 8) + bit, new_bit); 289 | } 290 | } 291 | } 292 | OldValue[group] = value; //запоминаем новое значение 293 | } 294 | } 295 | usleep(100000); 296 | } 297 | return 0; 298 | } 299 | -------------------------------------------------------------------------------- /utils/hisi_gpio_watcher/src/hisi_gpio_watcher.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #define SYSFS_GPIO_DIR "/sys/class/gpio" 11 | #define MAX_BUF 64 12 | 13 | //#define DEBUG_ENABLE 0 //debug 1 14 | 15 | #define DEFAULT_MD_LEN 128 16 | #define PAGE_SIZE 0x1000 17 | #define PAGE_SIZE_MASK (~(0xfff)) 18 | 19 | int debug; 20 | 21 | typedef struct tag_MMAP_Node 22 | { 23 | unsigned long Start_P; 24 | unsigned long Start_V; 25 | unsigned long length; 26 | unsigned long refcount; 27 | struct tag_MMAP_Node * next; 28 | }TMMAP_Node_t; 29 | 30 | TMMAP_Node_t * pTMMAPNode = NULL; 31 | int fd = -1; 32 | const char dev[]="/dev/mem"; 33 | jmp_buf *sigbus_jmp; // global 34 | 35 | /**************************************************************** 36 | * signal_handler 37 | ****************************************************************/ 38 | void signal_handler (int sig) 39 | { 40 | if (sig == SIGBUS) 41 | { 42 | //printf("signal_handler SIGBUS!\n"); 43 | if(sigbus_jmp) siglongjmp(*sigbus_jmp, 1); 44 | // no one to catch the error, so abort 45 | abort(); 46 | } 47 | } 48 | /**************************************************************** 49 | * set_handle 50 | ****************************************************************/ 51 | int set_handler() 52 | { 53 | struct sigaction act; 54 | memset (&act, 0, sizeof(act)); 55 | act.sa_sigaction = (void *)signal_handler; 56 | act.sa_flags = SA_SIGINFO; 57 | if (sigaction(SIGBUS, &act, 0)) 58 | { 59 | perror ("sigaction"); 60 | return -1; 61 | } 62 | return 0; 63 | } 64 | /**************************************************************** 65 | * memmap 66 | ****************************************************************/ 67 | void * memmap(unsigned long phy_addr, unsigned long size) 68 | { 69 | unsigned long phy_addr_in_page; 70 | unsigned long page_diff; 71 | unsigned long size_in_page; 72 | unsigned long value = 0; 73 | TMMAP_Node_t * pTmp; 74 | TMMAP_Node_t * pNew; 75 | void *addr=NULL; 76 | if(size == 0) 77 | { 78 | printf("memmap():size can't be zero!\n"); 79 | return NULL; 80 | } 81 | /* check if the physical memory space have been mmaped */ 82 | pTmp = pTMMAPNode; 83 | while(pTmp != NULL) 84 | { 85 | if( (phy_addr >= pTmp->Start_P) && ( (phy_addr + size) <= (pTmp->Start_P + pTmp->length) ) ) 86 | { 87 | pTmp->refcount++; /* referrence count increase by 1 */ 88 | return (void *)(pTmp->Start_V + phy_addr - pTmp->Start_P); 89 | } 90 | pTmp = pTmp->next; 91 | } 92 | /* not mmaped yet */ 93 | if(fd < 0) 94 | { 95 | /* dev not opened yet, so open it */ 96 | fd = open (dev, O_RDONLY); 97 | if(fd < 0) 98 | { 99 | printf("memmap():open %s error!\n", dev); 100 | return NULL; 101 | } 102 | } 103 | /* addr align in page_size(4K) */ 104 | phy_addr_in_page = phy_addr & PAGE_SIZE_MASK; 105 | page_diff = phy_addr - phy_addr_in_page; 106 | /* size in page_size */ 107 | size_in_page =((size + page_diff - 1) & PAGE_SIZE_MASK) + PAGE_SIZE; 108 | addr = mmap((void *)0, size_in_page, PROT_READ, MAP_SHARED, fd, phy_addr_in_page); 109 | if(addr == MAP_FAILED) 110 | { 111 | printf("memmap():mmap @ 0x%x error!\n", phy_addr_in_page); 112 | return NULL; 113 | } 114 | /* add this mmap to MMAP Node */ 115 | pNew = (TMMAP_Node_t *)malloc(sizeof(TMMAP_Node_t)); 116 | if(NULL == pNew) 117 | { 118 | printf("memmap():malloc new node failed!\n"); 119 | return NULL; 120 | } 121 | pNew->Start_P = phy_addr_in_page; 122 | pNew->Start_V = (unsigned long)addr; 123 | pNew->length = size_in_page; 124 | pNew->refcount = 1; 125 | pNew->next = NULL; 126 | if(pTMMAPNode == NULL) 127 | { 128 | pTMMAPNode = pNew; 129 | } 130 | else 131 | { 132 | pTmp = pTMMAPNode; 133 | while(pTmp->next != NULL) 134 | { 135 | pTmp = pTmp->next; 136 | } 137 | pTmp->next = pNew; 138 | } 139 | return (void *)(addr+page_diff); 140 | } 141 | /**************************************************************** 142 | * GetValueRegister 143 | ****************************************************************/ 144 | unsigned long GetValueRegister(unsigned long adress) 145 | { 146 | void *pMem = NULL; 147 | unsigned long value = -1; 148 | jmp_buf sigbus_jmpbuf; 149 | sigbus_jmp = &sigbus_jmpbuf; 150 | if(sigsetjmp(sigbus_jmpbuf, 1) == 0) 151 | { 152 | pMem = memmap(adress,DEFAULT_MD_LEN); 153 | if (pMem == NULL) 154 | { 155 | printf("memmap failed!\n"); 156 | return -1; 157 | } 158 | value = *(unsigned int*)pMem; 159 | } 160 | return value; 161 | } 162 | /**************************************************************** 163 | * parse_int 164 | ****************************************************************/ 165 | unsigned long parse_int (char *str) { 166 | long long result; 167 | char *endptr; 168 | 169 | result = strtoll(str, &endptr, 0); 170 | if (str == '\0' || *endptr != '\0') { 171 | fprintf(stderr, "\"%s\" is not a valid number\n", str); 172 | exit(EXIT_FAILURE); 173 | } 174 | 175 | return (unsigned long)result; 176 | } 177 | 178 | /**************************************************************** 179 | * gpio_get_value 180 | ****************************************************************/ 181 | int gpio_get_value(unsigned int gpio, unsigned long *value) 182 | { 183 | int fd, len; 184 | char buf[MAX_BUF]; 185 | char ch; 186 | 187 | len = snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio); 188 | 189 | fd = open(buf, O_RDONLY | O_NONBLOCK); 190 | if (fd < 0) { 191 | perror("gpio/get-value"); 192 | return fd; 193 | } 194 | 195 | read(fd, &ch, 1); 196 | 197 | if (ch != '0') { 198 | *value = 1; 199 | } else { 200 | *value = 0; 201 | } 202 | 203 | close(fd); 204 | return 0; 205 | } 206 | /**************************************************************** 207 | * gpio_get_dir 208 | ****************************************************************/ 209 | int gpio_get_dir(unsigned int gpio, unsigned long *value) 210 | { 211 | int fd, len, i; 212 | char buf[MAX_BUF]; 213 | char ch[5]; 214 | 215 | len = snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/direction", gpio); 216 | 217 | 218 | fd = open(buf, O_RDONLY | O_NONBLOCK); 219 | if (fd < 0) { 220 | perror("gpio/direction"); 221 | return fd; 222 | } 223 | i = read(fd, ch, 5); 224 | ch[i] = 0; 225 | 226 | 227 | if(!strncmp("in",ch,2)){*value = 0;} 228 | else if(!strncmp("out",ch,2)){*value = 1;} 229 | else {*value = -1;} 230 | 231 | close(fd); 232 | return 0; 233 | } 234 | /**************************************************************** 235 | * check_run 236 | ****************************************************************/ 237 | void check_run(unsigned char *runsh, int chkbit, int chkstat, int chkdirect) 238 | { 239 | if (chkbit==chkstat) 240 | { 241 | if(debug) 242 | { 243 | if (chkdirect==1) {printf("Direction: Output\n");} else {printf("Direction: Input\n");} 244 | printf("Check Level:%d Current Level:%d\n",chkstat,chkbit); 245 | printf("Run Script: %s\n", runsh);} 246 | system (runsh); 247 | 248 | } 249 | else if (chkstat==-1) 250 | { 251 | if(debug) 252 | { 253 | if (chkdirect==1) {printf("Direction: Output\n");} else {printf("Direction: Input\n");} 254 | printf("Check Level:%d Current Level:%d\n",chkstat,chkbit); 255 | printf("Run Script: %s\n", runsh);} 256 | system (runsh); 257 | 258 | } 259 | } 260 | /****************************************************************************** 261 | * show usage 262 | ******************************************************************************/ 263 | void show_sage(char *sPrgNm, int usgc) 264 | { 265 | const char gpiou[]="Usage : %s GPIO(gpioN) Status(on|off|both) 'Programm_run'.\n"; 266 | const char memu[]="Usage : %s GPIO_Base GPIO_Offset GPIO_Group GPIO_Bit Status(on|off|both) 'Programm_run'.\n"; 267 | 268 | switch (usgc) 269 | { 270 | case 1: 271 | printf(memu,sPrgNm); 272 | break; 273 | case 2: 274 | printf(gpiou,sPrgNm); 275 | break; 276 | default: 277 | printf(memu,sPrgNm); 278 | printf(gpiou,sPrgNm); 279 | exit(EXIT_FAILURE); 280 | } 281 | } 282 | 283 | //************************************************************ 284 | //************************************************************ 285 | //************************************************************ 286 | /**************************************************************** 287 | * main 288 | ****************************************************************/ 289 | int main(int argc, char *argv[]) 290 | { 291 | unsigned int gpio; 292 | int sfs = 0; 293 | char *stat = NULL; 294 | char *cmd = NULL; 295 | unsigned long GPIO_Base, GPIO_Offset; 296 | unsigned long adress = 0; 297 | unsigned long direct = 0; 298 | unsigned long value = 0; 299 | unsigned long OldValue= 0; 300 | int GPIO_Group, GPIO_Bit, old_bit, new_bit, status; 301 | 302 | if(set_handler()==-1) 303 | { 304 | printf("Set handler Error!\n"); 305 | return 0; 306 | } 307 | 308 | if ( (argc < 2)) 309 | { 310 | show_sage(argv[0], 0); 311 | exit(EXIT_FAILURE); 312 | } 313 | 314 | debug = (argv[0][strlen(argv[0])-1])- '0'; //debug ON 315 | if ((debug) == 1){ printf("Debug ON!\n"); } 316 | 317 | 318 | if ((sscanf (argv[1], "gpio%d", &gpio) == 1) || (!strncmp("gpio",argv[1],4))) 319 | { 320 | if (argc != 4) { 321 | show_sage(argv[0], 2); 322 | exit(EXIT_FAILURE);} 323 | 324 | sfs = 1; 325 | stat = malloc(strlen(argv[2])); 326 | strcpy(stat, argv[2]); //Status_on|off|both 327 | cmd = malloc(strlen(argv[3])); 328 | strcpy(cmd, argv[3]); //Programm_run 329 | gpio_get_value(gpio, &OldValue); //Save current value 330 | } 331 | else 332 | { 333 | if (argc != 7) { 334 | show_sage(argv[0], 1); 335 | exit(EXIT_FAILURE);} 336 | 337 | GPIO_Base=parse_int(argv[1]); //GPIO_Base 338 | GPIO_Offset=parse_int(argv[2]); //GPIO_Offset 339 | GPIO_Group=atoi(argv[3]); //GPIO_Group 340 | GPIO_Bit = atoi(argv[4]); //GPIO_Bit 341 | stat = malloc(strlen(argv[5])); 342 | strcpy(stat, argv[5]); //Status_on|off|both 343 | cmd = malloc(strlen(argv[6])); 344 | strcpy(cmd, argv[6]); //Programm_run 345 | } 346 | //Status 347 | if(!strcmp("on",stat)){status = 1;} //on = 1 348 | else if(!strcmp("off",stat)){status = 0;} //off = 0 349 | else if(!strcmp("both",stat)){status = -1;} //both = -1 (The script is executed twice) 350 | else {status = -1;} 351 | 352 | 353 | while(1) 354 | { 355 | if (sfs == 0) 356 | { 357 | adress=GPIO_Base+(GPIO_Group*GPIO_Offset)+0x3fc; 358 | value = GetValueRegister(adress); 359 | } 360 | else { 361 | gpio_get_value(gpio, &value); 362 | } 363 | 364 | if(OldValue!=value) 365 | { 366 | if (sfs == 0){ 367 | old_bit = (OldValue>>GPIO_Bit)&1; 368 | new_bit = (value>>GPIO_Bit)&1; 369 | 370 | if(old_bit!=new_bit) 371 | { 372 | adress=GPIO_Base+(GPIO_Group*GPIO_Offset)+0x400; 373 | direct = GetValueRegister(adress); 374 | direct = (direct>>GPIO_Bit)&1; 375 | adress=GPIO_Base+(GPIO_Group*GPIO_Offset)+(1< 87 | 88 | /* cJSON Types: */ 89 | #define cJSON_Invalid (0) 90 | #define cJSON_False (1 << 0) 91 | #define cJSON_True (1 << 1) 92 | #define cJSON_NULL (1 << 2) 93 | #define cJSON_Number (1 << 3) 94 | #define cJSON_String (1 << 4) 95 | #define cJSON_Array (1 << 5) 96 | #define cJSON_Object (1 << 6) 97 | #define cJSON_Raw (1 << 7) /* raw json */ 98 | 99 | #define cJSON_IsReference 256 100 | #define cJSON_StringIsConst 512 101 | 102 | /* The cJSON structure: */ 103 | typedef struct cJSON 104 | { 105 | /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */ 106 | struct cJSON *next; 107 | struct cJSON *prev; 108 | /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */ 109 | struct cJSON *child; 110 | 111 | /* The type of the item, as above. */ 112 | int type; 113 | 114 | /* The item's string, if type==cJSON_String and type == cJSON_Raw */ 115 | char *valuestring; 116 | /* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */ 117 | int valueint; 118 | /* The item's number, if type==cJSON_Number */ 119 | double valuedouble; 120 | 121 | /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ 122 | char *string; 123 | } cJSON; 124 | 125 | typedef struct cJSON_Hooks 126 | { 127 | /* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */ 128 | void *(CJSON_CDECL *malloc_fn)(size_t sz); 129 | void (CJSON_CDECL *free_fn)(void *ptr); 130 | } cJSON_Hooks; 131 | 132 | typedef int cJSON_bool; 133 | 134 | /* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them. 135 | * This is to prevent stack overflows. */ 136 | #ifndef CJSON_NESTING_LIMIT 137 | #define CJSON_NESTING_LIMIT 1000 138 | #endif 139 | 140 | /* returns the version of cJSON as a string */ 141 | CJSON_PUBLIC(const char*) cJSON_Version(void); 142 | 143 | /* Supply malloc, realloc and free functions to cJSON */ 144 | CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks); 145 | 146 | /* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */ 147 | /* Supply a block of JSON, and this returns a cJSON object you can interrogate. */ 148 | CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value); 149 | CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length); 150 | /* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */ 151 | /* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */ 152 | CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated); 153 | CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated); 154 | 155 | /* Render a cJSON entity to text for transfer/storage. */ 156 | CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item); 157 | /* Render a cJSON entity to text for transfer/storage without any formatting. */ 158 | CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item); 159 | /* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */ 160 | CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt); 161 | /* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */ 162 | /* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */ 163 | CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format); 164 | /* Delete a cJSON entity and all subentities. */ 165 | CJSON_PUBLIC(void) cJSON_Delete(cJSON *item); 166 | 167 | /* Returns the number of items in an array (or object). */ 168 | CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array); 169 | /* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */ 170 | CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index); 171 | /* Get item "string" from object. Case insensitive. */ 172 | CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string); 173 | CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string); 174 | CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string); 175 | /* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */ 176 | CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void); 177 | 178 | /* Check item type and return its value */ 179 | CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item); 180 | CJSON_PUBLIC(double) cJSON_GetNumberValue(cJSON *item); 181 | 182 | /* These functions check the type of an item */ 183 | CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item); 184 | CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item); 185 | CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item); 186 | CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item); 187 | CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item); 188 | CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item); 189 | CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item); 190 | CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item); 191 | CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item); 192 | CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item); 193 | 194 | /* These calls create a cJSON item of the appropriate type. */ 195 | CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void); 196 | CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void); 197 | CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void); 198 | CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean); 199 | CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num); 200 | CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string); 201 | /* raw json */ 202 | CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw); 203 | CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void); 204 | CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void); 205 | 206 | /* Create a string where valuestring references a string so 207 | * it will not be freed by cJSON_Delete */ 208 | CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string); 209 | /* Create an object/array that only references it's elements so 210 | * they will not be freed by cJSON_Delete */ 211 | CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child); 212 | CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child); 213 | 214 | /* These utilities create an Array of count items. 215 | * The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/ 216 | CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count); 217 | CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count); 218 | CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count); 219 | CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count); 220 | 221 | /* Append item to the specified array/object. */ 222 | CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item); 223 | CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item); 224 | /* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object. 225 | * WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before 226 | * writing to `item->string` */ 227 | CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item); 228 | /* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */ 229 | CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item); 230 | CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item); 231 | 232 | /* Remove/Detach items from Arrays/Objects. */ 233 | CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item); 234 | CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which); 235 | CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which); 236 | CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string); 237 | CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string); 238 | CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string); 239 | CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string); 240 | 241 | /* Update array items. */ 242 | CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */ 243 | CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement); 244 | CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem); 245 | CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem); 246 | CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem); 247 | 248 | /* Duplicate a cJSON item */ 249 | CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse); 250 | /* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will 251 | * need to be released. With recurse!=0, it will duplicate any children connected to the item. 252 | * The item->next and ->prev pointers are always zero on return from Duplicate. */ 253 | /* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal. 254 | * case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */ 255 | CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive); 256 | 257 | /* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings. 258 | * The input pointer json cannot point to a read-only address area, such as a string constant, 259 | * but should point to a readable and writable adress area. */ 260 | CJSON_PUBLIC(void) cJSON_Minify(char *json); 261 | 262 | /* Helper functions for creating and adding items to an object at the same time. 263 | * They return the added item or NULL on failure. */ 264 | CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name); 265 | CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name); 266 | CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name); 267 | CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean); 268 | CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number); 269 | CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string); 270 | CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw); 271 | CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name); 272 | CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name); 273 | 274 | /* When assigning an integer value, it needs to be propagated to valuedouble too. */ 275 | #define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number)) 276 | /* helper for the cJSON_SetNumberValue macro */ 277 | CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number); 278 | #define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number)) 279 | /* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */ 280 | CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring); 281 | 282 | /* Macro for iterating over an array or object */ 283 | #define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next) 284 | 285 | /* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */ 286 | CJSON_PUBLIC(void *) cJSON_malloc(size_t size); 287 | CJSON_PUBLIC(void) cJSON_free(void *object); 288 | 289 | #ifdef __cplusplus 290 | } 291 | #endif 292 | 293 | #endif 294 | -------------------------------------------------------------------------------- /utils/hisi_gpio_scanner/src/hisi_gpio_scanner.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #define DEFAULT_MD_LEN 128 13 | #define PAGE_SIZE 0x1000 14 | #define PAGE_SIZE_MASK (~(0xfff)) 15 | 16 | typedef struct tag_MMAP_Node 17 | { 18 | unsigned long Start_P; 19 | unsigned long Start_V; 20 | unsigned long length; 21 | unsigned long refcount; 22 | struct tag_MMAP_Node * next; 23 | }TMMAP_Node_t; 24 | 25 | TMMAP_Node_t * pTMMAPNode = NULL; 26 | int fd = -1; 27 | const char dev[]="/dev/mem"; 28 | jmp_buf *sigbus_jmp; // global 29 | 30 | //************************************************************ 31 | void print_bin(unsigned long data) 32 | { 33 | int i; 34 | unsigned long ulbit; 35 | for (i = 7; i >= 0; i--) 36 | { 37 | ulbit = data >> i; 38 | if (ulbit & 1) printf("1"); else printf("0"); 39 | } 40 | } 41 | //************************************************************ 42 | void signal_handler (int sig) 43 | { 44 | if (sig == SIGBUS) 45 | { 46 | //printf("signal_handler SIGBUS!\n"); 47 | if(sigbus_jmp) siglongjmp(*sigbus_jmp, 1); 48 | // no one to catch the error, so abort 49 | abort(); 50 | } 51 | } 52 | //************************************************************ 53 | int set_handler() 54 | { 55 | struct sigaction act; 56 | memset (&act, 0, sizeof(act)); 57 | act.sa_sigaction = (void *)signal_handler; 58 | act.sa_flags = SA_SIGINFO; 59 | if (sigaction(SIGBUS, &act, 0)) 60 | { 61 | perror ("sigaction"); 62 | return -1; 63 | } 64 | return 0; 65 | } 66 | //************************************************************ 67 | void * memmap(unsigned long phy_addr, unsigned long size) 68 | { 69 | unsigned long phy_addr_in_page; 70 | unsigned long page_diff; 71 | unsigned long size_in_page; 72 | unsigned long value = 0; 73 | TMMAP_Node_t * pTmp; 74 | TMMAP_Node_t * pNew; 75 | void *addr=NULL; 76 | if(size == 0) 77 | { 78 | printf("memmap():size can't be zero!\n"); 79 | return NULL; 80 | } 81 | /* проверить, было ли преобразовано пространство физической памяти */ 82 | pTmp = pTMMAPNode; 83 | while(pTmp != NULL) 84 | { 85 | if( (phy_addr >= pTmp->Start_P) && ( (phy_addr + size) <= (pTmp->Start_P + pTmp->length) ) ) 86 | { 87 | pTmp->refcount++; /* referrence count increase by 1 */ 88 | return (void *)(pTmp->Start_V + phy_addr - pTmp->Start_P); 89 | } 90 | pTmp = pTmp->next; 91 | } 92 | /* not mmaped yet */ 93 | if(fd < 0) 94 | { 95 | /* dev not opened yet, so open it */ 96 | fd = open (dev, O_RDWR | O_SYNC); 97 | if(fd < 0) 98 | { 99 | printf("memmap():open %s error!\n", dev); 100 | return NULL; 101 | } 102 | } 103 | /* addr align in page_size(4K) */ 104 | phy_addr_in_page = phy_addr & PAGE_SIZE_MASK; 105 | page_diff = phy_addr - phy_addr_in_page; 106 | /* size in page_size */ 107 | size_in_page =((size + page_diff - 1) & PAGE_SIZE_MASK) + PAGE_SIZE; 108 | addr = mmap((void *)0, size_in_page, PROT_READ|PROT_WRITE, MAP_SHARED, fd, phy_addr_in_page); 109 | if(addr == MAP_FAILED) 110 | { 111 | printf("memmap():mmap @ 0x%x error!\n", phy_addr_in_page); 112 | return NULL; 113 | } 114 | /* add this mmap to MMAP Node */ 115 | pNew = (TMMAP_Node_t *)malloc(sizeof(TMMAP_Node_t)); 116 | if(NULL == pNew) 117 | { 118 | printf("memmap():malloc new node failed!\n"); 119 | return NULL; 120 | } 121 | pNew->Start_P = phy_addr_in_page; 122 | pNew->Start_V = (unsigned long)addr; 123 | pNew->length = size_in_page; 124 | pNew->refcount = 1; 125 | pNew->next = NULL; 126 | if(pTMMAPNode == NULL) 127 | { 128 | pTMMAPNode = pNew; 129 | } 130 | else 131 | { 132 | pTmp = pTMMAPNode; 133 | while(pTmp->next != NULL) 134 | { 135 | pTmp = pTmp->next; 136 | } 137 | pTmp->next = pNew; 138 | } 139 | return (void *)(addr+page_diff); 140 | } 141 | //************************************************************ 142 | unsigned long GetValueRegister(unsigned long adress) 143 | { 144 | void *pMem = NULL; 145 | unsigned long value = -1; 146 | jmp_buf sigbus_jmpbuf; 147 | sigbus_jmp = &sigbus_jmpbuf; 148 | if(sigsetjmp(sigbus_jmpbuf, 1) == 0) 149 | { 150 | pMem = memmap(adress,DEFAULT_MD_LEN); 151 | if (pMem == NULL) 152 | { 153 | printf("memmap failed!\n"); 154 | return -1; 155 | } 156 | value = *(unsigned int*)pMem; //читаем региср 157 | } 158 | return value; 159 | } 160 | //************************************************************ 161 | int SetValueRegister(unsigned long adress, unsigned long value) 162 | { 163 | void *pMem = NULL; 164 | pMem = memmap(adress,DEFAULT_MD_LEN); 165 | if (pMem == NULL) 166 | { 167 | printf("memmap failed!\n"); 168 | return -1; 169 | } 170 | *(unsigned int*)pMem = value; //пишем в регистр 171 | return 0; 172 | } 173 | //************************************************************ 174 | void get_chip_gpio_adress(unsigned long *Chip_Id, unsigned long *GPIO_Groups, unsigned long *GPIO_Base, unsigned long *GPIO_Offset) 175 | { 176 | switch (*Chip_Id) 177 | { 178 | //------------------------------------------- 179 | //Default: 0x3516A100 одна группа 180 | //Hi3516Av100 A7 @ 600 MHz 0x2014_0000 181 | case 0x3516A100: 182 | *GPIO_Groups = 17; //пропустить G15 183 | *GPIO_Base = 0x20140000; 184 | *GPIO_Offset = 0x10000; 185 | break; 186 | //Default: 0x3516A100 187 | //Hi3516Dv100 A7 @600 MHz 0x2014_0000 188 | case 0x3516D100: 189 | *GPIO_Groups = 15; 190 | *GPIO_Base = 0x20140000; 191 | *GPIO_Offset = 0x10000; 192 | break; 193 | //------------------------------------------- 194 | //Hi3518Ev100 ARM926 @ 440 MHz 0x2014_0000 195 | case 0x35180100: 196 | *GPIO_Groups = 12; 197 | *GPIO_Base = 0x20140000; 198 | *GPIO_Offset = 0x10000; 199 | break; 200 | //------------------------------------------- 201 | //Hi3516Cv100 ARM926 @ 440 MHz 0x2014_0000 202 | case 0x3516C100: 203 | *GPIO_Groups = 12; 204 | *GPIO_Base = 0x20140000; 205 | *GPIO_Offset = 0x10000; 206 | break; 207 | //------------------------------------------- 208 | //Default: 0x3516C300 209 | //Hi3516Cv300 ARM926 @ 800 MHz 0x1214_0000 210 | case 0x3516C300: 211 | *GPIO_Groups = 9; 212 | *GPIO_Base = 0x12140000; 213 | *GPIO_Offset = 0x1000; 214 | break; 215 | //------------------------------------------- 216 | //Default: 0x3516E200 217 | //Hi3516Ev200 A7 @ 900MHz 0x120B_0000 218 | case 0x3516E200: 219 | *GPIO_Groups = 9; 220 | *GPIO_Base = 0x120B0000; 221 | *GPIO_Offset = 0x1000; 222 | break; 223 | //------------------------------------------- 224 | //Default: 0x3516E300 225 | //Hi3516Ev300 A7 @ 900MHz 0x120B_0000 226 | case 0x3516E300: 227 | *GPIO_Groups = 10; 228 | *GPIO_Base = 0x120B0000; 229 | *GPIO_Offset = 0x1000; 230 | break; 231 | //------------------------------------------- 232 | //Default: 0x3518E200 одна группа 233 | //Hi3516Cv200 ARM926 @ 540 MHz 0x2014_0000 234 | case 0x3516C200: 235 | *GPIO_Groups = 9; 236 | *GPIO_Base = 0x20140000; 237 | *GPIO_Offset = 0x10000; 238 | break; 239 | //Default: 0x3518E200 240 | //Hi3518Ev200 ARM926 @ 540 MHz 0x2014_0000 241 | case 0x3518E200: 242 | *GPIO_Groups = 9; 243 | *GPIO_Base = 0x20140000; 244 | *GPIO_Offset = 0x10000; 245 | break; 246 | //Default: 0x3518E200 247 | //Hi3518Ev201 ARM926 @ 540 MHz 0x2014_0000 248 | case 0x3518E201: 249 | *GPIO_Groups = 9; 250 | *GPIO_Base = 0x20140000; 251 | *GPIO_Offset = 0x10000; 252 | break; 253 | //------------------------------------------- 254 | case 0x35350100: 255 | *GPIO_Groups = 15; 256 | *GPIO_Base = 0x20150000; 257 | *GPIO_Offset = 0x10000; 258 | break; 259 | //------------------------------------------- 260 | case 0x3536C100: 261 | *GPIO_Groups = 14; //пропустить G4 262 | *GPIO_Base = 0x12150000; 263 | *GPIO_Offset = 0x10000; 264 | break; 265 | //------------------------------------------- 266 | case 0x3536D100: 267 | *GPIO_Groups = 6; 268 | *GPIO_Base = 0x12150000; 269 | *GPIO_Offset = 0x10000; 270 | break; 271 | //------------------------------------------- 272 | default: 273 | *GPIO_Groups = 0; 274 | *GPIO_Base = 0; 275 | *GPIO_Offset = 0; 276 | break; 277 | //--------------------------------- 278 | } 279 | } 280 | //************************************************************ 281 | void get_chip_id(unsigned long *Chip_Id, unsigned char *cpu, unsigned char *hardware) 282 | { 283 | unsigned long SCBASE; 284 | unsigned long SCSYSID0 = 0xEE0; 285 | unsigned long SCSYSID1 = 0xEE4; 286 | unsigned long SCSYSID2 = 0xEE8; 287 | unsigned long SCSYSID3 = 0xEEC; 288 | unsigned long Chip_Ver; 289 | unsigned long Val; 290 | char Buffer[4096]; 291 | int i; 292 | 293 | //--------------------------------------------- 294 | SCBASE = 0x20050000; 295 | if(GetValueRegister(SCBASE)==-1) //читаем сначала один базовый адрес 296 | { 297 | SCBASE = 0x12020000; 298 | if(GetValueRegister(SCBASE)==-1) //затем читаем другой 299 | { 300 | sprintf(cpu,"unknown"); 301 | *Chip_Id = 0; 302 | return; 303 | } 304 | } 305 | //--------------------------------------------- 306 | if((GetValueRegister(SCBASE+SCSYSID0) & 0xFF000000) >> 24 == 0x35) //если старший байт = 0x35 значит все ID в одном регистре 307 | { 308 | *Chip_Id = GetValueRegister(SCBASE+SCSYSID0); 309 | Chip_Ver = 0; 310 | } 311 | else 312 | { 313 | Chip_Ver = (GetValueRegister(SCBASE+SCSYSID0) & 0xFF000000) >> 24; //старший байт регистра может быть версия чипа 314 | SCSYSID0 = GetValueRegister(SCBASE+SCSYSID0) & 0xFF; //читаем младший байт регистра 315 | SCSYSID1 = GetValueRegister(SCBASE+SCSYSID1) & 0xFF; //читаем младший байт регистра 316 | SCSYSID2 = GetValueRegister(SCBASE+SCSYSID2) & 0xFF; //читаем младший байт регистра 317 | SCSYSID3 = GetValueRegister(SCBASE+SCSYSID3) & 0xFF; //читаем младший байт регистра 318 | *Chip_Id = (SCSYSID3<<24)+(SCSYSID2<<16)+(SCSYSID1<<8)+(SCSYSID0); 319 | } 320 | //--------------------------------------------- 321 | if((*Chip_Id==0x3518E200)&(Chip_Ver==0x01)) *Chip_Id=0x3516C200; 322 | if((*Chip_Id==0x3518E200)&(Chip_Ver==0x02)) *Chip_Id=0x3518E200; 323 | if((*Chip_Id==0x3518E200)&(Chip_Ver==0x03)) *Chip_Id=0x3518E201; 324 | //--------------------------------------------- 325 | if((*Chip_Id==0x3516A100)&(Chip_Ver==0x01)) *Chip_Id=0x3516A100; 326 | if((*Chip_Id==0x3516A100)&(Chip_Ver==0x02)) *Chip_Id=0x3516D100; 327 | //--------------------------------------------- 328 | switch (*Chip_Id) 329 | { 330 | //------------------------------------------- 331 | //Default: 0x3516A100 332 | case 0x3516A100: 333 | sprintf(cpu,"Hi3516Av100"); 334 | sprintf(hardware,"A7 @ 600 MHz"); 335 | break; 336 | //------------------------------------------- 337 | //Default: 0x3516A100 338 | case 0x3516D100: 339 | sprintf(cpu,"Hi3516Dv100"); 340 | sprintf(hardware,"A7 @ 600 MHz"); 341 | break; 342 | //------------------------------------------- 343 | //Default: 0x35180100 344 | case 0x35180100: 345 | sprintf(cpu,"Hi3518Ev100"); 346 | sprintf(hardware,"ARM926 @ 440 MHz"); 347 | break; 348 | //------------------------------------------- 349 | case 0x3516C100: 350 | sprintf(cpu,"Hi3516Cv100"); 351 | sprintf(hardware,"ARM926 @ 440 MHz"); 352 | break; 353 | //------------------------------------------- 354 | //Default: 0x3516C300 355 | case 0x3516C300: 356 | sprintf(cpu,"Hi3516Cv300"); 357 | sprintf(hardware,"ARM926 @ 800 MHz"); 358 | break; 359 | //------------------------------------------- 360 | //Default: 0x3516E200 361 | case 0x3516E200: 362 | sprintf(cpu,"Hi3516Ev200"); 363 | sprintf(hardware,"A7 @ 900MHz"); 364 | break; 365 | //------------------------------------------- 366 | //Default: 0x3516E300 367 | case 0x3516E300: 368 | sprintf(cpu,"Hi3516Ev300"); 369 | sprintf(hardware,"A7 @ 900MHz"); 370 | break; 371 | //------------------------------------------- 372 | //Default: 0x3518E200 одна группа 373 | case 0x3516C200: 374 | sprintf(cpu,"Hi3516Cv200"); 375 | sprintf(hardware,"ARM926 @ 540 MHz"); 376 | break; 377 | //Default: 0x3518E200 378 | case 0x3518E200: 379 | sprintf(cpu,"Hi3518Ev200"); 380 | sprintf(hardware,"ARM926 @ 540 MHz"); 381 | break; 382 | //Default: 0x3518E200 383 | case 0x3518E201: 384 | sprintf(cpu,"Hi3518Ev201"); 385 | sprintf(hardware,"ARM926 @ 540 MHz"); 386 | break; 387 | //------------------------------------------- 388 | case 0x35350100: 389 | sprintf(cpu,"Hi3535v100"); 390 | sprintf(hardware,"A9 dual-core @ 900 MHz"); 391 | break; 392 | //------------------------------------------- 393 | case 0x3536C100: 394 | sprintf(cpu,"Hi3536Cv100"); 395 | sprintf(hardware,"A7 dual-core @ 1.3 GHz"); 396 | break; 397 | //------------------------------------------- 398 | case 0x3536D100: 399 | sprintf(cpu,"Hi3536Dv100"); 400 | sprintf(hardware,"A7 @ 850 MHz"); 401 | break; 402 | //------------------------------------------- 403 | default: //чип не поддерживается 404 | sprintf(cpu,"unknown"); 405 | sprintf(hardware,"unknown"); 406 | break; 407 | //--------------------------------- 408 | } 409 | } 410 | //************************************************************ 411 | int main(int argc, char *argv[]) 412 | { 413 | unsigned long Chip_Id = 0; 414 | unsigned char CPU[50]={""}; 415 | unsigned char HARDWARE[50]={""}; 416 | unsigned long GPIO_Groups,GPIO_Base,GPIO_Offset; 417 | unsigned long adress = 0; 418 | unsigned long direct = 0; 419 | unsigned long value = 0; 420 | unsigned long OldValue[20]; 421 | int bit,old_bit,new_bit; 422 | int i,group,mask; 423 | int HeaderByte,Skip,SkipPin; 424 | //--------------------------------------------------------------- 425 | if(set_handler()==-1) 426 | { 427 | printf("Set handler Error!\n"); 428 | return 0; 429 | } 430 | get_chip_id(&Chip_Id,&CPU[0],&HARDWARE[0]); 431 | printf("For skip pin exaple: %s 12 14 ...\n",argv[0]); 432 | printf("================ Hisilicon GPIO Scaner (2021) OpenIPC.org collective =================\n"); 433 | printf("Chip_Id: 0x%08X, CPU: %s, Hardware: %s\n",Chip_Id,CPU,HARDWARE); 434 | if(!strcmp(CPU,"unknown")) //чип не поддерживается 435 | { 436 | printf("This CPU not support!\n"); 437 | return 0; 438 | } 439 | get_chip_gpio_adress(&Chip_Id,&GPIO_Groups,&GPIO_Base,&GPIO_Offset); 440 | //----------------------------- 441 | for(group=0; group 1) 455 | { 456 | printf("--------------------------------------------------------------------------------------\n"); 457 | for (i = 1; i < argc; i++) printf("Skip Pin: GPIO%s\n",argv[i]); 458 | } 459 | printf("--------------------------------------------------------------------------------------\n"); 460 | printf("While change value...\n"); 461 | //----------------------------- 462 | while(1) 463 | { 464 | for(group=0; group= 0; bit--) //цикл побитного сравнения 472 | { 473 | old_bit = (OldValue[group]>>bit)&1; 474 | new_bit = (value>>bit)&1; 475 | Skip=0; 476 | //------------------------------- 477 | if(argc > 1) //Есть пин для пропуска 478 | { 479 | for (i = 1; i < argc; i++) 480 | { 481 | SkipPin=atoi(argv[i]); 482 | if(((group*8)+bit)==SkipPin) Skip=1; 483 | } 484 | } 485 | //------------------------------- 486 | if(Skip==0) 487 | { 488 | if(old_bit!=new_bit) 489 | { 490 | if(HeaderByte==0) //еще не выводили заголовок измененения байта 491 | { 492 | printf("--------------------------------------------------------------------------------------\n"); 493 | printf("Gr:%d, Addr:0x%08lX, Data:0x%02lX = 0b",group,adress,OldValue[group]); 494 | print_bin(OldValue[group]); 495 | printf(" --> 0x%02lX = 0b",value); 496 | print_bin(value); 497 | printf("\n"); 498 | HeaderByte=1; 499 | } 500 | adress=GPIO_Base+(group*GPIO_Offset)+0x400; //регистр направления портов 501 | direct = GetValueRegister(adress); 502 | direct = (direct>>bit)&1; //получили бит направления порта 0-вход 1-выход 503 | adress=GPIO_Base+(group*GPIO_Offset)+(1<BETA NOTICE:You may have to use the Reset/Edit tab to restore the 'default' (cleaned) configuration file to remove invalid charactors (comments, ; etc.)")) 27 | i.reset = false 28 | 29 | function i.handle(self, state, data) 30 | if luci.http.formvalue("cbid.settings.system.save_cfd_yaml_content") ~= "Save Changes" then 31 | if luci.http.formvalue("cbid.settings.system.restore_cfd_yaml_content") ~= "Restore" then 32 | if state == FORM_VALID then 33 | 34 | tbl2['system']['sensor_config'] = nil 35 | tbl2['system']['sensor_config_dir'] = nil 36 | tbl2['system']['log_level'] = data.log_level 37 | tbl2['system']['web_port'] = data.web_port 38 | tbl2['system']['update_channel'] = data.update_channel 39 | 40 | tbl2['isp']['max_pool_cnt'] = data.max_pool_cnt 41 | tbl2['isp']['thread_stack_size'] = data.thread_stack_size 42 | tbl2['isp']['blk_cnt'] = data.blk_cnt 43 | tbl2['isp']['align_width'] = data.align_width 44 | 45 | if(data.luminance_auto == "true") then 46 | tbl2['image']['luminance'] = "auto" 47 | else 48 | tbl2['image']['luminance'] = data.luminance 49 | end 50 | 51 | if(data.contrast_auto == "true") then 52 | tbl2['image']['contrast'] = "auto" 53 | else 54 | tbl2['image']['contrast'] = data.contrast 55 | end 56 | tbl2['image']['hue'] = data.hue 57 | tbl2['image']['saturation'] = data.saturation 58 | tbl2['image']['mirror'] = data.mirror 59 | tbl2['image']['flip'] = data.flip 60 | 61 | tbl2['night_mode']['ir_sensor_pin_invert'] = data.ir_sensor_pin_invert 62 | tbl2['night_mode']['check_interval_s'] = data.check_interval_s 63 | tbl2['night_mode']['ir_sensor_pin'] = data.ir_sensor_pin 64 | tbl2['night_mode']['enable'] = data.night_mode 65 | tbl2['night_mode']['pin_switch_delay_us'] = data.pin_switch_delay_us 66 | tbl2['night_mode']['ir_cut_pin2'] = data.ir_cut_pin2 67 | tbl2['night_mode']['ir_cut_pin1'] = data.ir_cut_pin1 68 | 69 | tbl2['motion_detect']['enable'] = data.motion_detect 70 | tbl2['motion_detect']['visualize'] = data.motion_visualize 71 | tbl2['motion_detect']['debug'] = data.motion_debug 72 | 73 | tbl2['osd']['font'] = data.osd_font 74 | tbl2['osd']['template'] = data.osd_template 75 | tbl2['osd']['enable'] = data.osd_enable 76 | tbl2['osd']['pos_y'] = data.osd_posy 77 | tbl2['osd']['pos_x'] = data.osd_posx 78 | 79 | tbl2['raw']['mode'] = data.raw 80 | 81 | tbl2['jpeg']['qfactor'] = data.jpeg_qfactor 82 | tbl2['jpeg']['height'] = data.jpeg_height 83 | tbl2['jpeg']['to_progressive'] = data.jpeg_progressive 84 | tbl2['jpeg']['enable'] = data.jpeg_enable 85 | tbl2['jpeg']['width'] = data.jpeg_width 86 | 87 | tbl2['video_0']['bitrate'] = data.video_0_bitrate 88 | tbl2['video_0']['codec'] = data.video_0_codec 89 | tbl2['video_0']['height'] = data.video_0_height 90 | tbl2['video_0']['fps'] = data.video_0_fps 91 | tbl2['video_0']['enable'] = data.video_0_enable 92 | tbl2['video_0']['width'] = data.video_0_width 93 | 94 | tbl2['video_1']['bitrate'] = data.video_1_bitrate 95 | tbl2['video_1']['codec'] = data.video_1_codec 96 | tbl2['video_1']['height'] = data.video_1_height 97 | tbl2['video_1']['fps'] = data.video_1_fps 98 | tbl2['video_1']['enable'] = data.video_1_enable 99 | tbl2['video_1']['width'] = data.video_1_width 100 | 101 | tbl2['rtsp']['enable'] = data.rtsp_enable 102 | tbl2['rtsp']['port'] = data.rtsp_port 103 | 104 | tbl2['mjpeg']['bitrate'] = data.mjpeg_bitrate 105 | tbl2['mjpeg']['height'] = data.mjpeg_height 106 | tbl2['mjpeg']['enable'] = data.mjpeg_enable 107 | tbl2['mjpeg']['fps'] = data.mjpeg_fps 108 | tbl2['mjpeg']['width'] = data.mjpeg_width 109 | 110 | tbl2['records']['enable'] = data.record_enable 111 | tbl2['records']['path'] = data.record_path 112 | tbl2['records']['max_usage'] = data.record_max 113 | 114 | tbl2['ipeye']['enable'] = data.ipeye_enable 115 | 116 | tbl2['netip']['password'] = data.netip_password 117 | tbl2['netip']['port'] = data.netip_port 118 | tbl2['netip']['user'] = data.netip_user 119 | tbl2['netip']['enable'] = data.netip_enable 120 | tbl2['netip']['snapshots'] = data.netip_snapshots 121 | 122 | tbl2['onvif']['enable'] = data.onvif_enable 123 | 124 | tbl2['http_post']['enable'] = data.http_post 125 | tbl2['http_post']['width'] = data.http_width 126 | tbl2['http_post']['host'] = data.http_host 127 | tbl2['http_post']['qfactor'] = data.http_qfactor 128 | tbl2['http_post']['password'] = data.http_password 129 | tbl2['http_post']['height'] = data.http_height 130 | tbl2['http_post']['url'] = data.http_url 131 | tbl2['http_post']['login'] = data.http_login 132 | tbl2['http_post']['interval'] = data.http_interval 133 | 134 | LIP.save("/etc/majestic.yaml", tbl2) 135 | 136 | sys.call("killall -sigint majestic") 137 | sys.call("export SENSOR=`fw_printenv -n sensor`; majestic 2>&1 | logger -p daemon.info -t majestic &") 138 | luci.http.redirect(luci.dispatcher.build_url("admin","ipcam","settings")) 139 | end 140 | end 141 | end 142 | end 143 | 144 | s2 = i:section(TypedSection, "_dummy", "IP Cam Configuration") 145 | s2.addremove = false 146 | s2.anonymous = true 147 | 148 | s2:tab("system", translate("System")) 149 | s2:tab("isp", translate("ISP")) 150 | s2:tab("image", translate("Image")) 151 | s2:tab("night", translate("Night")) 152 | s2:tab("motion", translate("Motion")) 153 | s2:tab("osd", translate("OSD")) 154 | s2:tab("raw", translate("RAW")) 155 | s2:tab("mjpeg", translate("MJPEG")) 156 | s2:tab("jpeg", translate("JPG")) 157 | s2:tab("video", translate("Video")) 158 | s2:tab("service", translate("Service")) 159 | s2:tab("cfg", translate("Reset/Edit")) 160 | 161 | function s2.cfgsections() 162 | return { "system" } 163 | end 164 | 165 | log_level = s2:taboption("system", ListValue, "log_level", translate("Log level")) 166 | log_level.default = cleanval(tbl2['system']['log_level']) 167 | log_level:value("TRACE", "TRACE") 168 | log_level:value("ERROR", "ERROR") 169 | log_level:value("WARN", "WARN") 170 | log_level:value("INFO", "INFO") 171 | log_level:value("DEBUG", "DEBUG") 172 | 173 | update_channel = s2:taboption("system", ListValue, "update_channel", translate("Update channel")) 174 | update_channel.default = cleanval(tbl2['system']['update_channel']) 175 | update_channel:value("stable", "stable") 176 | update_channel:value("beta", "beta") 177 | update_channel:value("testing", "testing") 178 | update_channel:value("none", "none") 179 | 180 | web_port = s2:taboption("system", Value, "web_port", translate("Web port")) 181 | web_port.default = tbl2['system']['web_port'] 182 | web_port.datatype = "port" 183 | 184 | align_width = s2:taboption("isp", Value, "align_width", translate("Align width")) 185 | align_width.default = tbl2['isp']['align_width'] 186 | 187 | max_pool_cnt = s2:taboption("isp", Value, "max_pool_cnt", translate("Max pool count")) 188 | max_pool_cnt.default = tbl2['isp']['max_pool_cnt'] 189 | 190 | blk_cnt = s2:taboption("isp", Value, "blk_cnt", translate("Block count"), translate("4 for hi3518E, 10 for hi3516C")) 191 | blk_cnt.default = tbl2['isp']['blk_cnt'] 192 | 193 | thread_stack_size = s2:taboption("isp", Value, "thread_stack_size", translate("Thread stack size"), translate("in Kbytes")) 194 | thread_stack_size.default = tbl2['isp']['thread_stack_size'] 195 | 196 | mirror = s2:taboption("image", ListValue, "mirror", translate("Mirror"), translate("Mirror image left to right")) 197 | mirror.default = cleanval(tbl2['image']['mirror']) 198 | mirror:value("true", "true") 199 | mirror:value("false", "false") 200 | 201 | flip = s2:taboption("image", ListValue, "flip", translate("Flip"), translate("Turn image upside down")) 202 | flip.default = cleanval(tbl2['image']['flip']) 203 | flip:value("true", "true") 204 | flip:value("false", "false") 205 | 206 | luminanceauto = s2:taboption("image", ListValue, "luminance_auto", translate("Luminance Auto"), translate("auto disables manual modes")) 207 | if(cleanval(tbl2['image']['luminance']) == "auto") then 208 | luminanceauto.default = "true" 209 | else 210 | luminanceauto.default = "false" 211 | end 212 | luminanceauto:value("true", "true") 213 | luminanceauto:value("false", "false") 214 | 215 | contrastauto = s2:taboption("image", ListValue, "contrast_auto", translate("Contrast Auto"), translate("auto disables manual modes")) 216 | if(cleanval(tbl2['image']['contrast']) == "auto") then 217 | contrastauto.default = "true" 218 | else 219 | contrastauto.default = "false" 220 | end 221 | contrastauto:value("true", "true") 222 | contrastauto:value("false", "false") 223 | 224 | luminance = s2:taboption("image", Value, "luminance", translate("Luminance"), translate("(1-99) Default (50)")) 225 | if(cleanval(tbl2['image']['luminance']) == "auto") then 226 | luminance.default = "50" 227 | else 228 | luminance.default = tbl2['image']['luminance'] 229 | end 230 | luminance.template = "admin_ipcam/range" 231 | luminance.max = "99" 232 | luminance.min = "1" 233 | luminance.size = "250" 234 | luminance:depends("luminance_auto", "false") 235 | 236 | contrast = s2:taboption("image", Value, "contrast", translate("Contrast"), translate("(1-99) Default (50)")) 237 | if(cleanval(tbl2['image']['contrast']) == "auto") then 238 | contrast.default = "50" 239 | else 240 | contrast.default = tbl2['image']['contrast'] 241 | end 242 | contrast.template = "admin_ipcam/range" 243 | contrast.max = "99" 244 | contrast.min = "1" 245 | contrast.size = "250" 246 | contrast:depends("contrast_auto", "false") 247 | 248 | hue = s2:taboption("image", Value, "hue", translate("Hue"), translate("(1-99) Default (50)")) 249 | hue.default = tbl2['image']['hue'] 250 | hue.template = "admin_ipcam/range" 251 | hue.max = "99" 252 | hue.min = "1" 253 | hue.size = "250" 254 | 255 | saturation = s2:taboption("image", Value, "saturation", translate("Saturation"), translate("(1-99) Default (50)")) 256 | saturation.default = tbl2['image']['saturation'] 257 | saturation.template = "admin_ipcam/range" 258 | saturation.max = "100" 259 | saturation.min = "0" 260 | saturation.size = "250" 261 | 262 | night_mode = s2:taboption("night", ListValue, "night_mode", translate("Enable")) 263 | night_mode.default = cleanval(tbl2['night_mode']['enable']) 264 | night_mode:value("true", "true") 265 | night_mode:value("false", "false") 266 | 267 | ir_sensor_pin_invert = s2:taboption("night", ListValue, "ir_sensor_pin_invert", translate("IR cut pin invert")) 268 | ir_sensor_pin_invert.default = cleanval(tbl2['night_mode']['ir_sensor_pin_invert']) 269 | ir_sensor_pin_invert:value("true", "true") 270 | ir_sensor_pin_invert:value("false", "false") 271 | 272 | check_interval_s = s2:taboption("night", Value, "check_interval_s", translate("Check interval seconds"), translate("Interval to check light sensor state in seconds")) 273 | check_interval_s.default = tbl2['night_mode']['check_interval_s'] 274 | 275 | pin_switch_delay_us = s2:taboption("night", Value, "pin_switch_delay_us", translate("Pin Switch Delay Us"), translate("Switch delay in us on IRcut filter pins. WARNING! a very long delay can damage the IRcut filter!")) 276 | pin_switch_delay_us.default = tbl2['night_mode']['pin_switch_delay_us'] 277 | 278 | ir_sensor_pin = s2:taboption("night", Value, "ir_sensor_pin", translate("IR Cut Sensor Pin")) 279 | ir_sensor_pin.default = tbl2['night_mode']['ir_sensor_pin'] 280 | 281 | ir_cut_pin1 = s2:taboption("night", Value, "ir_cut_pin1", translate("IR Cut Pin 1")) 282 | ir_cut_pin1.default = tbl2['night_mode']['ir_cut_pin1'] 283 | 284 | ir_cut_pin2 = s2:taboption("night", Value, "ir_cut_pin2", translate("IR Cut Pin 2")) 285 | ir_cut_pin2.default = tbl2['night_mode']['ir_cut_pin2'] 286 | 287 | motion_detect = s2:taboption("motion", ListValue, "motion_detect", translate("Enable")) 288 | motion_detect.default = cleanval(tbl2['motion_detect']['enable']) 289 | motion_detect:value("true", "true") 290 | motion_detect:value("false", "false") 291 | 292 | motion_visualize = s2:taboption("motion", ListValue, "motion_visualize", translate("Visualize")) 293 | motion_visualize.default = cleanval(tbl2['motion_detect']['visualize']) 294 | motion_visualize:value("true", "true") 295 | motion_visualize:value("false", "false") 296 | 297 | motion_debug = s2:taboption("motion", ListValue, "motion_debug", translate("Debug")) 298 | motion_debug.default = cleanval(tbl2['motion_detect']['debug']) 299 | motion_debug:value("true", "true") 300 | motion_debug:value("false", "false") 301 | 302 | osd_enable = s2:taboption("osd", ListValue, "osd_enable", translate("Enable")) 303 | osd_enable.default = cleanval(tbl2['osd']['enable']) 304 | osd_enable:value("true", "true") 305 | osd_enable:value("false", "false") 306 | 307 | osd_font = s2:taboption("osd", Value, "osd_font", translate("Font")) 308 | osd_font.default = tbl2['osd']['font'] 309 | 310 | osd_template = s2:taboption("osd", Value, "osd_template", translate("Text Template"), translate("%a %e %B %Y, %H:%M:%S (add %f to show milliseconds, takes more resources)")) 311 | osd_template.default = tbl2['osd']['template'] 312 | 313 | osd_posy = s2:taboption("osd", Value, "osd_posy", translate("Pos Y")) 314 | osd_posy.default =tbl2['osd']['pos_y'] 315 | 316 | osd_posx = s2:taboption("osd", Value, "osd_posx", translate("Pos X")) 317 | osd_posx.default = tbl2['osd']['pos_x'] 318 | 319 | raw = s2:taboption("raw", ListValue, "raw", translate("Mode")) 320 | raw.default = cleanval(tbl2['raw']['mode']) 321 | raw:value("slow", "slow") 322 | raw:value("fast", "fast") 323 | raw:value("none", "none") 324 | 325 | mjpeg_enable = s2:taboption("mjpeg", ListValue, "mjpeg_enable", translate("Enable")) 326 | mjpeg_enable.default = cleanval(tbl2['mjpeg']['enable']) 327 | mjpeg_enable:value("true", "true") 328 | mjpeg_enable:value("false", "false") 329 | 330 | mjpeg_bitrate = s2:taboption("mjpeg", Value, "mjpeg_bitrate", translate("Bitrate")) 331 | mjpeg_bitrate.default = tbl2['mjpeg']['bitrate'] 332 | 333 | mjpeg_fps = s2:taboption("mjpeg", Value, "mjpeg_fps", translate("FPS")) 334 | mjpeg_fps.default = tbl2['mjpeg']['fps'] 335 | 336 | mjpeg_height = s2:taboption("mjpeg", Value, "mjpeg_height", translate("Height")) 337 | mjpeg_height.default = tbl2['mjpeg']['height'] 338 | 339 | 340 | mjpeg_width = s2:taboption("mjpeg", Value, "mjpeg_width", translate("Width")) 341 | mjpeg_width.default = tbl2['mjpeg']['width'] 342 | 343 | jpeg_enable = s2:taboption("jpeg", ListValue, "jpeg_enable", translate("Enable")) 344 | jpeg_enable.default = cleanval(tbl2['jpeg']['enable']) 345 | jpeg_enable:value("true", "true") 346 | jpeg_enable:value("false", "false") 347 | 348 | jpeg_progressive = s2:taboption("jpeg", ListValue, "jpeg_progressive", translate("Progressive Mode")) 349 | jpeg_progressive.default = cleanval(tbl2['jpeg']['to_progressive']) 350 | jpeg_progressive:value("true", "true") 351 | jpeg_progressive:value("false", "false") 352 | 353 | jpeg_qfactor = s2:taboption("jpeg", Value, "jpeg_qfactor", translate("qfactor")) 354 | jpeg_qfactor.default = tbl2['jpeg']['qfactor'] 355 | 356 | jpeg_height = s2:taboption("jpeg", Value, "jpeg_height", translate("Height")) 357 | jpeg_height.default = tbl2['jpeg']['height'] 358 | 359 | jpeg_width = s2:taboption("jpeg", Value, "jpeg_width", translate("Width")) 360 | jpeg_width.default = tbl2['jpeg']['width'] 361 | 362 | video_0_enable = s2:taboption("video", ListValue, "video_0_enable", translate("V0 Enable")) 363 | video_0_enable.default = cleanval(tbl2['video_0']['enable']) 364 | video_0_enable:value("true", "true") 365 | video_0_enable:value("false", "false") 366 | 367 | video_0_codec = s2:taboption("video", ListValue, "video_0_codec", translate("V0 Codec")) 368 | video_0_codec.default = cleanval(tbl2['video_0']['codec']) 369 | video_0_codec:value("h265", "h265") 370 | video_0_codec:value("h264", "h264") 371 | 372 | video_0_bitrate = s2:taboption("video", Value, "video_0_bitrate", translate("V0 Bitrate")) 373 | video_0_bitrate.default = tbl2['video_0']['bitrate'] 374 | 375 | video_0_fps = s2:taboption("video", Value, "video_0_fps", translate("V0 FPS")) 376 | video_0_fps.default = tbl2['video_0']['fps'] 377 | 378 | video_0_width = s2:taboption("video", Value, "video_0_width", translate("V0 Width")) 379 | video_0_width.default = tbl2['video_0']['width'] 380 | 381 | video_0_height = s2:taboption("video", Value, "video_0_height", translate("V0 Height")) 382 | video_0_height.default = tbl2['video_0']['height'] 383 | 384 | video_1_enable = s2:taboption("video", ListValue, "video_1_enable", translate("V1 Enable")) 385 | video_1_enable.default = cleanval(tbl2['video_1']['enable']) 386 | video_1_enable:value("true", "true") 387 | video_1_enable:value("false", "false") 388 | 389 | video_1_codec = s2:taboption("video", ListValue, "video_1_codec", translate("V1 Codec")) 390 | video_1_codec.default = cleanval(tbl2['video_1']['codec']) 391 | video_1_codec:value("h265", "h265") 392 | video_1_codec:value("h264", "h264") 393 | 394 | video_1_bitrate = s2:taboption("video", Value, "video_1_bitrate", translate("V1 Bitrate")) 395 | video_1_bitrate.default = tbl2['video_1']['bitrate'] 396 | 397 | video_1_fps = s2:taboption("video", Value, "video_1_fps", translate("V1 FPS")) 398 | video_1_fps.default = tbl2['video_1']['fps'] 399 | 400 | video_1_width = s2:taboption("video", Value, "video_1_width", translate("V1 Width")) 401 | video_1_width.default = tbl2['video_1']['width'] 402 | 403 | video_1_height = s2:taboption("video", Value, "video_1_height", translate("V1 Height")) 404 | video_1_height.default = tbl2['video_1']['height'] 405 | 406 | rtsp_label = s2:taboption("service", DummyValue, "rtsp_label", translate("RTSP Server")) 407 | rtsp_label.rawhtml = true 408 | rtsp_label.title = nil 409 | rtsp_label.default = "RTSP Server" 410 | 411 | rtsp_enable = s2:taboption("service", ListValue, "rtsp_enable", translate("Enable")) 412 | rtsp_enable.default = cleanval(tbl2['rtsp']['enable']) 413 | rtsp_enable:value("true", "true") 414 | rtsp_enable:value("false", "false") 415 | 416 | rtsp_port = s2:taboption("service", Value, "rtsp_port", translate("Port")) 417 | rtsp_port.default = tbl2['rtsp']['port'] 418 | 419 | http_label = s2:taboption("service", DummyValue, "http_label", translate("HTTP Post Client")) 420 | http_label.rawhtml = true 421 | http_label.title = nil 422 | http_label.default = "HTTP Post Client" 423 | 424 | http_enable = s2:taboption("service", ListValue, "http_post", translate("Enable")) 425 | http_enable.default = cleanval(tbl2['http_post']['enable']) 426 | http_enable:value("true", "true") 427 | http_enable:value("false", "false") 428 | 429 | http_host = s2:taboption("service", Value, "http_host", translate("Host")) 430 | http_host.default = tbl2['http_post']['host'] 431 | 432 | http_url = s2:taboption("service", Value, "http_url", translate("URL")) 433 | http_url.default = tbl2['http_post']['url'] 434 | 435 | http_login = s2:taboption("service", Value, "http_login", translate("Login")) 436 | http_login.default = tbl2['http_post']['login'] 437 | 438 | http_password = s2:taboption("service", Value, "http_password", translate("Password")) 439 | http_password.default = tbl2['http_post']['password'] 440 | 441 | http_interval = s2:taboption("service", Value, "http_interval", translate("Interval Seconds")) 442 | http_interval.default = tbl2['http_post']['interval'] 443 | 444 | http_qfactor = s2:taboption("service", Value, "http_qfactor", translate("Jpg qfactor")) 445 | http_qfactor.default = tbl2['http_post']['qfactor'] 446 | 447 | http_height = s2:taboption("service", Value, "http_height", translate("Jpg Height")) 448 | http_height.default = tbl2['http_post']['height'] 449 | 450 | http_width = s2:taboption("service", Value, "http_width", translate("Jpg Width")) 451 | http_width.default = tbl2['http_post']['width'] 452 | 453 | record_label = s2:taboption("service", DummyValue, "record_label", translate("Recording")) 454 | record_label.rawhtml = true 455 | record_label.title = nil 456 | record_label.default = "Recording" 457 | 458 | record_enable = s2:taboption("service", ListValue, "record_enable", translate("Enable")) 459 | record_enable.default = cleanval(tbl2['records']['enable']) 460 | record_enable:value("true", "true") 461 | record_enable:value("false", "false") 462 | 463 | record_path = s2:taboption("service", Value, "record_path", translate("Path")) 464 | record_path.default = tbl2['records']['path'] 465 | 466 | record_max = s2:taboption("service", Value, "record_max", translate("Max Usage %")) 467 | record_max.default = tbl2['records']['max_usage'] 468 | 469 | netip_label = s2:taboption("service", DummyValue, "netip_label", translate("NetIP")) 470 | netip_label.rawhtml = true 471 | netip_label.title = nil 472 | netip_label.default = "NetIP" 473 | 474 | netip_enable = s2:taboption("service", ListValue, "netip_enable", translate("Enable")) 475 | netip_enable.default = cleanval(tbl2['netip']['enable']) 476 | netip_enable:value("true", "true") 477 | netip_enable:value("false", "false") 478 | 479 | netip_snapshots = s2:taboption("service", ListValue, "netip_snapshots", translate("Snapshots")) 480 | netip_snapshots.default = cleanval(tbl2['netip']['snapshots']) 481 | netip_snapshots:value("true", "true") 482 | netip_snapshots:value("false", "false") 483 | 484 | netip_portt = s2:taboption("service", Value, "netip_port", translate("Port")) 485 | netip_portt.default = tbl2['netip']['port'] 486 | 487 | netip_login = s2:taboption("service", Value, "netip_user", translate("Login")) 488 | netip_login.default = tbl2['netip']['user'] 489 | 490 | netip_password = s2:taboption("service", Value, "netip_password", translate("Password")) 491 | netip_password.default = tbl2['netip']['password'] 492 | 493 | onvif_label = s2:taboption("service", DummyValue, "onvif_label", translate("Onvif")) 494 | onvif_label.rawhtml = true 495 | onvif_label.title = nil 496 | onvif_label.default = "Onvif" 497 | 498 | onvif_enable = s2:taboption("service", ListValue, "onvif_enable", translate("Enable")) 499 | onvif_enable.default = cleanval(tbl2['onvif']['enable']) 500 | onvif_enable:value("true", "true") 501 | onvif_enable:value("false", "false") 502 | 503 | ipeye_label = s2:taboption("service", DummyValue, "ipeye_label", translate("Ipeye")) 504 | ipeye_label.rawhtml = true 505 | ipeye_label.title = nil 506 | ipeye_label.default = "Ipeye" 507 | 508 | ipeye_enable = s2:taboption("service", ListValue, "ipeye_enable", translate("Enable")) 509 | ipeye_enable.default = cleanval(tbl2['ipeye']['enable']) 510 | ipeye_enable:value("true", "true") 511 | ipeye_enable:value("false", "false") 512 | 513 | cfg_yaml = s2:taboption("cfg", DummyValue, "cfd_yaml", "/etc/majestic.yaml") 514 | cfg_yaml.rawhtml = true 515 | cfg_yaml.title = nil 516 | cfg_yaml.default = "Edit /etc/majestic.yaml" 517 | 518 | cfd_yaml_content = s2:taboption("cfg", TextValue, "cfd_yaml_content") 519 | cfd_yaml_content.rmempty = true 520 | cfd_yaml_content.rows = 30 521 | 522 | save_cfd_yaml_content = s2:taboption("cfg", Button, "save_cfd_yaml_content", translate("Save Changes"), translate("Save configuration changes made to the unparsed /etc/majestic.yaml file.")) 523 | 524 | function cfd_yaml_content.cfgvalue() 525 | return fs.readfile("/etc/majestic.yaml") or "" 526 | end 527 | 528 | sreset = s2:taboption("cfg", DummyValue, "sreset", "Restore Configuration") 529 | sreset.rawhtml = true 530 | sreset.title = nil 531 | sreset.default = "Restore Configuration" 532 | 533 | restore_cfd_yaml_content = s2:taboption("cfg", Button, "restore_cfd_yaml_content", translate("Restore"), translate("Remove all changes and restore default configuration")) 534 | restore_cfd_yaml_content.inputstyle = "remove" 535 | 536 | function save_cfd_yaml_content.write(self, section, data) 537 | fs.writefile("/etc/majestic.yaml", luci.http.formvalue("cbid.settings.system.cfd_yaml_content"):gsub("\r\n", "\n")) 538 | sys.call("killall -sigint majestic") 539 | sys.call("export SENSOR=`fw_printenv -n sensor`; majestic 2>&1 | logger -p daemon.info -t majestic &") 540 | luci.http.redirect(luci.dispatcher.build_url("admin","ipcam","settings")) 541 | end 542 | 543 | function restore_cfd_yaml_content.write() 544 | tbl2['raw']['mode'] = "slow" 545 | tbl2['video_1']['bitrate'] = "4096" 546 | tbl2['video_1']['codec'] = "h264" 547 | tbl2['video_1']['height'] = "576" 548 | tbl2['video_1']['fps'] = "15" 549 | tbl2['video_1']['enable'] = "false" 550 | tbl2['video_1']['width'] = "704" 551 | tbl2['motion_detect']['enable'] = "false" 552 | tbl2['motion_detect']['visualize'] = "true" 553 | tbl2['motion_detect']['debug'] = "true" 554 | tbl2['video_0']['bitrate'] = "4096" 555 | tbl2['video_0']['codec'] = "h264" 556 | tbl2['video_0']['height'] = "1080" 557 | tbl2['video_0']['fps'] = "30" 558 | tbl2['video_0']['enable'] = "true" 559 | tbl2['video_0']['width'] = "1920" 560 | tbl2['image']['hue'] = "50" 561 | tbl2['image']['saturation'] = "50" 562 | tbl2['image']['flip'] = "false" 563 | tbl2['image']['luminance'] = "auto" 564 | tbl2['image']['mirror'] = "false" 565 | tbl2['image']['contrast'] = "auto" 566 | tbl2['isp']['max_pool_cnt'] = "128" 567 | tbl2['isp']['thread_stack_size'] = "16" 568 | tbl2['isp']['blk_cnt'] = "4" 569 | tbl2['isp']['align_width'] = "64" 570 | tbl2['night_mode']['ir_sensor_pin_invert'] = "false" 571 | tbl2['night_mode']['check_interval_s'] = "10" 572 | tbl2['night_mode']['ir_sensor_pin'] = "62" 573 | tbl2['night_mode']['enable'] = "false" 574 | tbl2['night_mode']['pin_switch_delay_us'] = "150" 575 | tbl2['night_mode']['ir_cut_pin2'] = "2" 576 | tbl2['night_mode']['ir_cut_pin1'] = "1" 577 | tbl2['mjpeg']['bitrate'] = "1024" 578 | tbl2['mjpeg']['height'] = "1080" 579 | tbl2['mjpeg']['enable'] = "true" 580 | tbl2['mjpeg']['fps'] = "30" 581 | tbl2['mjpeg']['width'] = "1920" 582 | tbl2['rtsp']['enable'] = "true" 583 | tbl2['rtsp']['port'] = "554" 584 | tbl2['ipeye']['enable'] = "false" 585 | tbl2['http_post']['enable'] = "false" 586 | tbl2['http_post']['width'] = "640" 587 | tbl2['http_post']['host'] = "host" 588 | tbl2['http_post']['qfactor'] = "95" 589 | tbl2['http_post']['password'] = "password" 590 | tbl2['http_post']['height'] = "360" 591 | tbl2['http_post']['url'] = "/~login/000000000000/%Y/%m/%d/%H.%M.jpg" 592 | tbl2['http_post']['login'] = "login" 593 | tbl2['http_post']['interval'] = "60" 594 | tbl2['records']['enable'] = "false" 595 | tbl2['records']['path'] = "/sdcard/%Y/%m/%d/%H.mp4" 596 | tbl2['records']['max_usage'] = "95" 597 | tbl2['onvif']['enable'] = "false" 598 | tbl2['osd']['font'] = "fonts.bin" 599 | tbl2['osd']['template'] = "%a %e %B %Y, %H:%M:%S" 600 | tbl2['osd']['enable'] = "false" 601 | tbl2['osd']['pos_y'] = "100" 602 | tbl2['osd']['pos_x'] = "100" 603 | tbl2['netip']['password'] = "6V0Y4HLF" 604 | tbl2['netip']['port'] = "34567" 605 | tbl2['netip']['user'] = "admin" 606 | tbl2['netip']['enable'] = "false" 607 | tbl2['netip']['snapshots'] = "true" 608 | tbl2['jpeg']['qfactor'] = "99" 609 | tbl2['jpeg']['height'] = "1080" 610 | tbl2['jpeg']['to_progressive'] = "false" 611 | tbl2['jpeg']['enable'] = "true" 612 | tbl2['jpeg']['width'] = "1920" 613 | tbl2['system']['log_level'] = "TRACE" 614 | tbl2['system']['web_port'] = "8888" 615 | tbl2['system']['update_channel'] = "stable" 616 | LIP.save("/etc/majestic.yaml", tbl2) 617 | sys.call("killall -sigint majestic") 618 | sys.call("export SENSOR=`fw_printenv -n sensor`; majestic 2>&1 | logger -p daemon.info -t majestic &") 619 | luci.http.redirect(luci.dispatcher.build_url("admin","ipcam","settings")) 620 | end 621 | 622 | return i 623 | 624 | 625 | --------------------------------------------------------------------------------
26 | 27 |