Merge branch '2023_open_source_contest' of https://gitlink.org.cn/xuos/xiuos into workplace
@@ -1,13 +1,13 @@
|
||||
include $(KERNEL_ROOT)/.config
|
||||
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FEATURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
CSRCS +=
|
||||
include $(APPDIR)/Application.mk
|
||||
endif
|
||||
|
||||
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
ifeq ($(CONFIG_ADD_XIZI_FEATURES),y)
|
||||
SRC_DIR := general_functions app_test
|
||||
|
||||
SRC_FILES := main.c
|
||||
|
||||
@@ -8,7 +8,7 @@ menu "test app"
|
||||
bool "Config test adc"
|
||||
default n
|
||||
if USER_TEST_ADC
|
||||
if ADD_XIZI_FETURES
|
||||
if ADD_XIZI_FEATURES
|
||||
config ADC_DEV_DRIVER
|
||||
string "Set ADC dev path"
|
||||
default "/dev/adc1_dev"
|
||||
@@ -19,7 +19,7 @@ menu "test app"
|
||||
bool "Config test dac"
|
||||
default n
|
||||
if USER_TEST_DAC
|
||||
if ADD_XIZI_FETURES
|
||||
if ADD_XIZI_FEATURES
|
||||
config DAC_DEV_DRIVER
|
||||
string "Set DAC dev path"
|
||||
default "/dev/dac_dev"
|
||||
@@ -30,7 +30,7 @@ menu "test app"
|
||||
bool "Config test fs with sd or usb"
|
||||
default n
|
||||
if USER_TEST_FS
|
||||
if ADD_XIZI_FETURES
|
||||
if ADD_XIZI_FEATURES
|
||||
config FPATH
|
||||
string "Set test file path"
|
||||
default "/test_file"
|
||||
@@ -46,7 +46,7 @@ menu "test app"
|
||||
bool "Config test gpio with led and key"
|
||||
default n
|
||||
if USER_TEST_GPIO
|
||||
if ADD_XIZI_FETURES
|
||||
if ADD_XIZI_FEATURES
|
||||
config GPIO_DEV_DRIVER
|
||||
string "Set gpio dev path"
|
||||
default "/dev/pin_dev"
|
||||
@@ -62,7 +62,7 @@ menu "test app"
|
||||
bool "Config test uart(loraE220)"
|
||||
default n
|
||||
if USER_TEST_LORA
|
||||
if ADD_XIZI_FETURES
|
||||
if ADD_XIZI_FEATURES
|
||||
config LORA_UART_DEV_DRIVER
|
||||
string "Set uart dev path"
|
||||
default "/dev/uart2_dev2"
|
||||
@@ -80,7 +80,7 @@ menu "test app"
|
||||
bool "Config test uart(RS485)"
|
||||
default n
|
||||
if USER_TEST_RS485
|
||||
if ADD_XIZI_FETURES
|
||||
if ADD_XIZI_FEATURES
|
||||
config RS485_UART_DEV_DRIVER
|
||||
string "Set uart dev path"
|
||||
default "/dev/uart1_dev1"
|
||||
@@ -95,7 +95,7 @@ menu "test app"
|
||||
bool "Config test rtc"
|
||||
default n
|
||||
if USER_TEST_RTC
|
||||
if ADD_XIZI_FETURES
|
||||
if ADD_XIZI_FEATURES
|
||||
config RTC_DEV_DRIVER
|
||||
string "Set rtc dev path"
|
||||
default "/dev/rtc_dev"
|
||||
@@ -110,7 +110,7 @@ menu "test app"
|
||||
bool "Config test hwtimer"
|
||||
default n
|
||||
if USER_TEST_HWTIMER
|
||||
if ADD_XIZI_FETURES
|
||||
if ADD_XIZI_FEATURES
|
||||
config HWTIMER_TIMER_DEV_DRIVER
|
||||
string "Set pin dev path"
|
||||
default "/dev/timer0_dev0"
|
||||
@@ -125,7 +125,7 @@ menu "test app"
|
||||
bool "Config test watchdog"
|
||||
default n
|
||||
if USER_TEST_WDT
|
||||
if ADD_XIZI_FETURES
|
||||
if ADD_XIZI_FEATURES
|
||||
config WDT0_DEV_DRIVER
|
||||
string "Set wdt dev path"
|
||||
default "/dev/wdt0_dev0"
|
||||
@@ -137,7 +137,7 @@ menu "test app"
|
||||
bool "Config test lcd in PrivOpen"
|
||||
default n
|
||||
if USER_TEST_LCD_EDU
|
||||
if ADD_XIZI_FETURES
|
||||
if ADD_XIZI_FEATURES
|
||||
config EDU_LCD_DEV_DRIVER
|
||||
string "Set lcd dev path"
|
||||
default "/dev/lcd_dev"
|
||||
@@ -149,7 +149,7 @@ menu "test app"
|
||||
bool "Config test touch"
|
||||
default n
|
||||
if USER_TEST_TOUCH
|
||||
if ADD_XIZI_FETURES
|
||||
if ADD_XIZI_FEATURES
|
||||
config TOUCH_DEV_DRIVER
|
||||
string "Set touch dev path"
|
||||
default "/dev/touch_dev"
|
||||
@@ -164,7 +164,7 @@ menu "test app"
|
||||
bool "Config test i2c"
|
||||
default n
|
||||
if USER_TEST_I2C
|
||||
if ADD_XIZI_FETURES
|
||||
if ADD_XIZI_FEATURES
|
||||
config I2C_DEV_DRIVER
|
||||
string "Set i2c dev path"
|
||||
default "/dev/i2c1_dev0"
|
||||
@@ -176,7 +176,7 @@ menu "test app"
|
||||
bool "Config test can"
|
||||
default n
|
||||
if USER_TEST_CAN
|
||||
if ADD_XIZI_FETURES
|
||||
if ADD_XIZI_FEATURES
|
||||
config CAN_DEV_DRIVER
|
||||
string "Set can dev path"
|
||||
default "/dev/can2_dev1"
|
||||
@@ -189,7 +189,7 @@ menu "test app"
|
||||
bool "Config test camera with lcd"
|
||||
default n
|
||||
if USER_TEST_CAMERA
|
||||
if ADD_XIZI_FETURES
|
||||
if ADD_XIZI_FEATURES
|
||||
config CAMERA_DEV_DRIVER
|
||||
string "Set camera dev path"
|
||||
default "/dev/camera_dev"
|
||||
@@ -211,7 +211,7 @@ menu "test app"
|
||||
bool "Config test ethernet only for edu-riscv64"
|
||||
default n
|
||||
if USER_TEST_ETHERNET
|
||||
if ADD_XIZI_FETURES
|
||||
if ADD_XIZI_FEATURES
|
||||
choice
|
||||
prompt "set ethernet role as client or server"
|
||||
default ETHERNET_AS_SERVER
|
||||
@@ -229,7 +229,7 @@ menu "test app"
|
||||
bool "Config test w25q128 device"
|
||||
default n
|
||||
if USER_TEST_FLASH
|
||||
if ADD_XIZI_FETURES
|
||||
if ADD_XIZI_FEATURES
|
||||
config FLASH_DEV_DRIVER
|
||||
string "Set flash dev path"
|
||||
default "/dev/qspi_W25Q128"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
include $(KERNEL_ROOT)/.config
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FEATURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_SEMC),y)
|
||||
@@ -22,7 +22,7 @@ ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
ifeq ($(CONFIG_ADD_XIZI_FEATURES),y)
|
||||
SRC_FILES := test_shell.c
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_ADC),y)
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
|
||||
void TestAdc(void)
|
||||
{
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
|
||||
static uint16_t image_buff[384000];
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
|
||||
|
||||
void TestCAN(void)
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
|
||||
void TestDac(void)
|
||||
{
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
|
||||
#include <socket.h>
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
|
||||
void TestFlash(void)
|
||||
{
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
|
||||
#define MAX_READ_LENGTH 1000
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
|
||||
#ifdef BOARD_EDU_RISCV64_EVB
|
||||
#define BSP_LED_PIN 29
|
||||
|
||||
BIN
APP_Framework/Applications/app_test/test_hash/CompileSuccess.png
Normal file
|
After Width: | Height: | Size: 75 KiB |
BIN
APP_Framework/Applications/app_test/test_hash/ConfigOpen.png
Normal file
|
After Width: | Height: | Size: 102 KiB |
58
APP_Framework/Applications/app_test/test_hash/README.md
Normal file
@@ -0,0 +1,58 @@
|
||||
# 基于cortex-m3-emulator实现哈希表并测试验证##
|
||||
|
||||
## 1. 简介
|
||||
利用c语言实现了哈希表(HashMap),包括添加键值对(Put),获取键对应的值(Get), 删除健(Delete),清空哈希表(Clear), 迭代遍历哈希表(hashMapIterator)等功能
|
||||
操作。
|
||||
|
||||
利用数组(Entry)作为存储空间,利用链表(*next)解决冲突。当哈希表的大小超过数组大小后,为避免发生冲突过多的情况,可以对哈希表扩容。
|
||||
|
||||
## 2. 数据结构设计说明
|
||||
键值对结构
|
||||
typedef struct entry {
|
||||
void * key; // 键
|
||||
void * value; // 值
|
||||
struct entry * next; // 冲突链表
|
||||
}*Entry;
|
||||
|
||||
哈希结构
|
||||
typedef struct hashMap {
|
||||
int size; // 当前大小
|
||||
int listSize; // 有效空间大小
|
||||
HashCode hashCode; // 哈希函数
|
||||
Equal equal; // 判等函数
|
||||
Entry list; // 存储区域
|
||||
Put put; // 添加键的函数
|
||||
Get get; // 获取键对应值的函数
|
||||
Remove remove; // 删除键
|
||||
Clear clear; // 清空Map
|
||||
Exists exists; // 判断键是否存在
|
||||
Boolean autoAssign; // 设定是否根据当前数据量动态调整内存大小,默认开启
|
||||
}*HashMap;
|
||||
|
||||
包括以下函数功能,分别为:
|
||||
`createHashMap`:创建一个哈希结构
|
||||
`defaultPut`:添加键值对
|
||||
`defaultGet`:获取键对应值
|
||||
`defaultRemove`:删除指定键的键值对
|
||||
`defaultExists`:判断键值是否存在
|
||||
`defaultClear`:清空Map的函数类型
|
||||
`resetHashMap`:重新构建哈希表
|
||||
|
||||
|
||||
## 3. 测试程序说明
|
||||
测试了哈希表的插入键值对(Put),判断键是否存在(Exist),获取键对应的值(Get), 删除健(Delete),迭代遍历哈希表(hashMapIterator),清空哈希表(Clear)等操作。
|
||||
并展示了利用链地址法解决哈希冲突的示例, 两个不同的人(Bob和Li Ming)的hashcode相同。
|
||||
|
||||
## 4. 运行结果(##需结合运行测试截图按步骤说明##)
|
||||

|
||||
打开menuconfig之后,将test_hash_map开启(y),保存后退出
|
||||
|
||||

|
||||
编译XiZi-cortex-m3-emulator.elf成功
|
||||
|
||||

|
||||
启动qemu模拟Xiuos操作系统,验证TestHash注册Shell命令
|
||||
|
||||

|
||||
执行TestHash命令,打印测试结果。
|
||||
|
||||
BIN
APP_Framework/Applications/app_test/test_hash/ShellCommand.png
Normal file
|
After Width: | Height: | Size: 94 KiB |
BIN
APP_Framework/Applications/app_test/test_hash/TestHash.png
Normal file
|
After Width: | Height: | Size: 95 KiB |
323
APP_Framework/Applications/app_test/test_hash/test_hash.c
Normal file
@@ -0,0 +1,323 @@
|
||||
|
||||
/**
|
||||
* @file: test_hash.c
|
||||
* @brief: a application of test hash function
|
||||
* @version: 3.0
|
||||
* @author: Yao wenying
|
||||
* @date: 2023/05/26
|
||||
*/
|
||||
|
||||
#include <transform.h>
|
||||
#include"test_hash.h"
|
||||
|
||||
int defaultHashCode(HashMap hashMap, let key) {
|
||||
char * k = (char *)key;
|
||||
unsigned long h = 0;
|
||||
while (*k) {
|
||||
h = (h << 4) + *k++;
|
||||
unsigned long g = h & 0xF0000000L;
|
||||
if (g) {
|
||||
h ^= g >> 24;
|
||||
}
|
||||
h &= ~g;
|
||||
}
|
||||
return h % hashMap->listSize;
|
||||
}
|
||||
|
||||
Boolean defaultEqual(let key1, let key2) {
|
||||
return strcmp((string)key1, (string)key2) ? False : True;
|
||||
}
|
||||
|
||||
void resetHashMap(HashMap hashMap, int listSize) {
|
||||
|
||||
if (listSize < 8) return;
|
||||
|
||||
// 键值对临时存储空间
|
||||
Entry tempList = newEntryList(hashMap->size);
|
||||
|
||||
HashMapIterator iterator = createHashMapIterator(hashMap);
|
||||
int length = hashMap->size;
|
||||
for (int index = 0; hasNextHashMapIterator(iterator); index++) {
|
||||
// 迭代取出所有键值对
|
||||
iterator = nextHashMapIterator(iterator);
|
||||
tempList[index].key = iterator->entry->key;
|
||||
tempList[index].value = iterator->entry->value;
|
||||
tempList[index].next = NULL;
|
||||
}
|
||||
freeHashMapIterator(&iterator);
|
||||
|
||||
// 清除原有键值对数据
|
||||
hashMap->size = 0;
|
||||
for (int i = 0; i < hashMap->listSize; i++) {
|
||||
Entry current = &hashMap->list[i];
|
||||
current->key = NULL;
|
||||
current->value = NULL;
|
||||
if (current->next != NULL) {
|
||||
while (current->next != NULL) {
|
||||
Entry temp = current->next->next;
|
||||
free(current->next);
|
||||
current->next = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 更改内存大小
|
||||
hashMap->listSize = listSize;
|
||||
Entry relist = (Entry)realloc(hashMap->list, hashMap->listSize * sizeof(struct entry));
|
||||
if (relist != NULL) {
|
||||
hashMap->list = relist;
|
||||
relist = NULL;
|
||||
}
|
||||
|
||||
// 初始化数据
|
||||
for (int i = 0; i < hashMap->listSize; i++) {
|
||||
hashMap->list[i].key = NULL;
|
||||
hashMap->list[i].value = NULL;
|
||||
hashMap->list[i].next = NULL;
|
||||
}
|
||||
|
||||
// 将所有键值对重新写入内存
|
||||
for (int i = 0; i < length; i++) {
|
||||
hashMap->put(hashMap, tempList[i].key, tempList[i].value);
|
||||
}
|
||||
free(tempList);
|
||||
}
|
||||
|
||||
void defaultPut(HashMap hashMap, let key, let value) {
|
||||
// 获取哈希值
|
||||
int index = hashMap->hashCode(hashMap, key);
|
||||
|
||||
if (hashMap->list[index].key == NULL) {
|
||||
hashMap->size++;
|
||||
// 该地址为空时直接存储
|
||||
hashMap->list[index].key = key;
|
||||
hashMap->list[index].value = value;
|
||||
}
|
||||
else {
|
||||
|
||||
Entry current = &hashMap->list[index];
|
||||
while (current != NULL) {
|
||||
if (hashMap->equal(key, current->key)) {
|
||||
// 对于键值已经存在的直接覆盖
|
||||
current->value = value;
|
||||
return;
|
||||
}
|
||||
current = current->next;
|
||||
};
|
||||
|
||||
// 发生冲突则创建节点挂到相应位置的next上
|
||||
Entry entry = newEntry();
|
||||
entry->key = key;
|
||||
entry->value = value;
|
||||
entry->next = hashMap->list[index].next;
|
||||
hashMap->list[index].next = entry;
|
||||
hashMap->size++;
|
||||
}
|
||||
|
||||
if (hashMap->autoAssign && hashMap->size >= hashMap->listSize) {
|
||||
|
||||
// 内存扩充至原来的两倍
|
||||
// *注: 扩充时考虑的是当前存储元素数量与存储空间的大小关系,而不是存储空间是否已经存满,
|
||||
// 例如: 存储空间为10,存入了10个键值对,但是全部冲突了,所以存储空间空着9个,其余的全部挂在一个上面,
|
||||
// 这样检索的时候和遍历查询没有什么区别了,可以简单这样理解,当我存入第11个键值对的时候一定会发生冲突,
|
||||
// 这是由哈希函数本身的特性(取模)决定的,冲突就会导致检索变慢,所以这时候扩充存储空间,对原有键值对进行
|
||||
// 再次散列,会把冲突的数据再次分散开,加快索引定位速度。
|
||||
resetHashMap(hashMap, hashMap->listSize * 2);
|
||||
}
|
||||
}
|
||||
|
||||
let defaultGet(HashMap hashMap, let key) {
|
||||
if (hashMap->exists(hashMap, key)) {
|
||||
int index = hashMap->hashCode(hashMap, key);
|
||||
Entry entry = &hashMap->list[index];
|
||||
while (entry != NULL) {
|
||||
if (hashMap->equal(entry->key, key)) {
|
||||
return entry->value;
|
||||
}
|
||||
entry = entry->next;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
let defaultRemove(HashMap hashMap, let key) {
|
||||
int index = hashMap->hashCode(hashMap, key);
|
||||
Entry entry = &hashMap->list[index];
|
||||
if (entry->key == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
let entryKey = entry->key;
|
||||
Boolean result = False;
|
||||
if (hashMap->equal(entry->key, key)) {
|
||||
hashMap->size--;
|
||||
if (entry->next != NULL) {
|
||||
Entry temp = entry->next;
|
||||
entry->key = temp->key;
|
||||
entry->value = temp->value;
|
||||
entry->next = temp->next;
|
||||
free(temp);
|
||||
}
|
||||
else {
|
||||
entry->key = NULL;
|
||||
entry->value = NULL;
|
||||
}
|
||||
result = True;
|
||||
}
|
||||
else {
|
||||
Entry p = entry;
|
||||
entry = entry->next;
|
||||
while (entry != NULL) {
|
||||
if (hashMap->equal(entry->key, key)) {
|
||||
hashMap->size--;
|
||||
p->next = entry->next;
|
||||
free(entry);
|
||||
result = True;
|
||||
break;
|
||||
}
|
||||
p = entry;
|
||||
entry = entry->next;
|
||||
};
|
||||
}
|
||||
|
||||
// 如果空间占用不足一半,则释放多余内存
|
||||
if (result && hashMap->autoAssign && hashMap->size < hashMap->listSize / 2) {
|
||||
resetHashMap(hashMap, hashMap->listSize / 2);
|
||||
}
|
||||
return entryKey;
|
||||
}
|
||||
|
||||
Boolean defaultExists(HashMap hashMap, let key) {
|
||||
int index = hashMap->hashCode(hashMap, key);
|
||||
Entry entry = &hashMap->list[index];
|
||||
if (entry->key == NULL) {
|
||||
return False;
|
||||
}
|
||||
else {
|
||||
while (entry != NULL) {
|
||||
if (hashMap->equal(entry->key, key)) {
|
||||
return True;
|
||||
}
|
||||
entry = entry->next;
|
||||
}
|
||||
return False;
|
||||
}
|
||||
}
|
||||
|
||||
void defaultClear(HashMap hashMap) {
|
||||
for (int i = 0; i < hashMap->listSize; i++) {
|
||||
// 释放冲突值内存
|
||||
Entry entry = hashMap->list[i].next;
|
||||
while (entry != NULL) {
|
||||
Entry next = entry->next;
|
||||
free(entry);
|
||||
entry = next;
|
||||
}
|
||||
hashMap->list[i].next = NULL;
|
||||
}
|
||||
// 释放存储空间
|
||||
free(hashMap->list);
|
||||
hashMap->list = NULL;
|
||||
hashMap->size = -1;
|
||||
hashMap->listSize = 0;
|
||||
}
|
||||
|
||||
HashMap createHashMap(HashCode hashCode, Equal equal) {
|
||||
HashMap hashMap = newHashMap();
|
||||
if (hashMap == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
hashMap->size = 0;
|
||||
hashMap->listSize = 8;
|
||||
hashMap->hashCode = hashCode == NULL ? defaultHashCode : hashCode;
|
||||
hashMap->equal = equal == NULL ? defaultEqual : equal;
|
||||
hashMap->exists = defaultExists;
|
||||
hashMap->get = defaultGet;
|
||||
hashMap->put = defaultPut;
|
||||
hashMap->remove = defaultRemove;
|
||||
hashMap->clear = defaultClear;
|
||||
hashMap->autoAssign = True;
|
||||
|
||||
// 起始分配8个内存空间,溢出时会自动扩充
|
||||
hashMap->list = newEntryList(hashMap->listSize);
|
||||
if (hashMap->list == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
Entry p = hashMap->list;
|
||||
for (int i = 0; i < hashMap->listSize; i++) {
|
||||
p[i].key = p[i].value = p[i].next = NULL;
|
||||
}
|
||||
return hashMap;
|
||||
}
|
||||
|
||||
HashMapIterator createHashMapIterator(HashMap hashMap) {
|
||||
HashMapIterator iterator = newHashMapIterator();
|
||||
if (iterator == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
iterator->hashMap = hashMap;
|
||||
iterator->count = 0;
|
||||
iterator->hashCode = -1;
|
||||
iterator->entry = NULL;
|
||||
return iterator;
|
||||
}
|
||||
|
||||
Boolean hasNextHashMapIterator(HashMapIterator iterator) {
|
||||
return iterator->count < iterator->hashMap->size ? True : False;
|
||||
}
|
||||
|
||||
HashMapIterator nextHashMapIterator(HashMapIterator iterator) {
|
||||
if (hasNextHashMapIterator(iterator)) {
|
||||
if (iterator->entry != NULL && iterator->entry->next != NULL) {
|
||||
iterator->count++;
|
||||
iterator->entry = iterator->entry->next;
|
||||
return iterator;
|
||||
}
|
||||
while (++iterator->hashCode < iterator->hashMap->listSize) {
|
||||
Entry entry = &iterator->hashMap->list[iterator->hashCode];
|
||||
if (entry->key != NULL) {
|
||||
iterator->count++;
|
||||
iterator->entry = entry;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return iterator;
|
||||
}
|
||||
|
||||
void freeHashMapIterator(HashMapIterator * iterator) {
|
||||
free(*iterator);
|
||||
*iterator = NULL;
|
||||
}
|
||||
|
||||
#define Put(map, key, value) map->put(map, (void *)key, (void *)value);
|
||||
#define Get(map, key) (char *)map->get(map, (void *)key)
|
||||
#define Remove(map, key) map->remove(map, (void *)key)
|
||||
#define Existe(map, key) map->exists(map, (void *)key)
|
||||
|
||||
void TestHash() {
|
||||
HashMap map = createHashMap(NULL, NULL);
|
||||
Put(map, "000123", "Annie");
|
||||
Put(map, "000245", "Bob");
|
||||
Put(map, "000284", "Daniel");
|
||||
Put(map, "000281", "Luna");
|
||||
Put(map, "000587", "Yao");
|
||||
Put(map, "000985", "Li Ming");
|
||||
Put(map, "000852", "Janne");
|
||||
|
||||
printf("print the key-values in hashmap:\n");
|
||||
HashMapIterator iterator = createHashMapIterator(map);
|
||||
while (hasNextHashMapIterator(iterator)) {
|
||||
iterator = nextHashMapIterator(iterator);
|
||||
printf("{ key: %s, key: %s, hashcode: %d }\n",
|
||||
(char *)iterator->entry->key, (char *)iterator->entry->value, iterator->hashCode);
|
||||
}
|
||||
printf("key: 000852, exists: %s\n", Existe(map, "000852") ? "true" : "false");
|
||||
printf("000852: %s\n", Get(map, "000852"));
|
||||
printf("remove 000852 %s\n", Remove(map, "000852") ? "true" : "false");
|
||||
printf("key: 000852, exists: %s\n", Existe(map, "000852") ? "true" : "false");
|
||||
|
||||
map->clear(map);
|
||||
freeHashMapIterator(&iterator);
|
||||
}
|
||||
|
||||
PRIV_SHELL_CMD_FUNCTION(TestHash, Implement hash_map, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
129
APP_Framework/Applications/app_test/test_hash/test_hash.h
Normal file
@@ -0,0 +1,129 @@
|
||||
|
||||
/**
|
||||
* @file: test_hash.h
|
||||
* @brief: a application of test hash function
|
||||
* @version: 3.0
|
||||
* @author: Yao wenying
|
||||
* @date: 2023/05/26
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __HASHMAP_H__
|
||||
#define __HASHMAP_H__
|
||||
|
||||
#include<stdlib.h>
|
||||
#include<string.h>
|
||||
#include<stdio.h>
|
||||
|
||||
|
||||
// 实现数据的基本类型
|
||||
// 字符串类型
|
||||
#define string char *
|
||||
#define newString(str) strcpy((char *)malloc(strlen(str) + 1), str)
|
||||
#define NEW(type) (type *)malloc(sizeof(type))
|
||||
|
||||
// 布尔类型
|
||||
enum _Boolean { True = 1, False = 0 };
|
||||
typedef enum _Boolean Boolean;
|
||||
|
||||
#define let void *
|
||||
|
||||
typedef struct entry {
|
||||
let key; // 键
|
||||
let value; // 值
|
||||
struct entry * next; // 冲突链表
|
||||
}*Entry;
|
||||
|
||||
#define newEntry() NEW(struct entry)
|
||||
#define newEntryList(length) (Entry)malloc(length * sizeof(struct entry))
|
||||
|
||||
// 哈希结构
|
||||
typedef struct hashMap *HashMap;
|
||||
|
||||
#define newHashMap() NEW(struct hashMap)
|
||||
|
||||
// 哈希函数类型
|
||||
typedef int(*HashCode)(HashMap, let key);
|
||||
|
||||
// 判等函数类型
|
||||
typedef Boolean(*Equal)(let key1, let key2);
|
||||
|
||||
// 添加键函数类型
|
||||
typedef void(*Put)(HashMap hashMap, let key, let value);
|
||||
|
||||
// 获取键对应值的函数类型
|
||||
typedef let(*Get)(HashMap hashMap, let key);
|
||||
|
||||
// 删除键的函数类型
|
||||
typedef let(*Remove)(HashMap hashMap, let key);
|
||||
|
||||
// 清空Map的函数类型
|
||||
typedef void(*Clear)(HashMap hashMap);
|
||||
|
||||
// 判断键值是否存在的函数类型
|
||||
typedef Boolean(*Exists)(HashMap hashMap, let key);
|
||||
|
||||
typedef struct hashMap {
|
||||
int size; // 当前大小
|
||||
int listSize; // 有效空间大小
|
||||
HashCode hashCode; // 哈希函数
|
||||
Equal equal; // 判等函数
|
||||
Entry list; // 存储区域
|
||||
Put put; // 添加键的函数
|
||||
Get get; // 获取键对应值的函数
|
||||
Remove remove; // 删除键
|
||||
Clear clear; // 清空Map
|
||||
Exists exists; // 判断键是否存在
|
||||
Boolean autoAssign; // 设定是否根据当前数据量动态调整内存大小,默认开启
|
||||
}*HashMap;
|
||||
|
||||
// 迭代器结构
|
||||
typedef struct hashMapIterator {
|
||||
Entry entry; // 迭代器当前指向
|
||||
int count; // 迭代次数
|
||||
int hashCode; // 键值对的哈希值
|
||||
HashMap hashMap;
|
||||
}*HashMapIterator;
|
||||
|
||||
#define newHashMapIterator() NEW(struct hashMapIterator)
|
||||
|
||||
// 默认哈希函数
|
||||
static int defaultHashCode(HashMap hashMap, let key);
|
||||
|
||||
// 默认判断键值是否相等
|
||||
static Boolean defaultEqual(let key1, let key2);
|
||||
|
||||
// 默认添加键值对
|
||||
static void defaultPut(HashMap hashMap, let key, let value);
|
||||
|
||||
// 默认获取键对应值
|
||||
static let defaultGet(HashMap hashMap, let key);
|
||||
|
||||
// 默认删除键
|
||||
static let defaultRemove(HashMap hashMap, let key);
|
||||
|
||||
// 默认判断键是否存在
|
||||
static Boolean defaultExists(HashMap hashMap, let key);
|
||||
|
||||
// 默认清空Map
|
||||
static void defaultClear(HashMap hashMap);
|
||||
|
||||
// 重新构建
|
||||
static void resetHashMap(HashMap hashMap, int listSize);
|
||||
|
||||
// 创建一个哈希结构
|
||||
HashMap createHashMap(HashCode hashCode, Equal equal);
|
||||
|
||||
// 创建哈希结构迭代器
|
||||
HashMapIterator createHashMapIterator(HashMap hashMap);
|
||||
|
||||
// 迭代器是否有下一个
|
||||
Boolean hasNextHashMapIterator(HashMapIterator iterator);
|
||||
|
||||
// 迭代到下一次
|
||||
HashMapIterator nextHashMapIterator(HashMapIterator iterator);
|
||||
|
||||
// 释放迭代器内存
|
||||
void freeHashMapIterator(HashMapIterator * iterator);
|
||||
|
||||
#endif // !__HASHMAP_H__
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
|
||||
#define BSP_LED_PIN 134
|
||||
#define NULL_PARAMETER 0
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
|
||||
#define I2C_SLAVE_ADDRESS 0x0012U
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#include <transform.h>
|
||||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
#ifdef ADD_NUTTX_FEATURES
|
||||
|
||||
#ifdef CONFIG_K210_LCD
|
||||
void LcdDemo(void)
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
|
||||
#define GRAPHIC_CTRL_RECT_UPDATE 0x00
|
||||
#define LCD_STRING_TYPE 0
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
|
||||
#define NULL_PARAMETER 0
|
||||
#define E220_CFG_LENGTH
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#include <transform.h>
|
||||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
#ifdef ADD_NUTTX_FEATURES
|
||||
|
||||
#if defined(CONFIG_MUSL_LIBC) && defined(CONFIG_FS_AUTOMOUNTER)
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
# 基于k210-emulator实现基数树并测试验证
|
||||
|
||||
## 1. 简介
|
||||
|
||||
基于矽璓模拟器k210-emulator,实现基数树,并编写测试程序在shell终端打印结果。
|
||||
|
||||
## 2. 数据结构设计说明
|
||||
|
||||
基数树节点设计为:
|
||||
|
||||
```c
|
||||
typedef struct _node {
|
||||
void* value;
|
||||
struct _node* next[NODE_SIZE];
|
||||
} node;
|
||||
```
|
||||
|
||||
其中,节点在树中的路径即为键,`value` 存储值,`NODE_SIZE` 定义为 128,足以容纳所有 ASCII 值。
|
||||
|
||||
一共实现了 5 个函数,分别为:
|
||||
|
||||
- `CreateNode`:创建一个基数树节点
|
||||
- `InsertNode`:将一对键值对插入基数树
|
||||
- `DeleteNode`:删除指定键的键值对
|
||||
- `FindNode`:查找指定键对应的值
|
||||
- `DestroyTree`:销毁整个基数树
|
||||
|
||||
## 3. 测试程序说明
|
||||
|
||||
测试程序 `TestRadix` 已经注册为 shell 命令,可以调用执行。
|
||||
|
||||
测试程序定义了以下键值对:
|
||||
|
||||
```c
|
||||
char keys[][MAX_WORD_LEN] = {
|
||||
"what",
|
||||
"where",
|
||||
"why",
|
||||
"how",
|
||||
"hello!",
|
||||
"apple",
|
||||
"12345"
|
||||
};
|
||||
int values[] = {1, 2, 3, 4, 5, 6, 7};
|
||||
```
|
||||
|
||||
1. 程序的第一部分创建了基数树,并且将定义的 7 个键值对的前 6 个插入了基数树,然后分别查找 7 个键,前 6 个均可以找到对应的值,最后一个未插入,因此无法找到
|
||||
2. 程序的第二部分从基数树中删除了 `where` 和 `how` 两个键,再次分别查找 7 个键,删除的键值对和未插入的键值对均无法找到
|
||||
3. 程序的第三部分重新插入了已删除的 `where` 和未插入过的 `12345` ,再次分别查找 7 个键,新插入的值可以检索到
|
||||
4. 程序的第四部分将基数树销毁,再次分别查找 7 个键,所有的键值对均无法找到
|
||||
|
||||
## 4. 运行结果(##需结合运行测试截图按步骤说明##)
|
||||
|
||||
1. 在工作区终端中输入命令:`make BOARD=k210-emulator menuconfig`,进入配置页面
|
||||

|
||||
2. 依次进入 `APP_Framework` -> `Applications` -> `test app` 目录,将 `Enable application test function` 选项置为 `Y`
|
||||

|
||||
3. 进入 `Enable application test function` 将 `Config test radix tree` 选项置为 `Y`
|
||||

|
||||
4. 一直选择 `Exit` 退出配置,在最后需要确认的页面选择 `Yes` 保存配置
|
||||

|
||||
5. 执行编译命令:`make BOARD=k210-emulator`,正常情况下应当编译无误
|
||||

|
||||
6. 在 `qemu` 中运行:`qemu-system-riscv64 -nographic -machine sifive_u -bios build/XiZi-k210-emulator.elf`
|
||||

|
||||
7. 在 shell 中运行命令 `TestRadix`,执行结果与预期一致,验证完成。
|
||||

|
||||
BIN
APP_Framework/Applications/app_test/test_radix_tree/fig1.png
Normal file
|
After Width: | Height: | Size: 89 KiB |
BIN
APP_Framework/Applications/app_test/test_radix_tree/fig2.png
Normal file
|
After Width: | Height: | Size: 71 KiB |
BIN
APP_Framework/Applications/app_test/test_radix_tree/fig3.png
Normal file
|
After Width: | Height: | Size: 131 KiB |
BIN
APP_Framework/Applications/app_test/test_radix_tree/fig4.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
APP_Framework/Applications/app_test/test_radix_tree/fig5.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
APP_Framework/Applications/app_test/test_radix_tree/fig6.png
Normal file
|
After Width: | Height: | Size: 61 KiB |
BIN
APP_Framework/Applications/app_test/test_radix_tree/fig7.png
Normal file
|
After Width: | Height: | Size: 238 KiB |
@@ -0,0 +1,187 @@
|
||||
/**
|
||||
* @file: test_radix_tree.c
|
||||
* @brief: Implement a simple radix tree
|
||||
* @version: 1.0
|
||||
* @date: 2023/5/24
|
||||
*/
|
||||
|
||||
#include <transform.h>
|
||||
#include "test_radix_tree.h"
|
||||
|
||||
/**
|
||||
* @description: Create a radix tree node
|
||||
* @return node pointer
|
||||
*/
|
||||
node* CreateNode()
|
||||
{
|
||||
node* n = (node*)malloc(sizeof(node));
|
||||
n->value = NULL;
|
||||
for (int i = 0; i < NODE_SIZE; i++) {
|
||||
n->next[i] = NULL;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Insert a new node to radix tree
|
||||
* @param root - radix tree root
|
||||
* @param key - new node key
|
||||
* @param value - new node value
|
||||
* @return void
|
||||
*/
|
||||
void InsertNode(node* root, const char* key, void* value)
|
||||
{
|
||||
if (root == NULL) {
|
||||
return;
|
||||
}
|
||||
node* cur = root;
|
||||
size_t len = strlen(key);
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
uint8_t b = (uint8_t)key[i];
|
||||
if (cur->next[b] == NULL) {
|
||||
cur->next[b] = CreateNode();
|
||||
}
|
||||
cur = cur->next[b];
|
||||
}
|
||||
cur->value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Delete a node from radix tree
|
||||
* @param root - radix tree root
|
||||
* @param key - key which is needed to delete
|
||||
* @return void
|
||||
*/
|
||||
void DeleteNode(node* root, const char* key)
|
||||
{
|
||||
if (root == NULL) {
|
||||
return;
|
||||
}
|
||||
node** cur = &root;
|
||||
size_t len = strlen(key);
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
uint8_t b = (uint8_t)key[i];
|
||||
if ((*cur)->next[b] == NULL) {
|
||||
return;
|
||||
}
|
||||
cur = &((*cur)->next[b]);
|
||||
}
|
||||
|
||||
if ((*cur)->value == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
(*cur)->value = NULL;
|
||||
|
||||
int has_children = 0;
|
||||
for (int i = 0; i < NODE_SIZE; i++) {
|
||||
if ((*cur)->next[i] != NULL) {
|
||||
has_children = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!has_children) {
|
||||
free(*cur);
|
||||
(*cur) = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: find a node by key
|
||||
* @param root - radix tree root
|
||||
* @param key - key which is needed to find
|
||||
* @return value pointer corresponding to key
|
||||
*/
|
||||
void* FindNode(node* root, const char* key)
|
||||
{
|
||||
if (root == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
node* cur = root;
|
||||
size_t len = strlen(key);
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
uint8_t b = (uint8_t)key[i];
|
||||
if (cur->next[b] == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
cur = cur->next[b];
|
||||
}
|
||||
return cur->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Destroy the radix tree
|
||||
* @param root - radix tree root
|
||||
* @return void
|
||||
*/
|
||||
void DestroyTree(node* root)
|
||||
{
|
||||
if (root == NULL) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < NODE_SIZE; i++) {
|
||||
DestroyTree(root->next[i]);
|
||||
}
|
||||
free(root);
|
||||
}
|
||||
|
||||
void TestRadix()
|
||||
{
|
||||
char keys[][MAX_WORD_LEN] = {
|
||||
"what",
|
||||
"where",
|
||||
"why",
|
||||
"how",
|
||||
"hello!",
|
||||
"apple",
|
||||
"12345"
|
||||
};
|
||||
int values[] = {1, 2, 3, 4, 5, 6, 7};
|
||||
|
||||
printf("\nCreate tree and add key & value:\n");
|
||||
node* root = CreateNode();
|
||||
if (!root) printf("Create node failed.\n");
|
||||
|
||||
int num = sizeof(keys) / sizeof(keys[0]);
|
||||
for (int i = 0; i < num - 1; ++i) {
|
||||
InsertNode(root, keys[i], &values[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < num; ++i) {
|
||||
int* v = (int*)FindNode(root, keys[i]);
|
||||
if (v) printf("keys[%d] \"%s\"'v = %d, values[%d] = %d\n", i, keys[i], *v, i, values[i]);
|
||||
else printf("keys[%d] \"%s\" not found\n", i, keys[i]);
|
||||
}
|
||||
|
||||
printf("\nDelete \"where\" and \"how\":\n");
|
||||
DeleteNode(root, keys[1]);
|
||||
DeleteNode(root, keys[3]);
|
||||
|
||||
for (int i = 0; i < num; ++i) {
|
||||
int* v = (int*)FindNode(root, keys[i]);
|
||||
if (v) printf("keys[%d] \"%s\"'v = %d, values[%d] = %d\n", i, keys[i], *v, i, values[i]);
|
||||
else printf("keys[%d] \"%s\" not found\n", i, keys[i]);
|
||||
}
|
||||
|
||||
printf("\nInsert \"where\" and \"12345\":\n");
|
||||
InsertNode(root, keys[1], &values[1]);
|
||||
InsertNode(root, keys[6], &values[6]);
|
||||
|
||||
for (int i = 0; i < num; ++i) {
|
||||
int* v = (int*)FindNode(root, keys[i]);
|
||||
if (v) printf("keys[%d] \"%s\"'v = %d, values[%d] = %d\n", i, keys[i], *v, i, values[i]);
|
||||
else printf("keys[%d] \"%s\" not found\n", i, keys[i]);
|
||||
}
|
||||
|
||||
printf("\nDestroy tree:\n");
|
||||
DestroyTree(root);
|
||||
root = NULL;
|
||||
|
||||
for (int i = 0; i < num; ++i) {
|
||||
int* v = (int*)FindNode(root, keys[i]);
|
||||
if (v) printf("keys[%d] \"%s\"'v = %d, values[%d] = %d\n", i, keys[i], *v, i, values[i]);
|
||||
else printf("keys[%d] \"%s\" not found\n", i, keys[i]);
|
||||
}
|
||||
}
|
||||
|
||||
PRIV_SHELL_CMD_FUNCTION(TestRadix, Implement a simple radix tree, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* @file: test_radix_tree.h
|
||||
* @brief: Implement a simple radix tree
|
||||
* @version: 1.0
|
||||
* @date: 2023/5/24
|
||||
*/
|
||||
|
||||
#define NODE_SIZE 128
|
||||
#define MAX_WORD_LEN 128
|
||||
|
||||
typedef struct _node {
|
||||
void* value;
|
||||
struct _node* next[NODE_SIZE];
|
||||
} node;
|
||||
|
||||
node* CreateNode();
|
||||
void InsertNode(node* root, const char* key, void* value);
|
||||
void DeleteNode(node* root, const char* key);
|
||||
void* FindNode(node* root, const char* key);
|
||||
void DestroyTree(node* root);
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
|
||||
#define BSP_485_DIR_PIN 24
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
|
||||
void TestRTC(int argc,char *argv[])
|
||||
{
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include <transform.h>
|
||||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
#ifdef ADD_NUTTX_FEATURES
|
||||
|
||||
#ifdef CONFIG_BSP_USING_TOUCH
|
||||
void TestTouch(void)
|
||||
@@ -48,7 +48,7 @@ void TestTouch(void)
|
||||
#define LCD_DOT_TYPE 1
|
||||
#define LCD_SIZE 320
|
||||
|
||||
#elif defined ADD_XIZI_FETURES
|
||||
#elif defined ADD_XIZI_FEATURES
|
||||
|
||||
void TestTouch(void)
|
||||
{
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
|
||||
void TestWDT(int argc, char *agrv[])
|
||||
{
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
include $(KERNEL_ROOT)/.config
|
||||
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FEATURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
include $(APPDIR)/Application.mk
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
ifeq ($(CONFIG_ADD_XIZI_FEATURES),y)
|
||||
|
||||
ifeq ($(CONFIG_CONNECTION_ADAPTER_4G),y)
|
||||
SRC_DIR += 4g_app
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright (c) 2022 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file modbus_rtu_app.c
|
||||
* @brief support get data from and send data to Modbus rtu server
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022.12.12
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
#include <adapter.h>
|
||||
|
||||
#define ADAPTER_RTU_DATA_LENGTH 112
|
||||
#define ADAPTER_RTU_TRANSFER_DATA_LENGTH ADAPTER_RTU_DATA_LENGTH + 16
|
||||
|
||||
uint8_t client_join_data[ADAPTER_RTU_TRANSFER_DATA_LENGTH];
|
||||
|
||||
/* ----------------------- Modbus includes ----------------------------------*/
|
||||
#include "mb.h"
|
||||
#include "mbport.h"
|
||||
|
||||
/* ----------------------- Defines ------------------------------------------*/
|
||||
#define REG_INPUT_START 1000
|
||||
#define REG_INPUT_NREGS 4
|
||||
|
||||
/* ----------------------- Static variables ---------------------------------*/
|
||||
static USHORT usRegInputStart = REG_INPUT_START;
|
||||
static USHORT usRegInputBuf[REG_INPUT_NREGS];
|
||||
|
||||
/* ----------------------- Start implementation -----------------------------*/
|
||||
|
||||
eMBErrorCode
|
||||
eMBRegInputCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs )
|
||||
{
|
||||
eMBErrorCode eStatus = MB_ENOERR;
|
||||
int iRegIndex;
|
||||
|
||||
if( ( usAddress >= REG_INPUT_START )
|
||||
&& ( usAddress + usNRegs <= REG_INPUT_START + REG_INPUT_NREGS ) )
|
||||
{
|
||||
iRegIndex = ( int )( usAddress - usRegInputStart );
|
||||
while( usNRegs > 0 )
|
||||
{
|
||||
*pucRegBuffer++ =
|
||||
( unsigned char )( usRegInputBuf[iRegIndex] >> 8 );
|
||||
*pucRegBuffer++ =
|
||||
( unsigned char )( usRegInputBuf[iRegIndex] & 0xFF );
|
||||
iRegIndex++;
|
||||
usNRegs--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
eStatus = MB_ENOREG;
|
||||
}
|
||||
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
eMBErrorCode
|
||||
eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs,
|
||||
eMBRegisterMode eMode )
|
||||
{
|
||||
return MB_ENOREG;
|
||||
}
|
||||
|
||||
|
||||
eMBErrorCode
|
||||
eMBRegCoilsCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNCoils,
|
||||
eMBRegisterMode eMode )
|
||||
{
|
||||
return MB_ENOREG;
|
||||
}
|
||||
|
||||
eMBErrorCode
|
||||
eMBRegDiscreteCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNDiscrete )
|
||||
{
|
||||
return MB_ENOREG;
|
||||
}
|
||||
|
||||
|
||||
/******************Modbus RTU TEST*********************/
|
||||
int AdapterModbusRtuTest(void)
|
||||
{
|
||||
const char *send_msg = "Adapter_Modbus_Rtu Test";
|
||||
char recv_msg[256] = {0};
|
||||
int baud_rate = BAUD_RATE_115200;
|
||||
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_MODBUS_RTU_NAME);
|
||||
|
||||
struct AdapterData priv_rtu_net;
|
||||
priv_rtu_net.len = ADAPTER_RTU_TRANSFER_DATA_LENGTH;
|
||||
priv_rtu_net.buffer = client_join_data;
|
||||
|
||||
|
||||
AdapterDeviceOpen(adapter);
|
||||
AdapterDeviceControl(adapter, OPE_INT, &baud_rate);
|
||||
|
||||
AdapterDeviceJoin(adapter,(uint8_t *)&priv_rtu_net);
|
||||
|
||||
|
||||
|
||||
eMBErrorCode eStatus;
|
||||
|
||||
eStatus = eMBInit( MB_RTU, 0x0A, 0, 38400, MB_PAR_EVEN );
|
||||
|
||||
/* Enable the Modbus Protocol Stack. */
|
||||
eStatus = eMBEnable( );
|
||||
|
||||
for( ;; )
|
||||
{
|
||||
( void )eMBPoll( );//判断事件的发生,并执行对应的回调函数
|
||||
|
||||
/* Here we simply count the number of poll cycles. */
|
||||
usRegInputBuf[0]++;
|
||||
}
|
||||
|
||||
// while (1) {
|
||||
// AdapterDeviceSend(adapter, send_msg, strlen(send_msg));
|
||||
// AdapterDeviceRecv(adapter, recv_msg, 256);
|
||||
// printf("4G recv msg %s\n", recv_msg);
|
||||
// memset(recv_msg, 0, 256);
|
||||
// }
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
PRIV_SHELL_CMD_FUNCTION(AdapterModbusRtuTest, a Modbus Rtu adpter sample, PRIV_SHELL_CMD_FUNC_ATTR);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
ifeq ($(CONFIG_ADD_XIZI_FEATURES),y)
|
||||
SRC_FILES := lwip_tcp_socket_demo.c lwip_udp_socket_demo.c
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/.config
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FEATURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
CSRCS += lwip_tcp_socket_demo.c lwip_udp_socket_demo.c
|
||||
include $(APPDIR)/Application.mk
|
||||
|
||||
@@ -20,13 +20,13 @@
|
||||
|
||||
#include <transform.h>
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
#include <sys_arch.h>
|
||||
#include <lwip/sockets.h>
|
||||
#include "lwip/sys.h"
|
||||
#endif
|
||||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
#ifdef ADD_NUTTX_FEATURES
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
@@ -45,7 +45,7 @@ static char tcp_demo_ipaddr[] = {192, 168, 131, 77};
|
||||
static char tcp_demo_netmask[] = {255, 255, 254, 0};
|
||||
static char tcp_demo_gwaddr[] = {192, 168, 131, 1};
|
||||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
#ifdef ADD_NUTTX_FEATURES
|
||||
#define lw_print printf
|
||||
#define lw_notice printf
|
||||
#define lw_error printf
|
||||
@@ -151,7 +151,7 @@ void TcpSocketRecvTest(int argc, char *argv[])
|
||||
TcpSocketConfigParam(argv[1]);
|
||||
}
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
lwip_config_tcp(0, tcp_demo_ipaddr, tcp_demo_netmask, tcp_demo_gwaddr);
|
||||
|
||||
pthread_attr_t attr;
|
||||
@@ -159,7 +159,7 @@ void TcpSocketRecvTest(int argc, char *argv[])
|
||||
attr.stacksize = LWIP_TCP_DEMO_TASK_STACK_SIZE;
|
||||
#endif
|
||||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
#ifdef ADD_NUTTX_FEATURES
|
||||
pthread_attr_t attr = PTHREAD_ATTR_INITIALIZER;
|
||||
attr.priority = LWIP_TCP_DEMO_TASK_PRIO;
|
||||
attr.stacksize = LWIP_TCP_DEMO_TASK_STACK_SIZE;
|
||||
@@ -222,14 +222,14 @@ void TcpSocketSendTest(int argc, char *argv[])
|
||||
TcpSocketConfigParam(argv[1]);
|
||||
}
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
lwip_config_tcp(0, tcp_demo_ipaddr, tcp_demo_netmask, tcp_demo_gwaddr);
|
||||
|
||||
pthread_attr_t attr;
|
||||
attr.schedparam.sched_priority = LWIP_TCP_DEMO_TASK_PRIO;
|
||||
attr.stacksize = LWIP_TCP_DEMO_TASK_STACK_SIZE;
|
||||
#endif
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
#ifdef ADD_NUTTX_FEATURES
|
||||
pthread_attr_t attr = PTHREAD_ATTR_INITIALIZER;
|
||||
attr.priority = LWIP_TCP_DEMO_TASK_PRIO;
|
||||
attr.stacksize = LWIP_TCP_DEMO_TASK_STACK_SIZE;
|
||||
|
||||
@@ -19,12 +19,12 @@
|
||||
*/
|
||||
#include <transform.h>
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
#include <sys_arch.h>
|
||||
#include "lwip/sockets.h"
|
||||
#endif
|
||||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
#ifdef ADD_NUTTX_FEATURES
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
@@ -133,14 +133,14 @@ void UdpSocketRecvTest(int argc, char *argv[])
|
||||
UdpSocketConfigParam(argv[1]);
|
||||
}
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
lwip_config_tcp(0, udp_demo_ipaddr, udp_demo_netmask, udp_demo_gwaddr);
|
||||
|
||||
pthread_attr_t attr;
|
||||
attr.schedparam.sched_priority = LWIP_UDP_DEMO_TASK_PRIO;
|
||||
attr.stacksize = LWIP_UDP_DEMO_TASK_STACK_SIZE;
|
||||
#endif
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
#ifdef ADD_NUTTX_FEATURES
|
||||
pthread_attr_t attr = PTHREAD_ATTR_INITIALIZER;
|
||||
attr.priority = LWIP_UDP_DEMO_TASK_PRIO;
|
||||
attr.stacksize = LWIP_UDP_DEMO_TASK_STACK_SIZE;
|
||||
@@ -199,14 +199,14 @@ void UdpSocketSendTest(int argc, char *argv[])
|
||||
UdpSocketConfigParam(argv[1]);
|
||||
}
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
lwip_config_tcp(0, udp_demo_ipaddr, udp_demo_netmask, udp_demo_gwaddr);
|
||||
|
||||
pthread_attr_t attr;
|
||||
attr.schedparam.sched_priority = LWIP_UDP_DEMO_TASK_PRIO;
|
||||
attr.stacksize = LWIP_UDP_DEMO_TASK_STACK_SIZE;
|
||||
#endif
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
#ifdef ADD_NUTTX_FEATURES
|
||||
pthread_attr_t attr = PTHREAD_ATTR_INITIALIZER;
|
||||
attr.priority = LWIP_UDP_DEMO_TASK_PRIO;
|
||||
attr.stacksize = LWIP_UDP_DEMO_TASK_STACK_SIZE;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
SRC_DIR := advantech beckhoff br delta mitsubishi omron schneider siemens ge xinje inovance
|
||||
SRC_DIR := advantech beckhoff br delta mitsubishi omron schneider siemens ge xinje inovance keyence
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
SRC_FILES := inovance_am401_cpu1608tn_ethernet.c
|
||||
SRC_FILES := inovance_am401_cpu1608tn_ethernet.c inovance_am401_cpu1608tn_uart.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2022 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file inovance_am401_cpu1608tn_ethernet.c
|
||||
* @brief PLC inovance am401 app
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.5.15
|
||||
*/
|
||||
|
||||
#include <control.h>
|
||||
|
||||
extern int Adapter4GActive(void);
|
||||
|
||||
void ControlInovanceam401UartTest(void)
|
||||
{
|
||||
int i, j = 0;
|
||||
int read_data_length = 0;
|
||||
uint8_t read_data[128] = {0};
|
||||
|
||||
#ifdef CONNECTION_ADAPTER_4G
|
||||
Adapter4GActive();
|
||||
#endif
|
||||
|
||||
ControlProtocolType modbus_rtu_protocol = ControlProtocolFind();
|
||||
if (NULL == modbus_rtu_protocol) {
|
||||
printf("%s get modbus rtu protocol %p failed\n", __func__, modbus_rtu_protocol);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("%s get modbus rtu protocol %p successfull\n", __func__, modbus_rtu_protocol);
|
||||
|
||||
if (CONTROL_REGISTERED == modbus_rtu_protocol->protocol_status) {
|
||||
ControlProtocolOpen(modbus_rtu_protocol);
|
||||
|
||||
for (;;) {
|
||||
read_data_length = ControlProtocolRead(modbus_rtu_protocol, read_data, sizeof(read_data));
|
||||
printf("%s read [%d] modbus rtu data %d using receipe file\n", __func__, i, read_data_length);
|
||||
if (read_data_length) {
|
||||
for (j = 0; j < read_data_length; j ++) {
|
||||
printf("j %d data 0x%x\n", j, read_data[j]);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
memset(read_data, 0, sizeof(read_data));
|
||||
PrivTaskDelay(10000);
|
||||
}
|
||||
|
||||
//ControlProtocolClose(modbus_rtu_protocol);
|
||||
}
|
||||
}
|
||||
PRIV_SHELL_CMD_FUNCTION(ControlInovanceam401UartTest, inovance am401 uart Demo, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
{
|
||||
"device_id": 1,
|
||||
"device_name": "INOVANCE_am401_RTU",
|
||||
"communication_type": 1,
|
||||
"serial_config": {
|
||||
"station": 1,
|
||||
"baud_rate": 9600,
|
||||
"data_bits": 8,
|
||||
"stop_bits": 1,
|
||||
"check_mode":3
|
||||
},
|
||||
"protocol_type": 3,
|
||||
"read_period": 2000,
|
||||
"read_item_list": [
|
||||
{
|
||||
"value_name": "q00",
|
||||
"value_type": 1,
|
||||
"function_code": 1,
|
||||
"start_address": 0,
|
||||
"quantity": 1
|
||||
},
|
||||
{
|
||||
"value_name": "q01",
|
||||
"value_type": 1,
|
||||
"function_code": 1,
|
||||
"start_address":1,
|
||||
"quantity": 1
|
||||
},
|
||||
{
|
||||
"value_name": "q10",
|
||||
"value_type": 1,
|
||||
"function_code": 1,
|
||||
"start_address": 8,
|
||||
"quantity": 1
|
||||
},
|
||||
{
|
||||
"value_name": "mw100",
|
||||
"value_type": 3,
|
||||
"function_code": 3,
|
||||
"start_address": 100,
|
||||
"quantity": 1
|
||||
},
|
||||
{
|
||||
"value_name": "mw101",
|
||||
"value_type": 3,
|
||||
"function_code": 3,
|
||||
"start_address": 101,
|
||||
"quantity": 1
|
||||
},
|
||||
{
|
||||
"value_name": "md200",
|
||||
"value_type": 4,
|
||||
"function_code": 3,
|
||||
"start_address": 400,
|
||||
"quantity": 2
|
||||
},
|
||||
{
|
||||
"value_name": "md201",
|
||||
"value_type": 4,
|
||||
"function_code": 3,
|
||||
"start_address": 402,
|
||||
"quantity": 2
|
||||
},
|
||||
{
|
||||
"value_name": "md300",
|
||||
"value_type": 9,
|
||||
"function_code": 3,
|
||||
"start_address": 600,
|
||||
"quantity": 2
|
||||
},
|
||||
{
|
||||
"value_name": "md301",
|
||||
"value_type": 9,
|
||||
"function_code": 3,
|
||||
"start_address": 602,
|
||||
"quantity": 2
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
3
APP_Framework/Applications/control_app/plc_demo/keyence/Makefile
Executable file
@@ -0,0 +1,3 @@
|
||||
SRC_FILES := kv_8000.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
@@ -0,0 +1,22 @@
|
||||
# KEYENCE 通信测试
|
||||
|
||||
[TOC]
|
||||
|
||||
## 通信接线及参数设置
|
||||
|
||||
* 网口
|
||||
|
||||
*Mosbus TCP协议,IP:192.168.250.40,Port:502
|
||||
|
||||
## 存储区
|
||||
|
||||
- 存储区ZF区。
|
||||
|
||||
## 通信测试
|
||||
|
||||
(1)共测试INT16类型数据。
|
||||
|
||||
(2)测试ZF区数据。
|
||||
|
||||
(3)D区数据测试,用功能码03和06,以字为单位读写。如读写ZF1,则配方文件中起始地址则直接写1即可。
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2022 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file kv_8000.c
|
||||
* @brief PLC KEYENCE KV-8000 app
|
||||
* @version 3.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2023.4.12
|
||||
*/
|
||||
|
||||
#include <control.h>
|
||||
void ControlKV8000Test(void)
|
||||
{
|
||||
int i, j = 0;
|
||||
int read_data_length = 0;
|
||||
uint8_t read_data[128] = {0};
|
||||
ControlProtocolType modbus_tcp_protocol = ControlProtocolFind();
|
||||
if (NULL == modbus_tcp_protocol) {
|
||||
printf("%s get modbus tcp protocol %p failed\n", __func__, modbus_tcp_protocol);
|
||||
return;
|
||||
}
|
||||
printf("%s get modbus tcp protocol %p successfull\n", __func__, modbus_tcp_protocol);
|
||||
|
||||
if (CONTROL_REGISTERED == modbus_tcp_protocol->protocol_status) {
|
||||
ControlProtocolOpen(modbus_tcp_protocol);
|
||||
for (;;) {
|
||||
read_data_length = ControlProtocolRead(modbus_tcp_protocol, read_data, sizeof(read_data));
|
||||
printf("%s read [%d] modbus tcp data %d using receipe file\n", __func__, i, read_data_length);
|
||||
if (read_data_length) {
|
||||
for (j = 0; j < read_data_length; j ++) {
|
||||
printf("j %d data 0x%x\n", j, read_data[j]);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
memset(read_data, 0, sizeof(read_data));
|
||||
PrivTaskDelay(10000);
|
||||
}
|
||||
//ControlProtocolClose(modbus_tcp_protocol);
|
||||
}
|
||||
}
|
||||
PRIV_SHELL_CMD_FUNCTION(ControlKV8000Test, KEYENCE Plc KV_8000 Demo, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"device_id": 1,
|
||||
"device_name": "GJ2",
|
||||
"communication_type": 0,
|
||||
"socket_config": {
|
||||
"plc_ip": "192.168.250.40",
|
||||
"local_ip": "192.168.250.233",
|
||||
"gateway": "192.168.250.1",
|
||||
"netmask": "255.255.255.0",
|
||||
"port": 502
|
||||
},
|
||||
"protocol_type": 2,
|
||||
"read_period": 100,
|
||||
"read_item_list": [
|
||||
{
|
||||
"value_name": "ZF0",
|
||||
"value_type": 3,
|
||||
"function_code": 3,
|
||||
"start_address": 0,
|
||||
"quantity": 1
|
||||
},
|
||||
{
|
||||
"value_name": "ZF1",
|
||||
"value_type": 3,
|
||||
"function_code": 3,
|
||||
"start_address": 1,
|
||||
"quantity": 1
|
||||
},
|
||||
{
|
||||
"value_name": "ZF2",
|
||||
"value_type": 3,
|
||||
"function_code": 3,
|
||||
"start_address": 2,
|
||||
"quantity": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
# SCHNEIDER M241通信测试
|
||||
|
||||
[TOC]
|
||||
|
||||
## 通信接线及参数设置
|
||||
|
||||
* 串口
|
||||
* M241支持2路485串口,本次采用的是serial2。波特率:9600,数据位:8位,停止位:1位,校验:偶校验
|
||||
|
||||
## 存储区
|
||||
|
||||
- 存储区MW区。
|
||||
|
||||
## 通信测试
|
||||
|
||||
(1)共测试INT16共1种类型数据。
|
||||
|
||||
(2)测试MW区数据。
|
||||
|
||||
(3)MW区数据测试,用功能码03,以字为单位读取。如读MW100,则配方文件中起始地址则直接写100即可。
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
# XINJIE 通信测试
|
||||
|
||||
[TOC]
|
||||
|
||||
## 通信接线及参数设置
|
||||
|
||||
* 网口
|
||||
|
||||
*Mosbus TCP协议,IP:192.168.250.32,Port:502
|
||||
|
||||
## 存储区
|
||||
|
||||
- 存储区M、D区。
|
||||
|
||||
## 通信测试
|
||||
|
||||
(1)共测试BOOL,INT16共2种类型数据。
|
||||
|
||||
(2)测试M区及D区数据。
|
||||
|
||||
(3)D区数据测试,用功能码03和06,以字为单位读写。如读写D500,则配方文件中起始地址则直接写500即可。
|
||||
|
||||
(4)M区数据测试,用功能码01和05,以位为单位读写。如读写M19,则配方文件中起始地址则直接写19即可。
|
||||
@@ -1,11 +1,11 @@
|
||||
include $(KERNEL_ROOT)/.config
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FEATURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
CSRCS += circular_area_app.c
|
||||
include $(APPDIR)/Application.mk
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
ifeq ($(CONFIG_ADD_XIZI_FEATURES),y)
|
||||
SRC_FILES := circular_area_app.c
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
endif
|
||||
@@ -1,11 +1,11 @@
|
||||
include $(KERNEL_ROOT)/.config
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FEATURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
CSRCS += double_list.c single_list.c
|
||||
include $(APPDIR)/Application.mk
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
ifeq ($(CONFIG_ADD_XIZI_FEATURES),y)
|
||||
SRC_FILES := double_list.c single_list.c
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
endif
|
||||
@@ -1,6 +1,6 @@
|
||||
include $(KERNEL_ROOT)/.config
|
||||
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FEATURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
|
||||
ifeq ($(CONFIG_K210_FFT_TEST), y)
|
||||
|
||||
@@ -155,7 +155,7 @@ void k210_fft_test(void)
|
||||
cycle[FFT_SOFT][FFT_DIR_BACKWARD]/(sysctl_clock_get_freq(SYSCTL_CLOCK_CPU)/1000000));
|
||||
}
|
||||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
#ifdef ADD_NUTTX_FEATURES
|
||||
void nuttx_k210_fft_test(void)
|
||||
{
|
||||
pthread_t thread;
|
||||
|
||||
@@ -71,7 +71,7 @@ void mnist_nnom(int argc, char **argv)
|
||||
printf("Predicted label: %d\n", predic_label);
|
||||
printf("Probability: %d%%\n", (int)(prob * 100));
|
||||
}
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
PRIV_SHELL_CMD_FUNCTION(mnist_nnom, a mnist_nnom test sample, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
#endif
|
||||
#ifdef __RT_THREAD_H__
|
||||
|
||||
@@ -108,7 +108,7 @@ menu "sensor app"
|
||||
bool "Using sensor HS300x apps"
|
||||
default n
|
||||
|
||||
if ADD_NUTTX_FETURES
|
||||
if ADD_NUTTX_FEATURES
|
||||
endif
|
||||
|
||||
endif
|
||||
@@ -122,7 +122,7 @@ menu "sensor app"
|
||||
bool "Using sensor HS300x apps"
|
||||
default n
|
||||
|
||||
if ADD_NUTTX_FETURES
|
||||
if ADD_NUTTX_FEATURES
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
include $(KERNEL_ROOT)/.config
|
||||
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FEATURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_HCHO_TB600B_WQ_HCHO1OS), y)
|
||||
@@ -64,7 +64,7 @@ ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
ifeq ($(CONFIG_ADD_XIZI_FEATURES),y)
|
||||
SRC_FILES :=
|
||||
|
||||
ifeq ($(CONFIG_APPLICATION_SENSOR_HCHO_TB600B_WQ_HCHO1OS), y)
|
||||
|
||||