修改通讯串口逻辑,添加810,811,812指令
This commit is contained in:
1 parent
64d820b24c
commit
155358f5d0
42 files changed
+17864
-579
No files matched your search
+149
-58
@@ -23,6 +23,9 @@ rt_mq_t proc_mq;
|
||||
|
||||
char cjson_falg=0;//是否解析cjson
|
||||
char *json_buffer=NULL;
|
||||
|
||||
//
|
||||
|
||||
/**
|
||||
* 截取两个指定子串之间的内容
|
||||
* @param src 源字符串
|
||||
@@ -117,58 +120,63 @@ void pasre_DAT(const char *api, const char *json_str)
|
||||
}
|
||||
else if (strcmp(api, "SC810") == 0)
|
||||
{
|
||||
char STime[25];
|
||||
char pTime[10];
|
||||
char Work_[25];
|
||||
char Dye_[25];
|
||||
char STime_[25];
|
||||
char pTime_[10];
|
||||
// 字符串赋值
|
||||
GET_STRING(Work, root, "Work", sizeof(Work));
|
||||
GET_STRING(Dye, root, "Dye", sizeof(Dye));
|
||||
GET_STRING(STime, root, "STime", sizeof(STime));
|
||||
GET_STRING(pTime, root, "Time", sizeof(pTime));
|
||||
GET_STRING(Work_, root, "Work", sizeof(Work_));
|
||||
GET_STRING(Dye_, root, "Dye", sizeof(Dye_));
|
||||
GET_STRING(STime_, root, "STime", sizeof(STime_));
|
||||
GET_STRING(pTime_, root, "Time", sizeof(pTime_));
|
||||
|
||||
// 定义足够大的缓冲区
|
||||
char sql[512] = {0}; // 初始化为 0
|
||||
// 安全格式化
|
||||
rt_snprintf(sql, sizeof(sql),
|
||||
"INSERT INTO WorkorderSteps(WorkOrder,DYELOT,ReDye,StartTime,Time)"
|
||||
"VALUES('%s','%s',0,%s,%s,)",
|
||||
Work, Dye, STime,pTime);
|
||||
"INSERT INTO WorkOrder(WorkOrder,DYELOT,ReDye,StartTime,Time)"
|
||||
"VALUES('%s','%s',0,'%s','%s')",
|
||||
Work_, Dye_, STime_,pTime_);
|
||||
if( db_send_command(DB_CMD_EXEC, sql, 500)==RT_EOK) //
|
||||
{
|
||||
cJSON_AddItemToObject(dat,"Work",cJSON_CreateString(Work));
|
||||
cJSON_AddItemToObject(dat,"ReDye",cJSON_CreateNumber(Redye));
|
||||
cJSON_AddItemToObject(dat,"Work",cJSON_CreateString(Work_));
|
||||
cJSON_AddItemToObject(dat,"ReDye",cJSON_CreateNumber(0));
|
||||
}
|
||||
}
|
||||
else if (strcmp(api, "SC811") == 0)
|
||||
{//工单明细
|
||||
char Work_[25];
|
||||
char Dye_[25];
|
||||
char StepID_[4];
|
||||
char SIDS1_[4];
|
||||
int StepN_;
|
||||
int P1_;
|
||||
int P2_;
|
||||
int P3_;
|
||||
int P4_;
|
||||
int P5_;
|
||||
int P1S1_;
|
||||
int P2S1_;
|
||||
int P3S1_;
|
||||
int P4S1_;
|
||||
int P5S1_;
|
||||
// 字符串赋值
|
||||
GET_STRING(Work, root, "Work", sizeof(Work));
|
||||
GET_STRING(Dye, root, "Dye", sizeof(Dye));
|
||||
GET_STRING(StepID, root, "StepID", sizeof(StepID));
|
||||
GET_STRING(SIDS1, root, "SIDS1", sizeof(SIDS1));
|
||||
//GET_STRING(SIDS2, root, "SIDS2", sizeof(SIDS2));
|
||||
//GET_STRING(SIDS3, root, "SIDS3", sizeof(SIDS3));
|
||||
GET_STRING(Work_, root, "Work", sizeof(Work_));
|
||||
GET_STRING(Dye_, root, "Dye", sizeof(Dye_));
|
||||
GET_STRING(StepID_, root, "StepID", sizeof(StepID_));
|
||||
GET_STRING(SIDS1_, root, "SIDS1", sizeof(SIDS1_));
|
||||
//整数
|
||||
GET_INT_FROM_ANY(StepN, root, "Step", 0);
|
||||
GET_INT_FROM_ANY(P1, root, "P1", 0);
|
||||
GET_INT_FROM_ANY(P2, root, "P2", 0);
|
||||
GET_INT_FROM_ANY(P3, root, "P3", 0);
|
||||
GET_INT_FROM_ANY(P4, root, "P4", 0);
|
||||
GET_INT_FROM_ANY(P5, root, "P5", 0);
|
||||
GET_INT_FROM_ANY(P1S1, root, "P1S1",0);
|
||||
GET_INT_FROM_ANY(P2S1, root, "P2S1",0);
|
||||
GET_INT_FROM_ANY(P3S1, root, "P3S1",0);
|
||||
GET_INT_FROM_ANY(P4S1, root, "P4S1",0);
|
||||
GET_INT_FROM_ANY(P5S1, root, "P5S1",0);
|
||||
//GET_INT_FROM_ANY(P1S2, root, "P1S2",0);
|
||||
//GET_INT_FROM_ANY(P2S2, root, "P2S2",0);
|
||||
//GET_INT_FROM_ANY(P3S2, root, "P3S2",0);
|
||||
//GET_INT_FROM_ANY(P4S2, root, "P4S2",0);
|
||||
//GET_INT_FROM_ANY(P5S2, root, "P5S2",0);
|
||||
//GET_INT_FROM_ANY(P1S3, root, "P1S3",0);
|
||||
//GET_INT_FROM_ANY(P2S3, root, "P2S3",0);
|
||||
//GET_INT_FROM_ANY(P3S3, root, "P3S3",0);
|
||||
//GET_INT_FROM_ANY(P4S3, root, "P4S3",0);
|
||||
//GET_INT_FROM_ANY(P5S3, root, "P5S3",0);
|
||||
GET_INT_FROM_ANY(StepN_, root, "Step", 0);
|
||||
GET_INT_FROM_ANY(P1_, root, "P1", 0);
|
||||
GET_INT_FROM_ANY(P2_, root, "P2", 0);
|
||||
GET_INT_FROM_ANY(P3_, root, "P3", 0);
|
||||
GET_INT_FROM_ANY(P4_, root, "P4", 0);
|
||||
GET_INT_FROM_ANY(P5_, root, "P5", 0);
|
||||
GET_INT_FROM_ANY(P1S1_, root, "P1S1",0);
|
||||
GET_INT_FROM_ANY(P2S1_, root, "P2S1",0);
|
||||
GET_INT_FROM_ANY(P3S1_, root, "P3S1",0);
|
||||
GET_INT_FROM_ANY(P4S1_, root, "P4S1",0);
|
||||
GET_INT_FROM_ANY(P5S1_, root, "P5S1",0);
|
||||
|
||||
// 定义足够大的缓冲区
|
||||
char sql[512] = {0}; // 初始化为 0
|
||||
@@ -176,41 +184,124 @@ void pasre_DAT(const char *api, const char *json_str)
|
||||
// 安全格式化
|
||||
rt_snprintf(sql, sizeof(sql),
|
||||
"INSERT INTO WorkorderSteps(WorkOrder,DYELOT,ReDye,Step,StepID,P1,P2,P3,P4,P5,StepID_S1,P1_S1,P2_S1,P3_S1,P4_S1,P5_S1)"
|
||||
"VALUES('%s','%s',0,%d,%s,%d,%d,%d,%d,%d,'%s',%d,%d,%d,%d,%d)",
|
||||
Work, Dye, StepN,StepID,P1, P2, P3, P4, P5,SIDS1,P1S1,P2S1,P3S1,P4S1,P5S1 );
|
||||
"VALUES('%s','%s',0,%d,'%s',%d,%d,%d,%d,%d,'%s',%d,%d,%d,%d,%d)",
|
||||
Work_, Dye_, StepN_,StepID_,P1_, P2_, P3_, P4_, P5_,SIDS1_,P1S1_,P2S1_,P3S1_,P4S1_,P5S1_ );
|
||||
if( db_send_command(DB_CMD_EXEC, sql, 500)==RT_EOK) //
|
||||
{
|
||||
cJSON_AddItemToObject(dat,"Work",cJSON_CreateString(Work));
|
||||
cJSON_AddItemToObject(dat,"ReDye",cJSON_CreateNumber(Redye));
|
||||
cJSON_AddItemToObject(dat,"Step",cJSON_CreateNumber(StepN));
|
||||
cJSON_AddItemToObject(dat,"Work",cJSON_CreateString(Work_));
|
||||
cJSON_AddItemToObject(dat,"ReDye",cJSON_CreateNumber(0));
|
||||
cJSON_AddItemToObject(dat,"Step",cJSON_CreateNumber(StepN_));
|
||||
}
|
||||
}
|
||||
else if (strcmp(api, "SC812") == 0) {
|
||||
//工单设定
|
||||
else if (strcmp(api, "SC812") == 0)
|
||||
{//工单设定
|
||||
char Work_[25];
|
||||
int Pump_;
|
||||
int Blower_;
|
||||
int ClothWheel_;
|
||||
int Swing_;
|
||||
int Nozzle_;
|
||||
// 字符串赋值
|
||||
GET_STRING(Work_, root, "WorkOrder", sizeof(Work_));
|
||||
//整数
|
||||
GET_INT_FROM_ANY(Pump_, root, "PumpSpeed", 0);
|
||||
GET_INT_FROM_ANY(Blower_, root, "Blower", 0);
|
||||
GET_INT_FROM_ANY(ClothWheel_, root, "ClothWheel", 0);
|
||||
GET_INT_FROM_ANY(Swing_, root, "Swing", 0);
|
||||
GET_INT_FROM_ANY(Nozzle_, root, "Nozzle", 0);
|
||||
|
||||
// 定义足够大的缓冲区
|
||||
char sql[512] = {0}; // 初始化为 0
|
||||
// 安全格式化
|
||||
rt_snprintf(sql, sizeof(sql),
|
||||
"INSERT OR IGNORE INTO WorkOrderSet(WorkOrder,ReDye,PumpSpeed,Blower,ClothWheel,Swing,Nozzle)"
|
||||
"VALUES('%s',0,%d,%d,%d,%d,%d)",
|
||||
Work_, Pump_,Blower_,ClothWheel_, Swing_, Nozzle_);
|
||||
if( db_send_command(DB_CMD_EXEC, sql, 500)==RT_EOK) //
|
||||
{
|
||||
cJSON_AddItemToObject(dat,"Work",cJSON_CreateString(Work_));
|
||||
cJSON_AddItemToObject(dat,"ReDye",cJSON_CreateNumber(0));
|
||||
}
|
||||
}
|
||||
else if (strcmp(api, "SC813") == 0) {
|
||||
printf("Processing:SC813\n");
|
||||
else if (strcmp(api, "SC813") == 0)
|
||||
{//领料单插入
|
||||
char Work_[25];
|
||||
char Dye_[25];
|
||||
char ProductCode_[15];
|
||||
char ProductName_[15];
|
||||
char Grams_[8];
|
||||
int ProductType_;
|
||||
int StepN_;
|
||||
//字符
|
||||
GET_STRING(Work_, root, "Work", sizeof(Work_));
|
||||
GET_STRING(Dye_, root, "Dye", sizeof(Dye_));
|
||||
GET_STRING(ProductName_, root, "ProductName", sizeof(ProductName_));
|
||||
GET_STRING(ProductCode_, root, "ProductCode", sizeof(ProductCode_));
|
||||
GET_STRING(Grams_, root, "Grams", sizeof(Grams_));
|
||||
//整数
|
||||
GET_INT_FROM_ANY(StepN_, root, "Step", 0);
|
||||
GET_INT_FROM_ANY(ProductType_, root, "ProductType", 0);
|
||||
|
||||
// 定义足够大的缓冲区
|
||||
char sql[512] = {0}; // 初始化为 0
|
||||
// 安全格式化
|
||||
rt_snprintf(sql, sizeof(sql),
|
||||
"INSERT OR IGNORE INTO Dyelot(WorkOrder,Dyelot,ReDye,Step,ProductCode,ProductName,ProductType,Grams)"
|
||||
"VALUES('%s','%s',0,%d,%s,%s,%d,%s)",
|
||||
Work_, Dye_,StepN_,ProductCode_,ProductName_ ,ProductType_,Grams_);
|
||||
if( db_send_command(DB_CMD_EXEC, sql, 500)==RT_EOK) //
|
||||
{
|
||||
cJSON_AddItemToObject(dat,"Work",cJSON_CreateString(Work_));
|
||||
cJSON_AddItemToObject(dat,"Dye",cJSON_CreateString(Dye_));
|
||||
cJSON_AddItemToObject(dat,"ReDye",cJSON_CreateNumber(0));
|
||||
cJSON_AddItemToObject(dat,"Step",cJSON_CreateNumber(StepN_));
|
||||
}
|
||||
}
|
||||
else if (strcmp(api, "SC820") == 0) {
|
||||
printf("Processing:SC820\n");
|
||||
else if (strcmp(api, "SC820") == 0)
|
||||
{//设置系统时间
|
||||
char Time_[25];
|
||||
|
||||
GET_STRING(Time_, root, "Work", sizeof(Time_));
|
||||
|
||||
cJSON_AddItemToObject(dat,"time",cJSON_CreateString("systime"));
|
||||
}
|
||||
else if (strcmp(api, "SC821") == 0) {
|
||||
else if (strcmp(api, "SC821") == 0)
|
||||
{
|
||||
printf("Processing:SC821\n");
|
||||
}
|
||||
else if (strcmp(api, "SC822") == 0) {
|
||||
else if (strcmp(api, "SC822") == 0)
|
||||
{
|
||||
printf("Processing:SC822\n");
|
||||
}
|
||||
else if (strcmp(api, "SC827") == 0) {
|
||||
else if (strcmp(api, "SC827") == 0)
|
||||
{
|
||||
printf("Processing:SC827\n");
|
||||
}
|
||||
else if (strcmp(api, "SC828") == 0) {
|
||||
else if (strcmp(api, "SC828") == 0)
|
||||
{
|
||||
printf("Processing:SC828\n");
|
||||
}
|
||||
else if (strcmp(api, "SC829") == 0) {
|
||||
printf("Processing:SC829\n");
|
||||
else if (strcmp(api, "SC829") == 0)
|
||||
{//锁定自动
|
||||
char NAME_[4];
|
||||
char VALUE_[4];
|
||||
GET_STRING(NAME_, root, "NAME", sizeof(NAME_));
|
||||
GET_STRING(VALUE_, root, "VALUE", sizeof(VALUE_));
|
||||
|
||||
if (strcmp(NAME_, "LOCK") == 0) {
|
||||
if (strcmp(VALUE_, "True") == 0)
|
||||
{MACHINE_LOCK=1;}else{MACHINE_LOCK=0;}
|
||||
}
|
||||
if (strcmp(NAME_, "AUTO") == 0) {
|
||||
if (strcmp(VALUE_, "True") == 0)
|
||||
{MACHINE_AUTO=1;}else{MACHINE_AUTO=0;}
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(dat,"NAME",cJSON_CreateString(NAME_));
|
||||
cJSON_AddItemToObject(dat,"VALUE",cJSON_CreateString(VALUE_));
|
||||
}
|
||||
else if (strcmp(api, "SC830") == 0) {
|
||||
//当前信息
|
||||
else if (strcmp(api, "SC830") == 0)
|
||||
{//当前信息
|
||||
cJSON_AddItemToObject(dat,"ERR",cJSON_CreateBool(MACHINE_ERR));
|
||||
cJSON_AddItemToObject(dat,"LOCK",cJSON_CreateBool(MACHINE_LOCK));
|
||||
cJSON_AddItemToObject(dat,"Status",cJSON_CreateString(Message));
|
||||
@@ -382,7 +473,7 @@ int data_comm_init(void)
|
||||
}
|
||||
|
||||
rt_thread_t tid = rt_thread_create("data_comm", proc_thread_entry, RT_NULL,
|
||||
1024*4, 20, 10);
|
||||
1024*6, 20, 10);
|
||||
if (tid != RT_NULL)
|
||||
{
|
||||
rt_thread_startup(tid);
|
||||
|
||||
@@ -133,15 +133,42 @@ static rt_err_t uart_rx_ind(rt_device_t dev, rt_size_t size)
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
// 从环形缓冲区提取一行
|
||||
// 从环形缓冲区提取一行rt_kprintf("%s\n",buf);
|
||||
static int get_line(char *buf, int maxlen)
|
||||
{
|
||||
int len = rt_ringbuffer_get(&rx_rb, (rt_uint8_t*)buf, maxlen - 1);
|
||||
if (len > 0) {
|
||||
buf[len] = '\0';
|
||||
return len;
|
||||
}
|
||||
return 0;
|
||||
int len = 0;
|
||||
rt_uint8_t ch;
|
||||
|
||||
// 逐字节读取,直到遇到 '\n' 或缓冲区满
|
||||
while (len < maxlen - 1)
|
||||
{
|
||||
// 从环形缓冲区读一个字节
|
||||
if (rt_ringbuffer_getchar(&rx_rb, &ch) == 0)
|
||||
{
|
||||
// 缓冲区为空,无数据可读
|
||||
break;
|
||||
}
|
||||
|
||||
buf[len++] = ch;
|
||||
|
||||
// 检查是否为行结束符
|
||||
if (ch == '\n')
|
||||
{
|
||||
buf[len] = '\0'; // 添加字符串结束符
|
||||
return len; // 返回完整行长度
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有遇到 '\n',说明不是完整的一行
|
||||
// 我们可以选择:把已读的数据放回 ringbuffer,或丢弃(推荐放回)
|
||||
// 这里选择:把所有读取的字符重新放回 ringbuffer
|
||||
if (len > 0)
|
||||
{
|
||||
// 将已读取但未构成完整行的数据放回 ringbuffer 开头
|
||||
rt_ringbuffer_put(&(rx_rb), (rt_uint8_t*)buf, len);
|
||||
}
|
||||
|
||||
return 0; // 未收到完整行,返回 0
|
||||
}
|
||||
|
||||
// 启动 UART 线程
|
||||
|
||||
@@ -13,6 +13,7 @@ char machine_ID[3] = "23";
|
||||
// 状态标志
|
||||
char MACHINE_ERR = 0;
|
||||
char MACHINE_LOCK = 0;
|
||||
char MACHINE_AUTO = 0;
|
||||
char MACHINE_CALL = 0;
|
||||
char MACHINE_USER = 0;
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ extern char machine_ID[3];
|
||||
// ===== 布尔变量 =====
|
||||
extern char MACHINE_ERR;
|
||||
extern char MACHINE_LOCK;
|
||||
extern char MACHINE_AUTO;
|
||||
extern char MACHINE_CALL;
|
||||
extern char MACHINE_USER;
|
||||
|
||||
|
||||
Reference in new issue
Block a user