Ну и собственно сам парсер
описание возможных комбинаций полученных кодов.
void UART_answer(void) {
uint8_t exit = 1;
uint8_t count = 0;
uint8_t iter = 0;
while (exit) {
// rx IF
if (rxUartBuf[count + 0] == 0x49 && rxUartBuf[count + 1] == 0x46 && rxUartBuf[count + 2] == 0x3b) {//IF;
count += 3;
uIF.com[0] = 0x49;
uIF.com[1] = 0x46;//command "IF"
sprintf(uIF.p1, "%011d",
(int) freqToSi);// Specify the frequency in Hz (11-digit) The blank digits must be “0”.
sprintf(uIF.p2, " ");// 5-spaces
sprintf(uIF.p3, "+0000");//rit/xit
uIF.p4[0] = 0x30;//0: RIT OFF, 1: RIT ON
uIF.p5[0] = 0x30;//0: XIT OFF, 1: XIT ON
uIF.p6[0] = 0x30;//0
uIF.p7[0] = 0x30;
uIF.p7[1] = 0x30;//00
if (pttYN)uIF.p8[0] = 0x31; else uIF.p8[0] = 0x30;// 0: RX, 1: TX
if (USB_LSB_Array[nowBandIsNumber]) uIF.p9[0] = 0x32;//2usb
if (!USB_LSB_Array[nowBandIsNumber]) uIF.p9[0] = 0x31;//1lsb
if (!cwYN) uIF.p9[0] = 0x33;//3cw Operating mode. Refer to the MD commands for details.
uIF.p10[0] = 0x30;
uIF.p11[0] = 0x30;
uIF.p12[0] = 0x30;//0: Simplex operation, 1: Split operation
uIF.p13[0] = 0x30;//0: OFF, 1: TONE, 2: CTCSS
uIF.p14[0] = 0x30;
uIF.p14[1] = 0x30;//00 Tone number (00 ~ 42). Refer to the TN and CN command
uIF.p15[0] = 0x20;// space
uIF.p16[0] = 0x3b;// ;
// BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
// BSP_LCD_DisplayHStringAt(0, 10, (uint8_t *) &uIF, LEFT_MODE);
while (HAL_UART_Transmit(&huart5, (uint8_t *) &uIF.com[0], sizeof(uIF), 100) !=
HAL_OK) { BSP_LCD_DisplayHStringAt(0, 0, (uint8_t *) "error uart", LEFT_MODE); };
}
//ID;
if (rxUartBuf[count + 0] == 0x49 && rxUartBuf[count + 1] == 0x44 && rxUartBuf[count + 2] == 0x3b) {//ID;
count += 3;
uint8_t a[6] = "ID020;";
while (HAL_UART_Transmit(&huart5, (uint8_t *) a, 6, 500) !=
HAL_OK) { BSP_LCD_DisplayHStringAt(0, 0, (uint8_t *) "error uart", LEFT_MODE); };
BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
BSP_LCD_DisplayHStringAt(0, 45, (uint8_t *) &a, LEFT_MODE);
}
//FA;
if (rxUartBuf[count + 0] == 0x46 && rxUartBuf[count + 1] == 0x41 && rxUartBuf[count + 2] == 0x3b) {//FA;
count += 3;
uFA.com[0] = 0x46;
uFA.com[1] = 0x41; //FA
sprintf(uFA.p1, "%011d", (int) freqToSi);
uFA.p2[0] = 0x3b;
while (HAL_UART_Transmit(&huart5, (uint8_t *) &uFA.com, sizeof(uFA), 500) !=
HAL_OK) { BSP_LCD_DisplayHStringAt(0, 0, (uint8_t *) "error uart", LEFT_MODE); };
}
//FA OUT
if (rxUartBuf[count + 0] == 0x46 && rxUartBuf[count + 1] == 0x41 && rxUartBuf[count + 2] == 0x30) {//FA0;
count += 14;
oFA.com[0] = 0x46;
oFA.com[1] = 0x41; //FA
long f = atol((char *) &rxUartBuf[2]);
sprintf(oFA.p1, "%011d", f);
// BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
// BSP_LCD_DisplayHStringAt(0, 10, (uint8_t *) &oFA.p1, LEFT_MODE);
oFA.p2[0] = 0x3b;
while (HAL_UART_Transmit(&huart5, (uint8_t *) &oFA.com, sizeof(oFA), 500) !=
HAL_OK) { BSP_LCD_DisplayHStringAt(0, 0, (uint8_t *) "error uart", LEFT_MODE); };
freqToSi = (uint32_t) f;
getBandNumberByFreq(freqToSi);//установим диапазог если надо
if (USB_LSB_Array[nowBandIsNumber])
si5351aSetFrequency(freqToSi + freq.FREQ_IF1, freq.FREQ_IF1, ifYN);
else
si5351aSetFrequency(freqToSi + freq.FREQ_IF1 + (freq.FREQ_IF3usb - freq.FREQ_IF3lsb), freq.FREQ_IF1,
ifYN);
needToDrawYN = 1;
}
//MD;
if (rxUartBuf[count + 0] == 0x4D && rxUartBuf[count + 1] == 0x44 && rxUartBuf[count + 2] == 0x3b) {//MD;
count += 3;
uMD.com[0] = 0x4D;
uMD.com[1] = 0x44; //MD
if (USB_LSB_Array[nowBandIsNumber]) uMD.p1[0] = 0x32;//2usb
if (!USB_LSB_Array[nowBandIsNumber]) uMD.p1[0] = 0x31;//1lsb
if (!cwYN) uMD.p1[0] = 0x33;//3cw Operating mode. Refer to the MD commands for details.
uMD.p2[0] = 0x3b;
while (HAL_UART_Transmit(&huart5, (uint8_t *) &uMD, sizeof(uMD), 500) !=
HAL_OK) { BSP_LCD_DisplayHStringAt(0, 0, (uint8_t *) "error uart", LEFT_MODE); };
}
//FB
if (rxUartBuf[count + 0] == 0x46 && rxUartBuf[count + 1] == 0x42 && rxUartBuf[count + 2] == 0x3b) {//MD;
count += 3;
while (HAL_UART_Transmit(&huart5, (uint8_t *) "FB00000000000;", 14, 500) !=
HAL_OK) { BSP_LCD_DisplayHStringAt(0, 0, (uint8_t *) "error uart", LEFT_MODE); };
}
//SH
if (rxUartBuf[count + 0] == 0x53 && rxUartBuf[count + 1] == 0x48 && rxUartBuf[count + 2] == 0x3b) {//SH;
count += 3;
while (HAL_UART_Transmit(&huart5, (uint8_t *) "SH11;", 5, 500) !=
HAL_OK) { BSP_LCD_DisplayHStringAt(0, 0, (uint8_t *) "error uart", LEFT_MODE); };
}
//SL
if (rxUartBuf[count + 0] == 0x53 && rxUartBuf[count + 1] == 0x4C && rxUartBuf[count + 2] == 0x3b) {//SL;
count += 3;
while (HAL_UART_Transmit(&huart5, (uint8_t *) "SL00;", 5, 500) !=
HAL_OK) { BSP_LCD_DisplayHStringAt(0, 0, (uint8_t *) "error uart", LEFT_MODE); };
}
//PC
if (rxUartBuf[count + 0] == 0x50 && rxUartBuf[count + 1] == 0x43 && rxUartBuf[count + 2] == 0x3b) {//PC;
count += 3;
while (HAL_UART_Transmit(&huart5, (uint8_t *) "PC000;", 6, 500) !=
HAL_OK) { BSP_LCD_DisplayHStringAt(0, 0, (uint8_t *) "error uart", LEFT_MODE); };
}
//SM0; s-meter
if (rxUartBuf[count + 0] == 0x53 && rxUartBuf[count + 1] == 0x4D && rxUartBuf[count + 2] == 0x30 &&
rxUartBuf[count + 3] == 0x3b) {//PC;
count += 4;
while (HAL_UART_Transmit(&huart5, (uint8_t *) "SM00000;", 8, 500) !=
HAL_OK) { BSP_LCD_DisplayHStringAt(0, 0, (uint8_t *) "error uart", LEFT_MODE); };
}
//AG0; усилиние
if (rxUartBuf[count + 0] == 0x41 && rxUartBuf[count + 1] == 0x47 && rxUartBuf[count + 2] == 0x30 &&
rxUartBuf[count + 3] == 0x3b) {//AG0;
count += 4;
while (HAL_UART_Transmit(&huart5, (uint8_t *) "AG0000;", 7, 500) !=
HAL_OK) { BSP_LCD_DisplayHStringAt(0, 0, (uint8_t *) "error uart", LEFT_MODE); };
}
//TX
if (rxUartBuf[count + 0] == 0x54 && rxUartBuf[count + 1] == 0x58 && rxUartBuf[count + 2] == 0x3b) {//TX;
count += 3;
while (HAL_UART_Transmit(&huart5, (uint8_t *) "TX0;", 4, 500) !=
HAL_OK) { BSP_LCD_DisplayHStringAt(0, 0, (uint8_t *) "error uart", LEFT_MODE); };
pttYN = 0xff;
needDrawPttYN = 1;
needToDrawYN = 1;
needDrawPaAttYN = 1;
}
//RX
if (rxUartBuf[count + 0] == 0x52 && rxUartBuf[count + 1] == 0x58 && rxUartBuf[count + 2] == 0x3b) {//RX;
count += 3;
pttYN = 0;
needDrawPttYN = 1;
needToDrawYN = 1;
needDrawPaAttYN = 1;
while (HAL_UART_Transmit(&huart5, (uint8_t *) "RX0;", 4, 500) !=
HAL_OK) { BSP_LCD_DisplayHStringAt(0, 0, (uint8_t *) "error uart", LEFT_MODE); };
}
if (rxUartBuf[count] == 0 || ++iter == 4) exit = 0;
}
//поставим опять начало буфера
huart5.pRxBuffPtr = rxUartBuf;
huart5.RxXferSize = 200;
huart5.RxXferCount = 200;
for (int i = 0; i < 200; i++)rxUartBuf = 0;
uartStop = 0;
}
void getBandNumberByFreq(uint32_t ff) {
uint8_t b = 0;
if (ff > 1800000 && ff < 2200000) b = 1;
if (ff > 3400000 && ff < 4000000) b = 2;
if (ff > 6900000 && ff < 7300000) b = 3;
if (ff > 10000000 && ff < 10300000) b = 4;
if (ff > 13900000 && ff < 14400000) b = 5;
if (ff > 17900000 && ff < 18200000) b = 6;
if (ff > 20900000 && ff < 21500000) b = 7;
if (ff > 24700000 && ff < 25000000) b = 8;
if (ff > 27900000 && ff < 30000000) b = 9;
if (nowBandIsNumber != b && b) {
nowBandIsNumber = b;
paAttNewYN = 1;//перерисуем и включим атт
}
В Принципе как база пойдет для любых видов трансивера. Основное внимание следует уделить общению с UART портом, остальное и так понятно