海思hi3516dv300一些配置

1. 网络配置

嵌入式设备网络一般都是自己配置的,hi3516的网络配置在/etc/init.d/rcS 这个文件中。
在这里插入图片描述这是他的初始化配置。

但是网络ping 百度还是ping不通,是因为dns服务器没有配置。
配置DNS后,测试可以正常ping 通域名。

2.DNS配置

在/etc下添加resolv.conf文件,并在文件中至少添加一个有效DNS服务器地址, 则域名访问成功。
在这里插入图片描述
内容如图所示。

3.开机同步网络时间

屁话不多说,直接上代码,调用ntpdate 函数就好,返回时间。

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <time.h>
#include <string.h>
int get_yue(char *secons);
void ntpdate();
#include <iostream>
using namespace std;

string getFormatTime(int year, int mon, int day, int hour, int min, int sec, int type);
void get_alarm_time();

int main()
{
    ntpdate();
    return 0;
}

void ntpdate()
{
    //char *hostname=(char *)"163.117.202.33";
    //char *hostname=(char *)"pool.ntp.br";
    char *hostname = (char *)"200.20.186.76";
    int portno = 123;                                      //NTP is port 123
    int maxlen = 1024;                                     //check our buffers
    int i;                                                 // misc var i
    unsigned char msg[48] = {010, 0, 0, 0, 0, 0, 0, 0, 0}; // the packet we send
    unsigned long buf[maxlen];                             // the buffer we get back
    //struct in_addr ipaddr;        //
    struct protoent *proto; //
    struct sockaddr_in server_addr;
    int s;     // socket
    long tmit; // the time -- This is a time_t sort of

    //use Socket;
    //
    //#we use the system call to open a UDP socket
    //socket(SOCKET, PF_INET, SOCK_DGRAM, getprotobyname("udp")) or die "socket: $!";
    proto = getprotobyname("udp");
    s = socket(PF_INET, SOCK_DGRAM, proto->p_proto);
    perror("socket");
    //
    //#convert hostname to ipaddress if needed
    //$ipaddr   = inet_aton($HOSTNAME);
    memset(&server_addr, 0, sizeof(server_addr));
    server_addr.sin_family = AF_INET;
    server_addr.sin_addr.s_addr = inet_addr(hostname);
    //argv[1] );
    //i   = inet_aton(hostname,&server_addr.sin_addr);
    server_addr.sin_port = htons(portno);
    //printf("ipaddr (in hex): %x\n",server_addr.sin_addr);

    /*
 * build a message.  Our message is all zeros except for a one in the
 * protocol version field
 * msg[] in binary is 00 001 000 00000000 
 * it should be a total of 48 bytes long
*/

    // send the data
    //printf("sending data..\n");
    i = sendto(s, msg, sizeof(msg), 0, (struct sockaddr *)&server_addr, sizeof(server_addr));
    perror("sendto");
    // get the data back
    struct sockaddr saddr;
    socklen_t saddr_l = sizeof(saddr);
    i = recvfrom(s, buf, 48, 0, &saddr, &saddr_l);
    perror("recvfr:");

    //We get 12 long words back in Network order
    /*
for(i=0;i<12;i++) {
    //printf("%d\t%-8x\n",i,ntohl(buf[i]));
    long tmit2=ntohl((time_t)buf[i]);
    std::cout << "Round number " << i << " time is " << ctime(&tmit2)  << std::endl;
}
*/
    /*
 * The high word of transmit time is the 10th word we get back
 * tmit is the time in seconds not accounting for network delays which
 * should be way less than a second if this is a local NTP server
 */

    //tmit=ntohl((time_t)buf[10]);    //# get transmit time
    tmit = ntohl((time_t)buf[4]); //# get transmit time是将一个无符号长整形数从网络字节顺序转换为主机字节顺序
    //printf("tmit=%d\n",tmit);

    /*
 * Convert time to unix standard time NTP is number of seconds since 0000
 * UT on 1 January 1900 unix time is seconds since 0000 UT on 1 January
 * 1970 There has been a trend to add a 2 leap seconds every 3 years.
 * Leap seconds are only an issue the last second of the month in June and
 * December if you don't try to set the clock then it can be ignored but
 * this is importaint to people who coordinate times with GPS clock sources.
 */

    tmit -= 2208988800U;
    //printf("tmit=%d\n",tmit);
    /* use unix library function to show me the local time (it takes care
 * of timezone issues for both north and south of the equator and places
 * that do Summer time/ Daylight savings time.
 */

    //#compare to system time
    //printf("Time: %s",ctime(&tmit));

    // 一月JAN
    // 二月FEB
    // 三月MAR
    // 四月APR
    // 五月MAY
    // 六月JUN
    // 七月JUL
    // 八月AUG
    // 九月SEP
    // 十月OCT
    // 十一月NOV
    // 十二月DEC
    //Thu Mar 19 05:43:42 2020
    //std::cout << "time is " << ctime(&tmit) << std::endl;
    char *gTime = ctime(&tmit);
    char time_str[32] = {0};
    char year[5] = {0};
    char secons[3] = {0};
    char day[3] = {0};
    char s1[3] = {0};
    char f[3] = {0};
    char m[3] = {0};
    int tmp = 0;
    //年
    year[0] = gTime[20];
    year[1] = gTime[21];
    year[2] = gTime[22];
    year[3] = gTime[23];
    //月
    secons[0] = gTime[4];
    secons[1] = gTime[5];
    secons[2] = gTime[6];
    get_yue(secons);
    printf("get_yue:%s\n", secons);
    //日
    day[0] = gTime[8];
    day[1] = gTime[9];
    //时
    s1[0] = gTime[11];
    s1[1] = gTime[12];
    tmp = atoi(s1);
    tmp += 8; //调整时区到东八区。
    if (tmp >= 24)
        tmp %= 24;
    sprintf(s1, "%d", tmp);
    //分
    f[0] = gTime[14];
    f[1] = gTime[15];
    //秒
    m[0] = gTime[17];
    m[1] = gTime[18];


    //date -s "2020-03-24 17:03:50"

    sprintf(time_str, "date -s  \"%s-%s-%s %s:%s:%s\"", year, secons, day, s1, f, m);

    printf("%s     -----%s\n", time_str, gTime);
    system(time_str);
}

int get_yue(char *secons)
{
    printf("secons %s\n", secons);
    int seconss = -1;
    if (strncmp(secons, "Jan", 3) == 0)
    {
        secons[0] = '0';
        secons[1] = '1';
    }
    else if (strncmp(secons, "Feb", 3) == 0)
    {
        secons[0] = '0';
        secons[1] = '2';
    }
    else if (strncmp(secons, "Mar", 3) == 0)
    {
        secons[0] = '0';
        secons[1] = '3';
    }
    else if (strncmp(secons, "Apr", 3) == 0)
    {
        secons[0] = '0';
        secons[1] = '4';
    }
    else if (strncmp(secons, "May", 3) == 0)
    {
        secons[0] = '0';
        secons[1] = '5';
    }
    else if (strncmp(secons, "Jun", 3) == 0)
    {
        secons[0] = '0';
        secons[1] = '6';
    }
    else if (strncmp(secons, "Jul", 3) == 0)
    {
        secons[0] = '0';
        secons[1] = '7';
    }
    else if (strncmp(secons, "Aug", 3) == 0)
    {
        secons[0] = '0';
        secons[1] = '8';
    }
    else if (strncmp(secons, "Sep", 3) == 0)
    {
        secons[0] = '0';
        secons[1] = '9';
    }
    else if (strncmp(secons, "Oct", 3) == 0)
    {
        secons[0] = '1';
        secons[1] = '0';
    }
    else if (strncmp(secons, "Nov", 3) == 0)
    {
        secons[0] = '1';
        secons[1] = '1';
    }
    else if (strncmp(secons, "Dec", 3) == 0)
    {
        secons[0] = '1';
        secons[1] = '2';
    }
    else
    {
        printf("Error!\n");
    }
    seconss = 1;
    secons[2] = 0;
    return seconss;
}

void get_alarm_time()
{
    time_t time_seconds = time(0);
    struct tm now_time;
    localtime_r(&time_seconds, &now_time);

    string alarmTimeAsName = getFormatTime(now_time.tm_year + 1900, now_time.tm_mon + 1, now_time.tm_mday, now_time.tm_hour, now_time.tm_min, now_time.tm_sec, 0);
    string alarmTimeAsDate = getFormatTime(now_time.tm_year + 1900, now_time.tm_mon + 1, now_time.tm_mday, now_time.tm_hour, now_time.tm_min, now_time.tm_sec, 1);
}

std::string getFormatTime(int year, int mon, int day, int hour, int min, int sec, int type)
{
    std::string yearStr = std::to_string(year);
    std::string monStr, dayStr, hourStr, minStr, secStr;
    if (mon >= 10)
        monStr = std::to_string(mon);
    else
        monStr = "0" + std::to_string(mon);
    if (day >= 10)
        dayStr = std::to_string(day);
    else
        dayStr = "0" + std::to_string(day);
    if (hour >= 10)
        hourStr = std::to_string(hour);
    else
        hourStr = "0" + std::to_string(hour);
    if (min >= 10)
        minStr = std::to_string(min);
    else
        minStr = "0" + std::to_string(min);
    if (sec >= 10)
        secStr = std::to_string(sec);
    else
        secStr = "0" + std::to_string(sec);

    if (!type)
        return (yearStr + monStr + dayStr + hourStr + minStr + secStr);
    if (type == 1)
        return (yearStr + "-" + monStr + "-" + dayStr + "%20" + hourStr + ":" + minStr + ":" + secStr);
}
海思hi3516dv300硬件设计用户指南是一本针对海思公司推出的hi3516dv300芯片的硬件设计的指导手册。该手册的目的是帮助用户了解hi3516dv300芯片的硬件设计要求和规范,并提供相关的设计指导和建议。 hi3516dv300芯片是一款高性能、低功耗的视频处理芯片,主要应用于视频监控、智能交通和安防等领域。硬件设计是确保芯片正常工作和发挥最佳性能的基础,因此对于使用hi3516dv300芯片的设计人员来说,掌握硬件设计指南是非常重要的。 在这本指南中,首先介绍了hi3516dv300芯片的主要特性和功能,包括处理能力、视频编解码、音频处理等。然后详细讲解了芯片的外部接口和引脚分配,包括视频输入、输出接口、音频接口、以太网接口等。同时,还对时钟、电源、存储器和外设等方面的设计进行了说明和建议。 此外,指南中还提供了关于PCB设计的一些建议,包括地域分布、信号电源分离、阻抗匹配、电磁兼容性等方面,帮助设计人员提高设计质量和可靠性。 总之,海思hi3516dv300硬件设计用户指南是一本重要的参考资料,它提供了关于hi3516dv300芯片硬件设计方面的详尽说明和建议,对于希望使用该芯片进行设计的用户来说是不可或缺的。通过认真阅读和遵循指南中的规范和要求,设计人员可以更好地实现hi3516dv300芯片的应用,提高产品的性能和可靠性。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

刘仕豪

IT发展快就是因为有开源精神

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值