Merge branch 'prepare_for_master' of https://gitlink.org.cn/xuos/xiuos into lorawan_develop

This commit is contained in:
Liu_Weichao
2023-04-14 14:05:31 +08:00
209 changed files with 564233 additions and 652 deletions
@@ -112,15 +112,20 @@ static int ModbusUartGetDataBySerial(ModbusUartReadItem *p_read_item)
ModbusUartDataInfo *p_modbus_uart_data_info = &(p_read_item->data_info);
BasicPlcDataInfo *p_base_data_info = &(p_modbus_uart_data_info->base_data_info);
ModbusUartFunctionCode function_code = p_modbus_uart_data_info->function_code;
ModbusUartFunctionCode function_code = p_modbus_uart_data_info->function_code;
uint16_t quantity = p_read_item->quantity;//++
ControlPrintfList("SEND", p_base_data_info->p_command, p_base_data_info->command_length);
SerialWrite(p_base_data_info->p_command, p_base_data_info->command_length);
if (READ_COIL_STATUS == function_code || READ_INPUT_STATUS == function_code) {
cmd_length = 6;
} else if (READ_HOLDING_REGISTER == function_code || READ_INPUT_REGISTER == function_code) {
} else if ((READ_HOLDING_REGISTER == function_code || READ_INPUT_REGISTER == function_code) && quantity == 1 ) {
cmd_length = 7;
} else if ((READ_HOLDING_REGISTER == function_code || READ_INPUT_REGISTER == function_code) && quantity == 2 ) {
cmd_length = 9;
} else if ((READ_HOLDING_REGISTER == function_code || READ_INPUT_REGISTER == function_code) && quantity == 4 ) {
cmd_length = 13;
} else if (WRITE_SINGLE_COIL == function_code || WRITE_SINGLE_REGISTER == function_code) {
cmd_length = 8;
} else {
@@ -369,7 +374,7 @@ static struct ControlDone modbusuart_protocol_done =
};
/**
* @description: Modbus TCP Protocol Cmd Generate
* @description: Modbus Uart Protocol Cmd Generate
* @param p_recipe - recipe pointer
* @param protocol_format_info - protocol format info pointer
* @return success : 0 error : -1
@@ -402,7 +407,7 @@ int ModbusUartProtocolFormatCmd(struct ControlRecipe *p_recipe, ProtocolFormatIn
}
/**
* @description: Modbus TCP Protocol Init
* @description: Modbus Uart Protocol Init
* @param p_recipe - recipe pointer
* @return success : 0 error : -1
*/
@@ -270,7 +270,7 @@ static uint16_t Melsec3eqlGenerateCommand(uint8_t *p_command, uint32_t command_c
uint16_t head_device_number = 0;
for (uint8_t i = 0; i < 6; i++) {
if (0 != p_read_item->head_device_number_string[i])
head_device_number = TransformAsciiToHex(p_read_item->head_device_number_string[i]) + head_device_number * (((0x9c == (uint8_t)p_read_item->device_code) || (0x9d == (uint8_t)p_read_item->device_code)) ? 16 : 10);
head_device_number = TransformAsciiToHex(p_read_item->head_device_number_string[i]) + head_device_number * (((0x9c == (uint8_t)p_read_item->device_code) || (0x9d == (uint8_t)p_read_item->device_code) || (0xa0 == (uint8_t)p_read_item->device_code) || (0xb4 == (uint8_t)p_read_item->device_code)) ? 16 : 10);
else
break;
}
@@ -297,7 +297,7 @@ static uint16_t Melsec3eiqrGenerateCommand(uint8_t *p_command, uint32_t command_
uint16_t head_device_number = 0;
for (uint8_t i = 0; i < 6; i++) {
if (0 != p_read_item->head_device_number_string[i])
head_device_number = TransformAsciiToHex(p_read_item->head_device_number_string[i]) + head_device_number * (((0x9c == (uint8_t)p_read_item->device_code) || (0x9d == (uint8_t)p_read_item->device_code)) ? 16 : 10);
head_device_number = TransformAsciiToHex(p_read_item->head_device_number_string[i]) + head_device_number * (((0x9c == (uint8_t)p_read_item->device_code) || (0x9d == (uint8_t)p_read_item->device_code)|| (0xa0 == (uint8_t)p_read_item->device_code)|| (0xb4 == (uint8_t)p_read_item->device_code)) ? 16 : 10);
else
break;
}
@@ -567,7 +567,7 @@ static int MelsecTransformRecvBuffToData(MelsecReadItem *p_read_item, uint8_t *r
p_data[2 * i] = TransformAsciiToHex(recv_buff[recv_buff_index]) * 16 + TransformAsciiToHex(recv_buff[recv_buff_index + 1]);
p_data[2 * i + 1] = TransformAsciiToHex(recv_buff[recv_buff_index + 2]) * 16 + TransformAsciiToHex(recv_buff[recv_buff_index + 3]);
}
printf("0x%x 0x%x", p_data[2 * i], p_data[2 * i + 1]);
printf("0x%x 0x%x ", p_data[2 * i], p_data[2 * i + 1]);
}
}
printf("\n");
@@ -629,16 +629,51 @@ static int MelsecGetDataBySocket(int32_t socket, MelsecReadItem *p_read_item)
*/
static int MelsecGetDataBySerial(MelsecReadItem *p_read_item)
{
uint32_t read_length = 0;
uint32_t cmd_length,read_length = 0;
memset(recv_buff, 0, sizeof(recv_buff));
MelsecDataInfo *p_melsec_data_info = &(p_read_item->data_info);
BasicPlcDataInfo *p_base_data_info = &(p_melsec_data_info->base_data_info);
BasicPlcDataInfo *p_base_data_info = &(p_melsec_data_info->base_data_info);
MelsecCommandType melsec_command_type = p_melsec_data_info->command_type;//++
MelsecFrameType melsec_frame_type= p_melsec_data_info->frame_type;//++
uint16_t device_points_count = p_read_item->device_points_count;//++
ControlPrintfList("SEND", p_base_data_info->p_command, p_base_data_info->command_length);
SerialWrite(p_base_data_info->p_command, p_base_data_info->command_length);
//++
if (MELSEC_1C_FRAME == melsec_frame_type) {
if (READ_IN_BITS == melsec_command_type ) {
cmd_length = 9;
} else if (READ_IN_WORD == melsec_command_type && device_points_count==1 ) {
cmd_length = 12;
} else if (READ_IN_WORD == melsec_command_type && device_points_count==2 ) {
cmd_length = 16;
} else if (READ_IN_WORD == melsec_command_type && device_points_count==4 ) {
cmd_length = 24;
} else {
//MULTIPLE_COIL and MULTIPLE_REGISTER to do
cmd_length = 0;
}
}else if(MELSEC_3C_FRAME == melsec_frame_type){
if (READ_IN_BITS == melsec_command_type ) {
cmd_length = 15;
} else if (READ_IN_WORD == melsec_command_type && device_points_count==1 ) {
cmd_length = 18;
} else if (READ_IN_WORD == melsec_command_type && device_points_count==2 ) {
cmd_length = 22;
} else if (READ_IN_WORD == melsec_command_type && device_points_count==4 ) {
cmd_length = 30;
} else {
//MULTIPLE_COIL and MULTIPLE_REGISTER to do
cmd_length = 0;
}
read_length = SerialRead(recv_buff, sizeof(recv_buff));
}
//++
read_length = SerialRead(recv_buff, cmd_length);
if (read_length) {
ControlPrintfList("RECV", recv_buff, read_length);
return MelsecTransformRecvBuffToData(p_read_item, recv_buff);
@@ -363,6 +363,8 @@ typedef struct
#define IOCTRL_CAMERA_SET_EFFECT (28) //set effect
#define IOCTRL_CAMERA_SET_EXPOSURE (29) //set auto exposure
/*********************shell***********************/
#ifndef SEPARATE_COMPILE
//for int func(int argc, char *agrv[])
#define PRIV_SHELL_CMD_MAIN_ATTR (SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN))
@@ -379,6 +381,15 @@ typedef struct
#define PRIV_SHELL_CMD_FUNCTION(_func, _desc, _attr) \
SHELL_EXPORT_CMD(_attr, _func, _func, _desc)
#else
//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()
#define PRIV_SHELL_CMD_FUNCTION(_func, _desc, _attr)
#endif
/**********************mutex**************************/
int PrivMutexCreate(pthread_mutex_t *p_mutex, const pthread_mutexattr_t *attr);
@@ -32,33 +32,33 @@ extern "C" {
typedef int pid_t;
typedef unsigned long int pthread_t;
struct sched_param {
int sched_priority; /* process execution scheduling priority */
size_t slice; /* time slice in SCHED_RR mode (ms) */
};
typedef struct pthread_attr {
unsigned char is_initialized; /* if the attr is initialized set to 1, otherwise set to 0 */
void *stackaddr; /* the start addr of the stack of the pthead */
size_t stacksize; /* the size of the stack of the pthead */
unsigned char contentionscope; /* the scope of contention, only PTHREAD_SCOPE_SYSTEM is supported */
unsigned char inheritsched; /* when set to PTHREAD_INHERIT_SCHED, specifies that the thread scheduling attributes
shall be inherited from the creating thread, and the scheduling attributes in this
attr argument shall be ignored */
unsigned char schedpolicy; /* the sched policy of the thread */
struct sched_param schedparam; /* the parameter of the thread scheduling */
size_t guardsize; /* guardsize is set to protect the stack, not supported */
unsigned char detachstate; /* when set to PTHREAD_CREATE_JOINABLE, thread will not end untill the creating thread end */
} pthread_attr_t;
// struct sched_param {
// int sched_priority; /* process execution scheduling priority */
// size_t slice; /* time slice in SCHED_RR mode (ms) */
// };
// typedef struct pthread_attr {
// unsigned char is_initialized; /* if the attr is initialized set to 1, otherwise set to 0 */
// void *stackaddr; /* the start addr of the stack of the pthead */
// size_t stacksize; /* the size of the stack of the pthead */
// unsigned char contentionscope; /* the scope of contention, only PTHREAD_SCOPE_SYSTEM is supported */
// unsigned char inheritsched; /* when set to PTHREAD_INHERIT_SCHED, specifies that the thread scheduling attributes
// shall be inherited from the creating thread, and the scheduling attributes in this
// attr argument shall be ignored */
// unsigned char schedpolicy; /* the sched policy of the thread */
// struct sched_param schedparam; /* the parameter of the thread scheduling */
// size_t guardsize; /* guardsize is set to protect the stack, not supported */
// unsigned char detachstate; /* when set to PTHREAD_CREATE_JOINABLE, thread will not end untill the creating thread end */
// } pthread_attr_t;
typedef struct pthread_mutexattr {
int is_initialized;
int type;
int protocol;
int prioceiling;
int pshared;
} pthread_mutexattr_t;
// typedef struct pthread_mutexattr {
// int is_initialized;
// int type;
// int protocol;
// int prioceiling;
// int pshared;
// } pthread_mutexattr_t;
typedef int pthread_mutex_t ;
// typedef int pthread_mutex_t ;
#ifdef __cplusplus
}
@@ -60,6 +60,16 @@ extern "C" {
// PTHREAD_SCOPE_SYSTEM,
// };
// #define NULL_PARAM_CHECK(param) \
// do \
// { \
// if(param == NULL) { \
// printf("PARAM CHECK FAILED ...%s %d %s is NULL.\n", __func__, __LINE__, #param); \
// while(1); \
// } \
// }while (0)
typedef int pid_t;
// typedef int pthread_mutex_t ;
@@ -67,8 +67,8 @@ int pthread_attr_init(pthread_attr_t *attr)
int pthread_attr_setschedparam(pthread_attr_t *attr,
struct sched_param const *param)
{
NULL_PARAM_CHECK(attr != NULL);
NULL_PARAM_CHECK(param != NULL);
// NULL_PARAM_CHECK(attr);
// NULL_PARAM_CHECK(param);
attr->schedparam.sched_priority = param->sched_priority;
@@ -30,7 +30,7 @@
#ifdef SEPARATE_COMPILE
#include "../../../../../../Ubiquitous/XiZi/arch/kswitch.h"
#include "../../../../../../Ubiquitous/XiZi_IIoT/arch/kswitch.h"
#define TASK_INFO 1
#define MEM_INFO 2