海思hi3516dv300一些配置

2024-05-31 17:48
文章标签 配置 海思 hi3516dv300

本文主要是介绍海思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 123int maxlen = 1024;                                     //check our buffersint i;                                                 // misc var iunsigned char msg[48] = {010, 0, 0, 0, 0, 0, 0, 0, 0}; // the packet we sendunsigned long buf[maxlen];                             // the buffer we get back//struct in_addr ipaddr;        //struct protoent *proto; //struct sockaddr_in server_addr;int s;     // socketlong 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 backstruct 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 timetmit = 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);elsemonStr = "0" + std::to_string(mon);if (day >= 10)dayStr = std::to_string(day);elsedayStr = "0" + std::to_string(day);if (hour >= 10)hourStr = std::to_string(hour);elsehourStr = "0" + std::to_string(hour);if (min >= 10)minStr = std::to_string(min);elseminStr = "0" + std::to_string(min);if (sec >= 10)secStr = std::to_string(sec);elsesecStr = "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一些配置的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1018618

相关文章

IDEA中配置Tomcat全过程

《IDEA中配置Tomcat全过程》文章介绍了在IDEA中配置Tomcat的六步流程,包括添加服务器、配置部署选项、设置应用服务器及启动,并提及Maven依赖可能因约定大于配置导致问题,需检查依赖版本... 目录第一步第二步第三步第四步第五步第六步总结第一步选择这个方框第二步选择+号,找到Tomca

Win10安装Maven与环境变量配置过程

《Win10安装Maven与环境变量配置过程》本文介绍Maven的安装与配置方法,涵盖下载、环境变量设置、本地仓库及镜像配置,指导如何在IDEA中正确配置Maven,适用于Java及其他语言项目的构建... 目录Maven 是什么?一、下载二、安装三、配置环境四、验证测试五、配置本地仓库六、配置国内镜像地址

SpringBoot多环境配置数据读取方式

《SpringBoot多环境配置数据读取方式》SpringBoot通过环境隔离机制,支持properties/yaml/yml多格式配置,结合@Value、Environment和@Configura... 目录一、多环境配置的核心思路二、3种配置文件格式详解2.1 properties格式(传统格式)1.

Debian系和Redhat系防火墙配置方式

《Debian系和Redhat系防火墙配置方式》文章对比了Debian系UFW和Redhat系Firewalld防火墙的安装、启用禁用、端口管理、规则查看及注意事项,强调SSH端口需开放、规则持久化,... 目录Debian系UFW防火墙1. 安装2. 启用与禁用3. 基本命令4. 注意事项5. 示例配置R

PyCharm中配置PyQt的实现步骤

《PyCharm中配置PyQt的实现步骤》PyCharm是JetBrains推出的一款强大的PythonIDE,结合PyQt可以进行pythion高效开发桌面GUI应用程序,本文就来介绍一下PyCha... 目录1. 安装China编程PyQt1.PyQt 核心组件2. 基础 PyQt 应用程序结构3. 使用 Q

Redis MCP 安装与配置指南

《RedisMCP安装与配置指南》本文将详细介绍如何安装和配置RedisMCP,包括快速启动、源码安装、Docker安装、以及相关的配置参数和环境变量设置,感兴趣的朋友一起看看吧... 目录一、Redis MCP 简介二、安www.chinasem.cn装 Redis MCP 服务2.1 快速启动(推荐)2.

Spring Boot配置和使用两个数据源的实现步骤

《SpringBoot配置和使用两个数据源的实现步骤》本文详解SpringBoot配置双数据源方法,包含配置文件设置、Bean创建、事务管理器配置及@Qualifier注解使用,强调主数据源标记、代... 目录Spring Boot配置和使用两个数据源技术背景实现步骤1. 配置数据源信息2. 创建数据源Be

Spring Boot Maven 插件如何构建可执行 JAR 的核心配置

《SpringBootMaven插件如何构建可执行JAR的核心配置》SpringBoot核心Maven插件,用于生成可执行JAR/WAR,内置服务器简化部署,支持热部署、多环境配置及依赖管理... 目录前言一、插件的核心功能与目标1.1 插件的定位1.2 插件的 Goals(目标)1.3 插件定位1.4 核

RabbitMQ消息总线方式刷新配置服务全过程

《RabbitMQ消息总线方式刷新配置服务全过程》SpringCloudBus通过消息总线与MQ实现微服务配置统一刷新,结合GitWebhooks自动触发更新,避免手动重启,提升效率与可靠性,适用于配... 目录前言介绍环境准备代码示例测试验证总结前言介绍在微服务架构中,为了更方便的向微服务实例广播消息,

nginx 负载均衡配置及如何解决重复登录问题

《nginx负载均衡配置及如何解决重复登录问题》文章详解Nginx源码安装与Docker部署,介绍四层/七层代理区别及负载均衡策略,通过ip_hash解决重复登录问题,对nginx负载均衡配置及如何... 目录一:源码安装:1.配置编译参数2.编译3.编译安装 二,四层代理和七层代理区别1.二者混合使用举例