Linux启动服务


chkconfig命令

查看当前开机启动项

# chkconfig --list

添加开机启动项

# chkconfig --add <service> 

删除开机启动项

# chkconfig --del <service> 

设置启动等级:

# chkconfig --level 2345 <service> on

启动服务

# chkconfig <service> on

关闭服务

# chkconfig <service> off

update-rc.d命令:

适用于Debian8

需要在/etc/init.d/目录下编写对应脚本文件,设置/删除服务实际上是将对应脚本复制到/etc/rcN.d/目录中。

删除自动启动服务:(所有级别)

# update-rc.d -f <basename> remove

设置启动服务:

# update-rc.d -f <basename> start  <order> <runlevels>

order - 启动顺序,主要用于设置相关联服务的先后顺序,可省略
runlevels - 运行级别 0~6,可取值为defaults

关闭服务:

# update-rc.d -f <basename> stop <order> <runlevels>

systemctl命令:
需要编写对应脚本放置在/lib/systemd/system目录中;

适用于Debian8(实际上调用update-rc.d)

使能自动启动服务:

# systemctl enable <basename>

关闭自动启动服务:

# systemctl disable <basename>

启动服务:

# systemctl start <basename>

停止服务:

# systemctl stop <basename>

- 阅读全文 -

SQLite数据库移植及应用


SQLite简介: SQLite是一个进程内的库,实现了自给自足的、无服务器的、零配置的、事务性的 SQL 数据库引擎。它是一个零配置的数据库,这意味着与其他数据库一样,您不需要在系统中配置。就像其他数据库,SQLite 引擎不是一个独立的进程,可以按应用程序需求进行静态或动态连接。SQLite 直接访问其存储文件。

参考文档: https://www.runoob.com/sqlite/sqlite-c-cpp.html


下载sqlite源码:
http://sqlite.org/download.html

编译安装

# ./configure --host=arm-linux prefix=/home/user/rootfs
# make
# make install

注意事项:
host=arm-linux
prefix指明安装路径
(手工安装时文件清单:)
将bin目录下的sqlite3复制至目标标bin目录下
将lib目录下的文件复制至目标文件系统的lib目录中
将lib目录下的文件复制至交叉编译器的lib目录中
将include目录下的文件复制至交叉编译器的include目录中
bin目录下的sqlite3是用于测试的文件


C语言API函数使用说明


创建数据库:

int  sqlite3_open(const char *filename,  // 数据库路径
                  sqlite3 **ppdb);       // 数据库句柄

关闭数据库:

int  sqlite3_close(sqlite3 *db);  

如果filename为NULL,则在RAM中创建数据库;
如果文件已存在则打开数据库存,不存在则创建数据库;


构建sql语句:

char *sqlite3_mprintf(const char*, va_list);  
int  sqlite3_free(char *);

例:

// 构建SQL语句
sql = sqlite3_mprintf("delete from %s where %s = %d;", val1, val2, val3);
// 添加执行语句......
sqlite3_exec(db, sql, callback, NULL, NULL); 
// 释放内存 
sqlite3_free(sql);  

说明:sqlite3_mprintft和sqlite3_free总是成对出现,否则会造成内存泄露

执行sql语句:

int  sqlite3_exec(sqlite3 *db,        // 数据库句柄
                  const char *sql,    // SQL语句
                  int (*sqlite3_callback)(void *,int, char**,char**), // 回调函数
                  void *data,                                         // 传给回调函数的参数指针
                  char **errmsg);                                     // 错误消息字符串指针

回调函数定义:

int callback_fun(void *para,         // 执行语句传入的data参数
                 int n_column,       // 字段数
                 char **column_value,// 字段内容数组 
                 char **column_name);// 字段名称数组

非回调查询:

int  sqlite3_get_table(sqlite3 *, 
                       const char *sql, 
                       char **resultp, 
                       int *nrow, 
                       int *ncolumn, 
                       char **errmsg);  

void sqlite3_free_table(char **resultp);  

sqlite3_get_table必须与sqlite3_free_table成对使用

- 阅读全文 -

IAR工程文件说明


文章摘要: 本文主要描述了IAR工程的相关配置
软件版本: EW8051-7601A

IAR工程主要由两个文件组成:
Proj.eww - workspace描述

<?xml version="1.0" encoding="iso-8859-1"?>

<workspace>
  <!-- 在此指明工程描述文件的位置(重要) $WS_DIR$表示eww文件所在的目录 -->        
  <project>
    <path>$WS_DIR$\SerialApp.ewp</path>
  </project>

  <batchBuild>
    <batchDefinition>
      <name>ALL</name>
      <member>
        <project>SerialApp</project>
        <configuration>CoordinatorEB</configuration>
      </member>
      <member>
        <project>SerialApp</project>
        <configuration>RouterEB</configuration>
      </member>
      <member>
        <project>SerialApp</project>
        <configuration>EndDeviceEB</configuration>
      </member>
    </batchDefinition>
  </batchBuild>
</workspace>

Proj.ewp - 工程描述文件
工程描述文件主要由若干个configuration字段和若干个group字段组成;
configuration主要是描述配置
group主要是描述文件目录结构

<Project>
  <fileVersion>2</fileVersion>
  <configuration>

  </configuration>

  <configuration>

  </configuration>

  <group>
  </group>

  <group>
  </group>

</Project>

  <group>
    <name>OnBoard</name> 
    <file>
      <name>$PROJ_DIR$\..\OnBoard\chipcon_cstartup.s51</name>
    </file>
    <file>
      <name>$PROJ_DIR$\..\OnBoard\OnBoard.c</name>
    </file>
    <file>
      <name>$PROJ_DIR$\..\OnBoard\OnBoard.h</name>
    </file>
    <file>
      <name>$PROJ_DIR$\..\OnBoard\ZMain.c</name>
    </file>
  </group>

- 阅读全文 -

Python学习笔记--基础知识


软件版本:Python3
操作系统:Raspbian


Python库安装:

$ sudo pip3 install xxxx

临时指定软件源: 仅本次命令有效

$ sudo pip3 install xxxx  -i https://pypi.tuna.tsinghua.edu.cn/simple  

设置默认软件源:

$ sudo pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

实际操作是在用户家目录下新建文件 ~/.pip/pip.conf

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

有的系统默认是~/.config/pip/pip.conf,但建立在~/.pip/pip.conf也行。
/etc/pip.conf文件中也可以设置源,与用户目录中设置的可同时使用,用户设置优先。


常用的国内镜像:

清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
阿里云 http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban) http://pypi.douban.com/simple/
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/


Python脚本描述:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

标准输出:(默认换行)

print('Hello World')

输出不换行:

print('Hello World', end='')

格式化输出:

print('Hello %s, you have $%d.' % ('Alexander', 1000000))

格式化与C语言一致


标准输入:

name = input('please enter your name: ')
print("Hello", name)

将字符转换为Unicode编码:

ord("中")
ord("A")

将Unicode编码转换成字符:

chr(65)
chr(20013)

字符编码:转换成byte类型

>>> 'ABC'.encode('ascii')
b'ABC'
>>> '中文'.encode('utf-8')
b'\xe4\xb8\xad\xe6\x96\x87'

字符解码:

 b'\xe4\xb8\xad\xe6\x96\x87'.decode('utf-8')
'中文'

 b'\xe4\xb8\xad\xff'.decode('utf-8', errors='ignore')

errors='ignore' 表示忽略错误


计算字符串长度:

>>> len('ABC')
3
>>> len('中文')
2
>>> len('中文'.encode('utf-8'))
6

时间戳:

import time
print time.time()

- 阅读全文 -

Altium Designer 19 应用笔记


软件版本: Altium Designer 19 (AD19)


显示中文菜单:
Preferences...->
System->General->Localization
选中以下几项:
Use localized resources(使用本地资源)
Display localized dialogs(显示本地化对话框)
Localized menus(本地化菜单)

配置完成,重启应用程序即可。


铺铜选项:

Preferences...->
PCB Editor -> General
Polygon Rebuild(铺铜重建)
选择 Repour Polygons After Modification(铺铜修改后自动重铺)

如果不使能该选项,铺铜修改后会消失。


设置3D模式颜色:
View->Panel->Veiw Configuration(或者点击底部LS旁边的颜色框)
在View Options选项卡中设置


旋转3D视图:

shift + 右键 旋转视图
v -> b 翻转至背面
0 恢复至默认视图

删除测量显示:

shift + c

修改导入PCB元件的默认字体

Preferences...->PCB Editor ->Defaults-->
修改Comment和Designator两项的参数

取消探针
shift + c

过孔封油/过孔开窗
双击过孔调出属性页面,Solder Mask Expansion项
勾选对应层(Top/Bottom)的Tented,表示过孔封油,不勾选默认开窗。
对应了Solder图层,可通过3D视图看出对应不同的效果。


隐藏/显示某一网络预拉线:
N-->隐藏网络(H)/显示网络(S)-->网络(N),点击需要隐藏/显示的网络。

- 阅读全文 -


Copyright©2025 春天花会开, All Rights Reserved. Email: webmaster@oroct.com