#include <iostream>
#include <string.h>
#include "RFM2gAPI.h"

using namespace std;

// 写数据函数
int RFM2gWrite(RFM2GHANDLE handle, void *buffer, RFM2GOFFSET offset, size_t count) {
    int ret;
    RFM2G_STATUS status;

    // 写入数据
    status = RFM2gWrite(handle, buffer, offset, count, RFM2G_QOS_FIFO);

    // 检查写入状态
    if (status != RFM2G_SUCCESS) {
        cout << "写入失败,错误码为 " << status << endl;
        ret = -1;
    } else {
        cout << "写入成功" << endl;
        ret = 0;
    }

    return ret;
}

// 读数据函数
int RFM2gRead(RFM2GHANDLE handle, void *buffer, RFM2GOFFSET offset, size_t count) {
    int ret;
    RFM2G_STATUS status;

    // 读取数据
    status = RFM2gRead(handle, buffer, offset, count);

    // 检查读取状态
    if (status != RFM2G_SUCCESS) {
        cout << "读取失败,错误码为 " << status << endl;
        ret = -1;
    } else {
        cout << "读取成功" << endl;
        ret = 0;
    }

    return ret;
}

int main() {
    RFM2GHANDLE handle;
    RFM2G_NODE node = 0;
    char *buf = "Hello World";
    int len = strlen(buf) + 1;

    // 打开设备
    RFM2gOpen(&handle, node);

    // 写入字符串数据
    RFM2G_ADDRESS addr = 0;
    RFM2GOFFSET offset = 0;
    RFM2gWrite(handle, buf, offset, len);

    // 读取字符串数据
    char read_buf[100];
    offset = 0;
    RFM2gRead(handle, read_buf, offset, len);

    // 输出读取的数据
    cout << "读取到的数据为: " << read_buf << endl;

    // 关闭设备
    RFM2gClose(handle);

    return 0;
}

</string.h></iostream>