cjb 5 months ago
commit
cdd594e160

+ 35 - 0
BUILDss.gn

@@ -0,0 +1,35 @@
+import("//build/ohos.gni")
+config("it3256_controller_config") {
+  include_dirs = [
+    "include"
+  ]
+}
+ohos_executable("it3256_get_exe") {
+  sources = [
+    "src/main.cpp",
+    "src/command.cpp"
+  ]
+   cflags = [
+            "-Wno-error=delete-abstract-non-virtual-dtor",
+            "-Wno-error=unused-variable",
+            "-Wno-error=overloaded-virtual",
+            "-frtti",
+            "-Wno-error=pessimizing-move"
+        ]
+    cflags_c = []
+    cflags_cc = [
+        # "--verbose",
+        "-std=c++17",
+    ]
+    ldflags = [
+        "-lpthread"
+        ]
+  external_deps = [
+     "hilog:libhilog"
+     ]
+  configs = [ ":it3256_controller_config" ]
+  part_name = "sony_camera"
+  subsystem_name = "_mysubsystem"
+  install_enable = true  
+  install_images = [ "vendor" ] 
+}

+ 35 - 0
BUILDssss.gn

@@ -0,0 +1,35 @@
+import("//build/ohos.gni")
+config("it3256_config") {
+  include_dirs = [
+    "include",
+  ]
+}
+ohos_shared_library("it3256") {
+  sources = [
+    "src/uart.cpp",
+    "src/it32567.cpp",
+    "src/command.cpp"
+  ]
+   cflags = [
+            "-Wno-error=delete-abstract-non-virtual-dtor",
+            "-Wno-error=unused-variable",
+            "-Wno-error=overloaded-virtual",
+            "-frtti",
+            "-Wno-error=pessimizing-move"
+        ]
+    cflags_c = []
+    cflags_cc = [
+        # "--verbose",
+        "-std=c++17",
+    ]
+    ldflags = [
+        "-lpthread"
+        ]
+  configs = [ ":it3256_config" ]
+  external_deps = [
+     "hilog:libhilog",
+      "napi:ace_napi"
+     ]
+  part_name = "sony_camera"
+  subsystem_name = "_mysubsystem"
+}

+ 66 - 0
bundles.json

@@ -0,0 +1,66 @@
+{
+    "name" : "@ohos/sony_camera" ,
+    "description" : "sony camera",
+    "version" : "3.2",
+    "license" : "Apache License 2.0",
+    "publishAs" : "code-segment",
+    "segment" : {
+        "destPath" : "_mysubsystem/sonycamera"
+    },
+    "dirs" : {},
+    "scripts" : {},
+    "component":{
+        "name" : "sony_camera",
+        "subsystem" : "_mysubsystem",
+        "syscap" : [],
+        "features" : [],
+        "adapted_system_type" : ["mini","small","standard"],
+        "rom" : "100KB",
+        "ram" : "100KB",
+        "deps" : {
+            "components" : ["init","napi","hilog","common_event_service","ability_base","ipc","c_utils","samgr","safwk"],
+            "third_party" : [
+                "libusb"  
+            ]
+        },        
+        "build" : {
+           "group_type": {
+                "base_group": [
+
+                ],
+                "fwk_group": [
+                    "//_mysubsystem/sonycamera/ioc:it3256_inner",
+                    "//_mysubsystem/it3256/napi:it3256",
+                    "//_mysubsystem/it3256/core:it3256IO_core"
+
+                ],
+                "service_group": [
+                    "//_mysubsystem/it3256/service:it3256_service",
+                    "//_mysubsystem/it3256/sa_profile:it3256_sa_profile",
+                    "//_mysubsystem/it3256/etc/init:it3256IO.cfg"
+                ]
+            },
+            "inner_kits": [
+                {
+                "header": {
+                        "header_base" : "//_mysubsystem/it3256/core/include",
+                        "header_files": [
+                          "it3256_death_recipient.h",
+                          "it3256_proxy.h",
+                          "it3256_stub.h",
+                          "it3256_inter_face_code.h",
+                          "it3256_manager.h",
+                          "iit3256.h",
+                          "it3256_log.h",
+                          "it3256.h"
+                        ]
+                      },
+                      "name":"//_mysubsystem/it3256/core:it3256IO_core"
+                }
+                
+            ],
+            "test" : []
+        }
+
+    }
+}

+ 39 - 0
core/BUILD.gn

@@ -0,0 +1,39 @@
+import("//build/ohos.gni")
+config("it3256_core_config") {
+  include_dirs = [
+    "include"
+  ]
+}
+ohos_shared_library("it3256IO_core") {
+  sources = [
+   "src/it3256_stub.cpp",
+   "src/it3256_proxy.cpp",
+   "src/it3256.cpp",
+   "src/it3256_death_recipient.cpp",
+   "src/it3256_manager.cpp"
+  ]
+   cflags = [
+            "-Wno-error=delete-abstract-non-virtual-dtor",
+            "-Wno-error=unused-variable",
+            "-Wno-error=overloaded-virtual",
+            "-frtti",
+            "-Wno-error=pessimizing-move"
+        ]
+    cflags_c = []
+    cflags_cc = [
+        # "--verbose",
+        "-std=c++17",
+    ]
+    ldflags = [
+        "-lpthread"
+        ]
+ external_deps = [ 
+         "hilog:libhilog",
+         "ipc:ipc_core",
+         "c_utils:utils",
+         "samgr:samgr_proxy"
+  ]
+  configs = [ ":it3256_core_config" ]
+  part_name = "sony_camera"
+  subsystem_name = "_mysubsystem"
+}

+ 17 - 0
core/include/iit3256.h

@@ -0,0 +1,17 @@
+#ifndef IIT3256_H
+#define IIT3256_H
+
+#include "iremote_broker.h"
+#include "iremote_object.h"
+namespace OHOS{
+namespace It3256 {
+class IIt3256IO : public IRemoteBroker {
+public:
+    DECLARE_INTERFACE_DESCRIPTOR(u"ohos.IT3256.IIt3256IO");
+
+    virtual bool SetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf) = 0;
+    virtual bool GetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf) = 0;
+};
+}  // namespace It3256
+}
+#endif // IIT3256_H

+ 38 - 0
core/include/it3256.h

@@ -0,0 +1,38 @@
+#ifndef IT3256_H
+#define IT3256_H
+
+#include <map>
+#include <mutex>
+#include <thread>
+#include "iit3256.h"
+#include "it3256_death_recipient.h"
+
+namespace OHOS {
+namespace It3256 {
+
+class It3256IO {
+public:
+    It3256IO() = default;
+    ~It3256IO() = default;
+
+    bool SetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf);
+    bool GetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf);
+    void ResetIt3256IOProxy();
+    bool Reconnect();
+
+private:
+    static constexpr int32_t MAX_RETRY_TIME = 3;
+    bool GetIt3256IOProxy();
+    
+    std::mutex mutex_;
+    bool isProxyValid_ = false;
+    sptr<IIt3256IO> It3256IOProxy_;
+    sptr<It3256IODeathRecipient> recipient_;
+
+    friend class It3256IODeathRecipient;
+}; 
+
+} // namespace It3256
+} // namespace OHOS
+
+#endif  //IT3256_H

+ 19 - 0
core/include/it3256_death_recipient.h

@@ -0,0 +1,19 @@
+#ifndef IT3256_DEATH_RECIPIENT_H
+#define IT3256_DEATH_RECIPIENT_H
+
+#include "iremote_object.h"
+
+namespace OHOS {
+namespace It3256 {
+
+class It3256IODeathRecipient : public IRemoteObject::DeathRecipient {
+public:
+    It3256IODeathRecipient() = default;
+    virtual ~It3256IODeathRecipient() = default;
+    void OnRemoteDied(const wptr<IRemoteObject>& remote) override;
+};
+
+} // namespace It3256
+} // namespace OHOS
+
+#endif // IT3256_DEATH_RECIPIENT_H

+ 27 - 0
core/include/it3256_inter_face_code.h

@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FOUNDATION_IT3256_SERVICE_IPC_INTERFACE_H
+#define FOUNDATION_IT3256_SERVICE_IPC_INTERFACE_H
+namespace OHOS{
+/* SAID:3256 */
+namespace It3256{
+    enum class It3256IOInterfaceCode {
+        TRANS_ID_SETAIRANGE = 1,  // openSession()对应ID
+        TRANS_ID_GETAIRANGE = 2          // shoot()对应ID
+    };
+}  
+}
+#endif //FOUNDATION_IT3256_SERVICE_IPC_INTERFACE_H

+ 46 - 0
core/include/it3256_log.h

@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef It3256_LOG_H
+#define It3256_LOG_H
+
+#include "hilog/log.h"
+
+#ifndef It3256_LOG_DOMAIN
+#define It3256_LOG_DOMAIN 0xD001200
+#endif
+#ifndef It3256_LOG_TAG
+#define It3256_LOG_TAG "It3256"
+#endif
+
+#define CUR_FILE_NAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
+
+#define It3256_LOGF(fmt, ...)            \
+    ((void)HILOG_IMPL(LOG_CORE, LOG_FATAL, It3256_LOG_DOMAIN, It3256_LOG_TAG, \
+    "[%{public}s(%{public}s:%{public}d)]" fmt, CUR_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__))
+#define It3256_LOGE(fmt, ...)            \
+    ((void)HILOG_IMPL(LOG_CORE, LOG_ERROR, It3256_LOG_DOMAIN, It3256_LOG_TAG, \
+    "[%{public}s(%{public}s:%{public}d)]" fmt, CUR_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__))
+#define It3256_LOGW(fmt, ...)            \
+    ((void)HILOG_IMPL(LOG_CORE, LOG_WARN, It3256_LOG_DOMAIN, It3256_LOG_TAG, \
+    "[%{public}s(%{public}s:%{public}d)]" fmt, CUR_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__))
+#define It3256_LOGI(fmt, ...)            \
+    ((void)HILOG_IMPL(LOG_CORE, LOG_INFO, It3256_LOG_DOMAIN, It3256_LOG_TAG, \
+    "[%{public}s(%{public}s:%{public}d)]" fmt, CUR_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__))
+#define It3256_LOGD(fmt, ...)            \
+    ((void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, It3256_LOG_DOMAIN, It3256_LOG_TAG, \
+    "[%{public}s(%{public}s:%{public}d)]" fmt, CUR_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__))
+
+#endif  

+ 30 - 0
core/include/it3256_manager.h

@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "it3256.h"
+#ifndef FOUNDATION_IT3256_SERVICE_IPC_INTERFACE_H
+#define FOUNDATION_IT3256_SERVICE_IPC_INTERFACE_H
+
+namespace OHOS{
+namespace It3256 {
+class It3256IOManager {
+public:
+
+    static bool SetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf);
+ 
+    static bool GetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf);
+};
+}  // namespace EventFwk
+}
+#endif  // FOUNDATION_IT3256_SERVICE_IPC_INTERFACE_H

+ 24 - 0
core/include/it3256_proxy.h

@@ -0,0 +1,24 @@
+#ifndef IT3256_PROXY_H
+#define IT3256_PROXY_H
+
+#include "iit3256.h"
+#include "it3256_inter_face_code.h"
+#include "iremote_proxy.h"
+namespace OHOS{
+namespace It3256 {
+class It3256IOProxy : public IRemoteProxy<IIt3256IO> {
+public:
+    explicit It3256IOProxy(const sptr<IRemoteObject> &object);
+    virtual ~It3256IOProxy();
+
+    bool SetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf) override;
+    bool GetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf) override;
+
+private:
+    bool SendRequest(It3256IOInterfaceCode code, MessageParcel &data, MessageParcel &reply);
+    static inline BrokerDelegator<It3256IOProxy> delegator_;
+};
+}  // namespace It3256
+}
+
+#endif // IT3256_PROXY_H

+ 47 - 0
core/include/it3256_stub.h

@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ #ifndef It3256_STUB_H
+ #define It3256_STUB_H
+ 
+ #include "it3256_inter_face_code.h"
+ #include "iit3256.h"
+ #include "iremote_stub.h"
+ #include "nocopyable.h"
+ #include "message_parcel.h"
+ #include "message_option.h"
+ namespace OHOS{
+ namespace It3256 {
+ class It3256IOStub : public IRemoteStub<IIt3256IO> {
+ public:
+     It3256IOStub();
+     virtual ~It3256IOStub();
+     
+     int OnRemoteRequest(uint32_t code, 
+                        MessageParcel &data, 
+                        MessageParcel &reply, 
+                        MessageOption &option) override;
+ 
+     bool SetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf) override;
+     bool GetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf) override;
+ 
+ private:
+     DISALLOW_COPY_AND_MOVE(It3256IOStub);
+ };
+ } 
+}
+ 
+ #endif  // It3256_STUB_H
+ 

+ 106 - 0
core/src/it3256.cpp

@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "it3256.h"
+#include "it3256_log.h"
+#include "iservice_registry.h"
+#include "system_ability_definition.h"
+namespace OHOS{
+namespace It3256 {
+bool It3256IO::SetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf)
+{
+    if (!GetIt3256IOProxy()) {
+        It3256_LOGI("Failed to get It3256IO proxy");
+        return false;
+    }
+    It3256_LOGI("succed to get It3256IO proxy");
+    return It3256IOProxy_->SetAIRangeCode(startch,  stopch, poutbuf);
+}
+
+bool It3256IO::GetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf)
+{
+    if (!GetIt3256IOProxy()) {
+        It3256_LOGI("Failed to get It3256IO proxy");
+        return false;
+    }
+    return It3256IOProxy_->GetAIRangeCode(startch,  stopch, poutbuf);
+} 
+
+void It3256IO::ResetIt3256IOProxy()
+{
+    It3256_LOGI("enter");
+    std::lock_guard<std::mutex> lock(mutex_);
+    isProxyValid_ = false;
+    if ((It3256IOProxy_ == nullptr) || (It3256IOProxy_->AsObject() == nullptr)) {
+        It3256_LOGI("invalid proxy state");
+        return;
+    }
+    It3256IOProxy_->AsObject()->RemoveDeathRecipient(recipient_);
+}
+
+bool It3256IO::Reconnect()
+{
+    It3256_LOGI("enter");
+    for (int32_t i = 0; i < MAX_RETRY_TIME; i++) {
+        // Sleep 1000 milliseconds before reconnect.
+        std::this_thread::sleep_for(std::chrono::milliseconds(1000));
+        // try to connect ces
+        if (!GetIt3256IOProxy()) {
+            It3256_LOGI("get ces proxy fail, try again.");
+            continue;
+        }
+        It3256_LOGI("get ces proxy success.");
+        return true;
+    }
+
+    return false;
+}
+bool It3256IO::GetIt3256IOProxy()
+{
+    if (!It3256IOProxy_ || !isProxyValid_) {
+        std::lock_guard<std::mutex> lock(mutex_);
+        if (!It3256IOProxy_ || !isProxyValid_) {
+            sptr<ISystemAbilityManager> systemAbilityManager =
+                SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
+            if (!systemAbilityManager) {
+                It3256_LOGI("Failed to get system ability mgr.");
+                return false;
+            }
+
+            sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(It3256IO_SERVICE_ID);
+            if (!remoteObject) {
+                It3256_LOGI("Failed to get It3256IO Manager.");
+                return false;
+            }
+
+            It3256IOProxy_ = iface_cast<IIt3256IO>(remoteObject);
+            if ((!It3256IOProxy_) || (!It3256IOProxy_->AsObject())) {
+                It3256_LOGI("Failed to get It3256IO Manager's proxy");
+                return false;
+            }
+
+            recipient_ = new (std::nothrow) It3256IODeathRecipient();
+            if (!recipient_) {
+                It3256_LOGI("Failed to create death Recipient ptr It3256IODeathRecipient!");
+                return false;
+            }
+            It3256IOProxy_->AsObject()->AddDeathRecipient(recipient_);
+            isProxyValid_ = true;
+        }
+    }
+    return true;
+}
+}
+}

+ 21 - 0
core/src/it3256_death_recipient.cpp

@@ -0,0 +1,21 @@
+#include "it3256_death_recipient.h"
+#include "singleton.h"
+#include "it3256.h"
+namespace OHOS{
+namespace It3256 {
+
+void It3256IODeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
+{
+    // 使用 OHOS::DelayedSingleton
+    auto it3256IO = DelayedSingleton<It3256IO>::GetInstance();
+
+    // 调用 It3256IO 的方法
+    it3256IO->ResetIt3256IOProxy();
+
+    if (it3256IO->Reconnect()) {
+        return;
+    }
+}
+
+} // namespace It3256
+}

+ 30 - 0
core/src/it3256_manager.cpp

@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include "it3256_manager.h"
+#include "singleton.h"
+namespace OHOS{
+namespace It3256{
+bool It3256IOManager::SetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf)
+{
+    return DelayedSingleton<It3256IO>::GetInstance()->SetAIRangeCode(startch,  stopch, poutbuf);
+}
+bool It3256IOManager::GetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf)
+{
+    return DelayedSingleton<It3256IO>::GetInstance()->GetAIRangeCode(startch,  stopch, poutbuf);
+}
+} 
+}

+ 94 - 0
core/src/it3256_proxy.cpp

@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ #include "it3256.h"
+ #include "it3256_log.h"
+ #include "it3256_proxy.h"
+#include "string_ex.h"
+ 
+ namespace OHOS {
+ namespace It3256 {
+ 
+ It3256IOProxy::It3256IOProxy(const sptr<IRemoteObject> &object)
+     : IRemoteProxy<IIt3256IO>(object)
+ {
+     It3256_LOGI("It3256IOProxy instance created");
+ }
+ 
+ It3256IOProxy::~It3256IOProxy()
+ {
+     It3256_LOGI("It3256IOProxy instance destroyed");
+ }
+ 
+ bool It3256IOProxy::SetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf)
+ {
+     MessageParcel data;
+     MessageParcel reply;
+ 
+     if (!data.WriteUint8(startch) || !data.WriteUint8(stopch)) {
+         It3256_LOGI("Failed to write params");
+         return false;
+     }
+     It3256_LOGI("scuccess to write params");
+     bool ret = SendRequest(It3256IOInterfaceCode::TRANS_ID_SETAIRANGE, data, reply);
+     if (ret) {
+         ret = reply.ReadBool();
+         if (ret && poutbuf != nullptr) {
+             *poutbuf = reply.ReadUint8();
+         }
+     }
+     return ret;
+ }
+ 
+ bool It3256IOProxy::GetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf)
+ {
+     MessageParcel data;
+     MessageParcel reply;
+ 
+     if (!data.WriteUint8(startch) || !data.WriteUint8(stopch)) {
+         It3256_LOGI("Failed to write params");
+         return false;
+     }
+ 
+     bool ret = SendRequest(It3256IOInterfaceCode::TRANS_ID_GETAIRANGE, data, reply);
+     if (ret) {
+         ret = reply.ReadBool();
+         if (ret && poutbuf != nullptr) {
+             *poutbuf = reply.ReadUint8();
+         }
+     }
+     return ret;
+ }
+ 
+ bool It3256IOProxy::SendRequest(It3256IOInterfaceCode code, MessageParcel &data, MessageParcel &reply)
+ {
+     MessageOption option;
+     sptr<IRemoteObject> remote = Remote();
+     if (remote == nullptr) {
+         It3256_LOGE("Remote object is null");
+         return false;
+     }
+ 
+     int32_t result = remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
+     if (result != ERR_NONE) {
+         It3256_LOGE("SendRequest failed, error code: %d", result);
+         return false;
+     }
+     return true;
+ }
+ 
+ } // namespace It3256
+ } // namespace OHOS
+ 

+ 80 - 0
core/src/it3256_stub.cpp

@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "it3256_stub.h"
+#include "it3256_log.h"
+#include "string_ex.h"
+namespace OHOS{
+namespace It3256 {
+
+It3256IOStub::It3256IOStub()
+{}
+
+It3256IOStub::~It3256IOStub()
+{}
+
+int It3256IOStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
+{
+    /*if (data.ReadInterfaceToken() != GetDescriptor()) {
+        It3256_LOGI("local descriptor is not equal to remote");
+        return ERR_TRANSACTION_FAILED;
+    }*/
+    It3256_LOGI("OnRemoteRequest code:%{public}u", code);
+    switch (code) {
+        case static_cast<uint32_t>(It3256IOInterfaceCode::TRANS_ID_SETAIRANGE): {
+            unsigned char startch = data.ReadUint8();
+            unsigned char stopch = data.ReadUint8();
+            unsigned char outbuf = 0;
+            bool ret = SetAIRangeCode(startch, stopch, &outbuf);
+            if (!reply.WriteBool(ret) || !reply.WriteUint8(outbuf)) {
+                It3256_LOGI("Failed to write reply");
+                return -1;
+            }
+            break;
+        }
+        case static_cast<uint32_t>(It3256IOInterfaceCode::TRANS_ID_GETAIRANGE): {
+            unsigned char startch = data.ReadUint8();
+            unsigned char stopch = data.ReadUint8();
+            unsigned char outbuf = 0;
+            bool ret = GetAIRangeCode(startch, stopch, &outbuf);
+            if (!reply.WriteBool(ret) || !reply.WriteUint8(outbuf)) {
+                It3256_LOGI("Failed to write reply");
+                return -1;
+            }
+            break;
+        }
+        default:
+            return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
+    }
+    return 0;
+}
+
+
+
+bool It3256IOStub::SetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf)
+{
+   
+    return true;
+}
+
+
+bool It3256IOStub::GetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf)
+{
+   
+
+    return true;
+}
+} 
+}

+ 23 - 0
etc/init/BUILD.gn

@@ -0,0 +1,23 @@
+# Copyright (C) 2021 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build/ohos.gni")
+
+################################################################################
+
+ohos_prebuilt_etc("it3256IO.cfg") {
+  source = "it3256IO.cfg"
+  relative_install_dir = "init"
+  part_name = "sony_camera"
+  subsystem_name = "_mysubsystem"
+}

+ 21 - 0
etc/init/inputmethodservice.rc

@@ -0,0 +1,21 @@
+# Copyright (C) 2021 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+on boot
+    start inputmethod_service
+service inputmethod_service /system/bin/sa_main /system/profile/inputmethod_service.json
+    class z_core
+    user system
+    group system shell
+    capabilities SYS_TIME
+    seclabel u:r:time_service:s0

+ 17 - 0
etc/init/it3256IO.cfg

@@ -0,0 +1,17 @@
+{
+    "jobs" : [{
+            "name" : "early-boot",
+            "cmds" : []
+        }
+    ],
+    "services" : [{
+            "name" : "it3256IO_service",
+            "path" : ["/system/bin/sa_main", "/system/profile/it3256_sa_profile.json"],
+            "uid" : "it3256IO",
+            "gid" : ["it3256IO", "shell"],
+            "permission" : [],
+            "caps" : [],
+            "secon" : "u:r:it3256IO_service:s0"
+        }
+    ]
+}

+ 27 - 0
etc/para/BUILD.gn

@@ -0,0 +1,27 @@
+# Copyright (C) 2022 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//base/inputmethod/imf/inputmethod.gni")
+import("//build/ohos.gni")
+
+ohos_prebuilt_etc("inputmethod.para") {
+  source = "//base/inputmethod/imf/etc/para/inputmethod.para"
+  part_name = "imf"
+  module_install_dir = "etc/param"
+}
+
+ohos_prebuilt_etc("inputmethod.para.dac") {
+  source = "//base/inputmethod/imf/etc/para/inputmethod.para.dac"
+  part_name = "imf"
+  module_install_dir = "etc/param"
+}

+ 14 - 0
etc/para/inputmethod.para

@@ -0,0 +1,14 @@
+# Copyright (C) 2022 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+persist.sys.default_ime=com.example.kikakeyboard/ServiceExtAbility

+ 14 - 0
etc/para/inputmethod.para.dac

@@ -0,0 +1,14 @@
+# Copyright (C) 2022 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+persist.sys.default_ime = inputmethod:inputmethod:0444

+ 37 - 0
napi/BUILD.gn

@@ -0,0 +1,37 @@
+import("//build/ohos.gni")
+config("it3256_napi_config") {
+  include_dirs = [
+    "include",
+    "//_mysubsystem/it3256/core/include"
+  ]
+}
+
+ohos_shared_library("it3256") {
+  sources = [
+    "src/it3256_napi.cpp",
+    "src/uart.cpp"
+  ]
+   cflags = [
+            "-Wno-error=delete-abstract-non-virtual-dtor",
+            "-Wno-error=unused-variable",
+            "-Wno-error=overloaded-virtual",
+            "-frtti",
+            "-Wno-error=pessimizing-move"
+        ]
+    cflags_c = []
+    cflags_cc = [
+        # "--verbose",
+        "-std=c++17",
+    ]
+    ldflags = [
+        "-lpthread"
+        ]
+  configs = [ ":it3256_napi_config" ]
+  external_deps = [ 
+         "napi:ace_napi",
+         "hilog:libhilog"
+     ]
+  deps = ["//_mysubsystem/it3256/core:it3256IO_core"]
+  part_name = "sony_camera"
+  subsystem_name = "_mysubsystem"
+}

File diff suppressed because it is too large
+ 1005 - 0
napi/include/advio.h


+ 46 - 0
napi/include/camera_log.h

@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FOUNDATION_IT3256_COMMON_LOG_INCLUDE_IT3256_LOG_WRAPPER_H
+#define FOUNDATION_IT3256_COMMON_LOG_INCLUDE_IT3256_LOG_WRAPPER_H
+
+#include "hilog/log.h"
+
+#ifndef IT3256_LOG_DOMAIN
+#define IT3256_LOG_DOMAIN 0xD001200
+#endif
+#ifndef IT3256_LOG_TAG
+#define IT3256_LOG_TAG "IT3256"
+#endif
+
+#define CUR_FILE_NAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
+
+#define  IT3256_LOGF(fmt, ...)            \
+    ((void)HILOG_IMPL(LOG_CORE, LOG_FATAL,  IT3256_LOG_DOMAIN,  IT3256_LOG_TAG, \
+    "[%{public}s(%{public}s:%{public}d)]" fmt, CUR_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__))
+#define  IT3256_LOGE(fmt, ...)            \
+    ((void)HILOG_IMPL(LOG_CORE, LOG_ERROR,  IT3256_LOG_DOMAIN,  IT3256_LOG_TAG, \
+    "[%{public}s(%{public}s:%{public}d)]" fmt, CUR_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__))
+#define  IT3256_LOGW(fmt, ...)            \
+    ((void)HILOG_IMPL(LOG_CORE, LOG_WARN,  IT3256_LOG_DOMAIN,  IT3256_LOG_TAG, \
+    "[%{public}s(%{public}s:%{public}d)]" fmt, CUR_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__))
+#define  IT3256_LOGI(fmt, ...)            \
+    ((void)HILOG_IMPL(LOG_CORE, LOG_INFO,  IT3256_LOG_DOMAIN,  IT3256_LOG_TAG, \
+    "[%{public}s(%{public}s:%{public}d)]" fmt, CUR_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__))
+#define  IT3256_LOGD(fmt, ...)            \
+    ((void)HILOG_IMPL(LOG_CORE, LOG_DEBUG,  IT3256_LOG_DOMAIN,  IT3256_LOG_TAG, \
+    "[%{public}s(%{public}s:%{public}d)]" fmt, CUR_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__))
+
+#endif  // FOUNDATION_ IT3256_COMMON_LOG_INCLUDE_ IT3256_LOG_WRAPPER_H

+ 35 - 0
napi/include/command.h

@@ -0,0 +1,35 @@
+#include <cstdint>
+#include <map>
+#include <iostream>
+#include <cstring>
+#include <cstdio>
+#include <string>
+#include <memory>
+#include "camera_log.h"
+class CommandExecutor
+{
+private:
+static std::string executeCommand(const std::string &command)
+    {
+        // 使用 popen 执行命令并捕获其输出
+        std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(command.c_str(), "r"), pclose);
+        if (!pipe)
+        {   
+            IT3256_LOGI("it3256 Failed to execute command %{public}s", command.c_str());
+            std::cerr << ": Failed to execute command: " << command << std::endl;
+            return "-1";
+        }
+        // 读取命令的输出
+        char buffer[128];
+        std::string result;
+        while (fgets(buffer, sizeof(buffer), pipe.get()) != nullptr)
+        {
+            result += buffer;
+        }
+        IT3256_LOGI("it3256 success to execute command %{public}s", result.c_str());
+        return result;
+    }
+
+public:
+    static int getAIRange(unsigned char startChannel, unsigned char stopChannel, unsigned char *poutbuf);
+};

+ 34 - 0
napi/include/uart.h

@@ -0,0 +1,34 @@
+// uart_lib.h
+#ifndef UART_LIB_H
+#define UART_LIB_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stddef.h>
+#include <unistd.h> /*Unix 标准函数定义*/
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>   /*文件控制定义*/
+#include <termios.h> /*POSIX 终端控制定义*/
+#include <errno.h>   /*错误号定义*/
+#include <string.h>  /*字符串功能函数*/
+#include <stdio.h>   /* perror */
+
+typedef int UART_HANDLE;
+extern const UART_HANDLE UART_INVALID_HANDLE;
+
+// 初始化/反初始化
+UART_HANDLE UartInit(const char *dev, int baudrate, int byteSize, int stopBits, int parity);
+int UartUninit(UART_HANDLE handle);
+
+// 数据收发
+int UartSend(UART_HANDLE handle, const void *buf, size_t size);
+int UartRecv(UART_HANDLE handle, void *buf, size_t size);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // UART_LIB_H

+ 42 - 0
napi/src/command.cpp

@@ -0,0 +1,42 @@
+#include "command.h"
+#include <cstdio>
+#include <cstring>
+#include <string> 
+#include <stdexcept>
+#include "camera_log.h"
+int CommandExecutor::getAIRange(unsigned char startChannel, unsigned char stopChannel, unsigned char *poutbuf)
+{
+    std::string command = "/vendor/bin/aigetrange " + std::to_string(startChannel) + " " + std::to_string(stopChannel);
+
+    // 执行命令并获取输出
+    IT3256_LOGI("it3256 AdvioDevGetAIRangeCode2 %{public}u", startChannel);
+    IT3256_LOGI("it3256 AdvioDevGetAIRangeCode2 %{public}u", stopChannel);
+    IT3256_LOGI("it3256 AdvioDevGetAIRangeCode2 %{public}s", command.c_str());
+    std::string output = executeCommand(command);
+    IT3256_LOGI("it3256 AdvioDevGetAIRangeCode2 %{public}s", output.c_str());
+    // 处理输出
+    if (output == "-1")
+    {
+        return -1; // 命令返回错误
+    }
+    unsigned int value1, value2;
+    if (sscanf(output.c_str(), "%x %x", &value1, &value2) == 2) {
+        // 根据规则存储结果
+        IT3256_LOGI("value1: 0x%{public}x, value2: 0x%{public}x", value1, value2);
+        if (value1 == 0x149) {  // 使用十六进制常量
+            poutbuf[0] = 0;
+        } else if (value1 == 0x182) {  // 使用十六进制常量
+            poutbuf[0] = 1;
+        }
+        if (value2 == 0x149) {  // 使用十六进制常量
+            poutbuf[1] = 0;
+        } else if (value2 == 0x182) {  // 使用十六进制常量
+            poutbuf[1] = 1;
+        }
+        return 0; // 成功
+    }
+    else
+    {
+        return -1; // 输出格式错误
+    }
+}

+ 43 - 0
napi/src/init.cpp

@@ -0,0 +1,43 @@
+
+
+#include "camera_napi.h"
+#include "napi/native_api.h"
+#include "napi/native_node_api.h"
+
+namespace CameraNapi {
+EXTERN_C_START
+
+/*
+ * Module export function
+ */
+static napi_value Init(napi_env env, napi_value exports)
+{
+    /*
+     * Initialize camera module
+     */
+     CameraInit(env, exports);
+     return exports;
+}
+EXTERN_C_END
+
+/*
+ * Module define
+ */
+static napi_module _module = {
+    .nm_version = 1,
+    .nm_flags = 0,
+    .nm_filename = nullptr,
+    .nm_register_func = Init,
+    .nm_modname = "sonycameracontrol",  // 模块名称,在JS中引用时使用
+    .nm_priv = ((void *)0),
+    .reserved = {0}
+};
+
+/*
+ * Module register function
+ */
+extern "C" __attribute__((constructor)) void RegisterModule(void)
+{
+    napi_module_register(&_module);
+}
+}  // namespace SonyCameraNapi

File diff suppressed because it is too large
+ 1013 - 0
napi/src/it3256.cpp


+ 288 - 0
napi/src/it3256_napi.cpp

@@ -0,0 +1,288 @@
+#include "napi/native_api.h"
+#include "napi/native_node_api.h"
+#include "uart.h"
+#include <bits/alltypes.h>
+#include <stdlib.h>
+#include "command.h"
+#include "camera_log.h"
+#include "it3256_manager.h"
+using namespace OHOS::HiviewDFX;
+using namespace OHOS::It3256;
+typedef struct {
+    UART_HANDLE handle;
+} UartHandleWrapper;
+enum UartErrorCode { INVALID_ARGUMENT = -1, INTERNAL_INTERFACE_ERROR = -2, CREATE_ERROR = -3 };
+
+static napi_value AdvioDevGetAIRangeCode(napi_env env, napi_callback_info info) {
+    size_t argc = 2;
+    napi_value args[2];
+    IT3256_LOGI("it3256 AdvioDevGetAIRangeCode");
+    napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
+
+    if (argc != 2) {
+        napi_throw_error(env, "INVALID_ARGUMENTS", "Invalid arguments passed to the function");
+        return nullptr;
+    }
+    unsigned char startch, stopch;
+    uint32_t tmp;
+    if (napi_get_value_uint32(env, args[0], &tmp) != napi_ok || tmp > 0xFF) {
+        napi_throw_error(env, "INVALID_ARGUMENTS", "Invalid arguments passed to the function");
+        return nullptr;
+    }
+    startch = static_cast<unsigned char>(tmp);
+
+    if (napi_get_value_uint32(env, args[1], &tmp) != napi_ok || tmp > 0xFF || tmp < startch) {
+        napi_throw_error(env, "INVALID_ARGUMENTS", "Invalid arguments passed to the function");
+        return nullptr;
+    }
+    stopch = static_cast<unsigned char>(tmp);
+    const uint32_t channelCount = stopch - startch + 1;
+    const size_t bufferSize = channelCount * 2;
+
+    void *bufferData;
+    napi_value arrayBuffer;
+    if (napi_create_arraybuffer(env, bufferSize, &bufferData, &arrayBuffer) != napi_ok) {
+        napi_throw_error(env, "INVALID_ARGUMENTS", "Invalid arguments passed to the function");
+        return nullptr;
+    }
+    napi_value typedArray;
+    if (napi_create_typedarray(env, napi_uint8_array, bufferSize, arrayBuffer, 0, &typedArray) != napi_ok) {
+        napi_throw_error(env, "INVALID_ARGUMENTS", "Invalid arguments passed to the function");
+        return nullptr;
+    }
+
+    bool result = It3256IOManager::GetAIRangeCode(startch, stopch, static_cast<unsigned char *>(bufferData));
+    if (result == 0) {
+        return typedArray;
+    } else {
+        char errorMessage[64];  
+        snprintf(errorMessage, sizeof(errorMessage), "Operation failed with code: %u", result);
+        napi_throw_error(env, "OPERATION_FAILED", errorMessage);
+        return nullptr;
+    }
+}
+
+
+static napi_value AdvioDevSetAIRangeCode(napi_env env, napi_callback_info info) {
+    size_t argc = 3;
+    napi_value args[3];
+    napi_value ret;
+    napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
+
+    if (argc != 3) {
+        napi_throw_error(env, "INVALID_ARGUMENTS", "Invalid arguments passed to the function");
+        return nullptr;
+    }
+
+    unsigned char startch, stopch;
+    uint32_t tmp;
+    if (napi_get_value_uint32(env, args[0], &tmp) != napi_ok || tmp > 0xFF) {
+        napi_throw_error(env, "INVALID_ARGUMENTS", "Invalid arguments passed to the function");
+        return nullptr;
+    }
+    startch = static_cast<unsigned char>(tmp);
+
+    if (napi_get_value_uint32(env, args[1], &tmp) != napi_ok || tmp > 0xFF || tmp < startch) {
+        napi_throw_error(env, "INVALID_ARGUMENTS", "Invalid arguments passed to the function");
+        return nullptr;
+    }
+    stopch = static_cast<unsigned char>(tmp);
+
+    const uint32_t channelCount = stopch - startch + 1;
+    const size_t bufferSize = channelCount * 2;
+
+    napi_typedarray_type array_type;
+    size_t length;
+    void *data;
+    napi_value buffer;
+    size_t byte_offset;
+    if (napi_get_typedarray_info(env, args[2], &array_type, &length, &data, &buffer, &byte_offset) != napi_ok) {
+        napi_throw_error(env, "INVALID_ARGUMENTS", "Invalid arguments passed to the function");
+        return nullptr;
+    }
+    if (array_type != napi_uint8_array || bufferSize != length) {
+        napi_throw_error(env, "INVALID_ARGUMENTS", "Invalid arguments passed to the function");
+        return nullptr;
+    }
+    bool result = It3256IOManager::SetAIRangeCode(startch, stopch, static_cast<unsigned char *>(data));
+    if (result == 0) {
+        napi_create_int32(env, result, &ret);
+    } else {
+        char errorMessage[64];  
+        snprintf(errorMessage, sizeof(errorMessage), "Operation failed with code: %u", result);
+        napi_throw_error(env, "OPERATION_FAILED", errorMessage);
+        return nullptr;
+    }
+    return ret;
+}
+
+
+
+static napi_value UartInit(napi_env env, napi_callback_info info) {
+    size_t argc = 5;
+    napi_value args[5];
+    napi_value ret;
+
+    napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
+    if (argc < 5) {
+        napi_throw_error(env, "INVALID_ARGUMENTS", "Invalid arguments passed to the function");
+        return nullptr;
+    }
+
+    napi_valuetype types[5];
+    for (int i = 0; i < 5; ++i) {
+        napi_typeof(env, args[i], &types[i]);
+    }
+
+    if (types[0] != napi_string || types[1] != napi_number || types[2] != napi_number || types[3] != napi_number ||
+        types[4] != napi_number) {
+        napi_throw_error(env, "INVALID_ARGUMENTS", "Invalid arguments passed to the function");
+        return nullptr;
+    }
+
+    char dev[32];
+    size_t str_len;
+    int baudrate, byteSize, stopBits, parity;
+
+    napi_get_value_string_utf8(env, args[0], dev, sizeof(dev), &str_len);
+    napi_get_value_int32(env, args[1], &baudrate);
+    napi_get_value_int32(env, args[2], &byteSize);
+    napi_get_value_int32(env, args[3], &stopBits);
+    napi_get_value_int32(env, args[4], &parity);
+
+    UART_HANDLE handle = UartInit(dev, baudrate, byteSize, stopBits, parity);
+    napi_create_int32(env, handle, &ret);
+    return ret;
+}
+
+static napi_value UartSend(napi_env env, napi_callback_info info) {
+    size_t argc = 2;
+    napi_value args[2];
+    napi_value ret;
+    napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
+    if (argc != 2) {
+         //OH_LOG_ERROR(LOG_APP, "Invalid arguments");
+        napi_create_int32(env, INVALID_ARGUMENT, &ret);
+        return ret;
+    }
+    int32_t handle;
+    if (napi_get_value_int32(env, args[0], &handle) != napi_ok) {
+         //OH_LOG_ERROR(LOG_APP, "Invalid arguments");
+        napi_create_int32(env, INVALID_ARGUMENT, &ret);
+        return ret;
+    }
+
+    napi_typedarray_type array_type;
+    size_t array_length;
+    void *data;
+    napi_value buffer;
+    size_t byte_offset;
+    if (napi_get_typedarray_info(env, args[1], &array_type, &array_length, &data, &buffer, &byte_offset) != napi_ok) {
+         //OH_LOG_ERROR(LOG_APP, "Invalid arguments");
+        napi_create_int32(env, INVALID_ARGUMENT, &ret);
+        return ret;
+    }
+    if (array_type != napi_uint8_array) {
+         //OH_LOG_ERROR(LOG_APP, "array_type is uint8_array");
+        napi_create_int32(env, INVALID_ARGUMENT, &ret);
+        return ret;
+    }
+    uint8_t *byteArray = (uint8_t *)data;
+    size_t result = UartSend(handle, byteArray, array_length);
+    if (result != array_length ) {
+         //OH_LOG_ERROR(LOG_APP, "Send failed");
+        napi_create_int32(env, INTERNAL_INTERFACE_ERROR, &ret);
+        return ret;
+    }
+    napi_create_int32(env, result, &ret);
+    return ret;
+}
+
+static napi_value UartRecv(napi_env env, napi_callback_info info) {
+    size_t argc = 2;
+    napi_value args[2];
+    napi_value ret;
+
+    napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
+    if (argc < 2) {
+         //OH_LOG_ERROR(LOG_APP, "Invalid arguments");
+        napi_create_int32(env, INVALID_ARGUMENT, &ret);
+        return ret;
+    }
+
+    int32_t handle;
+    if (napi_get_value_int32(env, args[0], &handle) != napi_ok) {
+         //OH_LOG_ERROR(LOG_APP, "Invalid arguments");
+        napi_create_int32(env, INVALID_ARGUMENT, &ret);
+        return ret;
+    }
+
+    void *buffer_data;
+    size_t buffer_length;
+    if (napi_get_buffer_info(env, args[1], &buffer_data, &buffer_length) != napi_ok) {
+         //OH_LOG_ERROR(LOG_APP, "Invalid arguments");
+        napi_create_int32(env, INVALID_ARGUMENT, &ret);
+        return ret;
+    }
+
+    int result = UartRecv(handle, buffer_data, buffer_length);
+    if (result > 0) {
+        napi_create_int32(env, result, &ret);
+    } else {
+         //OH_LOG_ERROR(LOG_APP, "Receive failed");
+        napi_create_int32(env, INTERNAL_INTERFACE_ERROR, &ret);
+    }
+    return ret;
+}
+
+static napi_value UartUninit(napi_env env, napi_callback_info info) {
+    size_t argc = 1;
+    napi_value args[1];
+    napi_value ret;
+
+    napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
+    if (argc < 1) {
+         //OH_LOG_ERROR(LOG_APP, "Invalid arguments");
+        napi_create_int32(env, INVALID_ARGUMENT, &ret);
+        return ret;
+    }
+    int32_t handle;
+    if (napi_get_value_int32(env, args[0], &handle) != napi_ok) {
+         //OH_LOG_ERROR(LOG_APP, "Invalid arguments");
+        napi_create_int32(env, INVALID_ARGUMENT, &ret);
+        return ret;
+    }
+
+    int result = UartUninit(handle);
+
+    napi_create_int32(env, result, &ret);
+    return ret;
+}
+
+EXTERN_C_START
+static napi_value Init(napi_env env, napi_value exports) {
+    napi_property_descriptor desc[] = {
+        {"uartInit", nullptr, UartInit, nullptr, nullptr, nullptr, napi_default, nullptr},
+        {"uartSend", nullptr, UartSend, nullptr, nullptr, nullptr, napi_default, nullptr},
+        {"uartRecv", nullptr, UartRecv, nullptr, nullptr, nullptr, napi_default, nullptr},
+        {"uartUninit", nullptr, UartUninit, nullptr, nullptr, nullptr, napi_default, nullptr},
+        {"devGetAIRangeCode", nullptr, AdvioDevGetAIRangeCode, nullptr, nullptr, nullptr, napi_default, nullptr},
+        {"devSetAIRangeCode", nullptr, AdvioDevSetAIRangeCode, nullptr, nullptr, nullptr, napi_default, nullptr},
+    };
+    napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
+    return exports;
+}
+EXTERN_C_END
+
+// 模块定义
+static napi_module demoModule = {
+    .nm_version = 1,
+    .nm_flags = 0,
+    .nm_filename = nullptr,
+    .nm_register_func = Init,
+    .nm_modname = "it3256",
+    .nm_priv = ((void *)0),
+    .reserved = {0},
+};
+
+extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); }

+ 35 - 0
napi/src/main.cpp

@@ -0,0 +1,35 @@
+
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include "command.h"
+
+#define DO_CH_NUM 14
+
+int main(int argc, char *argv[])
+{
+    unsigned char startChannel = 0;
+    unsigned char stopChannel = 1;
+    unsigned char *poutbuf = new unsigned char[2]{0, 0};
+    int result = CommandExecutor::getAIRange(startChannel, stopChannel, poutbuf);
+
+    // 检查返回值
+    if (result != 0) {
+        printf("Error: getAIRange failed with code %d\n", result);
+        return result;
+    }
+
+    // 检查 poutbuf 是否为空
+    if (poutbuf == nullptr) {
+        printf("Error: poutbuf is null\n");
+        return -1;
+    }
+
+    // 打印 poutbuf 的值
+    printf("poutbuf[0] = %u, poutbuf[1] = %u\n", poutbuf[0], poutbuf[1]);
+
+    // 释放 poutbuf 的内存(假设 CommandExecutor::getAIRange 分配了内存)
+    delete[] poutbuf;
+
+    return 0;
+}

+ 207 - 0
napi/src/uart.cpp

@@ -0,0 +1,207 @@
+//
+// Created on 2025-01-03.
+//
+// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
+// please include "napi/native_api.h".
+
+#include "uart.h"
+#include <unistd.h>
+#include <errno.h>
+#include <iomanip>
+#include <map>
+#include <algorithm>
+#include <cctype>
+
+
+// 类型别名增强可读性
+using UART_HANDLE = int;
+const UART_HANDLE UART_INVALID_HANDLE = -1;
+
+// 设备映射表(建议改为const静态初始化)
+static const std::map<std::string, std::string> UART_DEV_MAP = {
+    {"com1", "/dev/ttyS4"},          // 根据实际设备调整
+    {"com2", "/dev/ttyS5"},
+    {"com3", "/dev/ttyS7"},
+    {"com4", "/dev/ttyS3"},
+    {"com5", "/dev/ttyCH343USB0"},
+    {"com6", "/dev/ttyCH343USB1"},
+    {"com7", "/dev/ttyCH343USB2"},
+    {"com8", "/dev/ttyCH343USB3"}
+};
+
+// 波特率转换辅助函数
+static speed_t _get_baud_rate(int baudrate) {
+    switch (baudrate) {
+        case 9600:    return B9600;
+        case 19200:   return B19200;
+        case 38400:   return B38400;
+        case 57600:   return B57600;
+        case 115200:  return B115200;
+        case 230400:  return B230400;
+        case 460800:  return B460800;
+        case 921600:  return B921600;
+        default:      return B115200; // 默认值
+    }
+}
+
+UART_HANDLE UartInit(const char *dev, int baudrate, int byteSize, 
+                     int stopBits, int parity) {
+    // 参数校验
+    if (!dev || baudrate <= 0 || byteSize < 5 || byteSize > 8 ||
+        stopBits < 1 || stopBits > 2 || parity < 0 || parity > 2) {
+        return UART_INVALID_HANDLE;
+    }
+
+    // 查找设备路径(统一小写处理)
+    std::string devKey(dev);
+    std::transform(devKey.begin(), devKey.end(), devKey.begin(), ::tolower);
+    auto it = UART_DEV_MAP.find(devKey);
+    if (it == UART_DEV_MAP.end()) {
+        return UART_INVALID_HANDLE;
+    }
+    const std::string& devPath = it->second;
+
+    // 打开设备(非阻塞模式打开,配置完成后切回阻塞)
+    int fd = open(devPath.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK);
+    if (fd < 0) {
+        return UART_INVALID_HANDLE;
+    }
+
+    // 获取当前配置
+    struct termios options;
+    if (tcgetattr(fd, &options) != 0) {
+        close(fd); // 修复资源泄漏
+        return UART_INVALID_HANDLE;
+    }
+
+    //---------------- 核心配置开始 ----------------
+    // 1. 基本模式配置
+    cfmakeraw(&options); // 原始模式
+    options.c_cflag |= (CLOCAL | CREAD);
+
+    // 2. 波特率
+    speed_t speed = _get_baud_rate(baudrate);
+    cfsetispeed(&options, speed);
+    cfsetospeed(&options, speed);
+
+    // 3. 数据位
+    options.c_cflag &= ~CSIZE;
+    switch (byteSize) {
+        case 5: options.c_cflag |= CS5; break;
+        case 6: options.c_cflag |= CS6; break;
+        case 7: options.c_cflag |= CS7; break;
+        case 8: options.c_cflag |= CS8; break;
+        default: options.c_cflag |= CS8; // 默认8位
+    }
+
+    // 4. 停止位
+    if (stopBits == 2) {
+        options.c_cflag |= CSTOPB;
+    } else {
+        options.c_cflag &= ~CSTOPB;
+    }
+
+    // 5. 校验位
+    if (parity != 0) { // 0:无校验 1:奇校验 2:偶校验
+        options.c_cflag |= PARENB;
+        if (parity == 1) {
+            options.c_cflag |= PARODD;
+        } else {
+            options.c_cflag &= ~PARODD;
+        }
+    } else {
+        options.c_cflag &= ~PARENB;
+    }
+
+    // 6. 流控制(默认禁用)
+    options.c_cflag &= ~CRTSCTS;
+    options.c_iflag &= ~(IXON | IXOFF | IXANY);
+
+    // 7. 超时控制(根据需求调整)
+    options.c_cc[VTIME] = 5;  // 0.5秒超时
+    options.c_cc[VMIN]  = 0;  // 非阻塞模式
+
+    // 8. 应用配置
+    if (tcsetattr(fd, TCSAFLUSH, &options) != 0) {
+        close(fd);
+        return UART_INVALID_HANDLE;
+    }
+
+    // 切换为阻塞模式(可选)
+    int flags = fcntl(fd, F_GETFL, 0);
+    fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
+
+    return fd;
+}
+
+int UartUninit(UART_HANDLE handle) {
+    if (handle == UART_INVALID_HANDLE) {
+        return -1;
+    }
+    // 刷新并关闭串口
+    tcflush(handle, TCIOFLUSH);
+    int ret = close(handle);
+    
+    return (ret == 0) ? 0 : -2;
+}
+
+int UartSend(UART_HANDLE handle, const void *buf, size_t size) {
+    if (handle == UART_INVALID_HANDLE || !buf || size == 0) {
+        return -1;
+    }
+
+    ssize_t total_sent = 0;
+    const uint8_t* ptr = static_cast<const uint8_t*>(buf);
+
+    while (total_sent < static_cast<ssize_t>(size)) {
+        ssize_t sent = write(handle, ptr + total_sent, size - total_sent);
+        
+        if (sent < 0) {
+            if (errno == EINTR) {  // 被信号中断,重试
+                continue;
+            }
+            return -2;  // 其他错误
+        }
+        
+        if (sent == 0) {  // 理论上不会发生
+            break;
+        }
+        
+        total_sent += sent;
+    }
+    if (tcdrain(handle) != 0) {
+        return -3; // 发送完成确认失败
+    }
+    return total_sent;
+}
+
+int UartRecv(UART_HANDLE handle, void *buf, size_t size) {
+    if (handle == UART_INVALID_HANDLE || !buf || size == 0) {
+        return -1;
+    }
+
+    ssize_t total_read = 0;
+    uint8_t* ptr = static_cast<uint8_t*>(buf);
+
+    while (total_read < static_cast<ssize_t>(size)) {
+        ssize_t n = read(handle, ptr + total_read, size - total_read);
+        
+        if (n < 0) {
+            if (errno == EINTR) {  // 被信号中断,重试
+                continue;
+            }
+            if (errno == EAGAIN || errno == EWOULDBLOCK) {  // 非阻塞模式无数据
+                break;
+            }
+            return -2;  // 其他错误
+        }
+        
+        if (n == 0) {  // EOF或超时
+            break;
+        }
+        
+        total_read += n;
+    }
+    
+    return total_read;
+}

+ 12 - 0
sa_profile/3256.json

@@ -0,0 +1,12 @@
+{
+    "process": "it3256IO_service",
+    "systemability": [
+        {
+            "name": 3256,
+            "libpath": "libit3256_service.z.so",
+            "run-on-create": true,
+            "distributed": false,
+            "dump_level": 1
+        }
+    ]
+}

+ 20 - 0
sa_profile/BUILD.gn

@@ -0,0 +1,20 @@
+# Copyright (c) 2021 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build/ohos/sa_profile/sa_profile.gni")
+
+ohos_sa_profile("it3256_sa_profile") {
+  sources = [ "3256.json" ]
+
+  part_name = "sony_camera"
+}

+ 42 - 0
service/BUILD.gn

@@ -0,0 +1,42 @@
+import("//build/ohos.gni")
+config("it3256_service_config") {
+  include_dirs = [
+    "include",
+    "//_mysubsystem/it3256/core/include"
+  ]
+}
+ohos_shared_library("it3256_service") {
+  sources = [
+    "src/it3256_control.cpp",
+    "src/it3256_service.cpp"
+  ]
+   cflags = [
+            "-Wno-error=delete-abstract-non-virtual-dtor",
+            "-Wno-error=unused-variable",
+            "-Wno-error=overloaded-virtual",
+            "-frtti",
+            "-Wno-error=pessimizing-move"
+        ]
+    cflags_c = []
+    cflags_cc = [
+        # "--verbose",
+        "-std=c++17",
+    ]
+    ldflags = [
+        "-lpthread"
+        ]
+  configs = [ ":it3256_service_config" ]
+  deps = [ 
+        "//third_party/libusb:libusb"
+     ]
+   external_deps = [ 
+         "hilog:libhilog",
+         "ipc:ipc_core",
+         "c_utils:utils",
+         "samgr:samgr_proxy",
+        "safwk:system_ability_fwk"
+  ]
+  deps += ["//_mysubsystem/it3256/core:it3256IO_core"]
+  part_name = "sony_camera"
+  subsystem_name = "_mysubsystem"
+}

File diff suppressed because it is too large
+ 1005 - 0
service/include/advio.h


+ 45 - 0
service/include/it3256_control.h

@@ -0,0 +1,45 @@
+#ifndef It3256_CONTROL_H
+#define It3256_CONTROL_H
+
+
+#include "it3256_stub.h"
+#include "advio.h"
+#include "it3256_log.h"
+#include <iostream>
+#include <cstdio>
+#include <string>
+#include <memory>
+namespace OHOS{
+namespace It3256 {
+
+class It3256IOControl : public It3256IOStub {
+public:
+    It3256IOControl();
+    ~It3256IOControl();
+
+    bool GetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf) override;
+    bool SetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf) override;
+    std::string executeCommand(const std::string& command) {
+        // 使用 popen 执行命令并捕获其输出
+        std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(command.c_str(), "r"), pclose);
+        if (!pipe) {
+            std::cerr << ": Failed to execute command: " << command << std::endl;
+            return "-1";
+        }
+    
+        // 读取命令的输出
+        char buffer[128];
+        std::string result;
+        while (fgets(buffer, sizeof(buffer), pipe.get()) != nullptr) {
+            result += buffer;
+        }
+    
+        return result;
+    }
+
+private:
+    bool initialized_ = false;
+};
+}
+} // namespace It3256
+#endif // It3256_CONTROL_H

+ 46 - 0
service/include/it3256_log.h

@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef It3256_LOG_H
+#define It3256_LOG_H
+
+#include "hilog/log.h"
+
+#ifndef It3256_LOG_DOMAIN
+#define It3256_LOG_DOMAIN 0xD001200
+#endif
+#ifndef It3256_LOG_TAG
+#define It3256_LOG_TAG "It3256"
+#endif
+
+#define CUR_FILE_NAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
+
+#define It3256_LOGF(fmt, ...)            \
+    ((void)HILOG_IMPL(LOG_CORE, LOG_FATAL, It3256_LOG_DOMAIN, It3256_LOG_TAG, \
+    "[%{public}s(%{public}s:%{public}d)]" fmt, CUR_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__))
+#define It3256_LOGE(fmt, ...)            \
+    ((void)HILOG_IMPL(LOG_CORE, LOG_ERROR, It3256_LOG_DOMAIN, It3256_LOG_TAG, \
+    "[%{public}s(%{public}s:%{public}d)]" fmt, CUR_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__))
+#define It3256_LOGW(fmt, ...)            \
+    ((void)HILOG_IMPL(LOG_CORE, LOG_WARN, It3256_LOG_DOMAIN, It3256_LOG_TAG, \
+    "[%{public}s(%{public}s:%{public}d)]" fmt, CUR_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__))
+#define It3256_LOGI(fmt, ...)            \
+    ((void)HILOG_IMPL(LOG_CORE, LOG_INFO, It3256_LOG_DOMAIN, It3256_LOG_TAG, \
+    "[%{public}s(%{public}s:%{public}d)]" fmt, CUR_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__))
+#define It3256_LOGD(fmt, ...)            \
+    ((void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, It3256_LOG_DOMAIN, It3256_LOG_TAG, \
+    "[%{public}s(%{public}s:%{public}d)]" fmt, CUR_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__))
+
+#endif  // FOUNDATION_It3256_COMMON_LOG_INCLUDE_It3256_LOG_WRAPPER_H

+ 36 - 0
service/include/it3256_service.h

@@ -0,0 +1,36 @@
+#ifndef IT3256_SERVICE_H
+#define IT3256_SERVICE_H
+
+#include "system_ability.h"
+#include "it3256_stub.h"
+#include "it3256_control.h"
+#include "system_ability_definition.h"
+
+namespace OHOS {
+namespace It3256 {
+
+class It3256IOService : public SystemAbility, public It3256IOStub {
+    DECLARE_SYSTEM_ABILITY(It3256IOService);
+public:
+    DISALLOW_COPY_AND_MOVE(It3256IOService);
+    explicit It3256IOService(int32_t systemAbilityId, bool runOnCreate = true);
+    ~It3256IOService() override;
+
+    // 从SystemAbility继承
+    void OnStart() override;
+    void OnStop() override;
+    
+    // 从It3256IOStub继承
+    bool SetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf) override;
+    bool GetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf) override;
+
+private:
+    bool Initialize();
+    std::shared_ptr<It3256IOControl> control_;
+    bool ready_ = false;
+};
+
+} // namespace It3256
+} // namespace OHOS
+
+#endif // IT3256_SERVICE_H

+ 71 - 0
service/src/it3256_control.cpp

@@ -0,0 +1,71 @@
+#include "it3256_control.h"
+#include "advio.h"
+#include "it3256_log.h"
+namespace OHOS{
+namespace It3256 {
+
+It3256IOControl::It3256IOControl() {
+    It3256_LOGI("It3256IOControl created");
+}
+
+It3256IOControl::~It3256IOControl() {
+    if (initialized_) {
+        AdvioDevClose();
+    }
+    It3256_LOGI("It3256IOControl destroyed");
+}
+
+bool It3256IOControl::GetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf) {
+    It3256_LOGI("GetAIRangeCode called");
+    ErrorCode ret = AdvioDevInit();
+    if (ret != 0) {
+        It3256_LOGE("AdvioDevInit failed");
+        return false;
+    }
+    
+    initialized_ = true;
+    ret = AdvioDevGetAIRangeCode(startch, stopch, poutbuf);
+    if (ret != 0) {
+        It3256_LOGE("AdvioDevGetAIRangeCode failed");
+        AdvioDevClose();
+        initialized_ = false;
+        return false;
+    }
+
+    ret = AdvioDevClose();
+    initialized_ = false;
+    return ret == 0;
+}
+
+bool It3256IOControl::SetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf) {
+    It3256_LOGI("SetAIRangeCode called");
+    It3256_LOGI("startch = 0x%{public}02X, stopch = 0x%{public}02X", startch, stopch);
+    uint16_t rangecode = 0x0149;
+ 
+    ErrorCode ret = AdvioDevInit();
+    if (ret != 0) {
+        It3256_LOGE("AdvioDevInit failed");
+        return false;
+    }
+    int sio = ((startch - stopch)+1)*2;
+    for (size_t i = 0; i < sio; ++i) {
+        It3256_LOGI("  poutbuf[%{public}zu] = 0x%{public}02X", i, poutbuf[i]);
+    }
+
+    initialized_ = true;
+    ret = AdvioDevSetAIRangeCode(0, 0, (uint8_t *)(&rangecode));
+    ret = AdvioDevSetAIRangeCode(1, 1, (uint8_t *)(&rangecode));
+    It3256_LOGI("ret = %{public}u", ret);
+    if (ret != 0) {
+        It3256_LOGE("AdvioDevSetAIRangeCode failed");
+        AdvioDevClose();
+        initialized_ = false;
+        return false;
+    }
+
+    ret = AdvioDevClose();
+    initialized_ = false;
+    return ret == 0;
+}
+}
+} // namespace It3256

+ 82 - 0
service/src/it3256_service.cpp

@@ -0,0 +1,82 @@
+#include "it3256_service.h"
+#include "it3256_log.h"
+#include "iservice_registry.h"
+
+namespace OHOS {
+namespace It3256 {
+REGISTER_SYSTEM_ABILITY_BY_ID(It3256IOService, It3256IO_SERVICE_ID, true);
+It3256IOService::It3256IOService(int32_t systemAbilityId, bool runOnCreate)
+    : SystemAbility(systemAbilityId, runOnCreate)
+{
+    It3256_LOGI("It3256IOService constructor");
+}
+
+It3256IOService::~It3256IOService()
+{
+    It3256_LOGI("It3256IOService destructor");
+}
+
+void It3256IOService::OnStart()
+{
+    It3256_LOGI("It3256IOService::OnStart start");
+    if (ready_) {
+        It3256_LOGI("It3256IOService has already started");
+        return;
+    }
+
+    if (!Initialize()) {
+        It3256_LOGE("Failed to initialize");
+        return;
+    }
+
+    // 发布服务
+    if (!Publish(this)) {
+        It3256_LOGE("Failed to publish service");
+        return;
+    }
+
+    ready_ = true;
+    It3256_LOGI("It3256IOService start success");
+}
+
+void It3256IOService::OnStop()
+{
+    It3256_LOGI("It3256IOService::OnStop start");
+    if (!ready_) {
+        return;
+    }
+    ready_ = false;
+    control_ = nullptr;
+    It3256_LOGI("It3256IOService stop success");
+}
+
+bool It3256IOService::Initialize()
+{
+    control_ = std::make_shared<It3256IOControl>();
+    if (!control_) {
+        It3256_LOGE("Failed to create It3256IOControl");
+        return false;
+    }
+    return true;
+}
+
+bool It3256IOService::SetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf)
+{
+    if (!ready_) {
+        It3256_LOGE("Service not ready");
+        return false;
+    }
+    return control_->SetAIRangeCode(startch, stopch, poutbuf);
+}
+
+bool It3256IOService::GetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf)
+{
+    if (!ready_) {
+        It3256_LOGE("Service not ready");
+        return false;
+    }
+    return control_->GetAIRangeCode(startch, stopch, poutbuf);
+}
+
+} // namespace It3256
+} // namespace OHOS