Compare commits
5
Commits
8dd17a5b9a
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db40049993 | ||
|
|
48fc4058d8 | ||
|
|
fdff2918c3 | ||
|
|
96d1d60145 | ||
|
|
988251e5aa |
@@ -1,7 +1,9 @@
|
||||
{
|
||||
"permissions": {
|
||||
"allow": [
|
||||
"Read(//c/Windows/Fonts//**)"
|
||||
"Read(//c/Windows/Fonts//**)",
|
||||
"Read(//z/work/**)",
|
||||
"Read(//z/work/lsh-SS524V100_SDK_V1.0/mpp/include/**)"
|
||||
],
|
||||
"deny": [
|
||||
"Edit",
|
||||
|
||||
@@ -289,7 +289,7 @@ void sample_vo_chn_switch(int value){
|
||||
}
|
||||
|
||||
#endif
|
||||
#if 1
|
||||
#if 1 //2lu
|
||||
switch (value) {
|
||||
case 0: /* 布局一 双屏:视频1(左) + 视频2(右),各 960x720 */
|
||||
vo_chn_switch(0, 1, 1);
|
||||
|
||||
Binary file not shown.
@@ -19,6 +19,13 @@
|
||||
#include "it6602.h"
|
||||
#include "it6602_reg.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
|
||||
char Firmware_date[] = __DATE__;
|
||||
char Firmware_time[] = __TIME__;
|
||||
|
||||
@@ -52,6 +59,66 @@ void InitMessage()
|
||||
|
||||
}
|
||||
|
||||
static void dump_regs(unsigned long addr, int n)
|
||||
{
|
||||
unsigned long page = addr & ~0xfffUL;
|
||||
int fd = open("/dev/mem", O_RDWR | O_SYNC);
|
||||
void *m;
|
||||
int i;
|
||||
|
||||
if (fd < 0) { perror("open /dev/mem"); return; }
|
||||
m = mmap(NULL, 0x10000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, page);
|
||||
if (m == MAP_FAILED) { perror("mmap"); close(fd); return; }
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
printf(" %08lx: %08x\n", addr + i * 4,
|
||||
*(volatile unsigned int *)((char *)m + (addr - page) + i * 4));
|
||||
|
||||
munmap(m, 0x10000);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
static void it66021_reset_gpio(void)
|
||||
{
|
||||
unsigned long base = 0x11095000; /* PL061 gpio_chip5 */
|
||||
int fd = open("/dev/mem", O_RDWR | O_SYNC);
|
||||
void *m;
|
||||
|
||||
if (fd < 0) { perror("open"); return; }
|
||||
m = mmap(NULL, 0x1000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, base);
|
||||
if (m == MAP_FAILED) { perror("mmap"); close(fd); return; }
|
||||
|
||||
printf("GPIO5 before: DATA=0x%02x DIR=0x%02x AFSEL=0x%02x DEN=0x%02x\n",
|
||||
*(volatile unsigned char *)((char *)m + 0x008),
|
||||
*(volatile unsigned char *)((char *)m + 0x400),
|
||||
*(volatile unsigned char *)((char *)m + 0x420),
|
||||
*(volatile unsigned char *)((char *)m + 0x51c));
|
||||
|
||||
/* 释放复位(bit1):输出 + 数字使能 + 拉高 */
|
||||
*(volatile unsigned char *)((char *)m + 0x400) |= 0x02; /* DIR */
|
||||
*(volatile unsigned char *)((char *)m + 0x51c) |= 0x02; /* DEN */
|
||||
*(volatile unsigned char *)((char *)m + 0x008) = 0x02; /* DATA(PL061 掩码写,bit1) */
|
||||
|
||||
usleep(10000);
|
||||
printf("GPIO5 after : DATA=0x%02x DIR=0x%02x\n",
|
||||
*(volatile unsigned char *)((char *)m + 0x008),
|
||||
*(volatile unsigned char *)((char *)m + 0x400));
|
||||
}
|
||||
|
||||
|
||||
void DumpI2cRegs(const char *tag)
|
||||
{
|
||||
printf("===== I2C dump: %s =====\n", tag);
|
||||
printf("-- I2C1 controller 0x11061000 --\n");
|
||||
dump_regs(0x11061000, 64);
|
||||
printf("-- I2C0 controller 0x11060000 --\n");
|
||||
dump_regs(0x11060000, 64);
|
||||
printf("-- CRG 0x11014280 (I2C0) --\n");
|
||||
dump_regs(0x11014280, 2);
|
||||
printf("-- CRG 0x11014288 (I2C1) --\n");
|
||||
dump_regs(0x11014288, 2);
|
||||
printf("=============================\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -64,14 +131,19 @@ void InitMessage()
|
||||
void main( void )
|
||||
{
|
||||
|
||||
USHORT loopinterval;
|
||||
USHORT loopinterval = 0;
|
||||
|
||||
InitMessage();
|
||||
open_i2c_fd();
|
||||
|
||||
it66021_reset_gpio();
|
||||
DumpI2cRegs("before IT6602_fsm_init"); /* ← 加这里,最重要 */
|
||||
|
||||
delay1ms(1000); //for power sequence
|
||||
IT6602_fsm_init();
|
||||
|
||||
DumpI2cRegs("after IT6602_fsm_init"); /* ← 再加这里 */
|
||||
|
||||
while(1)
|
||||
{
|
||||
loopinterval += getloopTicCount();
|
||||
@@ -85,3 +157,4 @@ void main( void )
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
USHORT getloopTicCount()
|
||||
{
|
||||
usleep(5000);
|
||||
return 1;
|
||||
return 5;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -59,7 +59,8 @@ static int fd;
|
||||
int open_i2c_fd()
|
||||
{
|
||||
int ret;
|
||||
fd = open("/dev/i2c-1", O_RDWR);
|
||||
//fd = open("/dev/i2c-1", O_RDWR);
|
||||
fd = open("/dev/i2c-0", O_RDWR);
|
||||
if (fd<0)
|
||||
{
|
||||
printf("Open i2c dev error!\n");
|
||||
|
||||
@@ -450,17 +450,17 @@ struct IT6602_REG_INI IT6602_HDMI_INIT_TABLE[] = {
|
||||
|
||||
{REG_RX_010, 0xFF, 0x17}, //[4]Auto Video Reset [2]Int Reset [1]Audio Reset [0]Video Reset
|
||||
|
||||
{REG_RX_011, 0xFF, 0x1F}, //Port 0:[4]EQ Reset [3]CLKD5 Reset [2]CDR Reset [1]HDCP Reset [0]All logic Reset
|
||||
{REG_RX_018, 0xFF, 0x1F}, //Port 1:[4]EQ Reset [3]CLKD5 Reset [2]CDR Reset [1]HDCP Reset [0]All logic Reset
|
||||
{REG_RX_011, 0xFF, 0x1F}, //Port 0[4]EQ Reset [3]CLKD5 Reset [2]CDR Reset [1]HDCP Reset [0]All logic Reset
|
||||
{REG_RX_018, 0xFF, 0x1F}, //Port 1[4]EQ Reset [3]CLKD5 Reset [2]CDR Reset [1]HDCP Reset [0]All logic Reset
|
||||
|
||||
{REG_RX_012, 0xFF, 0xF8}, //Port 0:[7:3] MHL Logic reset
|
||||
{REG_RX_012, 0xFF, 0xF8}, //Port 0[7:3] MHL Logic reset
|
||||
|
||||
{REG_RX_010, 0xFF, 0x10}, //[4]Auto Video Reset [2]Int Reset [1]Audio Reset [0]Video Reset
|
||||
|
||||
{REG_RX_011, 0xFF, 0xA0}, //Port 0:[7] Enable Auto Reset when Clock is not stable [5]Enable Auto Reset
|
||||
{REG_RX_018, 0xFF, 0xA0}, //Port 1:[7] Enable Auto Reset when Clock is not stable [5]Enable Auto Reset
|
||||
{REG_RX_011, 0xFF, 0xA0}, //Port 0[7] Enable Auto Reset when Clock is not stable [5]Enable Auto Reset
|
||||
{REG_RX_018, 0xFF, 0xA0}, //Port 1[7] Enable Auto Reset when Clock is not stable [5]Enable Auto Reset
|
||||
|
||||
{REG_RX_012, 0xFF, 0x00}, //Port 0:[7:3] MHL Logic reset
|
||||
{REG_RX_012, 0xFF, 0x00}, //Port 0[7:3] MHL Logic reset
|
||||
|
||||
{REG_RX_00F, 0x03, 0x01}, //change bank 1 //2013-0430 Andrew suggestion
|
||||
{REG_RX_1B0, 0x03, 0x01}, // MHL Port Set HPD = 0 at Power On initial state
|
||||
@@ -473,8 +473,8 @@ struct IT6602_REG_INI IT6602_HDMI_INIT_TABLE[] = {
|
||||
|
||||
|
||||
{REG_RX_00F, 0x03, 0x00}, //change bank 0 //2013-0430 Andrew suggestion
|
||||
{REG_RX_017, 0xC0, 0x80}, //Port 0:[7:6] = 10 invert Port 0 input HCLK , CLKD5I //2013-0430 Andrew suggestion
|
||||
{REG_RX_01E, 0xC0, 0x00}, //Port 1:[7:6] = 00 invert Port 1 input TMDS , CLKD5I //2013-0430 Andrew suggestion
|
||||
{REG_RX_017, 0xC0, 0x80}, //Port 0[7:6] = 10 invert Port 0 input HCLK , CLKD5I //2013-0430 Andrew suggestion
|
||||
{REG_RX_01E, 0xC0, 0x00}, //Port 1[7:6] = 00 invert Port 1 input TMDS , CLKD5I //2013-0430 Andrew suggestion
|
||||
|
||||
#ifdef Enable_IT6602_CEC
|
||||
{REG_RX_00E, 0xFF, 0xFF}, //for enable CEC Clock
|
||||
@@ -483,10 +483,10 @@ struct IT6602_REG_INI IT6602_HDMI_INIT_TABLE[] = {
|
||||
|
||||
// {0xFE, 0x80, 0x80}, //BUS10B for FPGA
|
||||
|
||||
{REG_RX_016, 0x08, 0x08}, //Port 0:[3]1: Enable CLKD5 auto power down
|
||||
{REG_RX_01D, 0x08, 0x08}, //Port 1:[3]1: Enable CLKD5 auto power down
|
||||
{REG_RX_016, 0x08, 0x08}, //Port 0[3]1: Enable CLKD5 auto power down
|
||||
{REG_RX_01D, 0x08, 0x08}, //Port 1[3]1: Enable CLKD5 auto power down
|
||||
|
||||
// {0x20, 0x01, 0x30}, //Port 0:AFE control
|
||||
// {0x20, 0x01, 0x30}, //Port 0AFE control
|
||||
|
||||
{REG_RX_02B, 0xFF, 0x07}, //FixTek3D
|
||||
// {REG_RX_031, 0xFF, 0x2C}, //[7:4]Enable repeater function [3:0] SCL hold time count & Update Ri sel
|
||||
@@ -679,7 +679,7 @@ struct IT6602_REG_INI IT6602_HDMI_INIT_TABLE[] = {
|
||||
|
||||
#if defined(_IT66023_)
|
||||
//FIX_ID_016 xxxxx Support Dual Pixel Mode for IT66023 Only
|
||||
{REG_RX_08C, 0x09, 0x09}, // Reg8C[0] = 1 // SPOutMode:// for enable IO Mapping for Signal Pixel mode
|
||||
{REG_RX_08C, 0x09, 0x09}, // Reg8C[0] = 1 // SPOutMode// for enable IO Mapping for Signal Pixel mode
|
||||
//FIX_ID_016 xxxxx
|
||||
#endif
|
||||
|
||||
@@ -711,14 +711,14 @@ static struct IT6602_REG_INI IT6602_MHL_INIT_TABLE[] = {
|
||||
{MHL_RX_53, 0xFF, 0x80}, //[7]=1 disable FW mode
|
||||
|
||||
{MHL_RX_32, 0xFF, 0x0C}, //CBUS arbitration Low time
|
||||
{MHL_RX_81, 0xFF, MHLVersion}, //DCAP00:MHL_VER_MAJOR and MINOR
|
||||
{MHL_RX_82, 0xFF, (PLIM<<5)+(POW<<4)+DEV_TYPE_SINK}, //DCAP02:DEVICE TYPE
|
||||
{MHL_RX_83, 0xFF, ADOPTER_ID_H}, //DCAP03:ADOPTER_ID
|
||||
{MHL_RX_81, 0xFF, MHLVersion}, //DCAP00MHL_VER_MAJOR and MINOR
|
||||
{MHL_RX_82, 0xFF, (PLIM<<5)+(POW<<4)+DEV_TYPE_SINK}, //DCAP02DEVICE TYPE
|
||||
{MHL_RX_83, 0xFF, ADOPTER_ID_H}, //DCAP03ADOPTER_ID
|
||||
{MHL_RX_84, 0xFF, ADOPTER_ID_L},
|
||||
{MHL_RX_8B, 0xFF, DEVICE_ID_H}, //DCAP0B:DEVICE_ID
|
||||
{MHL_RX_8B, 0xFF, DEVICE_ID_H}, //DCAP0BDEVICE_ID
|
||||
{MHL_RX_8C, 0xFF, DEVICE_ID_L},
|
||||
|
||||
{MHL_RX_28, 0x0F, 0x00}, //Port 0:[0] = 0 RS value of CH1 if req_setEQ=1 //2013-0430 Andrew suggestion
|
||||
{MHL_RX_28, 0x0F, 0x00}, //Port 0[0] = 0 RS value of CH1 if req_setEQ=1 //2013-0430 Andrew suggestion
|
||||
|
||||
{MHL_RX_0F, 0x20, 0x20}, //[5]Guard band swap when Pack Mode
|
||||
//FIX_ID_004 xxxxx //Add 100ms calibration for Cbus
|
||||
@@ -2092,11 +2092,11 @@ void IT66023OutputPixelModeSet(unsigned char bSignalPixelMode)
|
||||
{
|
||||
HDMIRX_VIDEO_PRINTF(("IT66023OutputPixelModeSet( ) 111111111111 Signal Pixel Mode\r\n"));
|
||||
// 1 . Signal Pixel Mode
|
||||
// Reg0D[3] = 0 // EnPHFClk:0 for disable PHFCLK for signal pixel mode
|
||||
// Reg8C[0] = 1 // SPOutMode:// for enable IO Mapping for Signal Pixel mode
|
||||
// Reg8C[3] = 1 // VDIO3en:// for enable QA IO
|
||||
// Reg8B[0] = 0 // EnDualPixel:0 for disable Dual Pixel mode
|
||||
// Reg8B[7] = 1 // PWDDownDualData:// for gating dual pix data output
|
||||
// Reg0D[3] = 0 // EnPHFClk0 for disable PHFCLK for signal pixel mode
|
||||
// Reg8C[0] = 1 // SPOutMode// for enable IO Mapping for Signal Pixel mode
|
||||
// Reg8C[3] = 1 // VDIO3en// for enable QA IO
|
||||
// Reg8B[0] = 0 // EnDualPixel0 for disable Dual Pixel mode
|
||||
// Reg8B[7] = 1 // PWDDownDualData// for gating dual pix data output
|
||||
hdmirxset(REG_RX_00D, 0x08, 0x00);
|
||||
hdmirxset(REG_RX_08C, 0x09, 0x09);
|
||||
hdmirxset(REG_RX_08B, 0x81, 0x80);
|
||||
@@ -2106,11 +2106,11 @@ void IT66023OutputPixelModeSet(unsigned char bSignalPixelMode)
|
||||
{
|
||||
HDMIRX_VIDEO_PRINTF(("IT66023OutputPixelModeSet( ) 00000000000000 Dual Pixel Mode\r\n"));
|
||||
// 2. Dual Pixel Mode
|
||||
// Reg0D[3] = 1 // EnPHFClk:// for enable PHFCLK for Dual pixel mode
|
||||
// Reg8C[0] = 0 // SPOutMode:0 for Disable IO Mapping for Dual Pixel mode
|
||||
// Reg8C[3] = 1 // VDIO3en:// for enable QA IO
|
||||
// Reg8B[0] = 1 // EnDualPixel:// for enable Dual Pixel mode
|
||||
// Reg8B[7] = 0 // PWDDownDualData:0 for PWD UP DUAL DATA
|
||||
// Reg0D[3] = 1 // EnPHFClk// for enable PHFCLK for Dual pixel mode
|
||||
// Reg8C[0] = 0 // SPOutMode0 for Disable IO Mapping for Dual Pixel mode
|
||||
// Reg8C[3] = 1 // VDIO3en// for enable QA IO
|
||||
// Reg8B[0] = 1 // EnDualPixel// for enable Dual Pixel mode
|
||||
// Reg8B[7] = 0 // PWDDownDualData0 for PWD UP DUAL DATA
|
||||
hdmirxset(REG_RX_00D, 0x08, 0x08);
|
||||
hdmirxset(REG_RX_08C, 0x09, 0x08);
|
||||
hdmirxset(REG_RX_08B, 0x81, 0x01);
|
||||
@@ -6713,7 +6713,7 @@ static void IT6602VideoOutputEnable(unsigned char bEnableOutput)
|
||||
|
||||
//FIX_ID_016 xxxxx Support Dual Pixel Mode for IT66023 Only
|
||||
#if defined(_IT66023_)
|
||||
hdmirxset(REG_RX_08C, 0x08, 0x00); // Reg8C[3] = 0 // VDIO3en:// for disable QA IO
|
||||
hdmirxset(REG_RX_08C, 0x08, 0x00); // Reg8C[3] = 0 // VDIO3en// for disable QA IO
|
||||
#endif
|
||||
//FIX_ID_016 xxxxx
|
||||
|
||||
|
||||
Binary file not shown.
@@ -1,3 +1,4 @@
|
||||
arm-mix410-linux-gcc -o lc6600_uart_hisi ctrl_pnl.c confile.c serial.c uartinf.c udp_util.c -lrt
|
||||
arm-mix410-linux-gcc -o lc660x_uart_hisi ctrl_pnl_new.c confile.c serial.c uartinf.c udp_util.c -lrt
|
||||
arm-mix410-linux-gcc -o lc660x_uart_hisi ctrl_pnl.c confile.c serial.c uartinf.c udp_util.c -lrt
|
||||
arm-mix410-linux-gcc -o lc660x_uart_hisi ctrl_pnl_test.c confile.c serial.c uartinf.c udp_util.c -lrt
|
||||
|
||||
@@ -125,9 +125,6 @@ int setup_lc6600(struct lc6600_param *pparam){
|
||||
if(read_ok == NULL){
|
||||
printf("can not exce AT+CFUN=1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
static long elapsed_ms(struct timeval *start, struct timeval *end)
|
||||
@@ -275,8 +272,6 @@ int get_rx2_freq(char *rx2){
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
int n_read;
|
||||
@@ -370,49 +365,49 @@ int main (int argc, char *argv[])
|
||||
|
||||
n_read = uart_read(ROUTE_UART, _rx_data);
|
||||
|
||||
printf("%s\n",_rx_data);
|
||||
printf("%s\n",_rx_data);
|
||||
|
||||
#if 1
|
||||
if(n_read > 10){
|
||||
if(n_read > 10){
|
||||
|
||||
//ip_str=strstr(_rx_data,argv[2]);
|
||||
//ip_str=strstr(_rx_data,"192.168.1.15");
|
||||
//ip_len = strlen(ip_str);
|
||||
//printf("ip_str %d \n ",ip_len);
|
||||
ip_str=strstr(_rx_data,argv[2]);
|
||||
ip_len = strlen(argv[2]);
|
||||
if(ip_str){
|
||||
//buffer_param[0] = 0x55;
|
||||
//printf("ip_str %s \n ",ip_str);
|
||||
memcpy(index,ip_str+(ip_len+2),1);
|
||||
//printf("index %s \n ",index);
|
||||
//ip_str=strstr(_rx_data,argv[2]);
|
||||
//ip_str=strstr(_rx_data,"192.168.1.15");
|
||||
//ip_len = strlen(ip_str);
|
||||
//printf("ip_str %d \n ",ip_len);
|
||||
ip_str=strstr(_rx_data,argv[2]);
|
||||
ip_len = strlen(argv[2]);
|
||||
if(ip_str){
|
||||
//buffer_param[0] = 0x55;
|
||||
//printf("ip_str %s \n ",ip_str);
|
||||
memcpy(index,ip_str+(ip_len+2),1);
|
||||
//printf("index %s \n ",index);
|
||||
|
||||
if(strcmp(index, "1") == 0){
|
||||
memcpy(rssi1,ip_str+(ip_len+5),3);
|
||||
dbm1 = atoi(rssi1);
|
||||
printf("++dbm1:%d\n",dbm1);
|
||||
buffer_param[1] = dbm1;
|
||||
gettimeofday(&tv_rx1, NULL);
|
||||
if(strcmp(index, "1") == 0){
|
||||
memcpy(rssi1,ip_str+(ip_len+5),3);
|
||||
dbm1 = atoi(rssi1);
|
||||
printf("++dbm1:%d\n",dbm1);
|
||||
buffer_param[1] = dbm1;
|
||||
gettimeofday(&tv_rx1, NULL);
|
||||
}
|
||||
|
||||
if(strcmp(index, "2") == 0){
|
||||
memcpy(rssi2,ip_str+(ip_len+5),3);
|
||||
dbm2 = atoi(rssi2);
|
||||
printf("++dbm2:%d\n",dbm2);
|
||||
buffer_param[2] = dbm2;
|
||||
gettimeofday(&tv_rx2, NULL);
|
||||
}
|
||||
|
||||
}else{
|
||||
printf("no signal\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(strcmp(index, "2") == 0){
|
||||
memcpy(rssi2,ip_str+(ip_len+5),3);
|
||||
dbm2 = atoi(rssi2);
|
||||
printf("++dbm2:%d\n",dbm2);
|
||||
buffer_param[2] = dbm2;
|
||||
gettimeofday(&tv_rx2, NULL);
|
||||
else{
|
||||
printf("no \n");
|
||||
uart_write(ROUTE_UART, "AT^DAPR=1\r");
|
||||
// buffer_param[0] = 0xAA;
|
||||
}
|
||||
|
||||
}else{
|
||||
printf("no signal\n");
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
printf("no \n");
|
||||
uart_write(ROUTE_UART, "AT^DAPR=1\r");
|
||||
// buffer_param[0] = 0xAA;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -0,0 +1,450 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h> // gettimeofday
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "serial.h"
|
||||
#include "uartinf.h"
|
||||
#include "confile.h"
|
||||
#include "udp_util.h"
|
||||
|
||||
char _rx_data[1024];
|
||||
|
||||
struct lc6600_param{
|
||||
int password;
|
||||
int freq;
|
||||
int power;
|
||||
int bw;
|
||||
int ap_sta;
|
||||
int ip;
|
||||
int setup;
|
||||
};
|
||||
|
||||
char freq1[10];
|
||||
char freq2[10];
|
||||
//char dbm1[5];
|
||||
//char dbm2[5];
|
||||
|
||||
#define RSSI_TIMEOUT_MS 3000 //超时时间
|
||||
#define RSSI_NO_SIGNAL 0x55 //无信号值
|
||||
|
||||
|
||||
|
||||
int setup_lc6600(struct lc6600_param *pparam){
|
||||
int n_read;
|
||||
char *read_ok;
|
||||
char str[30];
|
||||
|
||||
uart_write(ROUTE_UART, "AT+CFUN=0\r");
|
||||
n_read = uart_read(ROUTE_UART, _rx_data);
|
||||
read_ok = strstr(_rx_data,"OK");
|
||||
if(read_ok == NULL){
|
||||
printf("can not exce AT+CFUN=0");
|
||||
}
|
||||
sleep(1);
|
||||
//password
|
||||
sprintf(str,"AT^DAPI=%d\r",pparam->password);
|
||||
uart_write(ROUTE_UART, str);
|
||||
printf("%s\n",str);
|
||||
n_read = uart_read(ROUTE_UART, _rx_data);
|
||||
read_ok = strstr(_rx_data,"OK");
|
||||
if(read_ok == NULL){
|
||||
printf("can not exce AT^DAPI");
|
||||
}
|
||||
sleep(1);
|
||||
// 1 center 2 station
|
||||
sprintf(str,"AT^DDTC=%d\r",pparam->ap_sta);
|
||||
uart_write(ROUTE_UART, str);
|
||||
printf("%s\n",str);
|
||||
n_read = uart_read(ROUTE_UART, _rx_data);
|
||||
read_ok = strstr(_rx_data,"OK");
|
||||
if(read_ok == NULL){
|
||||
printf("can not exce AT^DDTC");
|
||||
}
|
||||
sleep(1);
|
||||
|
||||
// sprintf(str,"AT^DDTC=%d\r",pparam->ap_sta);
|
||||
uart_write(ROUTE_UART, "AT^DSTC=2\r");
|
||||
printf("AT^DSTC\n");
|
||||
n_read = uart_read(ROUTE_UART, _rx_data);
|
||||
read_ok = strstr(_rx_data,"OK");
|
||||
if(read_ok == NULL){
|
||||
printf("can not exce AT^DDSTC");
|
||||
}
|
||||
sleep(1);
|
||||
|
||||
|
||||
// 2 5M 3 10M 4 15M 5 20M "25" dbm
|
||||
sprintf(str,"AT^DRPS=,%d,\"%d\"\r",pparam->bw,pparam->power);
|
||||
uart_write(ROUTE_UART, str);
|
||||
printf("%s\n",str);
|
||||
n_read = uart_read(ROUTE_UART, _rx_data);
|
||||
read_ok = strstr(_rx_data,"OK");
|
||||
if(read_ok == NULL){
|
||||
printf("can not exce AT^DRPS\n");
|
||||
}
|
||||
sleep(1);
|
||||
// 01 800M 04 1.4G 08 2.4G
|
||||
sprintf(str,"AT^DAOCNDI=0%d\r",pparam->freq);
|
||||
uart_write(ROUTE_UART, str);
|
||||
printf("%s\n",str);
|
||||
n_read = uart_read(ROUTE_UART, _rx_data);
|
||||
read_ok = strstr(_rx_data,"OK");
|
||||
if(read_ok == NULL){
|
||||
printf("can not exce AT^DAOCNDI\n");
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
|
||||
|
||||
sprintf(str,"AT^NETIFCFG=2,\"192.168.2.%d\"\r",pparam->ip);
|
||||
uart_write(ROUTE_UART, str);
|
||||
printf("%s\n",str);
|
||||
n_read = uart_read(ROUTE_UART, _rx_data);
|
||||
read_ok = strstr(_rx_data,"OK");
|
||||
if(read_ok == NULL){
|
||||
printf("can not exce AT^DAOCNDI\n");
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
|
||||
uart_write(ROUTE_UART, "AT+CFUN=1\r");
|
||||
n_read = uart_read(ROUTE_UART, _rx_data);
|
||||
read_ok = strstr(_rx_data,"OK");
|
||||
if(read_ok == NULL){
|
||||
printf("can not exce AT+CFUN=1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
static long elapsed_ms(struct timeval *start, struct timeval *end)
|
||||
{
|
||||
return (end->tv_sec - start->tv_sec) * 1000L
|
||||
+ (end->tv_usec - start->tv_usec) / 1000L;
|
||||
}
|
||||
|
||||
#define LINK_FLAG "/tmp/link_stat"
|
||||
|
||||
static void write_link_stat(void)
|
||||
{
|
||||
char buf[64];
|
||||
int fd, n;
|
||||
|
||||
fd = open(LINK_FLAG ".tmp", O_CREAT | O_WRONLY | O_TRUNC, 0666);
|
||||
if (fd < 0)
|
||||
return;
|
||||
n = snprintf(buf, sizeof(buf), "link=1\nts=%ld\n", (long)time(NULL));
|
||||
write(fd, buf, n);
|
||||
close(fd);
|
||||
rename(LINK_FLAG ".tmp", LINK_FLAG);
|
||||
}
|
||||
|
||||
static int force_up = 0; /* 调试用:强制标记为已连通 */
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
int get_rx1_freq(char *rx1){
|
||||
|
||||
char *s1;
|
||||
char *s2;
|
||||
char *s3;
|
||||
char *s4;
|
||||
int len;
|
||||
int i;
|
||||
|
||||
s1=strchr(rx1,',');
|
||||
s2=strchr(s1+1,',');
|
||||
s3=strchr(s2+1,',');
|
||||
s4=strchr(s3+1,',');
|
||||
|
||||
len= s2-s1-1;
|
||||
|
||||
for(i=0;i<len;i++){
|
||||
freq1[i] = *(s1+1+i);
|
||||
}
|
||||
printf("freq %s\n",freq1);
|
||||
|
||||
len=s4-s3-1-2; //"-44"
|
||||
|
||||
for(i=0;i<len;i++){
|
||||
dbm1[i]=*(s3+2+i);
|
||||
}
|
||||
printf("dbm1 %s\n",dbm1);
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
int get_rx1_dbm(char *rx1){
|
||||
|
||||
char *s1;
|
||||
char *s2;
|
||||
char *s3;
|
||||
char *s4;
|
||||
int len;
|
||||
int i;
|
||||
|
||||
s1=strchr(rx1,',');
|
||||
s2=strchr(s1+1,',');
|
||||
s3=strchr(s2+1,',');
|
||||
s4=strchr(s3+1,',');
|
||||
|
||||
len= s2-s1-1;
|
||||
|
||||
for(i=0;i<len;i++){
|
||||
freq1[i] = *(s1+1+i);
|
||||
}
|
||||
//printf("freq %s\n",freq1);
|
||||
|
||||
len=s3-s2-1-2; //"-44"
|
||||
|
||||
for(i=0;i<len;i++){
|
||||
dbm1[i]=*(s2+2+i);
|
||||
}
|
||||
printf("dbm1 %s\n",dbm1);
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
int get_rx2_dbm(char *rx1){
|
||||
|
||||
char *s1;
|
||||
char *s2;
|
||||
char *s3;
|
||||
char *s4;
|
||||
int len;
|
||||
int i;
|
||||
|
||||
s1=strchr(rx1,',');
|
||||
s2=strchr(s1+1,',');
|
||||
s3=strchr(s2+1,',');
|
||||
s4=strchr(s3+1,',');
|
||||
|
||||
len= s2-s1-1;
|
||||
|
||||
for(i=0;i<len;i++){
|
||||
freq1[i] = *(s1+1+i);
|
||||
}
|
||||
printf("freq %s\n",freq1);
|
||||
|
||||
len=s3-s2-1-2; //"-44"
|
||||
|
||||
for(i=0;i<len;i++){
|
||||
dbm2[i]=*(s2+2+i);
|
||||
}
|
||||
printf("dbm2 %s\n",dbm2);
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int get_rx2_freq(char *rx2){
|
||||
|
||||
char *s1;
|
||||
char *s2;
|
||||
char *s3;
|
||||
char *s4;
|
||||
int len;
|
||||
int i;
|
||||
|
||||
s1=strchr(rx2,',');
|
||||
s2=strchr(s1+1,',');
|
||||
s3=strchr(s2+1,',');
|
||||
s4=strchr(s3+1,',');
|
||||
|
||||
len= s2-s1-1;
|
||||
|
||||
for(i=0;i<len;i++){
|
||||
freq2[i] = *(s1+1+i);
|
||||
}
|
||||
printf("freq %s\n",freq2);
|
||||
|
||||
len=s4-s3-1-2; //"-44"
|
||||
|
||||
for(i=0;i<len;i++){
|
||||
dbm2[i]=*(s3+2+i);
|
||||
}
|
||||
printf("dbm1 %s\n",dbm1);
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
int n_read;
|
||||
int i;
|
||||
struct lc6600_param lc6600;
|
||||
|
||||
char buffer[1024];
|
||||
char rssi1[3];
|
||||
char rssi2[3];
|
||||
//char ip[15];
|
||||
char index[1];
|
||||
//char *rx1;
|
||||
//char *rx2;
|
||||
//int rssi1;
|
||||
//int rssi2;
|
||||
int dbm1;
|
||||
int dbm2;
|
||||
char *ip_str;
|
||||
//char *ip_str1;
|
||||
|
||||
char *buffer_freq;
|
||||
char freq_str[8];
|
||||
int freq;
|
||||
int fq;
|
||||
|
||||
int fd_param;
|
||||
int *buffer_param;
|
||||
|
||||
struct timeval tv_rx1 = {0, 0}, tv_rx2 = {0, 0}, tv_now;
|
||||
|
||||
int ip_len;
|
||||
int len;
|
||||
int rx1_ok, rx2_ok;
|
||||
|
||||
unlink(LINK_FLAG); /* 清掉上次可能的残留 */
|
||||
|
||||
n_read = uart_init(ROUTE_UART, "/dev/ttyAMA2", 115200, 'N');
|
||||
if(n_read <=0 ) {
|
||||
printf("open /dev/ttyAMA2 failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
lc6600.ap_sta = atoi(argv[1]);
|
||||
|
||||
if(argc > 3)
|
||||
force_up = atoi(argv[3]);
|
||||
|
||||
|
||||
fd_param = shm_open("/param.txt",O_RDWR|O_CREAT|O_EXCL,0777);
|
||||
if(fd_param < 0){
|
||||
fd_param = shm_open("/param.txt",O_RDWR,0777);
|
||||
}else
|
||||
ftruncate(fd_param,4096);
|
||||
buffer_param= mmap(NULL,4096,PROT_READ|PROT_WRITE,MAP_SHARED,fd_param,0);
|
||||
|
||||
#if 1
|
||||
uart_write(ROUTE_UART, "AT^DRPS?\r");
|
||||
n_read = uart_read(ROUTE_UART, _rx_data);
|
||||
printf("%s\n",_rx_data);
|
||||
buffer_freq = (n_read > 0) ? strstr(_rx_data, "^DRPS:") : NULL;
|
||||
if(buffer_freq){
|
||||
memcpy(freq_str, buffer_freq+6, 6);
|
||||
freq_str[6] = '\0';
|
||||
|
||||
printf("drps : %s\n",freq_str);
|
||||
freq = atoi(freq_str);
|
||||
|
||||
printf("freq %d \n",freq);
|
||||
buffer_param[3]=freq;
|
||||
}else{
|
||||
printf("no freq\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//freq=atoi(argv[3]);
|
||||
// buffer_param[0] = 0x55;
|
||||
//buffer_param[3] = 14300;
|
||||
if(lc6600.ap_sta == 1){
|
||||
uart_write(ROUTE_UART, "AT^DAPR=1\r");
|
||||
// n_read = uart_read(ROUTE_UART, _rx_data);
|
||||
// printf("%s\n",_rx_data);
|
||||
|
||||
|
||||
while(1){
|
||||
|
||||
gettimeofday(&tv_now, NULL);
|
||||
|
||||
rx1_ok = (tv_rx1.tv_sec != 0 && elapsed_ms(&tv_rx1, &tv_now) <= RSSI_TIMEOUT_MS);
|
||||
rx2_ok = (tv_rx2.tv_sec != 0 && elapsed_ms(&tv_rx2, &tv_now) <= RSSI_TIMEOUT_MS);
|
||||
|
||||
if (!rx1_ok) {
|
||||
buffer_param[1] = RSSI_NO_SIGNAL;
|
||||
printf("rx1 no signal timeout\n");
|
||||
}
|
||||
|
||||
if (!rx2_ok) {
|
||||
buffer_param[2] = RSSI_NO_SIGNAL;
|
||||
printf("rx2 no signal timeout\n");
|
||||
}
|
||||
|
||||
if(force_up)
|
||||
write_link_stat();
|
||||
printf("%s\n",_rx_data);
|
||||
|
||||
#if 1
|
||||
if(n_read > 10){
|
||||
|
||||
//ip_str=strstr(_rx_data,argv[2]);
|
||||
//ip_str=strstr(_rx_data,"192.168.1.15");
|
||||
//ip_len = strlen(ip_str);
|
||||
//printf("ip_str %d \n ",ip_len);
|
||||
ip_str=strstr(_rx_data,argv[2]);
|
||||
ip_len = strlen(argv[2]);
|
||||
if(ip_str){
|
||||
write_link_stat();
|
||||
//buffer_param[0] = 0x55;
|
||||
//printf("ip_str %s \n ",ip_str);
|
||||
memcpy(index,ip_str+(ip_len+2),1);
|
||||
//printf("index %s \n ",index);
|
||||
|
||||
if(strcmp(index, "1") == 0){
|
||||
memcpy(rssi1,ip_str+(ip_len+5),3);
|
||||
dbm1 = atoi(rssi1);
|
||||
printf("++dbm1:%d\n",dbm1);
|
||||
buffer_param[1] = dbm1;
|
||||
gettimeofday(&tv_rx1, NULL);
|
||||
}
|
||||
|
||||
if(strcmp(index, "2") == 0){
|
||||
memcpy(rssi2,ip_str+(ip_len+5),3);
|
||||
dbm2 = atoi(rssi2);
|
||||
printf("++dbm2:%d\n",dbm2);
|
||||
buffer_param[2] = dbm2;
|
||||
gettimeofday(&tv_rx2, NULL);
|
||||
}
|
||||
|
||||
}else{
|
||||
printf("no signal\n");
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
printf("no \n");
|
||||
uart_write(ROUTE_UART, "AT^DAPR=1\r");
|
||||
// buffer_param[0] = 0xAA;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,421 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h> // gettimeofday
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "serial.h"
|
||||
#include "uartinf.h"
|
||||
#include "confile.h"
|
||||
#include "udp_util.h"
|
||||
|
||||
char _rx_data[1024];
|
||||
|
||||
struct lc6600_param{
|
||||
int password;
|
||||
int freq;
|
||||
int power;
|
||||
int bw;
|
||||
int ap_sta;
|
||||
int ip;
|
||||
int setup;
|
||||
};
|
||||
|
||||
char freq1[10];
|
||||
char freq2[10];
|
||||
//char dbm1[5];
|
||||
//char dbm2[5];
|
||||
|
||||
#define RSSI_TIMEOUT_MS 3000 //超时时间
|
||||
#define RSSI_NO_SIGNAL 0x55 //无信号值
|
||||
|
||||
|
||||
|
||||
int setup_lc6600(struct lc6600_param *pparam){
|
||||
int n_read;
|
||||
char *read_ok;
|
||||
char str[30];
|
||||
|
||||
uart_write(ROUTE_UART, "AT+CFUN=0\r");
|
||||
n_read = uart_read(ROUTE_UART, _rx_data);
|
||||
read_ok = strstr(_rx_data,"OK");
|
||||
if(read_ok == NULL){
|
||||
printf("can not exce AT+CFUN=0");
|
||||
}
|
||||
sleep(1);
|
||||
//password
|
||||
sprintf(str,"AT^DAPI=%d\r",pparam->password);
|
||||
uart_write(ROUTE_UART, str);
|
||||
printf("%s\n",str);
|
||||
n_read = uart_read(ROUTE_UART, _rx_data);
|
||||
read_ok = strstr(_rx_data,"OK");
|
||||
if(read_ok == NULL){
|
||||
printf("can not exce AT^DAPI");
|
||||
}
|
||||
sleep(1);
|
||||
// 1 center 2 station
|
||||
sprintf(str,"AT^DDTC=%d\r",pparam->ap_sta);
|
||||
uart_write(ROUTE_UART, str);
|
||||
printf("%s\n",str);
|
||||
n_read = uart_read(ROUTE_UART, _rx_data);
|
||||
read_ok = strstr(_rx_data,"OK");
|
||||
if(read_ok == NULL){
|
||||
printf("can not exce AT^DDTC");
|
||||
}
|
||||
sleep(1);
|
||||
|
||||
// sprintf(str,"AT^DDTC=%d\r",pparam->ap_sta);
|
||||
uart_write(ROUTE_UART, "AT^DSTC=2\r");
|
||||
printf("AT^DSTC\n");
|
||||
n_read = uart_read(ROUTE_UART, _rx_data);
|
||||
read_ok = strstr(_rx_data,"OK");
|
||||
if(read_ok == NULL){
|
||||
printf("can not exce AT^DDSTC");
|
||||
}
|
||||
sleep(1);
|
||||
|
||||
|
||||
// 2 5M 3 10M 4 15M 5 20M "25" dbm
|
||||
sprintf(str,"AT^DRPS=,%d,\"%d\"\r",pparam->bw,pparam->power);
|
||||
uart_write(ROUTE_UART, str);
|
||||
printf("%s\n",str);
|
||||
n_read = uart_read(ROUTE_UART, _rx_data);
|
||||
read_ok = strstr(_rx_data,"OK");
|
||||
if(read_ok == NULL){
|
||||
printf("can not exce AT^DRPS\n");
|
||||
}
|
||||
sleep(1);
|
||||
// 01 800M 04 1.4G 08 2.4G
|
||||
sprintf(str,"AT^DAOCNDI=0%d\r",pparam->freq);
|
||||
uart_write(ROUTE_UART, str);
|
||||
printf("%s\n",str);
|
||||
n_read = uart_read(ROUTE_UART, _rx_data);
|
||||
read_ok = strstr(_rx_data,"OK");
|
||||
if(read_ok == NULL){
|
||||
printf("can not exce AT^DAOCNDI\n");
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
|
||||
|
||||
sprintf(str,"AT^NETIFCFG=2,\"192.168.2.%d\"\r",pparam->ip);
|
||||
uart_write(ROUTE_UART, str);
|
||||
printf("%s\n",str);
|
||||
n_read = uart_read(ROUTE_UART, _rx_data);
|
||||
read_ok = strstr(_rx_data,"OK");
|
||||
if(read_ok == NULL){
|
||||
printf("can not exce AT^DAOCNDI\n");
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
|
||||
uart_write(ROUTE_UART, "AT+CFUN=1\r");
|
||||
n_read = uart_read(ROUTE_UART, _rx_data);
|
||||
read_ok = strstr(_rx_data,"OK");
|
||||
if(read_ok == NULL){
|
||||
printf("can not exce AT+CFUN=1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
static long elapsed_ms(struct timeval *start, struct timeval *end)
|
||||
{
|
||||
return (end->tv_sec - start->tv_sec) * 1000L
|
||||
+ (end->tv_usec - start->tv_usec) / 1000L;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
int get_rx1_freq(char *rx1){
|
||||
|
||||
char *s1;
|
||||
char *s2;
|
||||
char *s3;
|
||||
char *s4;
|
||||
int len;
|
||||
int i;
|
||||
|
||||
s1=strchr(rx1,',');
|
||||
s2=strchr(s1+1,',');
|
||||
s3=strchr(s2+1,',');
|
||||
s4=strchr(s3+1,',');
|
||||
|
||||
len= s2-s1-1;
|
||||
|
||||
for(i=0;i<len;i++){
|
||||
freq1[i] = *(s1+1+i);
|
||||
}
|
||||
printf("freq %s\n",freq1);
|
||||
|
||||
len=s4-s3-1-2; //"-44"
|
||||
|
||||
for(i=0;i<len;i++){
|
||||
dbm1[i]=*(s3+2+i);
|
||||
}
|
||||
printf("dbm1 %s\n",dbm1);
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
int get_rx1_dbm(char *rx1){
|
||||
|
||||
char *s1;
|
||||
char *s2;
|
||||
char *s3;
|
||||
char *s4;
|
||||
int len;
|
||||
int i;
|
||||
|
||||
s1=strchr(rx1,',');
|
||||
s2=strchr(s1+1,',');
|
||||
s3=strchr(s2+1,',');
|
||||
s4=strchr(s3+1,',');
|
||||
|
||||
len= s2-s1-1;
|
||||
|
||||
for(i=0;i<len;i++){
|
||||
freq1[i] = *(s1+1+i);
|
||||
}
|
||||
//printf("freq %s\n",freq1);
|
||||
|
||||
len=s3-s2-1-2; //"-44"
|
||||
|
||||
for(i=0;i<len;i++){
|
||||
dbm1[i]=*(s2+2+i);
|
||||
}
|
||||
printf("dbm1 %s\n",dbm1);
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
int get_rx2_dbm(char *rx1){
|
||||
|
||||
char *s1;
|
||||
char *s2;
|
||||
char *s3;
|
||||
char *s4;
|
||||
int len;
|
||||
int i;
|
||||
|
||||
s1=strchr(rx1,',');
|
||||
s2=strchr(s1+1,',');
|
||||
s3=strchr(s2+1,',');
|
||||
s4=strchr(s3+1,',');
|
||||
|
||||
len= s2-s1-1;
|
||||
|
||||
for(i=0;i<len;i++){
|
||||
freq1[i] = *(s1+1+i);
|
||||
}
|
||||
printf("freq %s\n",freq1);
|
||||
|
||||
len=s3-s2-1-2; //"-44"
|
||||
|
||||
for(i=0;i<len;i++){
|
||||
dbm2[i]=*(s2+2+i);
|
||||
}
|
||||
printf("dbm2 %s\n",dbm2);
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int get_rx2_freq(char *rx2){
|
||||
|
||||
char *s1;
|
||||
char *s2;
|
||||
char *s3;
|
||||
char *s4;
|
||||
int len;
|
||||
int i;
|
||||
|
||||
s1=strchr(rx2,',');
|
||||
s2=strchr(s1+1,',');
|
||||
s3=strchr(s2+1,',');
|
||||
s4=strchr(s3+1,',');
|
||||
|
||||
len= s2-s1-1;
|
||||
|
||||
for(i=0;i<len;i++){
|
||||
freq2[i] = *(s1+1+i);
|
||||
}
|
||||
printf("freq %s\n",freq2);
|
||||
|
||||
len=s4-s3-1-2; //"-44"
|
||||
|
||||
for(i=0;i<len;i++){
|
||||
dbm2[i]=*(s3+2+i);
|
||||
}
|
||||
printf("dbm1 %s\n",dbm1);
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
int n_read;
|
||||
int i;
|
||||
struct lc6600_param lc6600;
|
||||
|
||||
char buffer[1024];
|
||||
char rssi1[3];
|
||||
char rssi2[3];
|
||||
//char ip[15];
|
||||
char index[1];
|
||||
//char *rx1;
|
||||
//char *rx2;
|
||||
//int rssi1;
|
||||
//int rssi2;
|
||||
int dbm1;
|
||||
int dbm2;
|
||||
char *ip_str;
|
||||
//char *ip_str1;
|
||||
|
||||
char *buffer_freq;
|
||||
char freq_str[6];
|
||||
int freq;
|
||||
int fq;
|
||||
|
||||
int fd_param;
|
||||
int *buffer_param;
|
||||
|
||||
struct timeval tv_rx1 = {0, 0}, tv_rx2 = {0, 0}, tv_now;
|
||||
|
||||
int ip_len;
|
||||
int len;
|
||||
n_read = uart_init(ROUTE_UART, "/dev/ttyAMA2", 115200, 'N');
|
||||
if(n_read <=0 ) {
|
||||
printf("open /dev/ttyAMA2 failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
lc6600.ap_sta = atoi(argv[1]);
|
||||
|
||||
|
||||
|
||||
fd_param = shm_open("/param.txt",O_RDWR|O_CREAT|O_EXCL,0777);
|
||||
if(fd_param < 0){
|
||||
fd_param = shm_open("/param.txt",O_RDWR,0777);
|
||||
}else
|
||||
ftruncate(fd_param,4096);
|
||||
buffer_param= mmap(NULL,4096,PROT_READ|PROT_WRITE,MAP_SHARED,fd_param,0);
|
||||
|
||||
#if 1
|
||||
uart_write(ROUTE_UART, "AT^DRPS?\r");
|
||||
n_read = uart_read(ROUTE_UART, _rx_data);
|
||||
printf("%s\n",_rx_data);
|
||||
if(n_read>0){
|
||||
buffer_freq=strstr(_rx_data,"^DRPS:");
|
||||
memcpy(freq_str,buffer_freq+6,6);
|
||||
|
||||
printf("drps : %s\n",freq_str);
|
||||
freq = atoi(freq_str);
|
||||
|
||||
printf("freq %d \n",freq);
|
||||
buffer_param[3]=freq;
|
||||
}else{
|
||||
printf("no freq\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
//freq=atoi(argv[3]);
|
||||
// buffer_param[0] = 0x55;
|
||||
//buffer_param[3] = 14300;
|
||||
if(lc6600.ap_sta == 1){
|
||||
uart_write(ROUTE_UART, "AT^DAPR=1\r");
|
||||
// n_read = uart_read(ROUTE_UART, _rx_data);
|
||||
// printf("%s\n",_rx_data);
|
||||
|
||||
|
||||
while(1){
|
||||
|
||||
gettimeofday(&tv_now, NULL);
|
||||
|
||||
if (tv_rx1.tv_sec == 0 || elapsed_ms(&tv_rx1, &tv_now) > RSSI_TIMEOUT_MS) {
|
||||
buffer_param[1] = RSSI_NO_SIGNAL;
|
||||
printf("rx1 no signal timeout\n");
|
||||
}
|
||||
|
||||
if (tv_rx2.tv_sec == 0 || elapsed_ms(&tv_rx2, &tv_now) > RSSI_TIMEOUT_MS) {
|
||||
buffer_param[2] = RSSI_NO_SIGNAL;
|
||||
printf("rx2 no signal timeout\n");
|
||||
}
|
||||
|
||||
|
||||
n_read = uart_read(ROUTE_UART, _rx_data);
|
||||
|
||||
printf("%s\n",_rx_data);
|
||||
|
||||
#if 1
|
||||
if(n_read > 10){
|
||||
|
||||
//ip_str=strstr(_rx_data,argv[2]);
|
||||
//ip_str=strstr(_rx_data,"192.168.1.15");
|
||||
//ip_len = strlen(ip_str);
|
||||
//printf("ip_str %d \n ",ip_len);
|
||||
ip_str=strstr(_rx_data,argv[2]);
|
||||
ip_len = strlen(argv[2]);
|
||||
if(ip_str){
|
||||
//buffer_param[0] = 0x55;
|
||||
//printf("ip_str %s \n ",ip_str);
|
||||
memcpy(index,ip_str+(ip_len+2),1);
|
||||
//printf("index %s \n ",index);
|
||||
|
||||
if(strcmp(index, "1") == 0){
|
||||
memcpy(rssi1,ip_str+(ip_len+5),3);
|
||||
dbm1 = atoi(rssi1);
|
||||
printf("++dbm1:%d\n",dbm1);
|
||||
buffer_param[1] = dbm1;
|
||||
gettimeofday(&tv_rx1, NULL);
|
||||
}
|
||||
|
||||
if(strcmp(index, "2") == 0){
|
||||
memcpy(rssi2,ip_str+(ip_len+5),3);
|
||||
dbm2 = atoi(rssi2);
|
||||
printf("++dbm2:%d\n",dbm2);
|
||||
buffer_param[2] = dbm2;
|
||||
gettimeofday(&tv_rx2, NULL);
|
||||
}
|
||||
|
||||
}else{
|
||||
printf("no signal\n");
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
printf("no \n");
|
||||
uart_write(ROUTE_UART, "AT^DAPR=1\r");
|
||||
// buffer_param[0] = 0xAA;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -800,7 +800,7 @@ if((port == 20000) && (strcmp(fSubsession.mediumName(), "audio") == 0)){
|
||||
|
||||
#endif
|
||||
|
||||
#if 1 //luzhi save.h265
|
||||
#if 0 //luzhi save.h265
|
||||
FILE *fp1 = fopen("save.h265","a+b");
|
||||
if(fp1){
|
||||
fwrite(fReceiveBuffer,frameSize+4,1,fp1);
|
||||
|
||||
@@ -97,7 +97,7 @@ int get_parameter(struct decoce_param *pparam)
|
||||
printf("config file parse filed!\n");
|
||||
return -1;
|
||||
}
|
||||
pparam->light = get_conf_int("light", 0);
|
||||
pparam->light = get_conf_int("light", 1200);
|
||||
//pparam->osd_on = get_conf_int("osd_on", 0);
|
||||
printf("light %d \n",pparam->light);
|
||||
return 0;
|
||||
|
||||
@@ -0,0 +1,404 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h> // gettimeofday
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <errno.h>
|
||||
#include <time.h> /* 新增:clock_gettime / clock_nanosleep */
|
||||
#include <pthread.h>
|
||||
#include "serial.h"
|
||||
#include "uartinf.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#define RECV_PORT 12000 // UDP接收端口
|
||||
#define SEND_PORT 12001 // 发送端口(UART转NET)
|
||||
|
||||
/* ===================== 网络帧协议定义 ===================== */
|
||||
#define NET_FRAME_LEN 32 /* 收/发报文固定长度 */
|
||||
#define NET_TAIL 0xBB /* 帧尾 */
|
||||
|
||||
#define PAYLOAD_LEN 30 /* 帧长度 byte0..29 */
|
||||
#define BYTE_MODE 30 /* 接收帧 mode 字段偏移(0-4) */
|
||||
#define BYTE_TAIL 31 /* 接收帧帧尾偏移 */
|
||||
|
||||
#define CHECKSUM_END 30 /* 校验和覆盖 byte0..byte30(含) */
|
||||
#define NET_FRAME_MAX_LEN 256 /* recvfrom 缓冲大小 */
|
||||
|
||||
#define BYTE_NOSIG0 25 /* byte25 = 视频流0无信号标志(1=无信号,0=有信号) */
|
||||
#define BYTE_NOSIG1 26 /* byte26 = 视频流1无信号标志(1=无信号,0=有信号) */
|
||||
#define BYTE_RSSI1 28 /* 信号包=RSSI1;设备包=哨兵 */
|
||||
#define BYTE_RSSI2 29 /* 信号包=RSSI2;设备包=哨兵 */
|
||||
#define SIG_MARK 0x5A /* 设备包 byte28/29 哨兵值 */
|
||||
#define SIGNAL_INTERVAL_MS 100 /* 独立信号包发送间隔(ms) */
|
||||
#define FRAME_HEAD 0x11 /* 上行帧帧头(byte0),面板校验要求 */
|
||||
#define FRAME_TAIL 0x22 /* 上行帧帧尾(byte30),面板校验要求 */
|
||||
#define FRAME_HEAD_TX 0xAA /* 下行帧帧头(byte0),设备→面板 */
|
||||
|
||||
|
||||
/* ===================== 共享内存 ===================== */
|
||||
#define SHM_MSG_NAME "/video_switch"
|
||||
#define SHM_MODE_IDX 0 /* switch_mode -> shm[0](即 switch_video[0]) */
|
||||
|
||||
|
||||
static int *shm_msg = NULL;
|
||||
static int *buffer_param = NULL; /* 新增:/param.txt 共享内存,供信号线程读 RSSI */
|
||||
|
||||
char _rx_data[200];
|
||||
|
||||
|
||||
static int socket_descriptor;
|
||||
static struct sockaddr_in address;
|
||||
|
||||
bool first = false;
|
||||
|
||||
int socket_descriptor_recv;
|
||||
struct sockaddr_in address_recv;
|
||||
pthread_attr_t attr;
|
||||
pthread_t pkts_thread;
|
||||
|
||||
/* 打开共享内存 /param.txt(由 lc6600_uart 进程写入 RSSI) */
|
||||
static int *param_memory_open(void) {
|
||||
int fd = shm_open("/param.txt", O_RDWR, 0777);
|
||||
if (fd < 0) {
|
||||
fd = shm_open("/param.txt", O_RDWR | O_CREAT, 0777);
|
||||
if (fd < 0) { perror("shm_open /param.txt"); return NULL; }
|
||||
if (ftruncate(fd, 4096) == -1) { perror("ftruncate /param.txt"); return NULL; }
|
||||
}
|
||||
int *retval = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (retval == MAP_FAILED) { perror("mmap /param.txt"); return NULL; }
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
static int *switch_memory_open(void) {
|
||||
char buf[128];
|
||||
int fd;
|
||||
sprintf(buf, SHM_MSG_NAME);
|
||||
fd = shm_open(buf, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
|
||||
if(fd < 0) { perror("shm_open"); exit(1); }
|
||||
if (ftruncate(fd, 4096) == -1) { perror("ftruncate"); exit(1); }
|
||||
int *retval = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
int init_net_recv(int port){
|
||||
|
||||
int i;
|
||||
struct timeval tv;
|
||||
|
||||
bzero(&address_recv,sizeof(struct sockaddr_in));
|
||||
address_recv.sin_family=AF_INET;
|
||||
address_recv.sin_addr.s_addr=htonl(INADDR_ANY);
|
||||
address_recv.sin_port=htons(port);
|
||||
|
||||
socket_descriptor_recv=socket(AF_INET,SOCK_DGRAM,0);//IPV4
|
||||
|
||||
tv.tv_sec = 2;
|
||||
tv.tv_usec = 0;
|
||||
if (setsockopt(socket_descriptor_recv, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) {
|
||||
printf("socket option SO_RCVTIMEO not support\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (bind(socket_descriptor_recv, (struct sockaddr *)&address_recv, sizeof(struct sockaddr_in)) < 0)
|
||||
{
|
||||
perror("bind");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int udp_init(char *ip, int port){
|
||||
|
||||
|
||||
bzero(&address,sizeof(address));
|
||||
address.sin_family=AF_INET;
|
||||
address.sin_addr.s_addr=inet_addr(ip);
|
||||
address.sin_port=htons(port);
|
||||
|
||||
|
||||
socket_descriptor=socket(AF_INET,SOCK_DGRAM,0);//IPV4
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
void *net_recv(void *arg)
|
||||
{
|
||||
int i;
|
||||
struct sockaddr_in clientAddr;
|
||||
int len = sizeof(clientAddr);
|
||||
int ret;
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 5;
|
||||
tv.tv_usec = 0;
|
||||
if (setsockopt(socket_descriptor_recv, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) {
|
||||
printf("socket option SO_RCVTIMEO not support\n");
|
||||
//return -1;
|
||||
}
|
||||
|
||||
char buffer_cmd[200];
|
||||
while(1){
|
||||
i = recvfrom(socket_descriptor_recv, buffer_cmd, 200, 0, (struct sockaddr*)&clientAddr, &len);
|
||||
if(i>0){
|
||||
uart_write_len(ROUTE_UART,buffer_cmd,i);
|
||||
}
|
||||
else{
|
||||
printf(" time_out to receive data\n");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#if 1
|
||||
void *net_recv(void *arg)
|
||||
{
|
||||
int i, k;
|
||||
struct sockaddr_in clientAddr;
|
||||
socklen_t len;
|
||||
struct timeval tv;
|
||||
|
||||
char buffer_cmd[NET_FRAME_MAX_LEN];
|
||||
char frame_out[NET_FRAME_MAX_LEN];
|
||||
int sum;
|
||||
unsigned char checksum;
|
||||
|
||||
tv.tv_sec = 5;
|
||||
tv.tv_usec = 0;
|
||||
if (setsockopt(socket_descriptor_recv, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0)
|
||||
printf("socket option SO_RCVTIMEO not support\n");
|
||||
|
||||
while (1) {
|
||||
len = sizeof(clientAddr); /* 每次循环重置,recvfrom 会改写 len */
|
||||
i = recvfrom(socket_descriptor_recv, buffer_cmd, NET_FRAME_MAX_LEN, 0,
|
||||
(struct sockaddr*)&clientAddr, &len);
|
||||
if (i <= 0) {
|
||||
printf(" time_out to receive data\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i != NET_FRAME_LEN) {
|
||||
printf("bad frame len=%d\n", i);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* 帧尾校验 */
|
||||
if ((unsigned char)buffer_cmd[BYTE_TAIL] != NET_TAIL) {
|
||||
printf("bad tail=%02x\n", (unsigned char)buffer_cmd[BYTE_TAIL]);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* 解析 mode -> 写共享内存 */
|
||||
if (shm_msg) {
|
||||
static int last_mode = -1;
|
||||
int mode = (unsigned char)buffer_cmd[BYTE_MODE];
|
||||
|
||||
if (mode <= 4) {
|
||||
if (mode != last_mode) {
|
||||
shm_msg[SHM_MODE_IDX] = mode; //写入共享内存 viode_switch
|
||||
last_mode = mode;
|
||||
printf("write shm: mode=%d\n", mode);
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("filed mode=%d\n", mode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* 构造下行帧:byte0=0xAA 帧头,byte1..29 原样,byte30=0xBB 帧尾 */
|
||||
frame_out[0] = FRAME_HEAD_TX; /* [0] 帧头 0xAA */
|
||||
memcpy(frame_out + 1, buffer_cmd + 1, PAYLOAD_LEN - 1); /* [1..29] 原样 */
|
||||
frame_out[PAYLOAD_LEN] = NET_TAIL; /* [30] 帧尾 0xBB */
|
||||
|
||||
/* 校验和 = byte0..byte30 求和取低8位,写入 byte31 */
|
||||
sum = 0;
|
||||
for (k = 0; k <= CHECKSUM_END; k++)
|
||||
sum += (unsigned char)frame_out[k];
|
||||
checksum = sum & 0xFF;
|
||||
frame_out[PAYLOAD_LEN + 1] = checksum; /* [31] 校验和 */
|
||||
|
||||
|
||||
#if 0
|
||||
/* 打印发出的包 */
|
||||
printf(" send to uart %d bytes:", NET_FRAME_LEN);
|
||||
for (k = 0; k < NET_FRAME_LEN; k++)
|
||||
printf(" %02x", (unsigned char)frame_out[k]);
|
||||
printf("\n");
|
||||
#endif
|
||||
|
||||
uart_write_len(ROUTE_UART, frame_out, NET_FRAME_LEN); //发送给串口
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* 独立信号包线程:与串口收包完全解耦,固定 SIGNAL_INTERVAL_MS 周期发送。
|
||||
* 用绝对时间 clock_nanosleep 对齐发送时刻,避免 sendto/printf 开销累积成漂移。 */
|
||||
void *signal_send(void *arg)
|
||||
{
|
||||
char sig_frame[NET_FRAME_LEN];
|
||||
struct timespec next;
|
||||
int k, sum;
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &next);
|
||||
|
||||
while (1) {
|
||||
memset(sig_frame, 0, NET_FRAME_LEN);
|
||||
sig_frame[0] = (char)FRAME_HEAD; /* byte0 = 0x11 */
|
||||
|
||||
/* byte25/26 = 视频流0/1无信号,byte27 = 布局开关(light_pwm_lvds 的 0x68 按键) */
|
||||
sig_frame[BYTE_NOSIG0] = (shm_msg && shm_msg[2] == 0x55) ? 1 : 0;
|
||||
sig_frame[BYTE_NOSIG1] = (shm_msg && shm_msg[3] == 0x55) ? 1 : 0;
|
||||
sig_frame[27] = (shm_msg && shm_msg[1]) ? 1 : 0;
|
||||
printf("layout byte27 = %d\n", sig_frame[27]);
|
||||
|
||||
if (buffer_param) {
|
||||
sig_frame[BYTE_RSSI1] = (char)buffer_param[1];
|
||||
sig_frame[BYTE_RSSI2] = (char)buffer_param[2];
|
||||
}
|
||||
sig_frame[PAYLOAD_LEN] = (char)FRAME_TAIL; /* byte30 = 0x22 */
|
||||
|
||||
sum = 0;
|
||||
for (k = 0; k <= CHECKSUM_END; k++)
|
||||
sum += (unsigned char)sig_frame[k];
|
||||
sig_frame[CHECKSUM_END + 1] = (char)(sum & 0xFF);
|
||||
|
||||
sendto(socket_descriptor, sig_frame, NET_FRAME_LEN, 0,
|
||||
(struct sockaddr *)&address, sizeof(address));
|
||||
|
||||
/* 下一个发送时刻 = 本次时刻 + 周期,与实际执行耗时无关 */
|
||||
next.tv_nsec += (long)SIGNAL_INTERVAL_MS * 1000000L;
|
||||
while (next.tv_nsec >= 1000000000L) {
|
||||
next.tv_sec++;
|
||||
next.tv_nsec -= 1000000000L;
|
||||
}
|
||||
clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &next, NULL);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
int pthread_init()
|
||||
{
|
||||
int ret;
|
||||
pthread_t sig_thread;
|
||||
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
||||
ret = pthread_create(&pkts_thread, &attr, net_recv, NULL);
|
||||
|
||||
if(ret){
|
||||
printf("create pthread1 error\n");
|
||||
pthread_attr_destroy(&attr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = pthread_create(&sig_thread, &attr, signal_send, NULL);
|
||||
if(ret){
|
||||
printf("create pthread2 error\n");
|
||||
pthread_attr_destroy(&attr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
pthread_attr_destroy(&attr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
int n_read;
|
||||
int i;
|
||||
int count=0;
|
||||
|
||||
char buffer_send[100];
|
||||
int buffer_len;
|
||||
|
||||
n_read = uart_init(ROUTE_UART, "/dev/ttyAMA4", 115200, 'N');
|
||||
if(n_read <=0 ) {
|
||||
printf("open /dev/ttyAMA4 failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// udp_init(argv[1], atoi(argv[2]));
|
||||
// init_net_recv(atoi(argv[3]));
|
||||
udp_init("127.0.0.1", SEND_PORT); // 发送目标:本机回环 12001
|
||||
init_net_recv(RECV_PORT); // 接收:0.0.0.0:12000(INADDR_ANY)
|
||||
|
||||
|
||||
shm_msg = switch_memory_open();
|
||||
buffer_param = param_memory_open();
|
||||
|
||||
if (pthread_init()) {
|
||||
printf("pthread_init failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
while(1){
|
||||
n_read = uart_read(ROUTE_UART, _rx_data);
|
||||
if(n_read > 0 ){
|
||||
int k, sum = 0;
|
||||
|
||||
/* 收包校验:完整 32 字节帧,帧头 0x11、帧尾 0x22、byte31 校验和正确,否则丢弃 */
|
||||
if (n_read < NET_FRAME_LEN) {
|
||||
printf("drop bad frame: len=%d\n", n_read);
|
||||
continue;
|
||||
}
|
||||
if ((unsigned char)_rx_data[0] != FRAME_HEAD ||
|
||||
(unsigned char)_rx_data[CHECKSUM_END] != FRAME_TAIL) {
|
||||
printf("drop bad frame: head=%02x tail=%02x\n",
|
||||
(unsigned char)_rx_data[0], (unsigned char)_rx_data[CHECKSUM_END]);
|
||||
continue;
|
||||
}
|
||||
for (k = 0; k <= CHECKSUM_END; k++)
|
||||
sum += (unsigned char)_rx_data[k];
|
||||
if ((unsigned char)_rx_data[31] != (sum & 0xFF)) {
|
||||
printf("drop bad frame: checksum=%02x expect=%02x\n",
|
||||
(unsigned char)_rx_data[31], (unsigned char)(sum & 0xFF));
|
||||
continue;
|
||||
}
|
||||
|
||||
/* byte28/29 固定哨兵值,RSSI 改由独立信号包承载 */
|
||||
_rx_data[BYTE_RSSI1] = (char)SIG_MARK;
|
||||
_rx_data[BYTE_RSSI2] = (char)SIG_MARK;
|
||||
|
||||
|
||||
/* 和校验:byte0..byte30 求和取低 8 位,写入 byte31 */
|
||||
sum = 0;
|
||||
for (k = 0; k <= CHECKSUM_END; k++)
|
||||
sum += (unsigned char)_rx_data[k];
|
||||
_rx_data[31] = (char)(sum & 0xFF);
|
||||
|
||||
sendto(socket_descriptor, _rx_data, NET_FRAME_LEN, 0, (struct sockaddr *)&address, sizeof(address));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -48,16 +48,25 @@
|
||||
#define REF_NUM 2
|
||||
#define DISPLAY_NUM 2
|
||||
|
||||
#if 0
|
||||
|
||||
/*占位图要求:1920*1200 NV21 不压缩 yuv图片
|
||||
*生成命令:ffmpeg -i nosignal.png -vf scale=1920:1200 -pix_fmt nv21 -f rawvideo nosignal.yuv*/
|
||||
#define NOSIGNAL_YUV_PATH "./nosignal.yuv"
|
||||
|
||||
static ot_video_frame_info g_nosignal_src; /* 1920x1200 源图(VGS 输入) */
|
||||
static ot_vb_pool g_nosignal_src_pool = OT_VB_INVALID_POOL_ID;
|
||||
static ot_vb_blk g_nosignal_src_blk = OT_VB_INVALID_HANDLE;
|
||||
static td_bool g_nosignal_src_valid = TD_FALSE;
|
||||
/* 用户图片必须是"非压缩"帧,而公共池 0 是按 SEG 压缩模式算块大小的,
|
||||
* 装不下 1920x1200 YUV420 未压缩的 3.4MB,所以单独开一个非压缩公共池给它。 */
|
||||
#define NOSIGNAL_POOL_IDX 1
|
||||
#define NOSIGNAL_STRIDE OT_ALIGN_UP((td_u32)(STREAN_WIDTH), 16)
|
||||
#define NOSIGNAL_STRIDED_SIZE (((NOSIGNAL_STRIDE) * (STREAM_HEIGHT) * 3) / 2)
|
||||
#define NOSIGNAL_BLK_SIZE OT_ALIGN_UP((td_u32)(NOSIGNAL_STRIDED_SIZE), 0x100000)
|
||||
#define NOSIGNAL_CHN_NUM 2 /* 只有 chn 0-1 用占位图,其余通道断流时保持黑屏 */
|
||||
|
||||
static const td_bool g_nosignal_chn_enable[OT_VDEC_MAX_CHN_NUM] = { [0 ... (NOSIGNAL_CHN_NUM - 1)] = TD_TRUE };
|
||||
|
||||
static ot_video_frame_info g_nosignal_src; /* 1920x1200 占位图帧信息 */
|
||||
static ot_vb_blk g_nosignal_src_blk = OT_VB_INVALID_HANDLE;
|
||||
td_bool g_nosignal_src_valid = TD_FALSE; /* udp_get_nal_frame.c 里 extern 引用,不能加 static */
|
||||
td_bool g_nosignal_pic_set[OT_VDEC_MAX_CHN_NUM] = {TD_FALSE}; /* 每个通道占位图是否已 set 成功*/
|
||||
|
||||
#endif
|
||||
|
||||
static ot_vo_intf_sync g_intf_sync = OT_VO_OUT_3840x2160_30;
|
||||
|
||||
@@ -92,9 +101,6 @@ pthread_cond_t vid_au_cond;
|
||||
pthread_mutex_t vid_au_mutex;
|
||||
dqueue vid_au_q;
|
||||
|
||||
// static ot_vb_pool g_usrpic_pool = OT_VB_INVALID_POOL_ID;
|
||||
// static ot_video_frame_info g_usrpic_info;
|
||||
|
||||
|
||||
int do_exit_inner = 0;
|
||||
int vid_q_len = 0;
|
||||
@@ -224,9 +230,12 @@ static td_s32 sample_init_sys_and_vb(sample_vdec_attr *sample_vdec, td_u32 vdec_
|
||||
buf_attr.pixel_format = OT_PIXEL_FORMAT_YVU_SEMIPLANAR_420;
|
||||
|
||||
(td_void)memset_s(&vb_cfg, sizeof(ot_vb_cfg), 0, sizeof(ot_vb_cfg));
|
||||
vb_cfg.max_pool_cnt = 1;
|
||||
vb_cfg.max_pool_cnt = 2;
|
||||
vb_cfg.common_pool[0].blk_cnt = 10 * vdec_chn_num; /* 10:common vb cnt */
|
||||
vb_cfg.common_pool[0].blk_size = ot_common_get_pic_buf_size(&buf_attr);
|
||||
/* 1 号公共池:专给 nosignal 占位图用。块大小="未压缩原始图" */
|
||||
vb_cfg.common_pool[NOSIGNAL_POOL_IDX].blk_cnt = 2;
|
||||
vb_cfg.common_pool[NOSIGNAL_POOL_IDX].blk_size = NOSIGNAL_BLK_SIZE;
|
||||
ret = sample_comm_sys_init(&vb_cfg);
|
||||
if (ret != TD_SUCCESS) {
|
||||
sample_print("init sys fail for %#x!\n", ret);
|
||||
@@ -333,8 +342,6 @@ static td_s32 sample_start_vpss(ot_vpss_grp *vpss_grp, td_u32 vpss_grp_num, td_b
|
||||
vpss_chn_attr[1].depth = 0;
|
||||
vpss_chn_attr[1].mirror_en = TD_FALSE; //TD_TRUE; //180
|
||||
vpss_chn_attr[1].flip_en = TD_FALSE; //TD_TRUE; //180
|
||||
// vpss_chn_attr[1].mirror_en = TD_TRUE; //TD_TRUE; //180
|
||||
// vpss_chn_attr[1].flip_en = TD_TRUE; //TD_TRUE; //180
|
||||
vpss_chn_attr[1].border_en = TD_FALSE;
|
||||
vpss_chn_attr[1].aspect_ratio.mode = OT_ASPECT_RATIO_NONE;
|
||||
}
|
||||
@@ -567,119 +574,129 @@ static td_s32 sample_start_vdec(sample_vdec_attr *sample_vdec, td_u32 vdec_chn_n
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
/* ==================== no-signal 占位图 ==================== */
|
||||
|
||||
/* 启动时调用:读源图 nosignal.yuv(1920x1200) 到 VB,填成 user pic frame_info */
|
||||
|
||||
td_s32 load_nosignal_src(void)
|
||||
{
|
||||
td_u32 width = STREAN_WIDTH; /* 1920 */
|
||||
td_u32 height = STREAM_HEIGHT; /* 1200 */
|
||||
td_u32 stride = OT_ALIGN_UP(width, 16);
|
||||
td_u32 y_size = stride * height;
|
||||
td_u32 frame_size = y_size * 3 / 2;
|
||||
td_u32 file_size = width * height * 3 / 2;
|
||||
td_u32 width = STREAN_WIDTH;
|
||||
td_u32 height = STREAM_HEIGHT;
|
||||
td_u32 stride = NOSIGNAL_STRIDE;
|
||||
td_u32 y_size = stride * height ;
|
||||
td_u32 pic_size = NOSIGNAL_STRIDED_SIZE; /* 3456000 图像实际占用 */
|
||||
|
||||
td_phys_addr_t phys;
|
||||
td_u8 *virt = TD_NULL;
|
||||
td_u8 *file_buf = TD_NULL;
|
||||
td_u32 i;
|
||||
FILE *fp;
|
||||
ot_vb_pool_cfg pool_cfg = {0};
|
||||
|
||||
/* 建池 */
|
||||
pool_cfg.blk_size = frame_size;
|
||||
pool_cfg.blk_cnt = 1;
|
||||
pool_cfg.remap_mode = OT_VB_REMAP_MODE_NONE;
|
||||
g_nosignal_src_pool = ss_mpi_vb_create_pool(&pool_cfg);
|
||||
if (g_nosignal_src_pool == OT_VB_INVALID_POOL_ID) {
|
||||
printf("[nosignal] create src pool fail\n");
|
||||
return TD_FAILURE;
|
||||
}
|
||||
g_nosignal_src_blk = ss_mpi_vb_get_blk(g_nosignal_src_pool, frame_size, TD_NULL);
|
||||
/* 从专建的非压缩公共池取块 */
|
||||
g_nosignal_src_blk = ss_mpi_vb_get_blk(NOSIGNAL_POOL_IDX, pic_size, TD_NULL);
|
||||
if (g_nosignal_src_blk == OT_VB_INVALID_HANDLE) {
|
||||
printf("[nosignal] get src blk fail\n");
|
||||
printf("[nosignal] get vb blk fail(need %u bytes), nosignal disabled\n", pic_size);
|
||||
return TD_FAILURE;
|
||||
}
|
||||
|
||||
phys = ss_mpi_vb_handle_to_phys_addr(g_nosignal_src_blk);
|
||||
virt = (td_u8 *)ss_mpi_sys_mmap(phys, frame_size);
|
||||
virt = (td_u8 *)ss_mpi_sys_mmap(phys, pic_size);
|
||||
if (virt == TD_NULL) {
|
||||
printf("[nosignal] mmap src fail\n");
|
||||
return TD_FAILURE;
|
||||
}
|
||||
memset(virt, 0, pic_size);
|
||||
|
||||
/* 读源图 */
|
||||
fp = fopen(NOSIGNAL_YUV_PATH, "rb");
|
||||
if (fp == TD_NULL) {
|
||||
printf("[nosignal] open %s fail\n", NOSIGNAL_YUV_PATH);
|
||||
printf("[nosignal] open %s fail (当前工作目录里没有该文件!)\n", NOSIGNAL_YUV_PATH);
|
||||
return TD_FAILURE;
|
||||
}
|
||||
file_buf = (td_u8 *)malloc(file_size);
|
||||
if (file_buf == TD_NULL || fread(file_buf, 1, file_size, fp) != file_size) {
|
||||
file_buf = (td_u8 *)malloc(pic_size);
|
||||
if (file_buf == TD_NULL || fread(file_buf, 1, pic_size, fp) != pic_size) {
|
||||
fclose(fp);
|
||||
printf("[nosignal] read %s fail\n", NOSIGNAL_YUV_PATH);
|
||||
printf("[nosignal] read %s fail (need %u bytes, %ux%u YUV420SP)\n",
|
||||
NOSIGNAL_YUV_PATH, pic_size, width, height);
|
||||
return TD_FAILURE;
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
/* 按行拷贝处理 stride 对齐:Y 平面 + VU 交错平面 */
|
||||
for (i = 0; i < height; i++) {
|
||||
for (i = 0; i < height; i++) { /* Y 平面 */
|
||||
memcpy(virt + i * stride, file_buf + i * width, width);
|
||||
}
|
||||
{
|
||||
td_u8 *vu_dst = virt + y_size;
|
||||
td_u8 *vu_src = file_buf + width * height;
|
||||
for (i = 0; i < height / 2; i++) {
|
||||
memcpy(vu_dst + i * stride, vu_src + i * width, width);
|
||||
}
|
||||
for (i = 0; i < height / 2; i++) { /* VU 交错平面 */
|
||||
memcpy(virt + y_size + i * stride, file_buf + width * height + i * width, width);
|
||||
}
|
||||
free(file_buf);
|
||||
|
||||
/* 填源图 frame_info(VGS 输入) */
|
||||
memset(&g_nosignal_src, 0, sizeof(g_nosignal_src));
|
||||
g_nosignal_src.video_frame.field = OT_VIDEO_FIELD_FRAME;
|
||||
g_nosignal_src.video_frame.width = width;
|
||||
g_nosignal_src.video_frame.height = height;
|
||||
g_nosignal_src.video_frame.pixel_format = OT_PIXEL_FORMAT_YVU_SEMIPLANAR_420;
|
||||
g_nosignal_src.video_frame.video_format = OT_VIDEO_FORMAT_LINEAR;
|
||||
g_nosignal_src.video_frame.compress_mode = OT_COMPRESS_MODE_NONE;
|
||||
g_nosignal_src.video_frame.stride[0] = stride;
|
||||
g_nosignal_src.video_frame.stride[1] = stride;
|
||||
g_nosignal_src.video_frame.phys_addr[0] = phys;
|
||||
g_nosignal_src.video_frame.phys_addr[1] = phys + y_size;
|
||||
g_nosignal_src.video_frame.virt_addr[0] = virt;
|
||||
g_nosignal_src.video_frame.virt_addr[1] = virt + y_size;
|
||||
g_nosignal_src.pool_id = ss_mpi_vb_handle_to_pool_id(g_nosignal_src_blk);
|
||||
g_nosignal_src.mod_id = OT_ID_VDEC;
|
||||
g_nosignal_src_valid = TD_TRUE;
|
||||
g_nosignal_src.video_frame.pixel_format = OT_PIXEL_FORMAT_YVU_SEMIPLANAR_420; /* 8bit 420 */
|
||||
g_nosignal_src.video_frame.video_format = OT_VIDEO_FORMAT_LINEAR; /* 只支持 Linear */
|
||||
g_nosignal_src.video_frame.compress_mode = OT_COMPRESS_MODE_NONE; /* 不压缩 */
|
||||
g_nosignal_src.video_frame.dynamic_range = OT_DYNAMIC_RANGE_SDR8; /* 8bit */
|
||||
g_nosignal_src.video_frame.color_gamut = OT_COLOR_GAMUT_BT601;
|
||||
g_nosignal_src.video_frame.pts = 0; /* PTS 统一 0 */
|
||||
|
||||
printf("[nosignal] load src %ux%u ok, stride=%u, pool_id=%u, mod_id=%d\n",
|
||||
width, height, stride, g_nosignal_src.pool_id, g_nosignal_src.mod_id);
|
||||
g_nosignal_src.video_frame.stride[0] = stride;
|
||||
g_nosignal_src.video_frame.stride[1] = stride;
|
||||
|
||||
g_nosignal_src.video_frame.phys_addr[0] = phys;
|
||||
g_nosignal_src.video_frame.virt_addr[0] = virt;
|
||||
g_nosignal_src.video_frame.phys_addr[1] = phys + y_size;
|
||||
g_nosignal_src.video_frame.virt_addr[1] = virt + y_size;
|
||||
|
||||
g_nosignal_src.pool_id = ss_mpi_vb_handle_to_pool_id(g_nosignal_src_blk);
|
||||
g_nosignal_src.mod_id = OT_ID_USER; /* 必须是 USER,vdec_set_nosignal_userpic() */
|
||||
g_nosignal_src_valid = TD_TRUE;
|
||||
|
||||
printf(" load [nosignal] ok\n");
|
||||
return TD_SUCCESS;
|
||||
}
|
||||
|
||||
/* 停流后 set user pic(共享源图,无需缩放) */
|
||||
/* 设置用户图片 */
|
||||
td_s32 vdec_set_nosignal_userpic(ot_vdec_chn chn)
|
||||
{
|
||||
printf("[nosignal] pic: w=%u h=%u field=%d pix=%d vidfmt=%d comp=%d dr=%d cg=%d "
|
||||
"stride0=%u stride1=%u pool=%u mod=%d phys0=%#llx phys1=%#llx\n",
|
||||
g_nosignal_src.video_frame.width,
|
||||
g_nosignal_src.video_frame.height,
|
||||
g_nosignal_src.video_frame.field,
|
||||
g_nosignal_src.video_frame.pixel_format,
|
||||
g_nosignal_src.video_frame.video_format,
|
||||
g_nosignal_src.video_frame.compress_mode,
|
||||
g_nosignal_src.video_frame.dynamic_range,
|
||||
g_nosignal_src.video_frame.color_gamut,
|
||||
g_nosignal_src.video_frame.stride[0],
|
||||
g_nosignal_src.video_frame.stride[1],
|
||||
g_nosignal_src.pool_id,
|
||||
g_nosignal_src.mod_id,
|
||||
(unsigned long long)g_nosignal_src.video_frame.phys_addr[0],
|
||||
(unsigned long long)g_nosignal_src.video_frame.phys_addr[1]);
|
||||
td_s32 ret;
|
||||
|
||||
td_s32 ret = ss_mpi_vdec_set_user_pic(chn, &g_nosignal_src);
|
||||
printf("[nosignal] chn%d set_user_pic ret=%#x\n", chn, ret);
|
||||
ss_mpi_vdec_disable_user_pic(chn);
|
||||
ret = ss_mpi_vdec_set_user_pic(chn, &g_nosignal_src);
|
||||
if (ret != TD_SUCCESS) {
|
||||
printf("[nosignal] chn%d set_user_pic fail ret=%#x\n", chn, ret);
|
||||
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* 断流时调用:停流 -> (启动时没 set 成功补 set) -> enable 显示占位图。
|
||||
* 返回 enable_user_pic 的结果,决定超时是否重试。 */
|
||||
td_s32 vdec_enable_nosignal_pic(ot_vdec_chn chn)
|
||||
{
|
||||
td_s32 ret;
|
||||
|
||||
if (g_nosignal_chn_enable[chn] != TD_TRUE) {
|
||||
return TD_FAILURE; /* 该通道不使用占位图,直接返回,不碰通道状态 */
|
||||
}
|
||||
|
||||
ss_mpi_vdec_stop_recv_stream(chn); /*pic 只在停止接收码流时显示 */
|
||||
ss_mpi_vdec_disable_user_pic(chn);
|
||||
|
||||
if (g_nosignal_pic_set[chn] != TD_TRUE) {
|
||||
|
||||
ret = vdec_set_nosignal_userpic(chn);
|
||||
if (ret != TD_SUCCESS) {
|
||||
ss_mpi_vdec_start_recv_stream(chn); /*if set 不成功重新收流 */
|
||||
return ret;
|
||||
}
|
||||
g_nosignal_pic_set[chn] = TD_TRUE;
|
||||
}
|
||||
|
||||
ret = ss_mpi_vdec_enable_user_pic(chn, 1);
|
||||
if (ret != TD_SUCCESS) {
|
||||
printf("[nosignal] chn%d enable_user_pic fail ret=%#x\n", chn, ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -717,10 +734,24 @@ void* h265_vdec_vpss_vo()
|
||||
goto stop_sys;
|
||||
}
|
||||
|
||||
/* 新增:启动读源图并 set user pic(set 前必须先 disable) */
|
||||
// if (load_nosignal_src() != TD_SUCCESS) {
|
||||
// printf("[nosignal] load src fail, nosignal disabled\n");
|
||||
// }
|
||||
/* 启动时把用户图片 set 好,运行只做 enable/disable 切换 */
|
||||
if (load_nosignal_src() != TD_SUCCESS) {
|
||||
printf("[nosignal] load src fail, nosignal disabled\n");
|
||||
} else {
|
||||
for (i = 0; i < vdec_chn_num; i++) {
|
||||
if (g_nosignal_chn_enable[i] != TD_TRUE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ss_mpi_vdec_disable_user_pic(i);
|
||||
if (vdec_set_nosignal_userpic(i) == TD_SUCCESS) {
|
||||
g_nosignal_pic_set[i] = TD_TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
printf("[nosignal] setup done\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/************************************************
|
||||
|
||||
@@ -26,8 +26,7 @@
|
||||
|
||||
#include "sample_comm.h"
|
||||
|
||||
// extern td_s32 vdec_set_nosignal_userpic(ot_vdec_chn chn);
|
||||
|
||||
extern td_bool g_nosignal_src_valid;
|
||||
|
||||
|
||||
int port = 20000;
|
||||
@@ -81,7 +80,7 @@ int init_net(){
|
||||
|
||||
socket_descriptor[i]=socket(AF_INET,SOCK_DGRAM,0);//IPV4
|
||||
|
||||
tv.tv_sec = 4;
|
||||
tv.tv_sec = 2;
|
||||
tv.tv_usec = 0;
|
||||
if (setsockopt(socket_descriptor[i], SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) {
|
||||
printf("socket option SO_RCVTIMEO not support\n");
|
||||
@@ -116,9 +115,6 @@ void assemble_nal1(unsigned char* buf, unsigned int len)
|
||||
need_sumbit = 0;
|
||||
terminate = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
if((!memcmp(buf, nal_header , 4)) && (len >= 4)) { //is seperator
|
||||
if(wr_idx == 0) { // is new nal item
|
||||
memcpy(nal_buf_entry1[nalb_idx].buf + wr_idx, buf, len);
|
||||
@@ -160,10 +156,6 @@ void assemble_nal1(unsigned char* buf, unsigned int len)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
void *net_recv1(void *arg)
|
||||
{
|
||||
int i;
|
||||
@@ -171,103 +163,43 @@ void *net_recv1(void *arg)
|
||||
int len = sizeof(clientAddr);
|
||||
unsigned char buf[2048];
|
||||
static int count_time_out=0;
|
||||
static int nosignal_on = 0; //nosignal satuts
|
||||
static int nosignal_on = 0; //nosignal satuts
|
||||
ot_vdec_stream stream;
|
||||
int ret;
|
||||
|
||||
while(1){
|
||||
i = recvfrom(socket_descriptor[0],buf, 1472, 0, (struct sockaddr*)&clientAddr, &len);
|
||||
if(i>0){
|
||||
switch_video[2] = 0xAA;
|
||||
if (nosignal_on == 1) {
|
||||
ss_mpi_vdec_disable_user_pic(0);
|
||||
ss_mpi_vdec_start_recv_stream(0);
|
||||
nosignal_on = 0;
|
||||
while(1){
|
||||
i = recvfrom(socket_descriptor[0],buf, 1472, 0, (struct sockaddr*)&clientAddr, &len);
|
||||
if(i>0){
|
||||
switch_video[2] = 0xAA;
|
||||
if (nosignal_on == 1) {
|
||||
/* 恢复拉流:先撤占位图,再重新开始收流 */
|
||||
ret = ss_mpi_vdec_disable_user_pic(0);
|
||||
if (ret != TD_SUCCESS) {
|
||||
printf("[nosignal] chn0 disable_user_pic fail ret=%#x\n", ret);
|
||||
}
|
||||
|
||||
#if 0
|
||||
stream.pts = 0;
|
||||
stream.addr = buf;
|
||||
stream.len = i;
|
||||
stream.end_of_frame = TD_FALSE;
|
||||
stream.end_of_stream = TD_FALSE;
|
||||
stream.need_display = 1;
|
||||
|
||||
|
||||
do {
|
||||
ret = ss_mpi_vdec_send_stream(0, &stream, 0);
|
||||
// usleep(1000);
|
||||
} while (ret != TD_SUCCESS);
|
||||
|
||||
#endif
|
||||
assemble_nal1(buf,i);
|
||||
|
||||
}
|
||||
if(i<=0){
|
||||
if (nosignal_on == 0) {
|
||||
ss_mpi_vdec_stop_recv_stream(0);
|
||||
ss_mpi_vdec_enable_user_pic(0, 1); /* 延迟插入 */
|
||||
nosignal_on = 1;
|
||||
}
|
||||
switch_video[2] = 0x55;
|
||||
printf("net1 recv timeout %d\n",i);
|
||||
}
|
||||
ret = ss_mpi_vdec_start_recv_stream(0);
|
||||
if (ret != TD_SUCCESS) {
|
||||
printf("[nosignal] chn0 start_recv fail ret=%#x\n", ret);
|
||||
}
|
||||
nosignal_on = 0;
|
||||
}
|
||||
assemble_nal1(buf,i);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if(i<=0){
|
||||
if (nosignal_on == 0 && g_nosignal_src_valid) {
|
||||
/* 断流:显示占位图(停流/set/enable 都在里面做),失败下轮超时重试 */
|
||||
if (vdec_enable_nosignal_pic(0) == TD_SUCCESS) {
|
||||
printf(" set [nosignal] on chn0 ...ok\n");
|
||||
nosignal_on = 1;
|
||||
}
|
||||
}
|
||||
switch_video[2] = 0x55;
|
||||
printf("net1 recv timeout %d\n",i);
|
||||
}
|
||||
}
|
||||
|
||||
void *net_recv1(void *arg)
|
||||
{
|
||||
int i;
|
||||
struct sockaddr_in clientAddr;
|
||||
int len = sizeof(clientAddr);
|
||||
unsigned char buf[2048];
|
||||
static int count_time_out=0;
|
||||
// static int nosignal_on = 0; //nosignal satuts
|
||||
ot_vdec_stream stream;
|
||||
int ret;
|
||||
|
||||
while(1){
|
||||
i = recvfrom(socket_descriptor[0],buf, 1472, 0, (struct sockaddr*)&clientAddr, &len);
|
||||
if(i>0){
|
||||
switch_video[2] = 0xAA;
|
||||
// if (nosignal_on == 1) {
|
||||
// ret = ss_mpi_vdec_disable_user_pic(0);
|
||||
// printf("[nosignal] disable_user_pic ret=%#x\n", ret);
|
||||
// ret = ss_mpi_vdec_start_recv_stream(0);
|
||||
// printf("[nosignal] start_recv_stream ret=%#x\n", ret);
|
||||
// nosignal_on = 0;
|
||||
// printf("[nosignal] -> back to normal decode\n");
|
||||
// }
|
||||
|
||||
#if 0
|
||||
stream.pts = 0;
|
||||
stream.addr = buf;
|
||||
stream.len = i;
|
||||
stream.end_of_frame = TD_FALSE;
|
||||
stream.end_of_stream = TD_FALSE;
|
||||
stream.need_display = 1;
|
||||
|
||||
do {
|
||||
ret = ss_mpi_vdec_send_stream(0, &stream, 0);
|
||||
// usleep(1000);
|
||||
} while (ret != TD_SUCCESS);
|
||||
#endif
|
||||
assemble_nal1(buf,i);
|
||||
}
|
||||
if(i<=0){
|
||||
// if (nosignal_on == 0) {
|
||||
// ss_mpi_vdec_stop_recv_stream(0);
|
||||
// ss_mpi_vdec_disable_user_pic(0); /* 文档:set 前先 disable */
|
||||
// vdec_set_nosignal_userpic(0); /* 通道已停,此时 set 才合法 */
|
||||
// ss_mpi_vdec_enable_user_pic(0, 1); /* 立即显示占位图 */
|
||||
// nosignal_on = 1;
|
||||
// }
|
||||
switch_video[2] = 0x55;
|
||||
printf("net1 recv timeout %d\n",i);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -348,12 +280,28 @@ void *net_recv2(void *arg)
|
||||
int len = sizeof(clientAddr);
|
||||
unsigned char buf[2048];
|
||||
static int count_time_out=0;
|
||||
static int nosignal_on = 0;
|
||||
ot_vdec_stream stream;
|
||||
int ret;
|
||||
while(1){
|
||||
i = recvfrom(socket_descriptor[1],buf, 1472, 0, (struct sockaddr*)&clientAddr, &len);
|
||||
if(i>0){
|
||||
switch_video[3] = 0xAA;
|
||||
|
||||
if (nosignal_on == 1) {
|
||||
/* 恢复拉流:先撤占位图,再重新开始收流 */
|
||||
ret = ss_mpi_vdec_disable_user_pic(1);
|
||||
if (ret != TD_SUCCESS) {
|
||||
printf("[nosignal] chn1 disable_user_pic fail ret=%#x\n", ret);
|
||||
}
|
||||
ret = ss_mpi_vdec_start_recv_stream(1);
|
||||
if (ret != TD_SUCCESS) {
|
||||
printf("[nosignal] chn1 start_recv fail ret=%#x\n", ret);
|
||||
}
|
||||
nosignal_on = 0;
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
stream.pts = 0;
|
||||
stream.addr = buf;
|
||||
@@ -378,6 +326,15 @@ void *net_recv2(void *arg)
|
||||
//count_time_out++;
|
||||
//if(count_time_out >=1){
|
||||
switch_video[3] = 0x55;
|
||||
|
||||
if (nosignal_on == 0 && g_nosignal_src_valid) {
|
||||
/* 断流:显示占位图(停流/set/enable 都在里面做),失败下轮超时重试 */
|
||||
if (vdec_enable_nosignal_pic(1) == TD_SUCCESS) {
|
||||
printf(" set [nosignal] on chn1 ...ok\n");
|
||||
nosignal_on = 1;
|
||||
}
|
||||
}
|
||||
|
||||
printf("net2 recv timeout %d\n",i);
|
||||
// count_time_out =0;
|
||||
//}
|
||||
@@ -460,6 +417,7 @@ void *net_recv3(void *arg)
|
||||
int len = sizeof(clientAddr);
|
||||
unsigned char buf[2048];
|
||||
static int count_time_out=0;
|
||||
static int nosignal_on = 0; //nosignal satuts
|
||||
ot_vdec_stream stream;
|
||||
int ret;
|
||||
|
||||
@@ -468,6 +426,19 @@ void *net_recv3(void *arg)
|
||||
i = recvfrom(socket_descriptor[2],buf, 1472, 0, (struct sockaddr*)&clientAddr, &len);
|
||||
if(i>0){
|
||||
switch_video[4] = 0xAA;
|
||||
if (nosignal_on == 1) {
|
||||
/* 恢复拉流:先撤占位图,再重新开始收流 */
|
||||
ret = ss_mpi_vdec_disable_user_pic(2);
|
||||
if (ret != TD_SUCCESS) {
|
||||
printf("[nosignal] chn2 disable_user_pic fail ret=%#x\n", ret);
|
||||
}
|
||||
ret = ss_mpi_vdec_start_recv_stream(2);
|
||||
if (ret != TD_SUCCESS) {
|
||||
printf("[nosignal] chn2 start_recv fail ret=%#x\n", ret);
|
||||
}
|
||||
nosignal_on = 0;
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
stream.pts = 0;
|
||||
@@ -491,6 +462,15 @@ void *net_recv3(void *arg)
|
||||
//count_time_out++;
|
||||
//if(count_time_out >=1){
|
||||
switch_video[4] = 0x55;
|
||||
if (nosignal_on == 0 && g_nosignal_src_valid) {
|
||||
/* 断流:显示占位图(停流/set/enable 都在里面做),失败下轮超时重试 */
|
||||
if (vdec_enable_nosignal_pic(2) == TD_SUCCESS) {
|
||||
printf(" set [nosignal] on chn2 ...ok\n");
|
||||
nosignal_on = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
printf("net3 recv timeout %d\n",i);
|
||||
// count_time_out =0;
|
||||
//}
|
||||
@@ -573,6 +553,7 @@ void *net_recv4(void *arg)
|
||||
int len = sizeof(clientAddr);
|
||||
unsigned char buf[2048];
|
||||
static int count_time_out=0;
|
||||
static int nosignal_on = 0; //nosignal satuts
|
||||
ot_vdec_stream stream;
|
||||
int ret;
|
||||
|
||||
@@ -581,6 +562,20 @@ void *net_recv4(void *arg)
|
||||
i = recvfrom(socket_descriptor[3],buf, 1472, 0, (struct sockaddr*)&clientAddr, &len);
|
||||
if(i>0){
|
||||
switch_video[5] = 0xAA;
|
||||
|
||||
if (nosignal_on == 1) {
|
||||
/* 恢复拉流:先撤占位图,再重新开始收流 */
|
||||
ret = ss_mpi_vdec_disable_user_pic(3);
|
||||
if (ret != TD_SUCCESS) {
|
||||
printf("[nosignal] chn3 disable_user_pic fail ret=%#x\n", ret);
|
||||
}
|
||||
ret = ss_mpi_vdec_start_recv_stream(3);
|
||||
if (ret != TD_SUCCESS) {
|
||||
printf("[nosignal] chn3 start_recv fail ret=%#x\n", ret);
|
||||
}
|
||||
nosignal_on = 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
stream.pts = 0;
|
||||
stream.addr = buf;
|
||||
@@ -601,6 +596,14 @@ void *net_recv4(void *arg)
|
||||
// printf(" recv4 timeout %d\n",i);
|
||||
//count_time_out++;
|
||||
//if(count_time_out >=2){
|
||||
if (nosignal_on == 0 && g_nosignal_src_valid) {
|
||||
/* 断流:显示占位图(停流/set/enable 都在里面做),失败下轮超时重试 */
|
||||
if (vdec_enable_nosignal_pic(3) == TD_SUCCESS) {
|
||||
printf(" set [nosignal] on chn3 ...ok\n");
|
||||
nosignal_on = 1;
|
||||
}
|
||||
}
|
||||
|
||||
switch_video[5] = 0x55;
|
||||
printf("net4 recv timeout %d\n",i);
|
||||
// count_time_out =0;
|
||||
@@ -662,8 +665,6 @@ void assemble_nal5(unsigned char* buf, unsigned int len)
|
||||
} while (ret != TD_SUCCESS);
|
||||
|
||||
|
||||
|
||||
|
||||
wr_idx = 0;
|
||||
nalb_idx = (nalb_idx+1)%NUM_NAL_BUF;
|
||||
}
|
||||
@@ -689,6 +690,7 @@ void *net_recv5(void *arg)
|
||||
int len = sizeof(clientAddr);
|
||||
unsigned char buf[2048];
|
||||
static int count_time_out=0;
|
||||
static int nosignal_on = 0; //nosignal satuts
|
||||
ot_vdec_stream stream;
|
||||
int ret;
|
||||
|
||||
@@ -698,6 +700,20 @@ void *net_recv5(void *arg)
|
||||
i = recvfrom(socket_descriptor[4],buf, 1472, 0, (struct sockaddr*)&clientAddr, &len);
|
||||
if(i>0){
|
||||
switch_video[6] = 0xAA;
|
||||
|
||||
if (nosignal_on == 1) {
|
||||
/* 恢复拉流:先撤占位图,再重新开始收流 */
|
||||
ret = ss_mpi_vdec_disable_user_pic(4);
|
||||
if (ret != TD_SUCCESS) {
|
||||
printf("[nosignal] chn4 disable_user_pic fail ret=%#x\n", ret);
|
||||
}
|
||||
ret = ss_mpi_vdec_start_recv_stream(4);
|
||||
if (ret != TD_SUCCESS) {
|
||||
printf("[nosignal] chn4 start_recv fail ret=%#x\n", ret);
|
||||
}
|
||||
nosignal_on = 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
stream.pts = 0;
|
||||
stream.addr = buf;
|
||||
@@ -720,6 +736,15 @@ void *net_recv5(void *arg)
|
||||
// printf(" recv4 timeout %d\n",i);
|
||||
//count_time_out++;
|
||||
//if(count_time_out >=2){
|
||||
|
||||
if (nosignal_on == 0 && g_nosignal_src_valid) {
|
||||
/* 断流:显示占位图(停流/set/enable 都在里面做),失败下轮超时重试 */
|
||||
if (vdec_enable_nosignal_pic(4) == TD_SUCCESS) {
|
||||
printf(" set [nosignal] on chn4 ...ok\n");
|
||||
nosignal_on = 1;
|
||||
}
|
||||
}
|
||||
|
||||
switch_video[6] = 0x55;
|
||||
printf("net5 recv timeout %d\n",i);
|
||||
count_time_out =0;
|
||||
@@ -805,6 +830,7 @@ void *net_recv6(void *arg)
|
||||
int len = sizeof(clientAddr);
|
||||
unsigned char buf[2048];
|
||||
static int count_time_out=0;
|
||||
static int nosignal_on = 0; //nosignal satuts
|
||||
ot_vdec_stream stream;
|
||||
int ret;
|
||||
|
||||
@@ -812,6 +838,20 @@ void *net_recv6(void *arg)
|
||||
i = recvfrom(socket_descriptor[5],buf, 1472, 0, (struct sockaddr*)&clientAddr, &len);
|
||||
if(i>0){
|
||||
switch_video[7] = 0xAA;
|
||||
if (nosignal_on == 1) {
|
||||
/* 恢复拉流:先撤占位图,再重新开始收流 */
|
||||
ret = ss_mpi_vdec_disable_user_pic(5);
|
||||
if (ret != TD_SUCCESS) {
|
||||
printf("[nosignal] chn5 disable_user_pic fail ret=%#x\n", ret);
|
||||
}
|
||||
ret = ss_mpi_vdec_start_recv_stream(5);
|
||||
if (ret != TD_SUCCESS) {
|
||||
printf("[nosignal] chn5 start_recv fail ret=%#x\n", ret);
|
||||
}
|
||||
nosignal_on = 0;
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
stream.pts = 0;
|
||||
stream.addr = buf;
|
||||
@@ -834,6 +874,14 @@ void *net_recv6(void *arg)
|
||||
// printf(" recv4 timeout %d\n",i);
|
||||
//count_time_out++;
|
||||
//if(count_time_out >=2){
|
||||
if (nosignal_on == 0 && g_nosignal_src_valid) {
|
||||
/* 断流:显示占位图(停流/set/enable 都在里面做),失败下轮超时重试 */
|
||||
if (vdec_enable_nosignal_pic(5) == TD_SUCCESS) {
|
||||
printf(" set [nosignal] on chn5 ...ok\n");
|
||||
nosignal_on = 1;
|
||||
}
|
||||
}
|
||||
|
||||
switch_video[7] = 0x55;
|
||||
printf("net6 recv timeout %d\n",i);
|
||||
// count_time_out =0;
|
||||
@@ -918,6 +966,7 @@ void *net_recv7(void *arg)
|
||||
int len = sizeof(clientAddr);
|
||||
unsigned char buf[2048];
|
||||
static int count_time_out=0;
|
||||
static int nosignal_on = 0; //nosignal satuts
|
||||
ot_vdec_stream stream;
|
||||
int ret;
|
||||
|
||||
@@ -925,6 +974,19 @@ void *net_recv7(void *arg)
|
||||
i = recvfrom(socket_descriptor[6],buf, 1472, 0, (struct sockaddr*)&clientAddr, &len);
|
||||
if(i>0){
|
||||
switch_video[8] = 0xAA;
|
||||
if (nosignal_on == 1) {
|
||||
/* 恢复拉流:先撤占位图,再重新开始收流 */
|
||||
ret = ss_mpi_vdec_disable_user_pic(6);
|
||||
if (ret != TD_SUCCESS) {
|
||||
printf("[nosignal] chn6 disable_user_pic fail ret=%#x\n", ret);
|
||||
}
|
||||
ret = ss_mpi_vdec_start_recv_stream(6);
|
||||
if (ret != TD_SUCCESS) {
|
||||
printf("[nosignal] chn6 start_recv fail ret=%#x\n", ret);
|
||||
}
|
||||
nosignal_on = 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
stream.pts = 0;
|
||||
stream.addr = buf;
|
||||
@@ -945,7 +1007,15 @@ void *net_recv7(void *arg)
|
||||
// printf(" recv4 timeout %d\n",i);
|
||||
//count_time_out++;
|
||||
//if(count_time_out >=2){
|
||||
if (nosignal_on == 0 && g_nosignal_src_valid) {
|
||||
/* 断流:显示占位图(停流/set/enable 都在里面做),失败下轮超时重试 */
|
||||
if (vdec_enable_nosignal_pic(6) == TD_SUCCESS) {
|
||||
printf(" set [nosignal] on chn6 ...ok\n");
|
||||
nosignal_on = 1;
|
||||
}
|
||||
}
|
||||
switch_video[8] = 0x55;
|
||||
|
||||
printf("net7 recv timeout %d\n",i);
|
||||
// count_time_out =0;
|
||||
//}
|
||||
@@ -1031,6 +1101,7 @@ void *net_recv8(void *arg)
|
||||
int len = sizeof(clientAddr);
|
||||
unsigned char buf[2048];
|
||||
static int count_time_out=0;
|
||||
static int nosignal_on = 0; //nosignal satuts
|
||||
ot_vdec_stream stream;
|
||||
int ret;
|
||||
|
||||
@@ -1038,6 +1109,20 @@ void *net_recv8(void *arg)
|
||||
i = recvfrom(socket_descriptor[7],buf, 1472, 0, (struct sockaddr*)&clientAddr, &len);
|
||||
if(i>0){
|
||||
switch_video[9] = 0xAA;
|
||||
if (nosignal_on == 1) {
|
||||
/* 恢复拉流:先撤占位图,再重新开始收流 */
|
||||
ret = ss_mpi_vdec_disable_user_pic(7);
|
||||
if (ret != TD_SUCCESS) {
|
||||
printf("[nosignal] chn7 disable_user_pic fail ret=%#x\n", ret);
|
||||
}
|
||||
ret = ss_mpi_vdec_start_recv_stream(7);
|
||||
if (ret != TD_SUCCESS) {
|
||||
printf("[nosignal] chn7 start_recv fail ret=%#x\n", ret);
|
||||
}
|
||||
nosignal_on = 0;
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
stream.pts = 0;
|
||||
stream.addr = buf;
|
||||
@@ -1057,6 +1142,14 @@ void *net_recv8(void *arg)
|
||||
if(i<=0){
|
||||
// count_time_out++;
|
||||
// if(count_time_out >=2){
|
||||
if (nosignal_on == 0 && g_nosignal_src_valid) {
|
||||
/* 断流:显示占位图(停流/set/enable 都在里面做),失败下轮超时重试 */
|
||||
if (vdec_enable_nosignal_pic(7) == TD_SUCCESS) {
|
||||
printf(" set [nosignal] on chn6 ...ok\n");
|
||||
nosignal_on = 1;
|
||||
}
|
||||
}
|
||||
|
||||
switch_video[9] = 0x55;
|
||||
// printf("net8 recv timeout %d\n",i);
|
||||
// count_time_out =0;
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user