WLG/uart/uart_cmd.cpp

200 lines
5.9 KiB
C++
Raw Normal View History

2024-10-22 19:04:25 +08:00
#include "uart.hpp"
2024-10-23 19:51:01 +08:00
#include <zlog.h>
2024-10-22 19:04:25 +08:00
void Uart::UpdateZigbeeInfoCtrl() {
char command[5] = {0xab, 0xbc, 0xcd, 0xd1, 0xaa};
WriteToUart(command, 5);
2024-10-23 19:51:01 +08:00
zlog_info(zct,"UpdateZigbeeInfoCtrl ");
2024-10-22 19:04:25 +08:00
}
void Uart::modify_distaddr_info(unsigned short id, char *zigbee, unsigned char *distAddr) {
char command[6] = {0xDE, 0xDF, 0xEF, 0xDC, ((char *)&id)[1], ((char *)&id)[0]};
WriteToUart(command, 6);
mssleep(10000);
char command1[6] = {0xDE, 0xDF, 0xEF, 0xD2, distAddr[0], distAddr[1]};
WriteToUart(command1, 6);
}
void Uart::getZigbeeSignal(unsigned char *distAddr) {
mssleep(10000);
char command[6] = {0x00};
command[0] = 0xDE;
command[1] = 0xDF;
command[2] = 0xEF;
command[3] = 0xDA;
command[4] = distAddr[0];
command[5] = distAddr[1];
WriteToUart(command, 6);
}
void Uart::modify_DistAddr(unsigned char *distAddr) {
char command[6] = {0x00};
memset(command, 0x00, sizeof(command));
command[0] = 0xDE;
command[1] = 0xDF;
command[2] = 0xEF;
command[3] = 0xD2;
command[4] = distAddr[0];
command[5] = distAddr[1];
WriteToUart(command, 6);
}
void Uart::modify_LocalAddr(unsigned short id) {
char command[6] = {0x00};
command[0] = 0xDE;
command[1] = 0xDF;
command[2] = 0xEF;
command[3] = 0xDC;
command[4] = ((char *)&id)[1];
command[5] = ((char *)&id)[0];
WriteToUart(command, 6);
}
void Uart::modify_Localchannel(unsigned char pad) {
char command[6] = {0x00};
command[0] = 0xDE;
command[1] = 0xDF;
command[2] = 0xEF;
command[3] = 0xD1;
command[4] = pad & 0xff;
WriteToUart(command, 5);
}
void Uart::modify_LocalPanID(unsigned short padID) {
char command[6] = {0x00};
command[0] = 0xDE;
command[1] = 0xDF;
command[2] = 0xEF;
command[3] = 0xDB;
command[4] = ((char *)&padID)[1];
command[5] = ((char *)&padID)[0];
WriteToUart(command, 6);
}
void Uart::modify_info(unsigned short id, char *zigbee) {
int i, j, ret, con;
char command[100];
char command1[20];
char tmp = 0;
command[0] = 0xab;
command[1] = 0xbc;
command[2] = 0xcd;
command[3] = 0xd6;
command[4] = ((char *)&id)[0];
command[5] = ((char *)&id)[1];
command[6] = 0;
if (zigbee != NULL) {
con = 71;
memcpy(&(command[6]), zigbee + 4, 65);
} else {
con = 6;
}
for (i = 0; i < con; i++) {
tmp += command[i];
}
command[i] = 0xaa;
WriteToUart(command, i + 1);
sleep(1);
}
void Uart::zigbee_reset(unsigned short pad, unsigned short type) {
char command[10], tmp = 0, i;
command[0] = 0xab;
command[1] = 0xbc;
command[2] = 0xcd;
command[3] = 0xd9;
command[4] = ((char *)&pad)[1];
command[5] = ((char *)&pad)[0];
command[6] = ((char *)&type)[1];
command[7] = ((char *)&type)[0];
for (i = 0; i < 8; i++) {
tmp += command[i];
}
command[8] = tmp;
WriteToUart(command, 9);
}
void Uart::WriteChanl2Zigbee(unsigned char pad) {
2024-10-23 19:51:01 +08:00
zlog_info(zct,"WriteChanl2Zigbee : %d\n", pad);
2024-10-22 19:04:25 +08:00
unsigned char pad1 = pad;
unsigned short tmp;
tmp = GlobalConfig::Zigbee_G.MyAddr;
GlobalConfig::Zigbee_G.Chan = pad1;
modify_info(tmp, (char *)&GlobalConfig::Zigbee_G);
gpio_set(GlobalConfig::GPIO_G.zigReset, 0);
mssleep(10000);
gpio_set(GlobalConfig::GPIO_G.zigReset, 1);
}
void Uart::WritePanId2Zigbee(unsigned short pad) {
2024-10-23 19:51:01 +08:00
zlog_info(zct,"WritePanId2Zigbee : %d", pad);
2024-10-22 19:04:25 +08:00
unsigned short pad1 = pad, tmp;
tmp = GlobalConfig::Zigbee_G.MyAddr;
2024-10-23 19:51:01 +08:00
zlog_info(zct,"MyAddr : %d", GlobalConfig::Zigbee_G.MyAddr);
2024-10-22 19:04:25 +08:00
swap((char *)&pad1);
GlobalConfig::Zigbee_G.PanID = pad1;
modify_info(tmp, (char *)&GlobalConfig::Zigbee_G);
gpio_set(GlobalConfig::GPIO_G.zigReset, 0);
mssleep(10000);
gpio_set(GlobalConfig::GPIO_G.zigReset, 1);
}
void Uart::WriteSpeed2Zigbee() {
GlobalConfig::Zigbee_G.Serial_Rate = 0x07;
GlobalConfig::Zigbee_G.Serial_DataB = 0x08;
GlobalConfig::Zigbee_G.Serial_StopB = 0x01;
unsigned short tmp;
tmp = GlobalConfig::Zigbee_G.MyAddr;
modify_info(tmp, (char *)&GlobalConfig::Zigbee_G);
gpio_set(GlobalConfig::GPIO_G.zigReset, 0);
mssleep(10000);
gpio_set(GlobalConfig::GPIO_G.zigReset, 1);
}
void Uart::WriteTranTimeout2Zigbee(unsigned char Time) {
2024-10-23 19:51:01 +08:00
zlog_info(zct,"WriteTranTimeout2Zigbee : %d", Time);
2024-10-22 19:04:25 +08:00
unsigned short tmp = GlobalConfig::Zigbee_G.MyAddr;
GlobalConfig::Zigbee_G.PowerLevel = 0x03;
GlobalConfig::Zigbee_G.RetryNum = 0x64;
GlobalConfig::Zigbee_G.TranTimeout = Time;
modify_info(tmp, (char *)&GlobalConfig::Zigbee_G);
gpio_set(GlobalConfig::GPIO_G.zigReset, 0);
mssleep(10000);
gpio_set(GlobalConfig::GPIO_G.zigReset, 1);
}
void Uart::WriteShortAddr2Zigbee(unsigned short pad) {
2024-10-23 19:51:01 +08:00
zlog_info(zct,"WriteShortAddr2Zigbee : %4x", (unsigned short)pad);
2024-10-22 19:04:25 +08:00
unsigned short pad1 = pad, tmp;
tmp = GlobalConfig::Zigbee_G.MyAddr;
GlobalConfig::Zigbee_G.MyAddr = pad1;
modify_info(tmp, (char *)&GlobalConfig::Zigbee_G);
gpio_set(GlobalConfig::GPIO_G.zigReset, 0);
mssleep(10000);
gpio_set(GlobalConfig::GPIO_G.zigReset, 1);
sleep(1);
}
void Uart::WriteShortAddr_DistAddr2Zigbee(unsigned short pad, unsigned char *pDestShortAddr) {
2024-10-23 19:51:01 +08:00
zlog_info(zct,"WriteShortAddr2Zigbee : %4x\n", (unsigned short)pad);
2024-10-22 19:04:25 +08:00
unsigned short pad1 = pad, tmp;
tmp = GlobalConfig::Zigbee_G.MyAddr;
swap((char *)&pad1);
swap((char *)&tmp);
char tmpDest[8] = {0x00};
sprintf(tmpDest, "%02x%02x", pDestShortAddr[0], pDestShortAddr[1]);
memcpy(&GlobalConfig::Zigbee_G.DstAddr, pDestShortAddr, 2);
GlobalConfig::Zigbee_G.MyAddr = pad1;
2024-10-23 19:51:01 +08:00
zlog_info(zct,"DstAddr = %x\n", GlobalConfig::Zigbee_G.DstAddr);
2024-10-22 19:04:25 +08:00
GlobalConfig::ZigbeeInfo_G.MyAddr = "9999";
modify_info(tmp, (char *)&GlobalConfig::Zigbee_G);
gpio_set(GlobalConfig::GPIO_G.zigReset, 0);
mssleep(10000);
gpio_set(GlobalConfig::GPIO_G.zigReset, 1);
}