feat support PRIV_SHELL_CMD_FUNCTION to fit heterogeneous OS

This commit is contained in:
Liu_Weichao 2022-09-26 17:04:04 +08:00
parent fd69c3d400
commit dbca22a1a6
64 changed files with 916 additions and 893 deletions

View File

@ -4,10 +4,6 @@ menu "test app"
default n default n
if USER_TEST if USER_TEST
config USER_TEST_SPI_FLASH
bool "Config test spi flash"
default n
menuconfig USER_TEST_ADC menuconfig USER_TEST_ADC
bool "Config test adc" bool "Config test adc"
default n default n

View File

@ -1,8 +1,4 @@
SRC_FILES := SRC_FILES := test_shell.c
ifeq ($(CONFIG_USER_TEST_SPI_FLASH),y)
SRC_FILES += test_spi_flash.c
endif
ifeq ($(CONFIG_USER_TEST_ADC),y) ifeq ($(CONFIG_USER_TEST_ADC),y)
SRC_FILES += test_adc.c SRC_FILES += test_adc.c

View File

@ -0,0 +1,11 @@
import os
from building import *
Import('RTT_ROOT')
Import('rtconfig')
cwd = GetCurrentDir()
DEPENDS = [""]
SOURCES = ['test_shell.c']
path = [cwd]
objs = DefineGroup('app_test', src = SOURCES, depend = DEPENDS,CPPPATH = path)
Return("objs")

View File

@ -22,7 +22,7 @@
#include <string.h> #include <string.h>
#include <transform.h> #include <transform.h>
void test_adc() void TestAdc(void)
{ {
int adc_fd; int adc_fd;
uint8 adc_channel = 0x0; uint8 adc_channel = 0x0;
@ -56,6 +56,4 @@ void test_adc()
return; return;
} }
PRIV_SHELL_CMD_FUNCTION(TestAdc, a adc test sample, PRIV_SHELL_CMD_MAIN_ATTR);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
adc, test_adc, read 3.3 voltage data from adc);

View File

@ -22,7 +22,7 @@
#include <string.h> #include <string.h>
#include <transform.h> #include <transform.h>
void test_dac() void TestDac(void)
{ {
int dac_fd; int dac_fd;
uint16 dac_set_value = 800; uint16 dac_set_value = 800;
@ -56,5 +56,4 @@ void test_dac()
return; return;
} }
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), PRIV_SHELL_CMD_FUNCTION(TestDac, a dac test sample, PRIV_SHELL_CMD_MAIN_ATTR);
test_dac, test_dac, set digital data to dac);

View File

@ -1,11 +1,25 @@
/*
* Copyright (c) 2020 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.
*/
#ifdef ADD_XIZI_FETURES /**
#include <xizi.h> * @file: test_extsram.c
#endif * @brief: a extsram test application
* @version: 2.0
* @author: AIIT XUOS Lab
* @date: 2022/9/26
*
*/
#include <stdio.h> #include <transform.h>
#include <stdint.h>
#include "transform.h"
/* parameters for sram peripheral */ /* parameters for sram peripheral */
// /* stm32f4 Bank3:0X68000000 */ // /* stm32f4 Bank3:0X68000000 */
@ -22,7 +36,7 @@
#define TICK_PER_SECOND 100 #define TICK_PER_SECOND 100
int extsram_test(void) int ExtsramTest(void)
{ {
int i = 0; int i = 0;
uint32_t start_time = 0, time_cast = 0; uint32_t start_time = 0, time_cast = 0;
@ -89,9 +103,4 @@ int extsram_test(void)
return 0; return 0;
} }
PRIV_SHELL_CMD_FUNCTION(ExtsramTest, a extsram test sample, PRIV_SHELL_CMD_MAIN_ATTR);
#ifdef ADD_XIZI_FETURES
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),
sram_test, sram_test, sram_test);
#endif

View File

@ -0,0 +1,42 @@
/*
* Copyright (c) 2020 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: test_shell.c
* @brief: a application of shell function
* @version: 2.0
* @author: AIIT XUOS Lab
* @date: 2022/9/26
*/
#include <transform.h>
void TestShellMain(int argc, char *agrv[])
{
printf("%dparameter(s)\r\n", argc);
for (char i = 1; i < argc; i++) {
printf("%s\r\n", agrv[i]);
}
}
PRIV_SHELL_CMD_FUNCTION(TestShellMain, a shell main sample 1, PRIV_SHELL_CMD_MAIN_ATTR);
void TestShellMainVoid(void)
{
printf("XiUOS test_shell_main_void\r\n");
}
PRIV_SHELL_CMD_FUNCTION(TestShellMainVoid, a shell main sample 2, PRIV_SHELL_CMD_MAIN_ATTR);
void TestShellFunc(int i, char ch, char *str)
{
printf("input int: %d, char: %c, string: %s\r\n", i, ch, str);
}
PRIV_SHELL_CMD_FUNCTION(TestShellFunc, a shell func sample, PRIV_SHELL_CMD_FUNC_ATTR);

View File

@ -1,5 +1,3 @@
ifeq ($(CONFIG_ADD_XIZI_FETURES),y) ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
SRC_FILES := lwip_tcp_socket_demo.c lwip_udp_socket_demo.c SRC_FILES := lwip_tcp_socket_demo.c lwip_udp_socket_demo.c
include $(KERNEL_ROOT)/compiler.mk include $(KERNEL_ROOT)/compiler.mk

View File

@ -56,7 +56,6 @@ char tcp_socket_ip[] = {192, 168, 250, 252};
uint16_t tcp_socket_port = LWIP_TARGET_PORT; uint16_t tcp_socket_port = LWIP_TARGET_PORT;
/******************************************************************************/ /******************************************************************************/
static void TCPSocketRecvTask(void *arg) static void TCPSocketRecvTask(void *arg)
{ {
int fd = -1, clientfd; int fd = -1, clientfd;
@ -65,18 +64,15 @@ static void TCPSocketRecvTask(void *arg)
struct sockaddr_in tcp_addr; struct sockaddr_in tcp_addr;
socklen_t addr_len; socklen_t addr_len;
while(1) while(1) {
{
recv_buf = (char *)malloc(TCP_DEMO_BUF_SIZE); recv_buf = (char *)malloc(TCP_DEMO_BUF_SIZE);
if (recv_buf == NULL) if (recv_buf == NULL) {
{
lw_error("No memory\n"); lw_error("No memory\n");
continue; continue;
} }
fd = socket(AF_INET, SOCK_STREAM, 0); fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd < 0) if (fd < 0) {
{
lw_error("Socket error\n"); lw_error("Socket error\n");
free(recv_buf); free(recv_buf);
continue; continue;
@ -87,8 +83,7 @@ static void TCPSocketRecvTask(void *arg)
tcp_addr.sin_port = htons(tcp_socket_port); tcp_addr.sin_port = htons(tcp_socket_port);
memset(&(tcp_addr.sin_zero), 0, sizeof(tcp_addr.sin_zero)); memset(&(tcp_addr.sin_zero), 0, sizeof(tcp_addr.sin_zero));
if (bind(fd, (struct sockaddr *)&tcp_addr, sizeof(struct sockaddr)) == -1) if (bind(fd, (struct sockaddr *)&tcp_addr, sizeof(struct sockaddr)) == -1) {
{
lw_error("Unable to bind\n"); lw_error("Unable to bind\n");
close(fd); close(fd);
free(recv_buf); free(recv_buf);
@ -99,8 +94,7 @@ static void TCPSocketRecvTask(void *arg)
lw_notice("\n\nLocal Port:%d\n\n", tcp_socket_port); lw_notice("\n\nLocal Port:%d\n\n", tcp_socket_port);
// setup socket fd as listening mode // setup socket fd as listening mode
if (listen(fd, 5) != 0 ) if (listen(fd, 5) != 0 ) {
{
lw_error("Unable to listen\n"); lw_error("Unable to listen\n");
close(fd); close(fd);
free(recv_buf); free(recv_buf);
@ -111,12 +105,10 @@ static void TCPSocketRecvTask(void *arg)
clientfd = accept(fd, (struct sockaddr *)&tcp_addr, (socklen_t*)&addr_len); clientfd = accept(fd, (struct sockaddr *)&tcp_addr, (socklen_t*)&addr_len);
lw_notice("client %s connected\n", inet_ntoa(tcp_addr.sin_addr)); lw_notice("client %s connected\n", inet_ntoa(tcp_addr.sin_addr));
while(1) while(1) {
{
memset(recv_buf, 0, TCP_DEMO_BUF_SIZE); memset(recv_buf, 0, TCP_DEMO_BUF_SIZE);
recv_len = recvfrom(clientfd, recv_buf, TCP_DEMO_BUF_SIZE, 0, (struct sockaddr *)&tcp_addr, &addr_len); recv_len = recvfrom(clientfd, recv_buf, TCP_DEMO_BUF_SIZE, 0, (struct sockaddr *)&tcp_addr, &addr_len);
if(recv_len > 0) if(recv_len > 0) {
{
lw_notice("Receive from : %s\n", inet_ntoa(tcp_addr.sin_addr)); lw_notice("Receive from : %s\n", inet_ntoa(tcp_addr.sin_addr));
lw_notice("Receive data : %d - %s\n\n", recv_len, recv_buf); lw_notice("Receive data : %d - %s\n\n", recv_len, recv_buf);
} }
@ -133,11 +125,9 @@ void TCPSocketRecvTest(int argc, char *argv[])
{ {
int result = 0; int result = 0;
if(argc >= 2) if(argc >= 2) {
{
lw_print("lw: [%s] target ip %s\n", __func__, argv[1]); lw_print("lw: [%s] target ip %s\n", __func__, argv[1]);
if(sscanf(argv[1], "%d.%d.%d.%d:%d", &tcp_socket_ip[0], &tcp_socket_ip[1], &tcp_socket_ip[2], &tcp_socket_ip[3], &tcp_socket_port) == EOK) if(sscanf(argv[1], "%d.%d.%d.%d:%d", &tcp_socket_ip[0], &tcp_socket_ip[1], &tcp_socket_ip[2], &tcp_socket_ip[3], &tcp_socket_port) == 0) {
{
sscanf(argv[1], "%d.%d.%d.%d", &tcp_socket_ip[0], &tcp_socket_ip[1], &tcp_socket_ip[2], &tcp_socket_ip[3]); sscanf(argv[1], "%d.%d.%d.%d", &tcp_socket_ip[0], &tcp_socket_ip[1], &tcp_socket_ip[2], &tcp_socket_ip[3]);
} }
} }
@ -145,12 +135,9 @@ void TCPSocketRecvTest(int argc, char *argv[])
lwip_config_tcp(lwip_ipaddr, lwip_netmask, tcp_socket_ip); lwip_config_tcp(lwip_ipaddr, lwip_netmask, tcp_socket_ip);
sys_thread_new("TCPSocketRecvTask", TCPSocketRecvTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO); sys_thread_new("TCPSocketRecvTask", TCPSocketRecvTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
} }
PRIV_SHELL_CMD_FUNCTION(TCPSocketRecvTest, a tcp receive sample, PRIV_SHELL_CMD_MAIN_ATTR);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
TCPSocketRecv, TCPSocketRecvTest, TCP recv echo);
#endif #endif
static void TCPSocketSendTask(void *arg) static void TCPSocketSendTask(void *arg)
{ {
int cnt = LWIP_DEMO_TIMES; int cnt = LWIP_DEMO_TIMES;
@ -161,8 +148,7 @@ static void TCPSocketSendTask(void *arg)
memset(send_msg, 0, sizeof(send_msg)); memset(send_msg, 0, sizeof(send_msg));
fd = socket(AF_INET, SOCK_STREAM, 0); fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd < 0) if (fd < 0) {
{
lw_print("Socket error\n"); lw_print("Socket error\n");
return; return;
} }
@ -173,8 +159,7 @@ static void TCPSocketSendTask(void *arg)
tcp_sock.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(tcp_socket_ip[0], tcp_socket_ip[1], tcp_socket_ip[2], tcp_socket_ip[3])); tcp_sock.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(tcp_socket_ip[0], tcp_socket_ip[1], tcp_socket_ip[2], tcp_socket_ip[3]));
memset(&(tcp_sock.sin_zero), 0, sizeof(tcp_sock.sin_zero)); memset(&(tcp_sock.sin_zero), 0, sizeof(tcp_sock.sin_zero));
if (connect(fd, (struct sockaddr *)&tcp_sock, sizeof(struct sockaddr))) if (connect(fd, (struct sockaddr *)&tcp_sock, sizeof(struct sockaddr))) {
{
lw_print("Unable to connect\n"); lw_print("Unable to connect\n");
close(fd); close(fd);
return; return;
@ -182,8 +167,7 @@ static void TCPSocketSendTask(void *arg)
lw_notice("\n\nTarget Port:%d\n\n", tcp_socket_port); lw_notice("\n\nTarget Port:%d\n\n", tcp_socket_port);
while (cnt --) while (cnt --) {
{
lw_print("Lwip client is running.\n"); lw_print("Lwip client is running.\n");
snprintf(send_msg, sizeof(send_msg), "TCP test package times %d\r\n", cnt); snprintf(send_msg, sizeof(send_msg), "TCP test package times %d\r\n", cnt);
sendto(fd, send_msg, strlen(send_msg), 0, (struct sockaddr*)&tcp_sock, sizeof(struct sockaddr)); sendto(fd, send_msg, strlen(send_msg), 0, (struct sockaddr*)&tcp_sock, sizeof(struct sockaddr));
@ -195,14 +179,12 @@ static void TCPSocketSendTask(void *arg)
return; return;
} }
#ifdef ADD_XIZI_FETURES #ifdef ADD_XIZI_FETURES
void TCPSocketSendTest(int argc, char *argv[]) void TCPSocketSendTest(int argc, char *argv[])
{ {
if(argc >= 2) if(argc >= 2) {
{
lw_print("lw: [%s] target ip %s\n", __func__, argv[1]); lw_print("lw: [%s] target ip %s\n", __func__, argv[1]);
if(sscanf(argv[1], "%d.%d.%d.%d:%d", &tcp_socket_ip[0], &tcp_socket_ip[1], &tcp_socket_ip[2], &tcp_socket_ip[3], &tcp_socket_port) == EOK) if(sscanf(argv[1], "%d.%d.%d.%d:%d", &tcp_socket_ip[0], &tcp_socket_ip[1], &tcp_socket_ip[2], &tcp_socket_ip[3], &tcp_socket_port) == 0)
{ {
sscanf(argv[1], "%d.%d.%d.%d", &tcp_socket_ip[0], &tcp_socket_ip[1], &tcp_socket_ip[2], &tcp_socket_ip[3]); sscanf(argv[1], "%d.%d.%d.%d", &tcp_socket_ip[0], &tcp_socket_ip[1], &tcp_socket_ip[2], &tcp_socket_ip[3]);
} }
@ -211,12 +193,9 @@ void TCPSocketSendTest(int argc, char *argv[])
lwip_config_tcp(lwip_ipaddr, lwip_netmask, tcp_socket_ip); lwip_config_tcp(lwip_ipaddr, lwip_netmask, tcp_socket_ip);
sys_thread_new("TCP Socket Send", TCPSocketSendTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO); sys_thread_new("TCP Socket Send", TCPSocketSendTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
} }
PRIV_SHELL_CMD_FUNCTION(TCPSocketSendTest, a tcp send sample, PRIV_SHELL_CMD_MAIN_ATTR);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
TCPSocketSend, TCPSocketSendTest, TCP send demo);
#endif #endif
#ifdef ADD_NUTTX_FETURES #ifdef ADD_NUTTX_FETURES
void tcp_recv_demo(void) void tcp_recv_demo(void)
{ {

View File

@ -53,7 +53,6 @@ char udp_socket_ip[] = {192, 168, 250, 252};
uint16_t udp_socket_port = LWIP_LOCAL_PORT; uint16_t udp_socket_port = LWIP_LOCAL_PORT;
/*****************************************************************************/ /*****************************************************************************/
static void UdpSocketRecvTask(void *arg) static void UdpSocketRecvTask(void *arg)
{ {
int fd = -1; int fd = -1;
@ -62,18 +61,15 @@ static void UdpSocketRecvTask(void *arg)
int recv_len; int recv_len;
socklen_t addr_len; socklen_t addr_len;
while(1) while(1) {
{
recv_buf = (char *)malloc(UDP_BUF_SIZE); recv_buf = (char *)malloc(UDP_BUF_SIZE);
if(recv_buf == NULL) if(recv_buf == NULL) {
{
lw_error("No memory\n"); lw_error("No memory\n");
continue; continue;
} }
fd = socket(AF_INET, SOCK_DGRAM, 0); fd = socket(AF_INET, SOCK_DGRAM, 0);
if(fd < 0) if(fd < 0) {
{
lw_error("Socket error\n"); lw_error("Socket error\n");
free(recv_buf); free(recv_buf);
continue; continue;
@ -84,8 +80,7 @@ static void UdpSocketRecvTask(void *arg)
udp_addr.sin_port = htons(udp_socket_port); udp_addr.sin_port = htons(udp_socket_port);
memset(&(udp_addr.sin_zero), 0, sizeof(udp_addr.sin_zero)); memset(&(udp_addr.sin_zero), 0, sizeof(udp_addr.sin_zero));
if(bind(fd, (struct sockaddr *)&udp_addr, sizeof(struct sockaddr)) == -1) if(bind(fd, (struct sockaddr *)&udp_addr, sizeof(struct sockaddr)) == -1) {
{
lw_error("Unable to bind\n"); lw_error("Unable to bind\n");
close(fd); close(fd);
free(recv_buf); free(recv_buf);
@ -95,8 +90,7 @@ static void UdpSocketRecvTask(void *arg)
lw_notice("UDP bind sucess, start to receive.\n"); lw_notice("UDP bind sucess, start to receive.\n");
lw_notice("\n\nLocal Port:%d\n\n", udp_socket_port); lw_notice("\n\nLocal Port:%d\n\n", udp_socket_port);
while(1) while(1) {
{
memset(recv_buf, 0, UDP_BUF_SIZE); memset(recv_buf, 0, UDP_BUF_SIZE);
recv_len = recvfrom(fd, recv_buf, UDP_BUF_SIZE, 0, (struct sockaddr *)&server_addr, &addr_len); recv_len = recvfrom(fd, recv_buf, UDP_BUF_SIZE, 0, (struct sockaddr *)&server_addr, &addr_len);
if(recv_len > 0) if(recv_len > 0)
@ -115,11 +109,9 @@ static void UdpSocketRecvTask(void *arg)
#ifdef ADD_XIZI_FETURES #ifdef ADD_XIZI_FETURES
void UdpSocketRecvTest(int argc, char *argv[]) void UdpSocketRecvTest(int argc, char *argv[])
{ {
if(argc >= 2) if(argc >= 2) {
{
lw_notice("lw: [%s] target ip %s\n", __func__, argv[1]); lw_notice("lw: [%s] target ip %s\n", __func__, argv[1]);
if(sscanf(argv[1], "%d.%d.%d.%d:%d", &udp_socket_ip[0], &udp_socket_ip[1], &udp_socket_ip[2], &udp_socket_ip[3], &udp_socket_port) == EOK) if(sscanf(argv[1], "%d.%d.%d.%d:%d", &udp_socket_ip[0], &udp_socket_ip[1], &udp_socket_ip[2], &udp_socket_ip[3], &udp_socket_port) == 0) {
{
sscanf(argv[1], "%d.%d.%d.%d", &udp_socket_ip[0], &udp_socket_ip[1], &udp_socket_ip[2], &udp_socket_ip[3]); sscanf(argv[1], "%d.%d.%d.%d", &udp_socket_ip[0], &udp_socket_ip[1], &udp_socket_ip[2], &udp_socket_ip[3]);
} }
} }
@ -127,9 +119,7 @@ void UdpSocketRecvTest(int argc, char *argv[])
lwip_config_tcp(lwip_ipaddr, lwip_netmask, udp_socket_ip); lwip_config_tcp(lwip_ipaddr, lwip_netmask, udp_socket_ip);
sys_thread_new("UdpSocketRecvTask", UdpSocketRecvTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO); sys_thread_new("UdpSocketRecvTask", UdpSocketRecvTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
} }
PRIV_SHELL_CMD_FUNCTION(UdpSocketRecvTest, a udp receive sample, PRIV_SHELL_CMD_MAIN_ATTR);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
UDPSocketRecv, UdpSocketRecvTest, UDP Receive DEMO);
#endif #endif
static void UdpSocketSendTask(void *arg) static void UdpSocketSendTask(void *arg)
@ -141,8 +131,7 @@ static void UdpSocketSendTask(void *arg)
memset(send_str, 0, sizeof(send_str)); memset(send_str, 0, sizeof(send_str));
fd = socket(AF_INET, SOCK_DGRAM, 0); fd = socket(AF_INET, SOCK_DGRAM, 0);
if(fd < 0) if(fd < 0) {
{
lw_error("Socket error\n"); lw_error("Socket error\n");
return; return;
} }
@ -153,8 +142,7 @@ static void UdpSocketSendTask(void *arg)
udp_sock.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(udp_socket_ip[0], udp_socket_ip[1], udp_socket_ip[2], udp_socket_ip[3])); udp_sock.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(udp_socket_ip[0], udp_socket_ip[1], udp_socket_ip[2], udp_socket_ip[3]));
memset(&(udp_sock.sin_zero), 0, sizeof(udp_sock.sin_zero)); memset(&(udp_sock.sin_zero), 0, sizeof(udp_sock.sin_zero));
if(connect(fd, (struct sockaddr *)&udp_sock, sizeof(struct sockaddr))) if(connect(fd, (struct sockaddr *)&udp_sock, sizeof(struct sockaddr))) {
{
lw_error("Unable to connect\n"); lw_error("Unable to connect\n");
close(fd); close(fd);
return; return;
@ -163,8 +151,7 @@ static void UdpSocketSendTask(void *arg)
lw_print("UDP connect success, start to send.\n"); lw_print("UDP connect success, start to send.\n");
lw_notice("\n\nTarget Port:%d\n\n", udp_sock.sin_port); lw_notice("\n\nTarget Port:%d\n\n", udp_sock.sin_port);
while (cnt --) while (cnt --) {
{
snprintf(send_str, sizeof(send_str), "UDP test package times %d\r\n", cnt); snprintf(send_str, sizeof(send_str), "UDP test package times %d\r\n", cnt);
sendto(fd, send_str, strlen(send_str), 0, (struct sockaddr*)&udp_sock, sizeof(struct sockaddr)); sendto(fd, send_str, strlen(send_str), 0, (struct sockaddr*)&udp_sock, sizeof(struct sockaddr));
lw_notice("Send UDP msg: %s ", send_str); lw_notice("Send UDP msg: %s ", send_str);
@ -178,11 +165,9 @@ static void UdpSocketSendTask(void *arg)
#ifdef ADD_XIZI_FETURES #ifdef ADD_XIZI_FETURES
void UdpSocketSendTest(int argc, char *argv[]) void UdpSocketSendTest(int argc, char *argv[])
{ {
if(argc >= 2) if(argc >= 2) {
{
lw_notice("lw: [%s] target ip %s\n", __func__, argv[1]); lw_notice("lw: [%s] target ip %s\n", __func__, argv[1]);
if(sscanf(argv[1], "%d.%d.%d.%d:%d", &udp_socket_ip[0], &udp_socket_ip[1], &udp_socket_ip[2], &udp_socket_ip[3], &udp_socket_port) == EOK) if(sscanf(argv[1], "%d.%d.%d.%d:%d", &udp_socket_ip[0], &udp_socket_ip[1], &udp_socket_ip[2], &udp_socket_ip[3], &udp_socket_port) == 0) {
{
sscanf(argv[1], "%d.%d.%d.%d", &udp_socket_ip[0], &udp_socket_ip[1], &udp_socket_ip[2], &udp_socket_ip[3]); sscanf(argv[1], "%d.%d.%d.%d", &udp_socket_ip[0], &udp_socket_ip[1], &udp_socket_ip[2], &udp_socket_ip[3]);
} }
} }
@ -190,9 +175,7 @@ void UdpSocketSendTest(int argc, char *argv[])
lwip_config_tcp(lwip_ipaddr, lwip_netmask, udp_socket_ip); lwip_config_tcp(lwip_ipaddr, lwip_netmask, udp_socket_ip);
sys_thread_new("UdpSocketSendTask", UdpSocketSendTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO); sys_thread_new("UdpSocketSendTask", UdpSocketSendTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
} }
PRIV_SHELL_CMD_FUNCTION(UdpSocketSendTest, a udp send sample, PRIV_SHELL_CMD_MAIN_ATTR);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
UDPSocketSend, UdpSocketSendTest, UDP send echo);
#endif #endif
#ifdef ADD_NUTTX_FETURES #ifdef ADD_NUTTX_FETURES

View File

@ -20,9 +20,8 @@
#include <list.h> #include <list.h>
#include <transform.h> #include <transform.h>
#include "board.h" #include <open62541.h>
#include "open62541.h" #include <ua_api.h>
#include "ua_api.h"
/******************************************************************************* /*******************************************************************************
* Definitions * Definitions
@ -58,8 +57,7 @@ static void UaConnectTestTask(void* arg)
UA_Client* client = UA_Client_new(); UA_Client* client = UA_Client_new();
if(client == NULL) if(client == NULL) {
{
ua_error("ua: [%s] tcp client null\n", __func__); ua_error("ua: [%s] tcp client null\n", __func__);
return; return;
} }
@ -76,8 +74,7 @@ static void UaConnectTestTask(void* arg)
ret = UA_Client_connect(client, url); ret = UA_Client_connect(client, url);
if(ret != UA_STATUSCODE_GOOD) if(ret != UA_STATUSCODE_GOOD) {
{
ua_error("ua: [%s] connected failed %x\n", __func__, ret); ua_error("ua: [%s] connected failed %x\n", __func__, ret);
UA_Client_delete(client); UA_Client_delete(client);
fail_cnt++; fail_cnt++;
@ -90,12 +87,9 @@ static void UaConnectTestTask(void* arg)
static void UaConnectTest(int argc, char *argv[]) static void UaConnectTest(int argc, char *argv[])
{ {
if(argc == 2) if(argc == 2) {
{ if(isdigit(argv[1][0])) {
if(isdigit(argv[1][0])) if(sscanf(argv[1], "%d.%d.%d.%d", &test_ua_ip[0], &test_ua_ip[1], &test_ua_ip[2], &test_ua_ip[3]) == -1) {
{
if(sscanf(argv[1], "%d.%d.%d.%d", &test_ua_ip[0], &test_ua_ip[1], &test_ua_ip[2], &test_ua_ip[3]) == EOF)
{
lw_notice("input wrong ip\n"); lw_notice("input wrong ip\n");
return; return;
} }
@ -105,9 +99,7 @@ static void UaConnectTest(int argc, char *argv[])
lwip_config_tcp(lwip_ipaddr, lwip_netmask, test_ua_ip); lwip_config_tcp(lwip_ipaddr, lwip_netmask, test_ua_ip);
sys_thread_new("ua test", UaConnectTestTask, NULL, UA_STACK_SIZE, UA_TASK_PRIO); sys_thread_new("ua test", UaConnectTestTask, NULL, UA_STACK_SIZE, UA_TASK_PRIO);
} }
PRIV_SHELL_CMD_FUNCTION(UaConnectTest, a opcua connect sample, PRIV_SHELL_CMD_MAIN_ATTR);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
UaConnect, UaConnectTest, Test Opc UA connection);
void UaBrowserObjectsTestTask(void* param) void UaBrowserObjectsTestTask(void* param)
{ {
@ -115,8 +107,7 @@ void UaBrowserObjectsTestTask(void* param)
UA_Client* client = UA_Client_new(); UA_Client* client = UA_Client_new();
if(client == NULL) if(client == NULL) {
{
ua_error("ua: [%s] tcp client NULL\n", __func__); ua_error("ua: [%s] tcp client NULL\n", __func__);
return; return;
} }
@ -125,8 +116,7 @@ void UaBrowserObjectsTestTask(void* param)
UA_ClientConfig_setDefault(config); UA_ClientConfig_setDefault(config);
UA_StatusCode ret = UA_Client_connect(client, opc_server_url); UA_StatusCode ret = UA_Client_connect(client, opc_server_url);
if(ret != UA_STATUSCODE_GOOD) if(ret != UA_STATUSCODE_GOOD) {
{
ua_error("ua: [%s] connect failed %#x\n", __func__, ret); ua_error("ua: [%s] connect failed %#x\n", __func__, ret);
UA_Client_delete(client); UA_Client_delete(client);
return; return;
@ -144,12 +134,9 @@ void UaBrowserObjectsTestTask(void* param)
static void* UaBrowserObjectsTest(int argc, char* argv[]) static void* UaBrowserObjectsTest(int argc, char* argv[])
{ {
if(argc == 2) if(argc == 2) {
{ if(isdigit(argv[1][0])) {
if(isdigit(argv[1][0])) if(sscanf(argv[1], "%d.%d.%d.%d", &test_ua_ip[0], &test_ua_ip[1], &test_ua_ip[2], &test_ua_ip[3]) == -1) {
{
if(sscanf(argv[1], "%d.%d.%d.%d", &test_ua_ip[0], &test_ua_ip[1], &test_ua_ip[2], &test_ua_ip[3]) == EOF)
{
lw_notice("input wrong ip\n"); lw_notice("input wrong ip\n");
return NULL; return NULL;
} }
@ -160,17 +147,14 @@ static void* UaBrowserObjectsTest(int argc, char* argv[])
sys_thread_new("ua object", UaBrowserObjectsTestTask, NULL, UA_STACK_SIZE, UA_TASK_PRIO); sys_thread_new("ua object", UaBrowserObjectsTestTask, NULL, UA_STACK_SIZE, UA_TASK_PRIO);
return NULL; return NULL;
} }
PRIV_SHELL_CMD_FUNCTION(UaBrowserObjectsTest, a opcua object sample, PRIV_SHELL_CMD_MAIN_ATTR);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
UaObject, UaBrowserObjectsTest, UaObject [IP]);
void UaGetInfoTestTask(void* param) void UaGetInfoTestTask(void* param)
{ {
UA_Client* client = UA_Client_new(); UA_Client* client = UA_Client_new();
ua_notice("--- Get OPUCA objects ---\n", __func__); ua_notice("--- Get OPUCA objects ---\n", __func__);
if(client == NULL) if(client == NULL) {
{
ua_error("ua: [%s] tcp client null\n", __func__); ua_error("ua: [%s] tcp client null\n", __func__);
return; return;
} }
@ -179,8 +163,7 @@ void UaGetInfoTestTask(void* param)
UA_ClientConfig_setDefault(config); UA_ClientConfig_setDefault(config);
UA_StatusCode ret = UA_Client_connect(client, opc_server_url); UA_StatusCode ret = UA_Client_connect(client, opc_server_url);
if(ret != UA_STATUSCODE_GOOD) if(ret != UA_STATUSCODE_GOOD) {
{
ua_error("ua: [%s] connect failed %#x\n", __func__, ret); ua_error("ua: [%s] connect failed %#x\n", __func__, ret);
UA_Client_delete(client); UA_Client_delete(client);
return; return;
@ -192,14 +175,11 @@ void UaGetInfoTestTask(void* param)
UA_Client_delete(client); /* Disconnects the client internally */ UA_Client_delete(client); /* Disconnects the client internally */
} }
void* UaGetInfoTest(int argc, char* argv[]) void *UaGetInfoTest(int argc, char* argv[])
{ {
if(argc == 2) if(argc == 2) {
{ if(isdigit(argv[1][0])) {
if(isdigit(argv[1][0])) if(sscanf(argv[1], "%d.%d.%d.%d", &test_ua_ip[0], &test_ua_ip[1], &test_ua_ip[2], &test_ua_ip[3]) == -1) {
{
if(sscanf(argv[1], "%d.%d.%d.%d", &test_ua_ip[0], &test_ua_ip[1], &test_ua_ip[2], &test_ua_ip[3]) == EOF)
{
lw_notice("input wrong ip\n"); lw_notice("input wrong ip\n");
return NULL; return NULL;
} }
@ -210,17 +190,14 @@ void* UaGetInfoTest(int argc, char* argv[])
sys_thread_new("ua info", UaGetInfoTestTask, NULL, UA_STACK_SIZE, UA_TASK_PRIO); sys_thread_new("ua info", UaGetInfoTestTask, NULL, UA_STACK_SIZE, UA_TASK_PRIO);
return NULL; return NULL;
} }
PRIV_SHELL_CMD_FUNCTION(UaGetInfoTest, a opcua info sample, PRIV_SHELL_CMD_MAIN_ATTR);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
UaInfo, UaGetInfoTest, UaInfo [IP]);
void UaAddNodesTask(void* param) void UaAddNodesTask(void* param)
{ {
UA_Client* client = UA_Client_new(); UA_Client* client = UA_Client_new();
ua_notice("ua: [%s] start ...\n", __func__); ua_notice("ua: [%s] start ...\n", __func__);
if(client == NULL) if(client == NULL) {
{
ua_error("ua: [%s] client null\n", __func__); ua_error("ua: [%s] client null\n", __func__);
return; return;
} }
@ -229,8 +206,7 @@ void UaAddNodesTask(void* param)
UA_ClientConfig_setDefault(config); UA_ClientConfig_setDefault(config);
UA_StatusCode ret = UA_Client_connect(client, opc_server_url); UA_StatusCode ret = UA_Client_connect(client, opc_server_url);
if(ret != UA_STATUSCODE_GOOD) if(ret != UA_STATUSCODE_GOOD) {
{
ua_print("ua: [%s] connect failed %#x\n", __func__, ret); ua_print("ua: [%s] connect failed %#x\n", __func__, ret);
UA_Client_delete(client); UA_Client_delete(client);
return; return;
@ -242,14 +218,11 @@ void UaAddNodesTask(void* param)
UA_Client_delete(client); /* Disconnects the client internally */ UA_Client_delete(client); /* Disconnects the client internally */
} }
void* UaAddNodesTest(int argc, char* argv[]) void *UaAddNodesTest(int argc, char* argv[])
{ {
if(argc == 2) if(argc == 2){
{ if(isdigit(argv[1][0])) {
if(isdigit(argv[1][0])) if(sscanf(argv[1], "%d.%d.%d.%d", &test_ua_ip[0], &test_ua_ip[1], &test_ua_ip[2], &test_ua_ip[3]) == -1) {
{
if(sscanf(argv[1], "%d.%d.%d.%d", &test_ua_ip[0], &test_ua_ip[1], &test_ua_ip[2], &test_ua_ip[3]) == EOF)
{
lw_notice("input wrong ip\n"); lw_notice("input wrong ip\n");
return NULL; return NULL;
} }
@ -260,7 +233,4 @@ void* UaAddNodesTest(int argc, char* argv[])
sys_thread_new("ua add nodes", UaAddNodesTask, NULL, UA_STACK_SIZE, UA_TASK_PRIO); sys_thread_new("ua add nodes", UaAddNodesTask, NULL, UA_STACK_SIZE, UA_TASK_PRIO);
return NULL; return NULL;
} }
PRIV_SHELL_CMD_FUNCTION(UaAddNodesTest, a opcua add nodes sample, PRIV_SHELL_CMD_MAIN_ATTR);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
UaAdd, UaAddNodesTest, UA Add Nodes);

View File

@ -18,10 +18,10 @@
* @date 2022.2.22 * @date 2022.2.22
*/ */
#include "transform.h" #include <transform.h>
#include "open62541.h" #include <open62541.h>
#include "ua_api.h" #include <ua_api.h>
#include "sys_arch.h" #include <sys_arch.h>
#include "plc_demo.h" #include "plc_demo.h"
#define PLC_NS_FORMAT "n%d,%s" #define PLC_NS_FORMAT "n%d,%s"
@ -41,8 +41,7 @@ UA_NodeId test_nodeid = {4, UA_NODEIDTYPE_NUMERIC, 5};
void PlcDelay(int sec) void PlcDelay(int sec)
{ {
volatile uint32_t i = 0; volatile uint32_t i = 0;
for (i = 0; i < 100000000 * sec; ++i) for (i = 0; i < 100000000 * sec; ++i) {
{
__asm("NOP"); /* delay */ __asm("NOP"); /* delay */
} }
} }
@ -55,16 +54,12 @@ void PlcGetTestNodeId(char *str, UA_NodeId *id)
plc_print("plc: arg %s\n", str); plc_print("plc: arg %s\n", str);
if(sscanf(str, PLC_NS_FORMAT, &id->namespaceIndex, node_str) != EOF) if(sscanf(str, PLC_NS_FORMAT, &id->namespaceIndex, node_str) != EOF) {
{ if(isdigit(node_str[0])) {
if(isdigit(node_str[0]))
{
id->identifierType = UA_NODEIDTYPE_NUMERIC; id->identifierType = UA_NODEIDTYPE_NUMERIC;
id->identifier.numeric = atoi(node_str); id->identifier.numeric = atoi(node_str);
plc_print("ns %d num %d\n", id->namespaceIndex, id->identifier.numeric); plc_print("ns %d num %d\n", id->namespaceIndex, id->identifier.numeric);
} } else {
else
{
id->identifierType = UA_NODEIDTYPE_STRING; id->identifierType = UA_NODEIDTYPE_STRING;
id->identifier.string.length = strlen(node_str); id->identifier.string.length = strlen(node_str);
id->identifier.string.data = node_str; id->identifier.string.data = node_str;
@ -82,8 +77,7 @@ void PlcDemoChannelDrvInit(void)
lwip_config_tcp(lwip_ipaddr, lwip_netmask, test_ua_ip); lwip_config_tcp(lwip_ipaddr, lwip_netmask, test_ua_ip);
PlcChannelInit(&plc_demo_ch, PLC_CH_NAME); PlcChannelInit(&plc_demo_ch, PLC_CH_NAME);
if(PlcDriverInit(&plc_demo_drv, PLC_DRV_NAME) == EOK) if(PlcDriverInit(&plc_demo_drv, PLC_DRV_NAME) == 0) {
{
PlcDriverAttachToChannel(PLC_DRV_NAME, PLC_CH_NAME); PlcDriverAttachToChannel(PLC_DRV_NAME, PLC_CH_NAME);
} }
memset(&plc_demo_dev, 0, sizeof(plc_demo_dev)); memset(&plc_demo_dev, 0, sizeof(plc_demo_dev));
@ -101,8 +95,7 @@ static void PlcGetDemoDev(PlcDeviceType *dev, UA_NodeId *id)
dev->net = PLC_IND_ENET_OPCUA; dev->net = PLC_IND_ENET_OPCUA;
// register UA parameter // register UA parameter
if(!dev->priv_data) if(!dev->priv_data) {
{
dev->priv_data = (UaParamType*)malloc(sizeof(UaParamType)); dev->priv_data = (UaParamType*)malloc(sizeof(UaParamType));
} }
UaParamType* ua_ptr = dev->priv_data; UaParamType* ua_ptr = dev->priv_data;
@ -121,14 +114,12 @@ static void PlcCtrlDemoInit(void)
// register plc device // register plc device
PlcGetDemoDev(&plc_demo_dev, &test_nodeid); PlcGetDemoDev(&plc_demo_dev, &test_nodeid);
if(init_flag) if(init_flag){
{
return; return;
} }
init_flag = 1; init_flag = 1;
if(PlcDevRegister(&plc_demo_dev, NULL, plc_demo_dev.name) != EOK) if(PlcDevRegister(&plc_demo_dev, NULL, plc_demo_dev.name) != 0) {
{
return; return;
} }
PlcDeviceAttachToChannel(plc_demo_dev.name, PLC_CH_NAME); PlcDeviceAttachToChannel(plc_demo_dev.name, PLC_CH_NAME);
@ -144,16 +135,14 @@ void PlcReadUATask(void* arg)
ops = plc_demo_dev.ops; ops = plc_demo_dev.ops;
ret = ops->open(&plc_demo_dev); ret = ops->open(&plc_demo_dev);
if(EOK != ret) if(0 != ret) {
{
plc_print("plc: [%s] open failed %#x\n", __func__, ret); plc_print("plc: [%s] open failed %#x\n", __func__, ret);
return; return;
} }
ret = ops->read(&plc_demo_dev, buf, PLC_BUF_SIZE); ret = ops->read(&plc_demo_dev, buf, PLC_BUF_SIZE);
if(EOK != ret) if(0 != ret) {
{
plc_print("plc: [%s] read failed %x\n", __func__, ret); plc_print("plc: [%s] read failed %x\n", __func__, ret);
} }
@ -165,16 +154,13 @@ void PlcReadTestShell(int argc, char* argv[])
static char node_str[UA_NODE_LEN]; static char node_str[UA_NODE_LEN];
memset(node_str, 0, sizeof(node_str)); memset(node_str, 0, sizeof(node_str));
if(argc > 1) if(argc > 1) {
{
PlcGetTestNodeId(argv[1], &test_nodeid); PlcGetTestNodeId(argv[1], &test_nodeid);
} }
sys_thread_new("plc read", PlcReadUATask, NULL, PLC_STACK_SIZE, PLC_TASK_PRIO); sys_thread_new("plc read", PlcReadUATask, NULL, PLC_STACK_SIZE, PLC_TASK_PRIO);
} }
PRIV_SHELL_CMD_FUNCTION(PlcReadTestShell, a plc read sample, PRIV_SHELL_CMD_MAIN_ATTR);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
PlcRead, PlcReadTestShell, Read PLC);
void PlcWriteUATask(void* arg) void PlcWriteUATask(void* arg)
{ {
@ -187,16 +173,14 @@ void PlcWriteUATask(void* arg)
ops = plc_demo_dev.ops; ops = plc_demo_dev.ops;
ret = ops->open(&plc_demo_dev); ret = ops->open(&plc_demo_dev);
if(EOK != ret) if(0 != ret) {
{
plc_print("plc: [%s] open failed %#x\n", __func__, ret); plc_print("plc: [%s] open failed %#x\n", __func__, ret);
return; return;
} }
ret = ops->write(&plc_demo_dev, arg, PLC_BUF_SIZE); ret = ops->write(&plc_demo_dev, arg, PLC_BUF_SIZE);
if(EOK != ret) if(0 != ret) {
{
plc_print("plc: [%s] write failed\n", __func__); plc_print("plc: [%s] write failed\n", __func__);
} }
@ -210,22 +194,18 @@ void PlcWriteTestShell(int argc, char* argv[])
memset(node_str, 0, sizeof(node_str)); memset(node_str, 0, sizeof(node_str));
memset(val_param, 0, sizeof(val_param)); memset(val_param, 0, sizeof(val_param));
if(argc > 1) if(argc > 1) {
{
PlcGetTestNodeId(argv[1], &test_nodeid); PlcGetTestNodeId(argv[1], &test_nodeid);
} }
if(argc > 2) if(argc > 2) {
{
strcpy(val_param, argv[2]); strcpy(val_param, argv[2]);
plc_print("write value %s\n", val_param); plc_print("write value %s\n", val_param);
} }
sys_thread_new("plc write", PlcWriteUATask, val_param, PLC_STACK_SIZE, PLC_TASK_PRIO); sys_thread_new("plc write", PlcWriteUATask, val_param, PLC_STACK_SIZE, PLC_TASK_PRIO);
} }
PRIV_SHELL_CMD_FUNCTION(PlcWriteTestShell, a plc write sample, PRIV_SHELL_CMD_MAIN_ATTR);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
PlcWrite, PlcWriteTestShell, Read PLC);
// test motor // test motor
// clear parameter // clear parameter
@ -267,8 +247,7 @@ void PlcMotorTestTask(void* arg)
ops = plc_demo_dev.ops; ops = plc_demo_dev.ops;
ret = ops->open(&plc_demo_dev); ret = ops->open(&plc_demo_dev);
if(EOK != ret) if(0 != ret) {
{
plc_print("plc: [%s] open failed %#x\n", __func__, ret); plc_print("plc: [%s] open failed %#x\n", __func__, ret);
return; return;
} }
@ -276,38 +255,32 @@ void PlcMotorTestTask(void* arg)
UaParamType* ua_ptr = plc_demo_dev.priv_data; UaParamType* ua_ptr = plc_demo_dev.priv_data;
// initialize step // initialize step
for(int i = 0; i < 5; i++) for(int i = 0; i < 5; i++) {
{
plc_print("###\n### Clear %s\n###\n", test_notice[i]); plc_print("###\n### Clear %s\n###\n", test_notice[i]);
PlcGetTestNodeId(test_nodeid[i], &ua_ptr->ua_id); PlcGetTestNodeId(test_nodeid[i], &ua_ptr->ua_id);
ret = ops->write(&plc_demo_dev, "0b", PLC_BUF_SIZE); ret = ops->write(&plc_demo_dev, "0b", PLC_BUF_SIZE);
if(EOK != ret) if(0 != ret) {
{
plc_print("plc: [%s] %d write failed\n", __func__, __LINE__); plc_print("plc: [%s] %d write failed\n", __func__, __LINE__);
} }
PlcDelay(1); PlcDelay(1);
} }
if(plc_test_speed != 50) if(plc_test_speed != 50) {
{
snprintf(test_cmd[1], 4, "%d", plc_test_speed); snprintf(test_cmd[1], 4, "%d", plc_test_speed);
} }
if(plc_test_dir == 0) // if not postive, next running if(plc_test_dir == 0) // if not postive, next running
test_sort[2] = 3; test_sort[2] = 3;
for(int i = 0; i < sizeof(test_sort)/sizeof(test_sort[0]); i++) for(int i = 0; i < sizeof(test_sort)/sizeof(test_sort[0]); i++) {
{
PlcGetTestNodeId(test_nodeid[test_sort[i]], &ua_ptr->ua_id); PlcGetTestNodeId(test_nodeid[test_sort[i]], &ua_ptr->ua_id);
plc_print("###\n### %s\n###\n", test_notice[i]); plc_print("###\n### %s\n###\n", test_notice[i]);
ret = ops->write(&plc_demo_dev, test_cmd[i], PLC_BUF_SIZE); ret = ops->write(&plc_demo_dev, test_cmd[i], PLC_BUF_SIZE);
if(EOK != ret) if(0 != ret) {
{
plc_print("plc: [%s] %d write failed\n", __func__, __LINE__); plc_print("plc: [%s] %d write failed\n", __func__, __LINE__);
} }
PlcDelay(1); PlcDelay(1);
if(i == 2) // postive if(i == 2) {// postive
{
PlcDelay(10); PlcDelay(10);
} }
} }
@ -331,24 +304,18 @@ void PlcGetMotorParam(char *str)
void PlcMotorTestShell(int argc, char* argv[]) void PlcMotorTestShell(int argc, char* argv[])
{ {
if(plc_test_flag) if(plc_test_flag) {
{
plc_print("PLC Motor testing!\n"); plc_print("PLC Motor testing!\n");
return; return;
} }
plc_test_flag = 1; plc_test_flag = 1;
if(argc > 1) if(argc > 1) {
{ for(int i = 0; i < argc; i++) {
for(int i = 0; i < argc; i++)
{
PlcGetMotorParam(argv[i]); PlcGetMotorParam(argv[i]);
} }
} }
sys_thread_new("plc motor", PlcMotorTestTask, NULL, PLC_STACK_SIZE, PLC_TASK_PRIO); sys_thread_new("plc motor", PlcMotorTestTask, NULL, PLC_STACK_SIZE, PLC_TASK_PRIO);
} }
PRIV_SHELL_CMD_FUNCTION(PlcMotorTestShell, a plc motor sample, PRIV_SHELL_CMD_MAIN_ATTR);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
PlcMotorTest, PlcMotorTestShell, Run motor);

View File

@ -18,14 +18,13 @@
* @date 2022.02.24 * @date 2022.02.24
*/ */
#include "transform.h" #include <transform.h>
#include "list.h" #include <list.h>
#include "open62541.h"
#include "ua_api.h"
#include "sys_arch.h"
#include "plc_demo.h"
#include <open62541.h>
#include <ua_api.h>
#include <sys_arch.h>
#include <plc_demo.h>
#define PLC_DEMO_NUM 5 #define PLC_DEMO_NUM 5
@ -62,36 +61,31 @@ extern DoublelistType ch_linklist;
void PlcShowTitle(const char* item_array[]) void PlcShowTitle(const char* item_array[])
{ {
int i = 0, max_len = 65; int i = 0, max_len = 65;
KPrintf(" %-15s%-15s%-15s%-15s%-20s\n", item_array[0], item_array[1], item_array[2], item_array[3], item_array[4]); printf(" %-15s%-15s%-15s%-15s%-20s\n", item_array[0], item_array[1], item_array[2], item_array[3], item_array[4]);
while(i < max_len) while(i < max_len) {
{
i++; i++;
if(max_len == i) if(max_len == i) {
{ printf("-\n");
KPrintf("-\n"); } else {
} printf("-");
else
{
KPrintf("-");
} }
} }
} }
static ChDrvType ShowChannelFindDriver(struct Channel* ch) static ChDrvType ShowChannelFindDriver(struct Channel* ch)
{ {
struct ChDrv* driver = NONE; struct ChDrv* driver = NULL;
DoublelistType* node = NONE; DoublelistType* node = NULL;
DoublelistType* head = &ch->ch_drvlink; DoublelistType* head = &ch->ch_drvlink;
for(node = head->node_next; node != head; node = node->node_next) for(node = head->node_next; node != head; node = node->node_next) {
{
driver = DOUBLE_LIST_ENTRY(node, struct ChDrv, driver_link); driver = DOUBLE_LIST_ENTRY(node, struct ChDrv, driver_link);
return driver; return driver;
} }
return NONE; return NULL;
} }
static void PlcShowDemoInit(void) static void PlcShowDemoInit(void)
@ -100,8 +94,7 @@ static void PlcShowDemoInit(void)
int i; int i;
PlcDemoChannelDrvInit(); PlcDemoChannelDrvInit();
for(i = 0; i < PLC_DEMO_NUM; i++) for(i = 0; i < PLC_DEMO_NUM; i++) {
{
// register plc device // register plc device
plc_demo_array[i].state = CHDEV_INIT; plc_demo_array[i].state = CHDEV_INIT;
snprintf(plc_demo_array[i].name, PLC_NAME_SIZE, "PLC Demo %d", i); snprintf(plc_demo_array[i].name, PLC_NAME_SIZE, "PLC Demo %d", i);
@ -116,10 +109,8 @@ static void PlcShowDemoInit(void)
return; return;
init_flag = 1; init_flag = 1;
for(i = 0; i < PLC_DEMO_NUM; i++) for(i = 0; i < PLC_DEMO_NUM; i++) {
{ if(PlcDevRegister(&plc_demo_array[i], NULL, plc_demo_array[i].name) == 0) {
if(PlcDevRegister(&plc_demo_array[i], NULL, plc_demo_array[i].name) == EOK)
{
PlcDeviceAttachToChannel(plc_demo_array[i].name, PLC_CH_NAME); PlcDeviceAttachToChannel(plc_demo_array[i].name, PLC_CH_NAME);
} }
} }
@ -131,78 +122,60 @@ void PlcShowChannel(void)
ChDrvType driver; ChDrvType driver;
ChDevType device; ChDevType device;
int dev_cnt; int dev_cnt;
DoublelistType* ch_node = NONE; DoublelistType* ch_node = NULL;
DoublelistType* ch_head = &ch_linklist; DoublelistType* ch_head = &ch_linklist;
const char* item_array[] = {"ch_type", "ch_name", "drv_name", "dev_name", "cnt"}; const char* item_array[] = {"ch_type", "ch_name", "drv_name", "dev_name", "cnt"};
PlcShowDemoInit(); PlcShowDemoInit();
PlcShowTitle(item_array); PlcShowTitle(item_array);
ch_node = ch_head->node_next; ch_node = ch_head->node_next;
do do {
{
ch = DOUBLE_LIST_ENTRY(ch_node, struct Channel, ch_link); ch = DOUBLE_LIST_ENTRY(ch_node, struct Channel, ch_link);
if((ch) && (ch->ch_type == CH_PLC_TYPE)) if((ch) && (ch->ch_type == CH_PLC_TYPE)) {
{ printf("%s", " ");
KPrintf("%s", " "); printf("%-15s%-15s",
KPrintf("%-15s%-15s",
channel_type_str[ch->ch_type], channel_type_str[ch->ch_type],
ch->ch_name); ch->ch_name);
driver = ShowChannelFindDriver(ch); driver = ShowChannelFindDriver(ch);
if(driver) if(driver) {
{ printf("%-15s", driver->drv_name);
KPrintf("%-15s", driver->drv_name); } else {
} printf("%-15s", "nil");
else
{
KPrintf("%-15s", "nil");
} }
if(ch->haldev_cnt) if(ch->haldev_cnt) {
{ DoublelistType* dev_node = NULL;
DoublelistType* dev_node = NONE;
DoublelistType* dev_head = &ch->ch_devlink; DoublelistType* dev_head = &ch->ch_devlink;
dev_node = dev_head->node_next; dev_node = dev_head->node_next;
dev_cnt = 1; dev_cnt = 1;
while(dev_node != dev_head) while(dev_node != dev_head) {
{
device = DOUBLE_LIST_ENTRY(dev_node, struct ChDev, dev_link); device = DOUBLE_LIST_ENTRY(dev_node, struct ChDev, dev_link);
if(1 == dev_cnt) if(1 == dev_cnt) {
{ if(device) {
if(device) printf("%-16s%-4d\n", device->dev_name, dev_cnt);
{ } else {
KPrintf("%-16s%-4d\n", device->dev_name, dev_cnt); printf("%-16s%-4d\n", "nil", dev_cnt);
} }
else } else {
{ printf("%46s", " ");
KPrintf("%-16s%-4d\n", "nil", dev_cnt);
}
}
else
{
KPrintf("%46s", " ");
if(device) if(device) {
{ printf("%-16s%-4d\n", device->dev_name, dev_cnt);
KPrintf("%-16s%-4d\n", device->dev_name, dev_cnt); } else {
} printf("%-16s%-4d\n", "nil", dev_cnt);
else
{
KPrintf("%-16s%-4d\n", "nil", dev_cnt);
} }
} }
dev_cnt++; dev_cnt++;
dev_node = dev_node->node_next; dev_node = dev_node->node_next;
} }
} } else {
else printf("\n");
{
KPrintf("\n");
} }
} }
@ -212,36 +185,32 @@ void PlcShowChannel(void)
return; return;
} }
PRIV_SHELL_CMD_FUNCTION(PlcShowChannel, a plc show channel sample, PRIV_SHELL_CMD_MAIN_ATTR);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
ShowChannel, PlcShowChannel, Show PLC information);
void PlcShowDev(void) void PlcShowDev(void)
{ {
PlcDeviceType* plc_dev; PlcDeviceType* plc_dev;
ChDrvType driver; ChDrvType driver;
ChDevType device; ChDevType device;
DoublelistType* plc_node = NONE; DoublelistType* plc_node = NULL;
DoublelistType* plc_head = &plcdev_list; DoublelistType* plc_head = &plcdev_list;
const char* item_array[] = {"device", "vendor", "model", "product", "id"}; const char* item_array[] = {"device", "vendor", "model", "product", "id"};
PlcShowDemoInit(); PlcShowDemoInit();
PlcShowTitle(item_array); PlcShowTitle(item_array);
plc_node = plc_head->node_next; plc_node = plc_head->node_next;
do do {
{
plc_dev = DOUBLE_LIST_ENTRY(plc_node, struct PlcDevice, link); plc_dev = DOUBLE_LIST_ENTRY(plc_node, struct PlcDevice, link);
if(plc_dev) if(plc_dev) {
{ printf("%s", " ");
KPrintf("%s", " "); printf("%-15s%-15s%-15s%-15s%-20d",
KPrintf("%-15s%-15s%-15s%-15s%-20d",
plc_dev->name, plc_dev->name,
plc_dev->info.vendor, plc_dev->info.vendor,
plc_dev->info.model, plc_dev->info.model,
plc_dev->info.product, plc_dev->info.product,
plc_dev->info.id); plc_dev->info.id);
KPrintf("\n"); printf("\n");
} }
plc_node = plc_node->node_next; plc_node = plc_node->node_next;
@ -250,8 +219,4 @@ void PlcShowDev(void)
return; return;
} }
PRIV_SHELL_CMD_FUNCTION(PlcShowDev, a plc show dev sample, PRIV_SHELL_CMD_MAIN_ATTR);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
ShowPlc, PlcShowDev, Show PLC information);

View File

@ -123,7 +123,4 @@ int flashdb_app(void)
return 0; return 0;
} }
PRIV_SHELL_CMD_FUNCTION(flashdb_app, a flashdb test sample, PRIV_SHELL_CMD_MAIN_ATTR);
#ifdef __RT_THREAD_H__
MSH_CMD_EXPORT(flashdb_app, flashdb test);
#endif

View File

@ -26,6 +26,3 @@ void mnist_app(void);
int tfmnist(void) { int tfmnist(void) {
mnist_app(); mnist_app();
} }
// #ifndef SEPARATE_COMPILE
// SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, tfmnist, tfmnist, run mnist demo of tflite);
// #endif

View File

@ -1,3 +1,24 @@
/*
* Copyright (c) 2020 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: lv_demo.c
* @brief: a application using littleVgl
* @version: 2.0
* @author: AIIT XUOS Lab
* @date: 2022/9/26
*
*/
#include <lvgl.h> #include <lvgl.h>
#include <lv_port_indev_template.h> #include <lv_port_indev_template.h>
#include "lv_demo_calendar.h" #include "lv_demo_calendar.h"
@ -38,5 +59,4 @@ static int lvgl_demo_init(void)
return 0; return 0;
} }
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),lvgl_demo_init, lvgl_demo_init, lvgl_demo_init ); PRIV_SHELL_CMD_FUNCTION(lvgl_demo_init, a littlevgl init sample, PRIV_SHELL_CMD_MAIN_ATTR);

View File

@ -1,3 +1,24 @@
/*
* Copyright (c) 2020 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: lv_demo_calendar.c
* @brief: a calendar application using littleVgl
* @version: 2.0
* @author: AIIT XUOS Lab
* @date: 2022/9/26
*
*/
#include <lvgl.h> #include <lvgl.h>
#include "lv_demo_calendar.h" #include "lv_demo_calendar.h"
// #include <drv_lcd.h> // #include <drv_lcd.h>

View File

@ -1,3 +1,24 @@
/*
* Copyright (c) 2020 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: lv_demo_calendar.h
* @brief: a calendar application using littleVgl
* @version: 2.0
* @author: AIIT XUOS Lab
* @date: 2022/9/26
*
*/
#ifndef __LV_DEMO_CALENDAR_H__ #ifndef __LV_DEMO_CALENDAR_H__
#define __LV_DEMO_CALENDAR_H__ #define __LV_DEMO_CALENDAR_H__

View File

@ -1,3 +1,24 @@
/*
* Copyright (c) 2020 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: lv_init.c
* @brief: init littleVgl
* @version: 2.0
* @author: AIIT XUOS Lab
* @date: 2022/9/26
*
*/
#include <lvgl.h> #include <lvgl.h>
#define DBG_TAG "LVGL" #define DBG_TAG "LVGL"
#define DBG_LVL DBG_INFO #define DBG_LVL DBG_INFO

View File

@ -1,3 +1,24 @@
/*
* Copyright (c) 2020 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: lv_sensor_info.c
* @brief: a sensor info application using littleVgl
* @version: 2.0
* @author: AIIT XUOS Lab
* @date: 2022/9/26
*
*/
#include "lv_sensor_info.h" #include "lv_sensor_info.h"
static void draw_part_event_cb(lv_event_t* e) { static void draw_part_event_cb(lv_event_t* e) {
@ -25,12 +46,11 @@ static void draw_part_event_cb(lv_event_t* e) {
} }
} }
char* Double2Str(char* buf, double value) { char *Double2Str(char* buf, double value) {
sprintf(buf,"%.8f",value);//保留8位小数不够补0 sprintf(buf,"%.8f",value);//keep 8 bit float data
int index = 0; int index = 0;
int len = strlen(buf); int len = strlen(buf);
for(int i = len-1;i>0;i--) for(int i = len-1;i>0;i--) {
{
if(buf[i] == '0') if(buf[i] == '0')
continue; continue;
else { else {
@ -71,8 +91,7 @@ void lv_sensor_info(void) {
for (uint32_t i = 0; i < 2 * NR_VAL_PERLINE; ++i) { for (uint32_t i = 0; i < 2 * NR_VAL_PERLINE; ++i) {
if (i % 2 == 0) { if (i % 2 == 0) {
lv_table_set_col_width(lv_ssr_tb, i, 75); lv_table_set_col_width(lv_ssr_tb, i, 75);
} } else {
else {
lv_table_set_col_width(lv_ssr_tb, i, 85); lv_table_set_col_width(lv_ssr_tb, i, 85);
} }
} }
@ -100,12 +119,11 @@ void lv_sensor_info(void) {
lv_obj_add_event_cb(lv_ssr_tb, draw_part_event_cb, LV_EVENT_DRAW_PART_BEGIN, NULL); lv_obj_add_event_cb(lv_ssr_tb, draw_part_event_cb, LV_EVENT_DRAW_PART_BEGIN, NULL);
} }
void* lvgl_thd_show_sensor_info(void *parameter) void *lvgl_thd_show_sensor_info(void *parameter)
{ {
lv_sensor_info(); lv_sensor_info();
PrivMutexCreate(&ssr_val_lock, 0); PrivMutexCreate(&ssr_val_lock, 0);
while (1) while (1) {
{
lv_task_handler(); lv_task_handler();
sensor_update_table(); sensor_update_table();
@ -123,5 +141,4 @@ static int lvgl_show_sensor_info(void)
return 0; return 0;
} }
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),lvgl_show_sensor_info, lvgl_show_sensor_info, lvgl_show_sensor_info ); PRIV_SHELL_CMD_FUNCTION(lvgl_show_sensor_info, a littlevgl sensor info show sample, PRIV_SHELL_CMD_MAIN_ATTR);

View File

@ -1,3 +1,24 @@
/*
* Copyright (c) 2020 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: lv_sensor_info.h
* @brief: a sensor info application using littleVgl
* @version: 2.0
* @author: AIIT XUOS Lab
* @date: 2022/9/26
*
*/
#ifndef __LVGL_SENSOR_INFO_H__ #ifndef __LVGL_SENSOR_INFO_H__
#define __LVGL_SENSOR_INFO_H__ #define __LVGL_SENSOR_INFO_H__

View File

@ -1,3 +1,24 @@
/*
* Copyright (c) 2020 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: lv_sensor_info_update_demo.c
* @brief: a sensor info update application using littleVgl
* @version: 2.0
* @author: AIIT XUOS Lab
* @date: 2022/9/26
*
*/
#include "lv_sensor_info.h" #include "lv_sensor_info.h"
void* lvgl_thd_sensor_info_update_demo(void *parameter) void* lvgl_thd_sensor_info_update_demo(void *parameter)
@ -28,5 +49,4 @@ static int lvgl_sensor_info_update_demo(void)
return 0; return 0;
} }
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),lvgl_sensor_info_update_demo, lvgl_sensor_info_update_demo, lvgl_sensor_info_update_demo ); PRIV_SHELL_CMD_FUNCTION(lvgl_sensor_info_update_demo, a littlevgl sensor infor update sample, PRIV_SHELL_CMD_MAIN_ATTR);

View File

@ -1,3 +1,24 @@
/*
* Copyright (c) 2020 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: lv_sensor_update_info.c
* @brief: a sensor update info application using littleVgl
* @version: 2.0
* @author: AIIT XUOS Lab
* @date: 2022/9/26
*
*/
#include "lv_sensor_info.h" #include "lv_sensor_info.h"
uint32_t lv_ssr_map_idx(enum sensor_type st) { uint32_t lv_ssr_map_idx(enum sensor_type st) {

View File

@ -1,3 +1,24 @@
/*
* Copyright (c) 2020 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: ota_server.c
* @brief: a application ota task of system running in Linux
* @version: 1.0
* @author: AIIT XUOS Lab
* @date: 2021/11/3
*
*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>

View File

@ -18,7 +18,6 @@
* @date 2021.12.23 * @date 2021.12.23
*/ */
#include <user_api.h>
#include <sensor.h> #include <sensor.h>
/** /**

View File

@ -18,9 +18,6 @@
* @date 2021.12.10 * @date 2021.12.10
*/ */
#ifdef ADD_XIZI_FETURES
# include <user_api.h>
#endif
#include <sensor.h> #include <sensor.h>
/** /**

View File

@ -18,9 +18,7 @@
* @date 2021.12.23 * @date 2021.12.23
*/ */
// //
#ifdef ADD_XIZI_FETURES
# include <user_api.h>
#endif
#include <sensor.h> #include <sensor.h>
/** /**

View File

@ -18,9 +18,6 @@
* @date 2021.04.23 * @date 2021.04.23
*/ */
#ifdef ADD_XIZI_FETURES
# include <user_api.h>
#endif
#include <sensor.h> #include <sensor.h>
/** /**

View File

@ -18,12 +18,8 @@
* @date 2021.12.15 * @date 2021.12.15
*/ */
#ifdef ADD_XIZI_FETURES
# include <user_api.h>
#endif
#include <sensor.h> #include <sensor.h>
/** /**
* @description: Read a hcho * @description: Read a hcho
* @return 0 * @return 0

View File

@ -18,10 +18,6 @@
* @date 2021.04.23 * @date 2021.04.23
*/ */
#ifdef ADD_XIZI_FETURES
# include <user_api.h>
#endif
#include <sensor.h> #include <sensor.h>
/** /**
@ -31,7 +27,7 @@
void HumiHs300x(void) void HumiHs300x(void)
{ {
int i = 0; int i = 0;
int32 humidity; int32_t humidity;
struct SensorQuantity *humi = SensorQuantityFind(SENSOR_QUANTITY_HS300X_HUMIDITY, SENSOR_QUANTITY_HUMI); struct SensorQuantity *humi = SensorQuantityFind(SENSOR_QUANTITY_HS300X_HUMIDITY, SENSOR_QUANTITY_HUMI);
SensorQuantityOpen(humi); SensorQuantityOpen(humi);
for (i = 0; i < 100; i ++) { for (i = 0; i < 100; i ++) {

View File

@ -18,18 +18,8 @@
* @date 2021.12.14 * @date 2021.12.14
*/ */
#ifdef ADD_XIZI_FETURES
# include <user_api.h>
#endif
#include <sensor.h> #include <sensor.h>
// struct iaq_data {
// uint16_t gas;
// uint8_t TH;
// uint8_t TL;
// uint8_t RhH;
// uint8_t RhL;
// };
/** /**
* @description: Read a iaq * @description: Read a iaq
* @return 0 * @return 0

View File

@ -18,10 +18,6 @@
* @date 2021.04.23 * @date 2021.04.23
*/ */
#ifdef ADD_XIZI_FETURES
# include <user_api.h>
#endif
#include <sensor.h> #include <sensor.h>
/** /**

View File

@ -18,10 +18,6 @@
* @date 2021.04.23 * @date 2021.04.23
*/ */
#ifdef ADD_XIZI_FETURES
# include <user_api.h>
#endif
#include <sensor.h> #include <sensor.h>
/** /**

View File

@ -18,10 +18,6 @@
* @date 2021.12.28 * @date 2021.12.28
*/ */
#ifdef ADD_XIZI_FETURES
# include <user_api.h>
#endif
#include <sensor.h> #include <sensor.h>
/** /**

View File

@ -18,10 +18,6 @@
* @date 2021.04.23 * @date 2021.04.23
*/ */
#ifdef ADD_XIZI_FETURES
# include <user_api.h>
#endif
#include <sensor.h> #include <sensor.h>
/** /**
@ -31,7 +27,7 @@
void TempHs300x(void) void TempHs300x(void)
{ {
int i = 0; int i = 0;
int32 temperature; int32_t temperature;
struct SensorQuantity *temp = SensorQuantityFind(SENSOR_QUANTITY_HS300X_TEMPERATURE, SENSOR_QUANTITY_TEMP); struct SensorQuantity *temp = SensorQuantityFind(SENSOR_QUANTITY_HS300X_TEMPERATURE, SENSOR_QUANTITY_TEMP);
SensorQuantityOpen(temp); SensorQuantityOpen(temp);
for (i = 0; i < 100; i ++) { for (i = 0; i < 100; i ++) {

View File

@ -18,12 +18,8 @@
* @date 2021.12.15 * @date 2021.12.15
*/ */
#ifdef ADD_XIZI_FETURES
# include <user_api.h>
#endif
#include <sensor.h> #include <sensor.h>
/** /**
* @description: Read a tvoc * @description: Read a tvoc
* @return 0 * @return 0

View File

@ -18,7 +18,6 @@
* @date 2021.04.23 * @date 2021.04.23
*/ */
#include <transform.h>
#include <sensor.h> #include <sensor.h>
/** /**
@ -30,7 +29,7 @@ void VoiceD124(void)
struct SensorQuantity *voice = SensorQuantityFind(SENSOR_QUANTITY_D124_VOICE, SENSOR_QUANTITY_VOICE); struct SensorQuantity *voice = SensorQuantityFind(SENSOR_QUANTITY_D124_VOICE, SENSOR_QUANTITY_VOICE);
SensorQuantityOpen(voice); SensorQuantityOpen(voice);
PrivTaskDelay(2000); PrivTaskDelay(2000);
uint16 result = SensorQuantityReadValue(voice); uint16_t result = SensorQuantityReadValue(voice);
printf("voice : %d.%d dB\n", result/(10*voice->value.decimal_places), result%(10*voice->value.decimal_places)); printf("voice : %d.%d dB\n", result/(10*voice->value.decimal_places), result%(10*voice->value.decimal_places));
SensorQuantityClose(voice); SensorQuantityClose(voice);
} }

View File

@ -18,7 +18,6 @@
* @date 2021.12.14 * @date 2021.12.14
*/ */
#include <transform.h>
#include <sensor.h> #include <sensor.h>
/** /**
@ -30,11 +29,7 @@ void WindDirectionQsFx(void)
struct SensorQuantity *wind_direction = SensorQuantityFind(SENSOR_QUANTITY_QS_FX_WINDDIRECTION, SENSOR_QUANTITY_WINDDIRECTION); struct SensorQuantity *wind_direction = SensorQuantityFind(SENSOR_QUANTITY_QS_FX_WINDDIRECTION, SENSOR_QUANTITY_WINDDIRECTION);
SensorQuantityOpen(wind_direction); SensorQuantityOpen(wind_direction);
PrivTaskDelay(2000); PrivTaskDelay(2000);
uint16 result = SensorQuantityReadValue(wind_direction); uint16_t result = SensorQuantityReadValue(wind_direction);
printf("wind direction : %d degree\n", result); printf("wind direction : %d degree\n", result);
SensorQuantityClose(wind_direction); SensorQuantityClose(wind_direction);
} }
#ifdef ADD_XIZI_FETURES
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, WindDirectionQsFx, WindDirectionQsFx, WindDirectionQsFx function);
#endif

View File

@ -18,7 +18,6 @@
* @date 2021.12.14 * @date 2021.12.14
*/ */
#include <transform.h>
#include <sensor.h> #include <sensor.h>
/** /**
@ -30,11 +29,7 @@ void WindSpeedQsFs(void)
struct SensorQuantity *wind_speed = SensorQuantityFind(SENSOR_QUANTITY_QS_FS_WINDSPEED, SENSOR_QUANTITY_WINDSPEED); struct SensorQuantity *wind_speed = SensorQuantityFind(SENSOR_QUANTITY_QS_FS_WINDSPEED, SENSOR_QUANTITY_WINDSPEED);
SensorQuantityOpen(wind_speed); SensorQuantityOpen(wind_speed);
PrivTaskDelay(2000); PrivTaskDelay(2000);
uint16 result = SensorQuantityReadValue(wind_speed); uint16_t result = SensorQuantityReadValue(wind_speed);
printf("wind speed : %d.%d m/s\n", result/10, result%10); printf("wind speed : %d.%d m/s\n", result/10, result%10);
SensorQuantityClose(wind_speed); SensorQuantityClose(wind_speed);
} }
#ifdef ADD_XIZI_FETURES
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, WindSpeedQsFs, WindSpeedQsFs, WindSpeedQsFs function);
#endif

View File

@ -110,10 +110,4 @@ int Adapter4GTest(void)
return 0; return 0;
} }
PRIV_SHELL_CMD_FUNCTION(Adapter4GTest, a EC200T adpter sample, PRIV_SHELL_CMD_FUNC_ATTR);
#ifdef ADD_RTTHREAD_FETURES
MSH_CMD_EXPORT(Adapter4GTest,a EC200T adpter sample);
#endif
#ifdef ADD_XIZI_FETURES
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, Adapter4GTest, Adapter4GTest, show adapter 4G information);
#endif

View File

@ -111,9 +111,4 @@ int AdapterBlueToothTest(void)
return 0; return 0;
} }
#ifdef ADD_RTTHREAD_FETURES PRIV_SHELL_CMD_FUNCTION(AdapterBlueToothTest, a bluetooth test sample, PRIV_SHELL_CMD_MAIN_ATTR);
MSH_CMD_EXPORT(AdapterBlueToothTest,a bt adpter sample);
#endif
#ifdef ADD_XIZI_FETURES
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, AdapterBlueToothTest, AdapterBlueToothTest, show adapter bluetooth information);
#endif

View File

@ -122,8 +122,4 @@ int AdapterEthernetTest(void)
return 0; return 0;
} }
#ifdef ADD_RTTHREAD_FETURES PRIV_SHELL_CMD_FUNCTION(AdapterEthernetTest, a ethernet test sample, PRIV_SHELL_CMD_MAIN_ATTR);
MSH_CMD_EXPORT(AdapterEthernetTest,a ethernet adpter sample);
#elif definded ADD_XIZI_FETURES
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, AdapterEthernetTest, AdapterEthernetTest, show adapter ethernet information);
#endif

View File

@ -205,4 +205,4 @@ int AdapterEthercatTest(void)
return 0; return 0;
} }
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC) | SHELL_CMD_PARAM_NUM(0) | SHELL_CMD_DISABLE_RETURN, AdapterEthercatTest, AdapterEthercatTest, show adapter ethercat information); PRIV_SHELL_CMD_FUNCTION(AdapterEthercatTest, a ethercat test sample, PRIV_SHELL_CMD_MAIN_ATTR);

View File

@ -4,25 +4,11 @@
#ifdef POWERLINK_MN #ifdef POWERLINK_MN
extern int OplkDemoMnConsole(int argc, char *argv[]); extern int OplkDemoMnConsole(int argc, char *argv[]);
SHELL_EXPORT_CMD( PRIV_SHELL_CMD_FUNCTION(OplkDemoMnConsole, a openPOWERLINK MN sample, PRIV_SHELL_CMD_MAIN_ATTR);
SHELL_CMD_PERMISSION(0) |
SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) |
SHELL_CMD_PARAM_NUM(0) |
SHELL_CMD_DISABLE_RETURN,
OplkDemoMnConsole,
OplkDemoMnConsole,
openPOWERLINK demo MN (console version));
#endif #endif
#ifdef POWERLINK_CN #ifdef POWERLINK_CN
extern int OplkDemoCnConsole(int argc, char *argv[]); extern int OplkDemoCnConsole(int argc, char *argv[]);
SHELL_EXPORT_CMD( PRIV_SHELL_CMD_FUNCTION(OplkDemoCnConsole, a openPOWERLINK CN sample, PRIV_SHELL_CMD_MAIN_ATTR);
SHELL_CMD_PERMISSION(0) |
SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) |
SHELL_CMD_PARAM_NUM(0) |
SHELL_CMD_DISABLE_RETURN,
OplkDemoCnConsole,
OplkDemoCnConsole,
openPOWERLINK demo CN (console version));
#endif #endif

View File

@ -979,10 +979,4 @@ int AdapterLoraTest(void)
return 0; return 0;
} }
#ifdef ADD_RTTHREAD_FETURES PRIV_SHELL_CMD_FUNCTION(AdapterLoraTest, a lora test sample, PRIV_SHELL_CMD_MAIN_ATTR);
MSH_CMD_EXPORT(AdapterLoraTest,a Lora adpter sample);
#endif
#ifdef ADD_XIZI_FETURES
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, AdapterLoraTest, AdapterLoraTest, show adapter lora information);
#endif

View File

@ -705,8 +705,7 @@ static void LoraTest(void)
return; return;
} }
} }
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), PRIV_SHELL_CMD_FUNCTION(LoraTest, a lora test init sample, PRIV_SHELL_CMD_MAIN_ATTR);
LoraTest, LoraTest, lora send and receive message);
static void LoraSend(int argc, char *argv[]) static void LoraSend(int argc, char *argv[])
{ {
@ -724,8 +723,7 @@ static void LoraSend(int argc, char *argv[])
E220Send(adapter, Msg, strlen(Msg)); E220Send(adapter, Msg, strlen(Msg));
} }
} }
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), PRIV_SHELL_CMD_FUNCTION(LoraSend, a lora test send sample, PRIV_SHELL_CMD_MAIN_ATTR);
LoraSend, LoraSend, lora send message);
#endif #endif
#ifdef ADD_NUTTX_FETURES #ifdef ADD_NUTTX_FETURES
@ -765,39 +763,40 @@ void E220LoraSend(int argc, char *argv[])
#endif #endif
#ifdef ADD_RTTHREAD_FETURES #ifdef ADD_RTTHREAD_FETURES
static void LoraReadStart(void) static void LoraReadStart(void)
{ {
int ret; int ret;
LoraOpen(); LoraOpen();
rt_thread_t tid= rt_thread_create("LoraReadStart", LoraRead, RT_NULL,2048,10,5); rt_thread_t tid = rt_thread_create("LoraReadStart", LoraRead, RT_NULL,2048,10,5);
if(tid!=RT_NULL){ if(tid!=RT_NULL) {
rt_thread_startup(tid); rt_thread_startup(tid);
}else{ } else {
rt_kprintf("LoraReadStart task_lora_read failed \r\n"); rt_kprintf("LoraReadStart task_lora_read failed \r\n");
return; return;
} }
} }
MSH_CMD_EXPORT(LoraReadStart,Lora read task start sample); PRIV_SHELL_CMD_FUNCTION(LoraReadStart, a lora test start sample, PRIV_SHELL_CMD_MAIN_ATTR);
#define E22400T_M1_PIN (11U) #define E22400T_M1_PIN (11U)
#define E22400T_M0_PIN (9U) #define E22400T_M0_PIN (9U)
static void LoraSend(int argc, char *argv[]) static void LoraSend(int argc, char *argv[])
{ {
int8_t cmd[10]={0xFF,0xFF,0x02,0xAA,0XBB,0xCC}; //sned AA BB CC to address 01 channel05 int8_t cmd[10]={0xFF,0xFF,0x02,0xAA,0XBB,0xCC}; //sned AA BB CC to address 01 channel05
LoraOpen();
LoraOpen();
struct Adapter *adapter = AdapterDeviceFindByName(ADAPTER_LORA_NAME); struct Adapter *adapter = AdapterDeviceFindByName(ADAPTER_LORA_NAME);
if (NULL == adapter) { if (NULL == adapter) {
printf("LoraRead find lora adapter error\n"); printf("LoraRead find lora adapter error\n");
return; return;
} }
rt_pin_mode (E22400T_M1_PIN, PIN_MODE_OUTPUT);
rt_pin_mode (E22400T_M0_PIN, PIN_MODE_OUTPUT); rt_pin_mode (E22400T_M1_PIN, PIN_MODE_OUTPUT);
rt_pin_mode (E22400T_M0_PIN, PIN_MODE_OUTPUT);
rt_pin_write(E22400T_M1_PIN, PIN_LOW); rt_pin_write(E22400T_M1_PIN, PIN_LOW);
rt_pin_write(E22400T_M0_PIN, PIN_HIGH); rt_pin_write(E22400T_M0_PIN, PIN_HIGH);
E220Send(adapter, cmd, 6); E220Send(adapter, cmd, 6);
} }
MSH_CMD_EXPORT(LoraSend,Lora send sample); PRIV_SHELL_CMD_FUNCTION(LoraSend, a lora test send sample, PRIV_SHELL_CMD_MAIN_ATTR);
#endif #endif

View File

@ -17,6 +17,7 @@
* @author AIIT XUOS Lab * @author AIIT XUOS Lab
* @date 2021.06.25 * @date 2021.06.25
*/ */
#include <transform.h> #include <transform.h>
#include <adapter.h> #include <adapter.h>
#include <stdlib.h> #include <stdlib.h>
@ -80,7 +81,7 @@ int AdapterNbiotInit(void)
} }
/******************TEST*********************/ /******************TEST*********************/
int opennb(void) int OpenNb(void)
{ {
int ret = 0; int ret = 0;
@ -88,23 +89,18 @@ int opennb(void)
#ifdef ADAPTER_BC28 #ifdef ADAPTER_BC28
ret = AdapterDeviceOpen(adapter); ret = AdapterDeviceOpen(adapter);
if(ret < 0){ if(ret < 0) {
printf("open adapter failed\n"); printf("open adapter failed\n");
return -1; return -1;
} }
#endif #endif
return 0; return 0;
} }
#ifdef ADD_RTTHREAD_FETURES PRIV_SHELL_CMD_FUNCTION(OpenNb, a NBiot open sample, PRIV_SHELL_CMD_MAIN_ATTR);
MSH_CMD_EXPORT(opennb,open nb sample);
#endif
#ifdef ADD_XIZI_FETURES
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, opennb, opennb, show adapter nb information);
#endif
int closenb(void) int CloseNb(void)
{ {
int ret = 0; int ret = 0;
@ -112,87 +108,62 @@ int closenb(void)
#ifdef ADAPTER_BC28 #ifdef ADAPTER_BC28
ret = AdapterDeviceClose(adapter); ret = AdapterDeviceClose(adapter);
if(ret < 0){ if(ret < 0) {
printf("open adapter failed\n"); printf("open adapter failed\n");
return -1; return -1;
} }
#endif #endif
return 0; return 0;
} }
#ifdef ADD_RTTHREAD_FETURES PRIV_SHELL_CMD_FUNCTION(CloseNb, a NBiot close sample, PRIV_SHELL_CMD_MAIN_ATTR);
MSH_CMD_EXPORT(closenb,close nb sample);
#endif
#ifdef ADD_XIZI_FETURES
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, closenb, closenb, show adapter nb information);
#endif
int connectnb(int argc, char *argv[]) int ConnectNb(int argc, char *argv[])
{ {
const char *send_msg = argv[1]; const char *send_msg = argv[1];
int ret = 0; int ret = 0;
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_NBIOT_NAME); struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_NBIOT_NAME);
ret = AdapterDeviceConnect(adapter, 1, "101.68.82.219","9898",1);
ret = AdapterDeviceConnect(adapter, 1, "101.68.82.219","9898",1); if(ret < 0) {
if(ret < 0){ printf(" adapter send failed\n");
printf(" adapter send failed\n"); return -1;
return -1; }
}
return 0;
}
PRIV_SHELL_CMD_FUNCTION(ConnectNb, a NBiot connect sample, PRIV_SHELL_CMD_MAIN_ATTR);
return 0; int SendNb(int argc, char *argv[])
} {
#ifdef ADD_RTTHREAD_FETURES const char *send_msg = argv[1];
MSH_CMD_EXPORT(connectnb,connect nb test); int msg_len = atoi(argv[2]);
#endif int ret = 0;
#ifdef ADD_XIZI_FETURES
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(2)|SHELL_CMD_DISABLE_RETURN, connectnb, connectnb, show adapter nb information);
#endif
int sendnb(int argc, char *argv[]) struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_NBIOT_NAME);
{
const char *send_msg = argv[1];
int msg_len = atoi(argv[2]);
int ret = 0;
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_NBIOT_NAME); printf("send argv1 %s len = %d\n",argv[1],msg_len);
ret = AdapterDeviceSend(adapter, send_msg, msg_len);
if(ret < 0) {
printf(" adapter send failed\n");
return -1;
}
printf("nb send msg %s\n", send_msg);
printf("send argv1 %s len = %d\n",argv[1],msg_len); return 0;
ret = AdapterDeviceSend(adapter, send_msg, msg_len); }
if(ret < 0){ PRIV_SHELL_CMD_FUNCTION(SendNb, a NBiot send sample, PRIV_SHELL_CMD_MAIN_ATTR);
printf(" adapter send failed\n");
return -1;
}
printf("nb send msg %s\n", send_msg);
int RecvNb(void)
{
char recv_msg[128];
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_NBIOT_NAME);
memset(recv_msg,0,128);
AdapterDeviceRecv(adapter, recv_msg, 128);
PrivTaskDelay(2000);
printf("nb recv msg %s\n", recv_msg);
return 0; return 0;
} }
#ifdef ADD_RTTHREAD_FETURES PRIV_SHELL_CMD_FUNCTION(RecvNb, a NBiot receive sample, PRIV_SHELL_CMD_MAIN_ATTR);
MSH_CMD_EXPORT(sendnb,send nb test);
#endif
#ifdef ADD_XIZI_FETURES
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(2)|SHELL_CMD_DISABLE_RETURN, sendnb, sendnb, show adapter nb information);
#endif
int recvnb(void)
{
char recv_msg[128];
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_NBIOT_NAME);
memset(recv_msg,0,128);
AdapterDeviceRecv(adapter, recv_msg, 128);
PrivTaskDelay(2000);
printf("nb recv msg %s\n", recv_msg);
return 0;
}
#ifdef ADD_RTTHREAD_FETURES
MSH_CMD_EXPORT(recvnb,receive nb test);
#endif
#ifdef ADD_XIZI_FETURES
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, recvnb, recvnb, show adapter nb information);
#endif

View File

@ -1,3 +1,23 @@
/*
* Copyright (c) 2020 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 adapter_nbiot.h
* @brief Implement the connection nbiot adapter function
* @version 1.1
* @author AIIT XUOS Lab
* @date 2021.06.25
*/
#ifndef ADAPTER_NBIOT_H #ifndef ADAPTER_NBIOT_H
#define ADAPTER_NBIOT_H #define ADAPTER_NBIOT_H

View File

@ -11,7 +11,7 @@
*/ */
/** /**
* @file adapter_wifiiiii.c * @file adapter_wifi.c
* @brief Implement the connection wifi adapter function * @brief Implement the connection wifi adapter function
* @version 1.1 * @version 1.1
* @author AIIT XUOS Lab * @author AIIT XUOS Lab
@ -20,9 +20,6 @@
#include <adapter.h> #include <adapter.h>
#include "adapter_wifi.h" #include "adapter_wifi.h"
#ifdef ADD_XIZI_FETURES
#include <bus_pin.h>
#endif
#ifdef ADAPTER_HFA21_WIFI #ifdef ADAPTER_HFA21_WIFI
extern AdapterProductInfoType Hfa21WifiAttach(struct Adapter *adapter); extern AdapterProductInfoType Hfa21WifiAttach(struct Adapter *adapter);
@ -100,7 +97,6 @@ int AdapterWifiInit(void)
} }
/******************wifi TEST*********************/ /******************wifi TEST*********************/
#ifdef ADD_XIZI_FETURES
int AdapterWifiTest(void) int AdapterWifiTest(void)
{ {
char cmd[64]; char cmd[64];
@ -108,6 +104,7 @@ int AdapterWifiTest(void)
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME); struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
#if 0
#ifdef ADAPTER_HFA21_DRIVER_EXT_PORT #ifdef ADAPTER_HFA21_DRIVER_EXT_PORT
static BusType ch438_pin; static BusType ch438_pin;
ch438_pin = PinBusInitGet(); ch438_pin = PinBusInitGet();
@ -154,7 +151,7 @@ int AdapterWifiTest(void)
PrivClose(pin_fd); PrivClose(pin_fd);
#endif #endif
#endif
AdapterDeviceOpen(adapter); AdapterDeviceOpen(adapter);
// AdapterDeviceControl(adapter, OPE_INT, &baud_rate); // AdapterDeviceControl(adapter, OPE_INT, &baud_rate);
@ -182,38 +179,23 @@ int AdapterWifiTest(void)
PrivTaskDelay(1000); PrivTaskDelay(1000);
} }
} }
#endif PRIV_SHELL_CMD_FUNCTION(AdapterWifiTest, a WiFi test sample, PRIV_SHELL_CMD_MAIN_ATTR);
#ifdef ADD_RTTHREAD_FETURES int WifiOpen(void)
MSH_CMD_EXPORT(AdapterWifiTest,a wifi adpter sample);
#endif
#ifdef ADD_XIZI_FETURES
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, AdapterWifiTest, AdapterWifiTest, show adapter wifi information);
#endif
int wifiopen(void)
{ {
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME); struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
return AdapterDeviceOpen(adapter); return AdapterDeviceOpen(adapter);
} }
#ifdef ADD_XIZI_FETURES PRIV_SHELL_CMD_FUNCTION(WifiOpen, a WiFi open sample, PRIV_SHELL_CMD_MAIN_ATTR);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, wifiopen, wifiopen, open adapter wifi );
#endif int WifiClose(void)
#ifdef ADD_RTTHREAD_FETURES
MSH_CMD_EXPORT(wifiopen,a wifi adpter sample);
#endif
int wificlose(void)
{ {
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME); struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
return AdapterDeviceClose(adapter); return AdapterDeviceClose(adapter);
} }
#ifdef ADD_XIZI_FETURES PRIV_SHELL_CMD_FUNCTION(WifiClose, a WiFi close sample, PRIV_SHELL_CMD_MAIN_ATTR);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, wificlose, wificlose, close adapter wifi );
#endif int WifiSetup(int argc, char *argv[])
#ifdef ADD_RTTHREAD_FETURES
MSH_CMD_EXPORT(wificlose,a wifi adpter sample);
#endif
int wifisetup(int argc, char *argv[])
{ {
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME); struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
struct WifiParam param; struct WifiParam param;
@ -225,13 +207,9 @@ int wifisetup(int argc, char *argv[])
return AdapterDeviceSetUp(adapter); return AdapterDeviceSetUp(adapter);
} }
#ifdef ADD_XIZI_FETURES PRIV_SHELL_CMD_FUNCTION(WifiSetup, a WiFi setup sample, PRIV_SHELL_CMD_MAIN_ATTR);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(3)|SHELL_CMD_DISABLE_RETURN, wifisetup, wifisetup, setup adapter wifi );
#endif int WifiAddrSet(int argc, char *argv[])
#ifdef ADD_RTTHREAD_FETURES
MSH_CMD_EXPORT(wifisetup,a wifi adpter sample:wifisetup <server|client>);
#endif
int wifiaddrset(int argc, char *argv[])
{ {
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME); struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
char *ip = argv[1]; char *ip = argv[1];
@ -242,25 +220,17 @@ int wifiaddrset(int argc, char *argv[])
AdapterDevicePing(adapter, "36.152.44.95");///< ping www.baidu.com AdapterDevicePing(adapter, "36.152.44.95");///< ping www.baidu.com
return AdapterDeviceNetstat(adapter); return AdapterDeviceNetstat(adapter);
} }
#ifdef ADD_XIZI_FETURES PRIV_SHELL_CMD_FUNCTION(WifiAddrSet, a WiFi addr set sample, PRIV_SHELL_CMD_MAIN_ATTR);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(4)|SHELL_CMD_DISABLE_RETURN, wifiaddrset, wifiaddrset, addrset adapter wifi);
#endif int WifiPing(int argc, char *argv[])
#ifdef ADD_RTTHREAD_FETURES
MSH_CMD_EXPORT(wifiaddrset,a wifi adpter sample:wifiaddrset <server|client>);
#endif
int wifiping(int argc, char *argv[])
{ {
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME); struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
printf("ping %s\n",argv[1]); printf("ping %s\n",argv[1]);
return AdapterDevicePing(adapter, argv[1]); return AdapterDevicePing(adapter, argv[1]);
} }
#ifdef ADD_XIZI_FETURES PRIV_SHELL_CMD_FUNCTION(WifiPing, a WiFi ping sample, PRIV_SHELL_CMD_MAIN_ATTR);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(3), wifiping, wifiping, wifiping adapter );
#endif int WifiConnect(int argc, char *argv[])
#ifdef ADD_RTTHREAD_FETURES
MSH_CMD_EXPORT(wifiping,a wifi adpter sample:wifiping <server|client>);
#endif
int wificonnect(int argc, char *argv[])
{ {
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME); struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
char *ip = argv[1]; char *ip = argv[1];
@ -278,13 +248,9 @@ int wificonnect(int argc, char *argv[])
return AdapterDeviceConnect(adapter, net_role, ip, port, ip_type); return AdapterDeviceConnect(adapter, net_role, ip, port, ip_type);
} }
#ifdef ADD_XIZI_FETURES PRIV_SHELL_CMD_FUNCTION(WifiConnect, a WiFi connect sample, PRIV_SHELL_CMD_MAIN_ATTR);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(4)|SHELL_CMD_DISABLE_RETURN, wificonnect, wificonnect, wificonnect adapter);
#endif int WifiSend(int argc, char *argv[])
#ifdef ADD_RTTHREAD_FETURES
MSH_CMD_EXPORT(wificonnect,a wifi adpter sample:wificonnect <server|client>);
#endif
int wifisend(int argc, char *argv[])
{ {
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME); struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
@ -296,13 +262,9 @@ int wifisend(int argc, char *argv[])
} }
return 0; return 0;
} }
#ifdef ADD_XIZI_FETURES PRIV_SHELL_CMD_FUNCTION(WifiSend, a WiFi send sample, PRIV_SHELL_CMD_MAIN_ATTR);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(3)|SHELL_CMD_DISABLE_RETURN, wifisend, wifisend, wifisend adapter wifi information);
#endif int WifiRecv(int argc, char *argv[])
#ifdef ADD_RTTHREAD_FETURES
MSH_CMD_EXPORT(wifisend,a wifi adpter sample:wifisend <server|client>);
#endif
int wifirecv(int argc, char *argv[])
{ {
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME); struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
@ -313,12 +275,7 @@ int wifirecv(int argc, char *argv[])
printf("wifi recv [%s]\n",wifi_recv_msg); printf("wifi recv [%s]\n",wifi_recv_msg);
} }
} }
#ifdef ADD_XIZI_FETURES PRIV_SHELL_CMD_FUNCTION(WifiRecv, a WiFi receive sample, PRIV_SHELL_CMD_MAIN_ATTR);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(3)|SHELL_CMD_DISABLE_RETURN, wifirecv, wifirecv, wifirecv adapter wifi information);
#endif
#ifdef ADD_RTTHREAD_FETURES
MSH_CMD_EXPORT(wifirecv,a wifi adpter sample:wifirecv <server|client>);
#endif
#ifdef ADD_NUTTX_FETURES #ifdef ADD_NUTTX_FETURES

View File

@ -1,3 +1,23 @@
/*
* Copyright (c) 2020 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 adapter_wifi.h
* @brief Implement the connection wifi adapter function
* @version 1.1
* @author AIIT XUOS Lab
* @date 2021.07.25
*/
#ifndef ADAPTER_WIFI_H #ifndef ADAPTER_WIFI_H
#define ADAPTER_WIFI_H #define ADAPTER_WIFI_H

View File

@ -90,7 +90,7 @@ int AdapterZigbeeInit(void)
} }
/******************TEST*********************/ /******************TEST*********************/
int openzigbee(void) int OpenZigbee(void)
{ {
int ret = 0; int ret = 0;
@ -98,19 +98,19 @@ int openzigbee(void)
#ifdef ADAPTER_E18 #ifdef ADAPTER_E18
ret = AdapterDeviceOpen(adapter); ret = AdapterDeviceOpen(adapter);
if(ret < 0){ if(ret < 0) {
printf("open adapter failed\n"); printf("open adapter failed\n");
return -1; return -1;
} }
adapter->info->work_mode = 1; adapter->info->work_mode = 1;
ret = AdapterDeviceControl(adapter, CONFIG_ZIGBEE_NET_MODE,NULL); ret = AdapterDeviceControl(adapter, CONFIG_ZIGBEE_NET_MODE,NULL);
if(ret < 0){ if(ret < 0) {
printf("control adapter failed\n"); printf("control adapter failed\n");
return -1; return -1;
} }
ret = AdapterDeviceJoin(adapter, NULL); ret = AdapterDeviceJoin(adapter, NULL);
if(ret < 0){ if(ret < 0) {
printf("join adapter failed\n"); printf("join adapter failed\n");
return -1; return -1;
} }
@ -118,12 +118,9 @@ int openzigbee(void)
return 0; return 0;
} }
PRIV_SHELL_CMD_FUNCTION(OpenZigbee, a ZigBee open sample, PRIV_SHELL_CMD_MAIN_ATTR);
#ifdef ADD_XIZI_FETURES int SendZigbee(int argc, char *argv[])
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, openzigbee, openzigbee, show adapter zigbee information);
#endif
int sendzigbee(int argc, char *argv[])
{ {
const char *send_msg = argv[1]; const char *send_msg = argv[1];
int ret = 0; int ret = 0;
@ -132,20 +129,17 @@ int sendzigbee(int argc, char *argv[])
printf("send argv1 %s\n",argv[1]); printf("send argv1 %s\n",argv[1]);
ret = AdapterDeviceSend(adapter, send_msg, strlen(send_msg)); ret = AdapterDeviceSend(adapter, send_msg, strlen(send_msg));
if(ret < 0){ if(ret < 0) {
printf(" adapter send failed\n"); printf(" adapter send failed\n");
return -1; return -1;
} }
printf("zigbee send msg %s\n", send_msg); printf("zigbee send msg %s\n", send_msg);
return 0; return 0;
} }
#ifdef ADD_XIZI_FETURES PRIV_SHELL_CMD_FUNCTION(SendZigbee, a ZigBee send sample, PRIV_SHELL_CMD_MAIN_ATTR);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(2)|SHELL_CMD_DISABLE_RETURN, sendzigbee, sendzigbee, show adapter zigbee information);
#endif
int recvzigbee(void) int RecvZigbee(void)
{ {
char recv_msg[128]; char recv_msg[128];
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_ZIGBEE_NAME); struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_ZIGBEE_NAME);
@ -156,7 +150,4 @@ int recvzigbee(void)
return 0; return 0;
} }
#ifdef ADD_XIZI_FETURES PRIV_SHELL_CMD_FUNCTION(RecvZigbee, a ZigBee receive sample, PRIV_SHELL_CMD_MAIN_ATTR);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, recvzigbee, recvzigbee, show adapter zigbee information);
#endif

View File

@ -1,3 +1,23 @@
/*
* Copyright (c) 2020 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 adapter_zigbee.h
* @brief Implement the connection zigbee adapter function
* @version 1.1
* @author AIIT XUOS Lab
* @date 2021.09.15
*/
#ifndef ADAPTER_ZIGBEE_H #ifndef ADAPTER_ZIGBEE_H
#define ADAPTER_ZIGBEE_H #define ADAPTER_ZIGBEE_H

View File

@ -460,7 +460,7 @@ static int E18Recv(struct Adapter *adapter, void *buf, size_t len)
return 0; return 0;
} }
static int E18Quit(struct Adapter *adapter) static int E18Quit(struct Adapter *adapter, unsigned char *priv_net_group)
{ {
return 0; return 0;

View File

@ -358,7 +358,3 @@ void PlcSocketTask(int argc, char *argv[])
lwip_config_net(lwip_ipaddr, lwip_netmask, param->ip); lwip_config_net(lwip_ipaddr, lwip_netmask, param->ip);
PrivTaskCreate(&th_id, &attr, PlcSocketStart, param); PrivTaskCreate(&th_id, &attr, PlcSocketStart, param);
} }
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
PlcSocket, PlcSocketTask, Test PLC Socket);

View File

@ -112,9 +112,6 @@ void CtlCreateFileTest(void)
CtlFileClose(fd); CtlFileClose(fd);
} }
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
CtlCreateFile, CtlCreateFileTest, Test control file);
#ifdef LIB_USING_CJSON #ifdef LIB_USING_CJSON
void CtlParseJsonArray(cJSON *dat, int *cmd_len, char *cmd) void CtlParseJsonArray(cJSON *dat, int *cmd_len, char *cmd)
@ -205,9 +202,5 @@ void CtlParseFileTest(void)
CtlParseJsonData(file_buf); CtlParseJsonData(file_buf);
free(file_buf); free(file_buf);
} }
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
CtlParseFile, CtlParseFileTest, Parse control file);
#endif #endif

View File

@ -24,30 +24,30 @@
void sm3_test_case(){ void sm3_test_case(){
uint8_t result[SM3_DIGEST_LENGTH] = { 0 }; uint8_t result[SM3_DIGEST_LENGTH] = { 0 };
//test case 1 //test case 1
KPrintf("\n#################### sm3 test ##########################\n"); printf("\n#################### sm3 test ##########################\n");
char *msg = "abc"; char *msg = "abc";
KPrintf("\n####sm3 test case 1:\n"); printf("\n####sm3 test case 1:\n");
KPrintf( "%-15s %s\n", "digest message1:",msg); printf( "%-15s %s\n", "digest message1:",msg);
sm3(msg,3,result); sm3(msg,3,result);
KPrintf("%-15s ","digest result1: "); printf("%-15s ","digest result1: ");
for ( int i = 0 ; i < SM3_DIGEST_LENGTH ; i++){ for ( int i = 0 ; i < SM3_DIGEST_LENGTH ; i++){
KPrintf("%02x",result[i]); printf("%02x",result[i]);
} }
KPrintf("\n"); printf("\n");
//test case 2 //test case 2
KPrintf("\n####sm3 test case 2:\n"); printf("\n####sm3 test case 2:\n");
//msg = "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" //msg = "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd"
char msg1[64] = { 0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 }; char msg1[64] = { 0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 ,0x61, 0x62, 0x63, 0x64 };
KPrintf("digest message2: "); printf("digest message2: ");
for ( int i = 0 ; i < 64 ; i++){ for ( int i = 0 ; i < 64 ; i++){
KPrintf("%02x",msg1[i]); printf("%02x",msg1[i]);
} }
KPrintf("\n"); printf("\n");
sm3(msg1, 64,result); sm3(msg1, 64,result);
KPrintf("digest result2: "); printf("digest result2: ");
for ( int i = 0 ; i < SM3_DIGEST_LENGTH ; i++){ for ( int i = 0 ; i < SM3_DIGEST_LENGTH ; i++){
KPrintf("%02x",result[i]); printf("%02x",result[i]);
} }
KPrintf("\n"); printf("\n");
KPrintf("\n########################################################\n"); printf("\n########################################################\n");
} }

View File

@ -31,63 +31,63 @@ void sm4_test_case(){
sms4_key_t key; sms4_key_t key;
//test case 1 //test case 1
KPrintf("\n#################### sm4 test ##########################\n"); printf("\n#################### sm4 test ##########################\n");
KPrintf("\n####sm4 test case1:\n"); printf("\n####sm4 test case1:\n");
KPrintf("plaintext: "); printf("plaintext: ");
for (int i = 0; i< 16; i++){ for (int i = 0; i< 16; i++){
KPrintf("%02x ",input[i]); printf("%02x ",input[i]);
} }
KPrintf("\n"); printf("\n");
KPrintf("key: "); printf("key: ");
for (int i = 0; i< 16; i++){ for (int i = 0; i< 16; i++){
KPrintf("%02x",ukey[i]); printf("%02x",ukey[i]);
} }
KPrintf("\n"); printf("\n");
KPrintf("encryption:\n"); printf("encryption:\n");
sms4_set_encrypt_key(&key, ukey); sms4_set_encrypt_key(&key, ukey);
Sms4EcbEncryptNoPadding(input,16,res,&olen,&key); Sms4EcbEncryptNoPadding(input,16,res,&olen,&key);
KPrintf("ciphertext: "); printf("ciphertext: ");
for (int i = 0; i< 16; i++){ for (int i = 0; i< 16; i++){
KPrintf("%02x",res[i]); printf("%02x",res[i]);
} }
KPrintf("\n"); printf("\n");
KPrintf("decryption:\n"); printf("decryption:\n");
sms4_set_decrypt_key(&key, ukey); sms4_set_decrypt_key(&key, ukey);
KPrintf("round key in sms4_set_decrypt_key:\n"); printf("round key in sms4_set_decrypt_key:\n");
for (int i = 0; i < 32; i++){ for (int i = 0; i < 32; i++){
KPrintf("rk%d:%08x\n", i, key.rk[i]); printf("rk%d:%08x\n", i, key.rk[i]);
} }
Sms4EcbDecryptNoPadding(res,16,res,&olen,&key); Sms4EcbDecryptNoPadding(res,16,res,&olen,&key);
printf("plaintext: "); printf("plaintext: ");
for (int i = 0; i< 16; i++){ for (int i = 0; i< 16; i++){
KPrintf("%02x",res[i]); printf("%02x",res[i]);
} }
printf("\n"); printf("\n");
////test case 2 ////test case 2
KPrintf("\n####sm4 test case2:\n"); printf("\n####sm4 test case2:\n");
KPrintf("plaintext: "); printf("plaintext: ");
for (int i = 0; i< 16; i++){ for (int i = 0; i< 16; i++){
KPrintf("%02x",input[i]); printf("%02x",input[i]);
} }
KPrintf("\n"); printf("\n");
KPrintf("key: "); printf("key: ");
for (int i = 0; i< 16; i++){ for (int i = 0; i< 16; i++){
KPrintf("%02x",ukey[i]); printf("%02x",ukey[i]);
} }
KPrintf("\n"); printf("\n");
KPrintf("encrypt 1000000 times:\n"); printf("encrypt 1000000 times:\n");
sms4_set_encrypt_key(&key, ukey); sms4_set_encrypt_key(&key, ukey);
memcpy(plaintext, input, 16); memcpy(plaintext, input, 16);
for (int i = 0;i< 1000000; i++){ for (int i = 0;i< 1000000; i++){
Sms4EcbEncryptNoPadding(plaintext,16,ciphertext,&olen,&key); Sms4EcbEncryptNoPadding(plaintext,16,ciphertext,&olen,&key);
memcpy(plaintext, ciphertext, 16); memcpy(plaintext, ciphertext, 16);
} }
KPrintf("ciphertext: "); printf("ciphertext: ");
for (int i = 0; i< 16; i++){ for (int i = 0; i< 16; i++){
KPrintf("%02x",ciphertext[i]); printf("%02x",ciphertext[i]);
} }
KPrintf("\n"); printf("\n");
KPrintf("\n########################################################\n"); printf("\n########################################################\n");
} }

View File

@ -62,11 +62,11 @@ void SignAndVerifyTest()
SM9Init(); SM9Init();
KPrintf("------------------------------below is ks---------------------------------\n"); printf("------------------------------below is ks---------------------------------\n");
Big8wPrint(&ks); Big8wPrint(&ks);
Ppub_s = G2PointMult(ks, P2); Ppub_s = G2PointMult(ks, P2);
KPrintf("------------------------------below is Ppub_s-----------------------------\n"); printf("------------------------------below is Ppub_s-----------------------------\n");
Big8wPrint(&Ppub_s.x.high); Big8wPrint(&Ppub_s.x.high);
Big8wPrint(&Ppub_s.x.low); Big8wPrint(&Ppub_s.x.low);
Big8wPrint(&Ppub_s.y.high); Big8wPrint(&Ppub_s.y.high);
@ -75,79 +75,79 @@ void SignAndVerifyTest()
JoinIDhid(ID_Alice, 5, hid, Id_Alice_hid); JoinIDhid(ID_Alice, 5, hid, Id_Alice_hid);
t1 = Big8wAddMod(H(Id_Alice_hid, 5 + 1, 0x01), ks, curve.N); t1 = Big8wAddMod(H(Id_Alice_hid, 5 + 1, 0x01), ks, curve.N);
KPrintf("------------------------------below is t1---------------------------------\n"); printf("------------------------------below is t1---------------------------------\n");
Big8wPrint(&t1); Big8wPrint(&t1);
t2 = Big8wMultMod(ks, Big8wReverse(t1, curve.N), curve.N); t2 = Big8wMultMod(ks, Big8wReverse(t1, curve.N), curve.N);
KPrintf("------------------------------below is t2---------------------------------\n"); printf("------------------------------below is t2---------------------------------\n");
Big8wPrint(&t2); Big8wPrint(&t2);
dsA = G1pointMult(t2, P1); dsA = G1pointMult(t2, P1);
KPrintf("------------------------------below is dsA--------------------------------\n"); printf("------------------------------below is dsA--------------------------------\n");
Big8wPrint(&dsA.x); Big8wPrint(&dsA.x);
Big8wPrint(&dsA.y); Big8wPrint(&dsA.y);
g = BiLinearPairing(P1, Ppub_s); g = BiLinearPairing(P1, Ppub_s);
KPrintf("------------------------below is bilineapairing---------------------------\n"); printf("------------------------below is bilineapairing---------------------------\n");
Q12Print(&g); Q12Print(&g);
w = Q12PowerMod(g, r); w = Q12PowerMod(g, r);
KPrintf("------------------------------below is w----------------------------------\n"); printf("------------------------------below is w----------------------------------\n");
Q12Print(&w); Q12Print(&w);
msg_w = (uint8_t*)(malloc(msglen + BIG8W_BYTESIZE * 12)); msg_w = (uint8_t*)(malloc(msglen + BIG8W_BYTESIZE * 12));
JoinMsgW(message, msglen, &w, msg_w); JoinMsgW(message, msglen, &w, msg_w);
h = H(msg_w, msglen + BIG8W_BYTESIZE * 12, 0x02); h = H(msg_w, msglen + BIG8W_BYTESIZE * 12, 0x02);
KPrintf("------------------------------below is h----------------------------------\n"); printf("------------------------------below is h----------------------------------\n");
Big8wPrint(&h); Big8wPrint(&h);
big8w L = Big8wMinusMod(r, h, curve.N); big8w L = Big8wMinusMod(r, h, curve.N);
KPrintf("------------------------------below is L----------------------------------\n"); printf("------------------------------below is L----------------------------------\n");
Big8wPrint(&L); Big8wPrint(&L);
G1point S = G1pointMult(L, dsA); G1point S = G1pointMult(L, dsA);
KPrintf("------------------------------below is S----------------------------------\n"); printf("------------------------------below is S----------------------------------\n");
Big8wPrint(&S.x); Big8wPrint(&S.x);
Big8wPrint(&S.y); Big8wPrint(&S.y);
KPrintf("\n"); printf("\n");
// verify the signature // verify the signature
g = BiLinearPairing(P1, Ppub_s); g = BiLinearPairing(P1, Ppub_s);
KPrintf("------------------------below is bilineapairing---------------------------\n"); printf("------------------------below is bilineapairing---------------------------\n");
Q12Print(&g); Q12Print(&g);
t = Q12PowerMod(g, h); t = Q12PowerMod(g, h);
KPrintf("-----------------------------below is t-----------------------------------\n"); printf("-----------------------------below is t-----------------------------------\n");
Q12Print(&t); Q12Print(&t);
h1 = H(Id_Alice_hid, 5 + 1, 0x01); h1 = H(Id_Alice_hid, 5 + 1, 0x01);
KPrintf("-----------------------------below is h1----------------------------------\n"); printf("-----------------------------below is h1----------------------------------\n");
Big8wPrint(&h1); Big8wPrint(&h1);
P = G2PointAdd(Ppub_s, G2PointMult(h1, P2)); P = G2PointAdd(Ppub_s, G2PointMult(h1, P2));
KPrintf("------------------------------below is P----------------------------------\n"); printf("------------------------------below is P----------------------------------\n");
G2pointPrint(&P); G2pointPrint(&P);
u = BiLinearPairing(S, P); u = BiLinearPairing(S, P);
KPrintf("------------------------------below is u----------------------------------\n"); printf("------------------------------below is u----------------------------------\n");
Q12Print(&u); Q12Print(&u);
w = Q12MultMod(u, t); w = Q12MultMod(u, t);
KPrintf("------------------------------below is w----------------------------------\n"); printf("------------------------------below is w----------------------------------\n");
Q12Print(&w); Q12Print(&w);
h2 = H(msg_w, msglen + BIG8W_BYTESIZE * 12, 0x02); h2 = H(msg_w, msglen + BIG8W_BYTESIZE * 12, 0x02);
KPrintf("------------------------------below is h2---------------------------------\n"); printf("------------------------------below is h2---------------------------------\n");
Big8wPrint(&h2); Big8wPrint(&h2);
KPrintf("------------------------------below is h----------------------------------\n"); printf("------------------------------below is h----------------------------------\n");
Big8wPrint(&h); Big8wPrint(&h);
if (Big8wEqual(&h2, &h)) if (Big8wEqual(&h2, &h))
KPrintf("\nh2 = h, test verify success!\n"); printf("\nh2 = h, test verify success!\n");
sig = SM9Sign(message, msglen, dsA, Ppub_s); sig = SM9Sign(message, msglen, dsA, Ppub_s);
if (SM9VerifySignature(ID_Alice, 5, hid, message, msglen, sig, Ppub_s)) if (SM9VerifySignature(ID_Alice, 5, hid, message, msglen, sig, Ppub_s))
KPrintf("SM9 Sign and VerifySignature API run success!\n"); printf("SM9 Sign and VerifySignature API run success!\n");
/* /*
@ -172,8 +172,8 @@ void SignAndVerifyTest()
end = clock(); end = clock();
end_start = end - start; end_start = end - start;
KPrintf("\n"); printf("\n");
KPrintf("runtime of sign in: %d ms\n", end_start); printf("runtime of sign in: %d ms\n", end_start);
*/ */
free(Id_Alice_hid); free(Id_Alice_hid);
@ -239,21 +239,21 @@ void SM9KeyExchangeTest()
SM9Init(); SM9Init();
Ppub_e = G1pointMult(ke, P1); Ppub_e = G1pointMult(ke, P1);
KPrintf("------------------------------below is Ppub_e-----------------------------\n"); printf("------------------------------below is Ppub_e-----------------------------\n");
Big8wPrint(&Ppub_e.x); Big8wPrint(&Ppub_e.x);
Big8wPrint(&Ppub_e.y); Big8wPrint(&Ppub_e.y);
JoinIDhid(ID_Alice, 5, hid, Id_Alice_hid); JoinIDhid(ID_Alice, 5, hid, Id_Alice_hid);
t1 = Big8wAddMod(H(Id_Alice_hid, 5 + 1, 0x01), ke, curve.N); t1 = Big8wAddMod(H(Id_Alice_hid, 5 + 1, 0x01), ke, curve.N);
KPrintf("-----------------------------below is t1----------------------------------\n"); printf("-----------------------------below is t1----------------------------------\n");
Big8wPrint(&t1); Big8wPrint(&t1);
t2 = Big8wMultMod(ke, Big8wReverse(t1, curve.N), curve.N); t2 = Big8wMultMod(ke, Big8wReverse(t1, curve.N), curve.N);
KPrintf("-----------------------------below is t2----------------------------------\n"); printf("-----------------------------below is t2----------------------------------\n");
Big8wPrint(&t2); Big8wPrint(&t2);
deA = G2PointMult(t2, P2); deA = G2PointMult(t2, P2);
KPrintf("------------------------------below is deA--------------------------------\n"); printf("------------------------------below is deA--------------------------------\n");
Big8wPrint(&deA.x.high); Big8wPrint(&deA.x.high);
Big8wPrint(&deA.x.low); Big8wPrint(&deA.x.low);
Big8wPrint(&deA.y.high); Big8wPrint(&deA.y.high);
@ -262,15 +262,15 @@ void SM9KeyExchangeTest()
JoinIDhid(ID_Bob, 3, hid, ID_Bob_hid); JoinIDhid(ID_Bob, 3, hid, ID_Bob_hid);
t3 = Big8wAddMod(H(ID_Bob_hid, 3 + 1, 0x01), ke, curve.N); t3 = Big8wAddMod(H(ID_Bob_hid, 3 + 1, 0x01), ke, curve.N);
KPrintf("-----------------------------below is t3----------------------------------\n"); printf("-----------------------------below is t3----------------------------------\n");
Big8wPrint(&t3); Big8wPrint(&t3);
t4 = Big8wMultMod(ke, Big8wReverse(t3, curve.N), curve.N); t4 = Big8wMultMod(ke, Big8wReverse(t3, curve.N), curve.N);
KPrintf("-----------------------------below is t4----------------------------------\n"); printf("-----------------------------below is t4----------------------------------\n");
Big8wPrint(&t4); Big8wPrint(&t4);
deB = G2PointMult(t4, P2); deB = G2PointMult(t4, P2);
KPrintf("------------------------------below is deB--------------------------------\n"); printf("------------------------------below is deB--------------------------------\n");
Big8wPrint(&deB.x.high); Big8wPrint(&deB.x.high);
Big8wPrint(&deB.x.low); Big8wPrint(&deB.x.low);
Big8wPrint(&deB.y.high); Big8wPrint(&deB.y.high);
@ -279,208 +279,208 @@ void SM9KeyExchangeTest()
JoinIDhid(ID_Bob, 3, hid, ID_Bob_hid); JoinIDhid(ID_Bob, 3, hid, ID_Bob_hid);
h1 = H(ID_Bob_hid, 3 + 1, 0x01); h1 = H(ID_Bob_hid, 3 + 1, 0x01);
KPrintf("-----------------------------below is h1----------------------------------\n"); printf("-----------------------------below is h1----------------------------------\n");
Big8wPrint(&h1); Big8wPrint(&h1);
QB = G1pointAdd(Ppub_e, G1pointMult(h1, P1)); QB = G1pointAdd(Ppub_e, G1pointMult(h1, P1));
KPrintf("-----------------------------below is QB----------------------------------\n"); printf("-----------------------------below is QB----------------------------------\n");
Big8wPrint(&QB.x); Big8wPrint(&QB.x);
Big8wPrint(&QB.y); Big8wPrint(&QB.y);
RA = G1pointMult(rA, QB); RA = G1pointMult(rA, QB);
KPrintf("-----------------------------below is RA----------------------------------\n"); printf("-----------------------------below is RA----------------------------------\n");
Big8wPrint(&RA.x); Big8wPrint(&RA.x);
Big8wPrint(&RA.y); Big8wPrint(&RA.y);
JoinIDhid(ID_Alice, 5, hid, Id_Alice_hid); JoinIDhid(ID_Alice, 5, hid, Id_Alice_hid);
h1 = H(Id_Alice_hid, 5 + 1, 0x01); h1 = H(Id_Alice_hid, 5 + 1, 0x01);
KPrintf("-----------------------------below is h1----------------------------------\n"); printf("-----------------------------below is h1----------------------------------\n");
Big8wPrint(&h1); Big8wPrint(&h1);
QA = G1pointAdd(Ppub_e, G1pointMult(h1, P1)); QA = G1pointAdd(Ppub_e, G1pointMult(h1, P1));
KPrintf("-----------------------------below is QA----------------------------------\n"); printf("-----------------------------below is QA----------------------------------\n");
Big8wPrint(&QA.x); Big8wPrint(&QA.x);
Big8wPrint(&QA.y); Big8wPrint(&QA.y);
RB = G1pointMult(rB, QA); RB = G1pointMult(rB, QA);
KPrintf("-----------------------------below is RB----------------------------------\n"); printf("-----------------------------below is RB----------------------------------\n");
Big8wPrint(&RB.x); Big8wPrint(&RB.x);
Big8wPrint(&RB.y); Big8wPrint(&RB.y);
g1 = BiLinearPairing(RA, deB); g1 = BiLinearPairing(RA, deB);
KPrintf("-----------------------------below is g1----------------------------------\n"); printf("-----------------------------below is g1----------------------------------\n");
Q12Print(&g1); Q12Print(&g1);
g2 = BiLinearPairing(Ppub_e, P2); g2 = BiLinearPairing(Ppub_e, P2);
g2 = Q12PowerMod(g2, rB); g2 = Q12PowerMod(g2, rB);
KPrintf("-----------------------------below is g2----------------------------------\n"); printf("-----------------------------below is g2----------------------------------\n");
Q12Print(&g2); Q12Print(&g2);
g3 = Q12PowerMod(g1, rB); g3 = Q12PowerMod(g1, rB);
KPrintf("-----------------------------below is g3----------------------------------\n"); printf("-----------------------------below is g3----------------------------------\n");
Q12Print(&g3); Q12Print(&g3);
JoinIDAIDBRARBg123(ID_Alice, 5, ID_Bob, 3, &RA, &RB, &g1, &g2, &g3, strA); JoinIDAIDBRARBg123(ID_Alice, 5, ID_Bob, 3, &RA, &RB, &g1, &g2, &g3, strA);
KDF(strA, 5 + 3 + BIG8W_BYTESIZE * 2 * 2 + BIG8W_BYTESIZE * 12 * 3, klen, SKB); KDF(strA, 5 + 3 + BIG8W_BYTESIZE * 2 * 2 + BIG8W_BYTESIZE * 12 * 3, klen, SKB);
KPrintf("-----------------------------below is SKB---------------------------------\n"); printf("-----------------------------below is SKB---------------------------------\n");
for (i = 0; i < klen/8; i++){ for (i = 0; i < klen/8; i++){
KPrintf("%02x", SKB[i]); printf("%02x", SKB[i]);
if (((i+1)&0x3) == 0) if (((i+1)&0x3) == 0)
KPrintf(" "); printf(" ");
if (((i + 1) % 32) == 0) if (((i + 1) % 32) == 0)
KPrintf("\n"); printf("\n");
}
KPrintf("\n");
KPrintf("-----------------------------below is SB----------------------------------\n");
HashTwice(ID_Alice, 5, ID_Bob, 3, &RA, &RB, &g1, &g2, &g3, 0x82, SB);
HashTwice(ID_Alice, 5, ID_Bob, 3, &RA, &RB, &g1, &g2, &g3, 0x83, S2);
for (i = 0; i < 256/8; i++){
KPrintf("%02x", SB[i]);
if (((i+1)&0x3) == 0)
KPrintf(" ");
if (((i + 1) % 32) == 0)
KPrintf("\n");
}
KPrintf("\n");
g1 = BiLinearPairing(Ppub_e, P2);
g1 = Q12PowerMod(g1, rA);
KPrintf("-----------------------------below is g1----------------------------------\n");
Q12Print(&g1);
g2 = BiLinearPairing(RB, deA);
KPrintf("-----------------------------below is g2----------------------------------\n");
Q12Print(&g2);
g3 = Q12PowerMod(g2, rA);
KPrintf("-----------------------------below is g3----------------------------------\n");
Q12Print(&g3);
KPrintf("-----------------------------below is S1----------------------------------\n");
HashTwice(ID_Alice, 5, ID_Bob, 3, &RA, &RB, &g1, &g2, &g3, 0x82, S1);
for (i = 0; i < 256/8; i++){
KPrintf("%02x", S1[i]);
if (((i+1)&0x3) == 0)
KPrintf(" ");
if (((i + 1) % 32) == 0)
KPrintf("\n");
}
KPrintf("\n");
KDF(strA, 5 + 3 + BIG8W_BYTESIZE * 2 * 2 + BIG8W_BYTESIZE * 12 * 3, klen, SKA);
KPrintf("-----------------------------below is SKA---------------------------------\n");
for (i = 0; i < klen/8; i++){
KPrintf("%02x", SKA[i]);
if (((i+1)&0x3) == 0)
KPrintf(" ");
if (((i + 1) % 32) == 0)
KPrintf("\n");
} }
printf("\n"); printf("\n");
KPrintf("-----------------------------below is SA----------------------------------\n"); printf("-----------------------------below is SB----------------------------------\n");
HashTwice(ID_Alice, 5, ID_Bob, 3, &RA, &RB, &g1, &g2, &g3, 0x82, SB);
HashTwice(ID_Alice, 5, ID_Bob, 3, &RA, &RB, &g1, &g2, &g3, 0x83, S2);
for (i = 0; i < 256/8; i++){
printf("%02x", SB[i]);
if (((i+1)&0x3) == 0)
printf(" ");
if (((i + 1) % 32) == 0)
printf("\n");
}
printf("\n");
g1 = BiLinearPairing(Ppub_e, P2);
g1 = Q12PowerMod(g1, rA);
printf("-----------------------------below is g1----------------------------------\n");
Q12Print(&g1);
g2 = BiLinearPairing(RB, deA);
printf("-----------------------------below is g2----------------------------------\n");
Q12Print(&g2);
g3 = Q12PowerMod(g2, rA);
printf("-----------------------------below is g3----------------------------------\n");
Q12Print(&g3);
printf("-----------------------------below is S1----------------------------------\n");
HashTwice(ID_Alice, 5, ID_Bob, 3, &RA, &RB, &g1, &g2, &g3, 0x82, S1);
for (i = 0; i < 256/8; i++){
printf("%02x", S1[i]);
if (((i+1)&0x3) == 0)
printf(" ");
if (((i + 1) % 32) == 0)
printf("\n");
}
printf("\n");
KDF(strA, 5 + 3 + BIG8W_BYTESIZE * 2 * 2 + BIG8W_BYTESIZE * 12 * 3, klen, SKA);
printf("-----------------------------below is SKA---------------------------------\n");
for (i = 0; i < klen/8; i++){
printf("%02x", SKA[i]);
if (((i+1)&0x3) == 0)
printf(" ");
if (((i + 1) % 32) == 0)
printf("\n");
}
printf("\n");
printf("-----------------------------below is SA----------------------------------\n");
HashTwice(ID_Alice, 5, ID_Bob, 3, &RA, &RB, &g1, &g2, &g3, 0x83, SA); HashTwice(ID_Alice, 5, ID_Bob, 3, &RA, &RB, &g1, &g2, &g3, 0x83, SA);
for (i = 0; i < 256/8; i++){ for (i = 0; i < 256/8; i++){
KPrintf("%02x", SA[i]); printf("%02x", SA[i]);
if (((i+1)&0x3) == 0) if (((i+1)&0x3) == 0)
KPrintf(" "); printf(" ");
if (((i + 1) % 32) == 0) if (((i + 1) % 32) == 0)
KPrintf("\n"); printf("\n");
} }
KPrintf("\n"); printf("\n");
KPrintf("-----------------------------below is S2----------------------------------\n"); printf("-----------------------------below is S2----------------------------------\n");
for (i = 0; i < 256/8; i++){ for (i = 0; i < 256/8; i++){
KPrintf("%02x", S2[i]); printf("%02x", S2[i]);
if (((i+1)&0x3) == 0) if (((i+1)&0x3) == 0)
KPrintf(" "); printf(" ");
if (((i + 1) % 32) == 0) if (((i + 1) % 32) == 0)
KPrintf("\n"); printf("\n");
} }
KPrintf("\n"); printf("\n");
// Following is test of API, random big number generated in SM9KeyExchangeProduceR, so result is different from the former. // Following is test of API, random big number generated in SM9KeyExchangeProduceR, so result is different from the former.
// To get the same result, you should delete the line "*r = RandomNumGenerate();" in function SM9KeyExchangeR. (or set as note) // To get the same result, you should delete the line "*r = RandomNumGenerate();" in function SM9KeyExchangeR. (or set as note)
KPrintf("---------------------------SM9 key exchange API test----------------------\n"); printf("---------------------------SM9 key exchange API test----------------------\n");
SM9KeyExchangeProduceR(ID_Bob, 3, &rA, &RA, Ppub_e); SM9KeyExchangeProduceR(ID_Bob, 3, &rA, &RA, Ppub_e);
KPrintf("-----------------------------below is RA----------------------------------\n"); printf("-----------------------------below is RA----------------------------------\n");
Big8wPrint(&RA.x); Big8wPrint(&RA.x);
Big8wPrint(&RA.y); Big8wPrint(&RA.y);
SM9KeyExchangeProduceR(ID_Alice, 5, &rB, &RB, Ppub_e); SM9KeyExchangeProduceR(ID_Alice, 5, &rB, &RB, Ppub_e);
KPrintf("-----------------------------below is RB----------------------------------\n"); printf("-----------------------------below is RB----------------------------------\n");
Big8wPrint(&RB.x); Big8wPrint(&RB.x);
Big8wPrint(&RB.y); Big8wPrint(&RB.y);
SM9KeyExchangeProduceKey(&RA, &RB, &rA, klen, ID_Alice, 5, ID_Bob, 3, &g1, &g2, &g3, SKA, true, Ppub_e, deA); SM9KeyExchangeProduceKey(&RA, &RB, &rA, klen, ID_Alice, 5, ID_Bob, 3, &g1, &g2, &g3, SKA, true, Ppub_e, deA);
KPrintf("-----------------------------below is g1----------------------------------\n"); printf("-----------------------------below is g1----------------------------------\n");
Q12Print(&g1); Q12Print(&g1);
KPrintf("-----------------------------below is g2----------------------------------\n"); printf("-----------------------------below is g2----------------------------------\n");
Q12Print(&g2); Q12Print(&g2);
KPrintf("-----------------------------below is g3----------------------------------\n"); printf("-----------------------------below is g3----------------------------------\n");
Q12Print(&g3); Q12Print(&g3);
KPrintf("-----------------------------below is SKA---------------------------------\n"); printf("-----------------------------below is SKA---------------------------------\n");
for (i = 0; i < klen/8; i++){ for (i = 0; i < klen/8; i++){
KPrintf("%02x", SKA[i]); printf("%02x", SKA[i]);
if (((i+1)&0x3) == 0) if (((i+1)&0x3) == 0)
KPrintf(" "); printf(" ");
if (((i + 1) % 32) == 0) if (((i + 1) % 32) == 0)
KPrintf("\n"); printf("\n");
} }
KPrintf("\n"); printf("\n");
// g1,g2,g3 changed // g1,g2,g3 changed
// SM9KeyExchangeProduceKey(&RA, &RB, &rB, klen, ID_Alice, 5, ID_Bob, 3, &g1, &g2, &g3, SKB, false, Ppub_e, deB); // SM9KeyExchangeProduceKey(&RA, &RB, &rB, klen, ID_Alice, 5, ID_Bob, 3, &g1, &g2, &g3, SKB, false, Ppub_e, deB);
SM9KeyExchangeVerifyKey(&g1, &g2, &g3, &RA, &RB, ID_Alice, 5, ID_Bob, 3, S1, SA); SM9KeyExchangeVerifyKey(&g1, &g2, &g3, &RA, &RB, ID_Alice, 5, ID_Bob, 3, S1, SA);
KPrintf("-----------------------------below is SA----------------------------------\n"); printf("-----------------------------below is SA----------------------------------\n");
for (i = 0; i < 256/8; i++){ for (i = 0; i < 256/8; i++){
KPrintf("%02x", SA[i]); printf("%02x", SA[i]);
if (((i+1)&0x3) == 0) if (((i+1)&0x3) == 0)
KPrintf(" "); printf(" ");
if (((i + 1) % 32) == 0) if (((i + 1) % 32) == 0)
KPrintf("\n"); printf("\n");
} }
KPrintf("\n"); printf("\n");
KPrintf("-----------------------------below is S1----------------------------------\n"); printf("-----------------------------below is S1----------------------------------\n");
for (i = 0; i < 256/8; i++){ for (i = 0; i < 256/8; i++){
KPrintf("%02x", S1[i]); printf("%02x", S1[i]);
if (((i+1)&0x3) == 0) if (((i+1)&0x3) == 0)
KPrintf(" "); printf(" ");
if (((i + 1) % 32) == 0) if (((i + 1) % 32) == 0)
KPrintf("\n"); printf("\n");
} }
KPrintf("\n"); printf("\n");
SM9KeyExchangeVerifyKey(&g1, &g2, &g3, &RA, &RB, ID_Alice, 5, ID_Bob, 3, SB, S2); SM9KeyExchangeVerifyKey(&g1, &g2, &g3, &RA, &RB, ID_Alice, 5, ID_Bob, 3, SB, S2);
KPrintf("-----------------------------below is SB----------------------------------\n"); printf("-----------------------------below is SB----------------------------------\n");
for (i = 0; i < 256/8; i++){ for (i = 0; i < 256/8; i++){
KPrintf("%02x", SB[i]); printf("%02x", SB[i]);
if (((i+1)&0x3) == 0) if (((i+1)&0x3) == 0)
KPrintf(" "); printf(" ");
if (((i + 1) % 32) == 0) if (((i + 1) % 32) == 0)
KPrintf("\n"); printf("\n");
} }
KPrintf("\n"); printf("\n");
KPrintf("-----------------------------below is S2----------------------------------\n"); printf("-----------------------------below is S2----------------------------------\n");
for (i = 0; i < 256/8; i++){ for (i = 0; i < 256/8; i++){
KPrintf("%02x", S2[i]); printf("%02x", S2[i]);
if (((i+1)&0x3) == 0) if (((i+1)&0x3) == 0)
KPrintf(" "); printf(" ");
if (((i + 1) % 32) == 0) if (((i + 1) % 32) == 0)
KPrintf("\n"); printf("\n");
} }
KPrintf("\n"); printf("\n");
free(strA); free(strA);
free(strB); free(strB);
@ -535,25 +535,25 @@ void SM9PackDepackTest()
SM9Init(); SM9Init();
Ppub_e = G1pointMult(ke, P1); Ppub_e = G1pointMult(ke, P1);
KPrintf("-----------------------------below is Ppub_e------------------------------\n"); printf("-----------------------------below is Ppub_e------------------------------\n");
Big8wPrint(&Ppub_e.x); Big8wPrint(&Ppub_e.x);
Big8wPrint(&Ppub_e.y); Big8wPrint(&Ppub_e.y);
JoinIDhid(ID_Bob, 3, hid, ID_Bob_hid); JoinIDhid(ID_Bob, 3, hid, ID_Bob_hid);
t1 = H(ID_Bob_hid, 3 + 1, 0x01); t1 = H(ID_Bob_hid, 3 + 1, 0x01);
KPrintf("-----------------------------below is H1()--------------------------------\n"); printf("-----------------------------below is H1()--------------------------------\n");
Big8wPrint(&t1); Big8wPrint(&t1);
t1 = Big8wAddMod(t1, ke, curve.N); t1 = Big8wAddMod(t1, ke, curve.N);
KPrintf("-----------------------------below is t1----------------------------------\n"); printf("-----------------------------below is t1----------------------------------\n");
Big8wPrint(&t1); Big8wPrint(&t1);
t1 = Big8wReverse(t1, curve.N); t1 = Big8wReverse(t1, curve.N);
t2 = Big8wMultMod(ke, t1, curve.N); t2 = Big8wMultMod(ke, t1, curve.N);
KPrintf("-----------------------------below is t2----------------------------------\n"); printf("-----------------------------below is t2----------------------------------\n");
Big8wPrint(&t2); Big8wPrint(&t2);
deB = G2PointMult(t2, P2); deB = G2PointMult(t2, P2);
KPrintf("------------------------------below is deB--------------------------------\n"); printf("------------------------------below is deB--------------------------------\n");
Big8wPrint(&deB.x.high); Big8wPrint(&deB.x.high);
Big8wPrint(&deB.x.low); Big8wPrint(&deB.x.low);
Big8wPrint(&deB.y.high); Big8wPrint(&deB.y.high);
@ -562,53 +562,53 @@ void SM9PackDepackTest()
QB = G1pointAdd( QB = G1pointAdd(
G1pointMult(H(ID_Bob_hid, 3 + 1, 0x01), P1), G1pointMult(H(ID_Bob_hid, 3 + 1, 0x01), P1),
Ppub_e); Ppub_e);
KPrintf("-----------------------------below is QB----------------------------------\n"); printf("-----------------------------below is QB----------------------------------\n");
Big8wPrint(&QB.x); Big8wPrint(&QB.x);
Big8wPrint(&QB.y); Big8wPrint(&QB.y);
C = G1pointMult(r, QB); C = G1pointMult(r, QB);
KPrintf("-----------------------------below is C----------------------------------\n"); printf("-----------------------------below is C----------------------------------\n");
Big8wPrint(&C.x); Big8wPrint(&C.x);
Big8wPrint(&C.y); Big8wPrint(&C.y);
g = BiLinearPairing(Ppub_e, P2); g = BiLinearPairing(Ppub_e, P2);
KPrintf("-----------------------------below is g----------------------------------\n"); printf("-----------------------------below is g----------------------------------\n");
Q12Print(&g); Q12Print(&g);
w = Q12PowerMod(g, r); w = Q12PowerMod(g, r);
KPrintf("-----------------------------below is w----------------------------------\n"); printf("-----------------------------below is w----------------------------------\n");
Q12Print(&w); Q12Print(&w);
JoinCwID(&C, &w, ID_Bob, 3, c_w_id); JoinCwID(&C, &w, ID_Bob, 3, c_w_id);
KDF(c_w_id, c_w_id_len, klen, K_encap); KDF(c_w_id, c_w_id_len, klen, K_encap);
KPrintf("-----------------------------below is K-----------------------------------\n"); printf("-----------------------------below is K-----------------------------------\n");
for (i = 0; i < klen / 8; i++){ for (i = 0; i < klen / 8; i++){
KPrintf("%02x", K_encap[i]); printf("%02x", K_encap[i]);
if (((i+1)&0x3) == 0) if (((i+1)&0x3) == 0)
KPrintf(" "); printf(" ");
if (((i + 1) % 32) == 0) if (((i + 1) % 32) == 0)
KPrintf("\n"); printf("\n");
} }
KPrintf("\n"); printf("\n");
w = BiLinearPairing(C, deB); w = BiLinearPairing(C, deB);
KPrintf("-----------------------------below is w'----------------------------------\n"); printf("-----------------------------below is w'----------------------------------\n");
Q12Print(&w); Q12Print(&w);
JoinCwID(&C, &w, ID_Bob, 3, c_w_id); JoinCwID(&C, &w, ID_Bob, 3, c_w_id);
KDF(c_w_id, c_w_id_len, klen, K_encap); KDF(c_w_id, c_w_id_len, klen, K_encap);
KPrintf("-----------------------------below is K'----------------------------------\n"); printf("-----------------------------below is K'----------------------------------\n");
for (i = 0; i < klen / 8; i++){ for (i = 0; i < klen / 8; i++){
KPrintf("%02x", K_encap[i]); printf("%02x", K_encap[i]);
if (((i+1)&0x3) == 0) if (((i+1)&0x3) == 0)
KPrintf(" "); printf(" ");
if (((i + 1) % 32) == 0) if (((i + 1) % 32) == 0)
KPrintf("\n"); printf("\n");
} }
KPrintf("\n"); printf("\n");
KPrintf("pack and depack done\n"); printf("pack and depack done\n");
free(ID_Bob_hid); free(ID_Bob_hid);
free(K_encap); free(K_encap);
@ -671,22 +671,22 @@ void SM9EncryptDecryptTest()
SM9Init(); SM9Init();
Ppub_e = G1pointMult(ke, P1); Ppub_e = G1pointMult(ke, P1);
KPrintf("-----------------------------below is Ppub_e------------------------------\n"); printf("-----------------------------below is Ppub_e------------------------------\n");
Big8wPrint(&Ppub_e.x); Big8wPrint(&Ppub_e.x);
Big8wPrint(&Ppub_e.y); Big8wPrint(&Ppub_e.y);
JoinIDhid(ID_Bob, 3, hid, ID_Bob_hid); JoinIDhid(ID_Bob, 3, hid, ID_Bob_hid);
t1 = Big8wAddMod(H(ID_Bob_hid, 3 + 1, 0x01), ke, curve.N); t1 = Big8wAddMod(H(ID_Bob_hid, 3 + 1, 0x01), ke, curve.N);
KPrintf("-----------------------------below is t1----------------------------------\n"); printf("-----------------------------below is t1----------------------------------\n");
Big8wPrint(&t1); Big8wPrint(&t1);
t1 = Big8wReverse(t1, curve.N); t1 = Big8wReverse(t1, curve.N);
t2 = Big8wMultMod(ke, t1, curve.N); t2 = Big8wMultMod(ke, t1, curve.N);
KPrintf("-----------------------------below is t2----------------------------------\n"); printf("-----------------------------below is t2----------------------------------\n");
Big8wPrint(&t2); Big8wPrint(&t2);
deB = G2PointMult(t2, P2); deB = G2PointMult(t2, P2);
KPrintf("------------------------------below is deB--------------------------------\n"); printf("------------------------------below is deB--------------------------------\n");
Big8wPrint(&deB.x.high); Big8wPrint(&deB.x.high);
Big8wPrint(&deB.x.low); Big8wPrint(&deB.x.low);
Big8wPrint(&deB.y.high); Big8wPrint(&deB.y.high);
@ -695,46 +695,46 @@ void SM9EncryptDecryptTest()
QB = G1pointAdd( QB = G1pointAdd(
G1pointMult(H(ID_Bob_hid, 3 + 1, 0x01), P1), G1pointMult(H(ID_Bob_hid, 3 + 1, 0x01), P1),
Ppub_e); Ppub_e);
KPrintf("-----------------------------below is QB----------------------------------\n"); printf("-----------------------------below is QB----------------------------------\n");
Big8wPrint(&QB.x); Big8wPrint(&QB.x);
Big8wPrint(&QB.y); Big8wPrint(&QB.y);
C1 = G1pointMult(r, QB); C1 = G1pointMult(r, QB);
KPrintf("-----------------------------below is C1----------------------------------\n"); printf("-----------------------------below is C1----------------------------------\n");
Big8wPrint(&C1.x); Big8wPrint(&C1.x);
Big8wPrint(&C1.y); Big8wPrint(&C1.y);
g = BiLinearPairing(Ppub_e, P2); g = BiLinearPairing(Ppub_e, P2);
KPrintf("-----------------------------below is g-----------------------------------\n"); printf("-----------------------------below is g-----------------------------------\n");
Q12Print(&g); Q12Print(&g);
w = Q12PowerMod(g, r); w = Q12PowerMod(g, r);
KPrintf("-----------------------------below is w-----------------------------------\n"); printf("-----------------------------below is w-----------------------------------\n");
Q12Print(&w); Q12Print(&w);
JoinCwID(&C1, &w, ID_Bob, 3, C_w_id); JoinCwID(&C1, &w, ID_Bob, 3, C_w_id);
KDF(C_w_id, c_w_id_len, klen, K); KDF(C_w_id, c_w_id_len, klen, K);
KPrintf("-----------------------------below is K-----------------------------------\n"); printf("-----------------------------below is K-----------------------------------\n");
for (i = 0; i < klen / 8; i++) { for (i = 0; i < klen / 8; i++) {
KPrintf("%02x", K[i]); printf("%02x", K[i]);
if (((i+1)&0x3) == 0) if (((i+1)&0x3) == 0)
KPrintf(" "); printf(" ");
if (((i + 1) % 32) == 0) if (((i + 1) % 32) == 0)
KPrintf("\n"); printf("\n");
} }
KPrintf("\n"); printf("\n");
XOR(message, mlen / 8, K, C2); XOR(message, mlen / 8, K, C2);
KPrintf("-----------------------------below is C2----------------------------------\n"); printf("-----------------------------below is C2----------------------------------\n");
for (i = 0; i < mlen / 8; i++) { for (i = 0; i < mlen / 8; i++) {
KPrintf("%02x", C2[i]); printf("%02x", C2[i]);
if (((i + 1) & 0x3) == 0) if (((i + 1) & 0x3) == 0)
KPrintf(" "); printf(" ");
if (((i + 1) % 32) == 0) if (((i + 1) % 32) == 0)
KPrintf("\n"); printf("\n");
} }
KPrintf("\n"); printf("\n");
for (i = 0; i < mlen / 8; i++) for (i = 0; i < mlen / 8; i++)
C2K2[i] = C2[i]; C2K2[i] = C2[i];
@ -742,15 +742,15 @@ void SM9EncryptDecryptTest()
C2K2[i] = K[i]; C2K2[i] = K[i];
sm3(C2K2, (mlen / 8) + (K2_len / 8), C3); sm3(C2K2, (mlen / 8) + (K2_len / 8), C3);
KPrintf("----------------------------below is C3-----------------------------------\n"); printf("----------------------------below is C3-----------------------------------\n");
for (i = 0; i < 256/8; i++) { for (i = 0; i < 256/8; i++) {
KPrintf("%02x", C3[i]); printf("%02x", C3[i]);
if (((i + 1) & 0x3) == 0) if (((i + 1) & 0x3) == 0)
KPrintf(" "); printf(" ");
if (((i + 1) % 32) == 0) if (((i + 1) % 32) == 0)
KPrintf("\n"); printf("\n");
} }
KPrintf("\n"); printf("\n");
i = 0; i = 0;
Big8wIntou8string(&C1.x, C, i); Big8wIntou8string(&C1.x, C, i);
@ -764,44 +764,44 @@ void SM9EncryptDecryptTest()
for (; i < BIG8W_BYTESIZE * 2 + (256 / 8) + (mlen / 8); i++) for (; i < BIG8W_BYTESIZE * 2 + (256 / 8) + (mlen / 8); i++)
C[i] = C2[i - (BIG8W_BYTESIZE * 2 + 256 / 8)]; C[i] = C2[i - (BIG8W_BYTESIZE * 2 + 256 / 8)];
KPrintf("----------------------------below is C------------------------------------\n"); printf("----------------------------below is C------------------------------------\n");
for (i = 0; i < BIG8W_BYTESIZE * 2 + (256 / 8) + (mlen / 8); i++) { for (i = 0; i < BIG8W_BYTESIZE * 2 + (256 / 8) + (mlen / 8); i++) {
KPrintf("%02x", C[i]); printf("%02x", C[i]);
if (((i + 1) & 0x3) == 0) if (((i + 1) & 0x3) == 0)
KPrintf(" "); printf(" ");
if (((i + 1) % 32) == 0) if (((i + 1) % 32) == 0)
KPrintf("\n"); printf("\n");
} }
KPrintf("\n"); printf("\n");
// decrypt // decrypt
w = BiLinearPairing(C1, deB); w = BiLinearPairing(C1, deB);
KPrintf("----------------------------below is w'-----------------------------------\n"); printf("----------------------------below is w'-----------------------------------\n");
Q12Print(&w); Q12Print(&w);
JoinCwID(&C1, &w, ID_Bob, 3, C_w_id); JoinCwID(&C1, &w, ID_Bob, 3, C_w_id);
KDF(C_w_id, c_w_id_len, klen, K); KDF(C_w_id, c_w_id_len, klen, K);
KPrintf("----------------------------below is K'----------------------------------\n"); printf("----------------------------below is K'----------------------------------\n");
for (i = 0; i < (klen / 8); i++) { for (i = 0; i < (klen / 8); i++) {
KPrintf("%02x", K[i]); printf("%02x", K[i]);
if (((i + 1) & 0x3) == 0) if (((i + 1) & 0x3) == 0)
KPrintf(" "); printf(" ");
if (((i + 1) % 32) == 0) if (((i + 1) % 32) == 0)
KPrintf("\n"); printf("\n");
} }
KPrintf("\n"); printf("\n");
XOR(C2, mlen / 8, K, message); XOR(C2, mlen / 8, K, message);
KPrintf("----------------------------below is M'----------------------------------\n"); printf("----------------------------below is M'----------------------------------\n");
for (i = 0; i < mlen / 8; i++) { for (i = 0; i < mlen / 8; i++) {
KPrintf("%02x", message[i]); printf("%02x", message[i]);
if (((i + 1) & 0x3) == 0) if (((i + 1) & 0x3) == 0)
KPrintf(" "); printf(" ");
if (((i + 1) % 32) == 0) if (((i + 1) % 32) == 0)
KPrintf("\n"); printf("\n");
} }
KPrintf("\n"); printf("\n");
for (i = 0; i < mlen / 8; i++) for (i = 0; i < mlen / 8; i++)
C2K2[i] = C2[i]; C2K2[i] = C2[i];
@ -809,53 +809,53 @@ void SM9EncryptDecryptTest()
C2K2[i] = K[i]; C2K2[i] = K[i];
sm3(C2K2, (mlen / 8) + (K2_len / 8), C3); sm3(C2K2, (mlen / 8) + (K2_len / 8), C3);
KPrintf("----------------------------below is u-----------------------------------\n"); printf("----------------------------below is u-----------------------------------\n");
for (i = 0; i < 256 / 8; i++) { for (i = 0; i < 256 / 8; i++) {
KPrintf("%02x", C3[i]); printf("%02x", C3[i]);
if (((i + 1) & 0x3) == 0) if (((i + 1) & 0x3) == 0)
KPrintf(" "); printf(" ");
if (((i + 1) % 32) == 0) if (((i + 1) % 32) == 0)
KPrintf("\n"); printf("\n");
} }
KPrintf("\n"); printf("\n");
KPrintf("decrypted message:\n%s\n", message); printf("decrypted message:\n%s\n", message);
KPrintf("-------------SM9EncryptWithKDF and SM9DecryptWithKDF test----------------\n"); printf("-------------SM9EncryptWithKDF and SM9DecryptWithKDF test----------------\n");
SM9EncryptWithKDF(message, mlen, K2_len, ID_Bob, 3, hid, Ppub_e, C); SM9EncryptWithKDF(message, mlen, K2_len, ID_Bob, 3, hid, Ppub_e, C);
KPrintf("------------------below is C, encrypted message--------------------------\n"); printf("------------------below is C, encrypted message--------------------------\n");
for (i = 0; i < Cbyteslen_KDF; i++) { for (i = 0; i < Cbyteslen_KDF; i++) {
KPrintf("%02x", C[i]); printf("%02x", C[i]);
if (((i + 1) & 0x3) == 0) if (((i + 1) & 0x3) == 0)
KPrintf(" "); printf(" ");
if (((i + 1) % 32) == 0) if (((i + 1) % 32) == 0)
KPrintf("\n"); printf("\n");
} }
KPrintf("\n"); printf("\n");
SM9DecryptWithKDF(ID_Bob, 3, message, 20 * 8, K2_len, C, deB); SM9DecryptWithKDF(ID_Bob, 3, message, 20 * 8, K2_len, C, deB);
KPrintf("---------------below is M, decrypted message in test.c-------------------\n"); printf("---------------below is M, decrypted message in test.c-------------------\n");
KPrintf("message:\n%s\n", message); printf("message:\n%s\n", message);
KPrintf("-------------SM9EncryptWithSM4 and SM9DecryptWithSM4 test----------------\n"); printf("-------------SM9EncryptWithSM4 and SM9DecryptWithSM4 test----------------\n");
SM9EncryptWithSM4(message, mlen, K1_len, K2_len, ID_Bob, 3, hid, Ppub_e, C_SM4); SM9EncryptWithSM4(message, mlen, K1_len, K2_len, ID_Bob, 3, hid, Ppub_e, C_SM4);
KPrintf("---------------below is C_SM4 in test.c, encrypted message---------------\n"); printf("---------------below is C_SM4 in test.c, encrypted message---------------\n");
for (i = 0; i < Cbyteslen_SM4; i++) { for (i = 0; i < Cbyteslen_SM4; i++) {
KPrintf("%02x", C_SM4[i]); printf("%02x", C_SM4[i]);
if (((i + 1) & 0x3) == 0) if (((i + 1) & 0x3) == 0)
KPrintf(" "); printf(" ");
if (((i + 1) % 32) == 0) if (((i + 1) % 32) == 0)
KPrintf("\n"); printf("\n");
} }
KPrintf("\n"); printf("\n");
if (!SM9DecryptWithSM4(ID_Bob, 3, sm4msg, (mlen / 8), K1_len, K2_len, C_SM4, Cbyteslen_SM4, deB)) if (!SM9DecryptWithSM4(ID_Bob, 3, sm4msg, (mlen / 8), K1_len, K2_len, C_SM4, Cbyteslen_SM4, deB))
KPrintf("SM9DecryptWithSM4 failed\n"); printf("SM9DecryptWithSM4 failed\n");
KPrintf("---------------------below is M, decrypted message-----------------------\n"); printf("---------------------below is M, decrypted message-----------------------\n");
for (i = 0; i < (mlen / 8); i++) for (i = 0; i < (mlen / 8); i++)
KPrintf("%c", sm4msg[i]); printf("%c", sm4msg[i]);
KPrintf("\n"); printf("\n");
free(C_w_id); free(C_w_id);
free(K); free(K);

View File

@ -177,6 +177,22 @@ FAR void *realloc(FAR void *oldmem, size_t size);
FAR void *calloc(size_t n, size_t elem_size); FAR void *calloc(size_t n, size_t elem_size);
void free(FAR void *mem); void free(FAR void *mem);
/*********************shell***********************/
//for int func(int argc, char *agrv[])
#define PRIV_SHELL_CMD_MAIN_ATTR
//for int func(int i, char ch, char *str)
#define PRIV_SHELL_CMD_FUNC_ATTR
/**
* @brief Priv-shell Command definition
*
* @param _func Command function
* @param _desc Command description
* @param _attr Command attributes if need
*/
#define PRIV_SHELL_CMD_FUNCTION(_func, _desc, _attr)
/**********************mutex**************************/ /**********************mutex**************************/
int PrivMutexCreate(pthread_mutex_t *p_mutex, const pthread_mutexattr_t *attr); int PrivMutexCreate(pthread_mutex_t *p_mutex, const pthread_mutexattr_t *attr);

View File

@ -165,6 +165,23 @@ struct PrivIoctlCfg
void *args; void *args;
}; };
/*********************shell***********************/
//for int func(int argc, char *agrv[])
#define PRIV_SHELL_CMD_MAIN_ATTR
//for int func(int i, char ch, char *str)
#define PRIV_SHELL_CMD_FUNC_ATTR
/**
* @brief Priv-shell Command definition
*
* @param _func Command function
* @param _desc Command description
* @param _attr Command attributes if need
*/
#define PRIV_SHELL_CMD_FUNCTION(_func, _desc, _attr) \
MSH_CMD_EXPORT(_func, _desc)
/**********************mutex**************************/ /**********************mutex**************************/
int PrivMutexCreate(pthread_mutex_t *p_mutex, const pthread_mutexattr_t *attr); int PrivMutexCreate(pthread_mutex_t *p_mutex, const pthread_mutexattr_t *attr);

View File

@ -24,6 +24,7 @@
#include <pthread.h> #include <pthread.h>
#include <signal.h> #include <signal.h>
#include <semaphore.h> #include <semaphore.h>
#include <stdio.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <time.h> #include <time.h>
@ -200,6 +201,24 @@ typedef struct
#define PRIV_TOUCH_DEV "/dev/touch_dev" #define PRIV_TOUCH_DEV "/dev/touch_dev"
#define MY_INDEV_X BSP_LCD_Y_MAX #define MY_INDEV_X BSP_LCD_Y_MAX
#define MY_INDEV_Y BSP_LCD_X_MAX #define MY_INDEV_Y BSP_LCD_X_MAX
/*********************shell***********************/
//for int func(int argc, char *agrv[])
#define PRIV_SHELL_CMD_MAIN_ATTR (SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN))
//for int func(int i, char ch, char *str)
#define PRIV_SHELL_CMD_FUNC_ATTR (SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC))
/**
* @brief Priv-shell Command definition
*
* @param _func Command function
* @param _desc Command description
* @param _attr Command attributes if need
*/
#define PRIV_SHELL_CMD_FUNCTION(_func, _desc, _attr) \
SHELL_EXPORT_CMD(_attr, _func, _func, _desc)
/**********************mutex**************************/ /**********************mutex**************************/
int PrivMutexCreate(pthread_mutex_t *p_mutex, const pthread_mutexattr_t *attr); int PrivMutexCreate(pthread_mutex_t *p_mutex, const pthread_mutexattr_t *attr);

View File

@ -57,6 +57,9 @@ menuconfig KERNEL_TEST
bool "Config test i2c" bool "Config test i2c"
default n default n
config KERNEL_TEST_RISC_CAN config KERNEL_TEST_RISC_CAN
bool "Config test riscv can " bool "Config test riscv can"
default n
config KERNEL_TEST_SPI_FLASH
bool "Config test spi flash"
default n default n
endif endif

View File

@ -88,4 +88,8 @@ ifeq ($(CONFIG_KERNEL_TEST_RISC_CAN),y)
SRC_FILES += riscv_test_can.c SRC_FILES += riscv_test_can.c
endif endif
ifeq ($(CONFIG_KERNEL_TEST_SPI_FLASH),y)
SRC_FILES += test_spi_flash.c
endif
include $(KERNEL_ROOT)/compiler.mk include $(KERNEL_ROOT)/compiler.mk