每一个#ifndef或#ifdef后面都要跟着一个#endif吗?

是不是每一个#if开头的语句,都必须对应一个#endif,一个对应一个,#endif数目不能少?

c

1个回答

#endif用于结束条件编译,编译时与前面最近的#if、#ifdef或#ifndef作为一对.#if是条件编译,你要结束它所以必须得跟一个#endif.

cwh6319
cwh6319 那就是每个#if必须有一个对应的#endif了 谢谢你,老师
大约 3 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
C++ void 符号常量指针
初学 C++ 编译器(vs2012)上有这样一段代码无法编译:typedef void far * XMSDRIVER; 在 * 处提示错误 “应输入;” 关于 far 的定义如下: #ifndef FAR #ifdef NEED_FAR_POINTERS #define FAR far #else #define FAR #endif #endif
linux驱动模块加载不成功调试过程
版本:linux2.6.30 问题出现的过程: 1,我在Ubuntu环境下编译驱动模块 2,编译成功后,在板子上insmod出现了 embest_led: version magic '2.6.30 mod_unload modversions ARMv5 ' should be '2.6.30 preempt mod_unload ARMv5 ' insmod: error inserting 'embest_led.ko': -1 Invalid module format 3,我就更改了/usr/src/linux-2.6.30/include/vermagic.h文件,最终结果是用modinfo查看embest_led.ko信息是‘2.6.30 preempt mod_unload ARMv’同时在板子上insmod后没出现上述错误,而且用lsmod可以查看到embest信息,改动如下: 1 #include <linux/utsrelease.h> 2 #include <linux/module.h> 3 4 #define DEBUG 5 6 #ifdef DEBUG 7 #define CONFIG_PREEMPT 8 #define CONFIG_MODULE_UNLOAD 9 #endif 10 /* Simply sanity version stamp for modules. */ 11 #ifdef CONFIG_SMP 12 #define MODULE_VERMAGIC_SMP "SMP " 13 #else 14 #define MODULE_VERMAGIC_SMP "" 15 #endif 16 #ifdef CONFIG_PREEMPT 17 #define MODULE_VERMAGIC_PREEMPT "preempt " 18 #else 19 #define MODULE_VERMAGIC_PREEMPT "" 20 #endif 21 #ifdef CONFIG_MODULE_UNLOAD 22 #define MODULE_VERMAGIC_MODULE_UNLOAD "mod_unload " 23 #else 24 #define MODULE_VERMAGIC_MODULE_UNLOAD "" 25 #endif 26 27 #ifdef DEBUG 28 29 #ifdef CONFIG_MODVERSIONS 30 #define MODULE_VERMAGIC_MODVERSIONS "" 31 #else 32 #define MODULE_VERMAGIC_MODVERSIONS "modversions " 33 #endif 34 35 #else 36 37 #ifdef CONFIG_MODVERSIONS 38 #define MODULE_VERMAGIC_MODVERSIONS "modversions " 39 #else 40 #define MODULE_VERMAGIC_MODVERSIONS "" 41 #endif 42 43 #endif 44 45 #ifndef MODULE_ARCH_VERMAGIC 46 #define MODULE_ARCH_VERMAGIC "" 47 #endif 4,但是cat /proc/devices 时没有看到相关信息(主次设备号),在/dev/中也没有相应的节点。 5,最高不清楚的是在中断没有打印(我把中断级别调到8了),在/var/volatile/log/messages中也没有相关打印信息。 6,我怀疑是不是没有调用到源文件中module_init中的函数,就写了一个hello_world模块程序。问题是同样的。
HT32F52352的例程 头文件里一个看不懂的报错 是什么意思?
``` #ifndef __HT32F5XXXX_01_H__ #define __HT32F5XXXX_01_H__ #include "ht32_config.h" #ifdef __cplusplus extern "C" { #endif #if !defined(USE_HT32F52220_30) && \ !defined(USE_HT32F52231_41) && \ !defined(USE_HT32F52331_41) && \ !defined(USE_HT32F52342_52) && \ !defined(USE_HT32F52243_53) && \ !defined(USE_HT32F5826) && \ !defined(USE_HT32F0008) && \ !defined(USE_HT32F50220_30) && \ !defined(USE_HT32F50231_41) && \ !defined(USE_HT32F52344_54) && \ !defined(USE_HT32F0006) && \ !defined(USE_HT32F52357_67) && \ !defined(USE_HT32F65230_40) && \ !defined(USE_HT32F57331_41) && \ !defined(USE_HT32F57342_52) && \ !defined(USE_HT32F50343) //#define USE_HT32F52220_30 //#define USE_HT32F52231_41 //#define USE_HT32F52331_41 //#define USE_HT32F52342_52 //#define USE_HT32F52243_53 //#define USE_HT32F5826 //#define USE_HT32F0008 //#define USE_HT32F50220_30 //#define USE_HT32F50231_41 //#define USE_HT32F52344_54 //#define USE_HT32F0006 //#define USE_HT32F52357_67 //#define USE_HT32F65230_40 //#define USE_HT32F57331_41 //#define USE_HT32F57342_52 //#define USE_HT32F50343 #endif #if !defined(USE_NOCHIP) && \ !defined(USE_HT32F52220_30) && \ !defined(USE_HT32F52231_41) && \ !defined(USE_HT32F52331_41) && \ !defined(USE_HT32F52342_52) && \ !defined(USE_HT32F52243_53) && \ !defined(USE_HT32F5826) && \ !defined(USE_HT32F0008) && \ !defined(USE_HT32F50220_30) && \ !defined(USE_HT32F50231_41) && \ !defined(USE_HT32F52344_54) && \ !defined(USE_HT32F0006) && \ !defined(USE_HT32F52357_67) && \ !defined(USE_HT32F65230_40) && \ !defined(USE_HT32F57331_41) && \ !defined(USE_HT32F57342_52) && \ !defined(USE_HT32F50343) #error "Please add "USE_HT32Fxxxxx_xx" define into C Preprocessor Symbols of the Project configuration." #endif ``` 麻烦问一下最后这里报错是什么意思?
VS2013下qt5.4编译vc++的动态链接库错误lnk2019
本人小白一枚, 将qt5.4作为插件在vs2013上,创建qt工程,加载vc++生成的动态链接库,出现 错误 2 error LNK1120: 1 个无法解析的外部命令 C:\Users\Desktop\QTest\x64\Debug\\QTest.exe QTest 错误 1 error LNK2019: 无法解析的外部符号 __imp_add,该符号在函数 main 中被引用 C:\Users\LvKui\Desktop\QTest\QTest\main.obj QTest 注:add是我在vc下写的dll的接口函数。 头文件 #ifndef _MYDLL_H_ #define _MYDLL_H_ #ifdef DLL_API #else #define DLL_API _declspec(dllimport) #endif #ifdef __cplusplus extern "C" { #endif DLL_API int add(int a, int b); DLL_API int subtract(int a, int b); #ifdef __cplusplus } #endif #endif
第三方DLL库会导致ofstream不可以写入文件吗?
DLL 项目下面: DLLclass.h #ifndef WELDING_SEAM_H #define WELDING_SEAM_H #ifdef WELDING_SEAM_EXPORTS #define WELDING_SEAM_API __declspec(dllexport) #else #define WELDING_SEAM_API __declspec(dllimport) #endif class DLLclass { public: DLLclass(const Array2D<double> & input) { } DLLclass(std::string str) { } void WELDING_SEAM_API Implement(int a = 3, int b=2); }; DLLclass.cpp #include "DLLclass.h" void DLLclass::Implement (int a , int b) { } EXE 项目下面: UseDll.h class useDLL { Public: void run(int a=1,int b=1); } UseDll.cpp #include "UseDll.h" #include "DLLclass.h" void useDLL::run(int a,int b) { DLLclass this_Dllclass("test'); this_Dllclass.run(10,10): }
__declspec(dllexport)
问题和代码如下(问题在代码中有标注) #ifndef rcs_id_api_h #define rcs_id_api_h #if !defined(lint) static char* doors_ers_rcs_id_api_h = (char*)"@(#)DOORS %full_filespec: api.h~8.1.4:incl:ERS#1 % %date_created: Tue Jul 16 15:41:59 2013 %"; #endif #endif /********************************************************************** ** api.h */ /* Licensed Materials - Property of IBM - some unique copyrights (i.e., the ability to copy, modify, distribute) may be licensed in certain circumstances (e.g., sample/template code intended to be used by customers to build upon and distribute as their own products). DOORS - %full_filespec: api.h~8.1.4:incl:ERS#1 % %date_created: Tue Jul 16 15:41:59 2013 % (c) Copyright IBM Corporation 1993, 2008. All Rights Reserved. U.S. Government Users Restricted Rights: Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ #ifndef DOORS_API_H #define DOORS_API_H /* Required to build Serena Version Manager */ #ifndef NLS_ #define NLS_(a)a #endif /* Type seperation for 64 vs 32 bit variant */ #if defined (_WIN64) # if defined (datum) # undef datum # endif # define datum long long #else # if defined (datum) # undef datum # endif # define datum long #endif /* Categorize the type of C/C++ we are using */ #if defined(__cplusplus) || defined(c_plusplus) #define API_CPLUSPLUS 1 #else #define API_CPLUSPLUS 0 #endif #if defined(__STDC__) || API_CPLUSPLUS || defined(_WIN32) #define API_ARGS(args) args #else #define API_ARGS(args) () #endif /********************************************************************** ** Some typical CPP definitions */ #ifndef TRUE #define TRUE 1 #define FALSE 0 #endif #ifndef global #define global /* global entry point (extern in .h file) */ #define local static /* local entry point */ #define globalvar /* global variable (externvar .in .h file) */ #define externvar extern /* global variable .h file entry */ #endif #if defined(_WIN32) #define API_WIN32 #ifndef API_DLL #define API_DLL _declspec(dllexport) 编译的时候总在提示在(dllexport)前面那个括号出少了构造函数和析构函数,求大神指教 #define API_CALL _stdcall #endif #define API_EXTERN(type) API_DLL type API_CALL #define API_EXTERNVAR API_DLL #else #define API_EXTERN(type) extern type #define API_EXTERNVAR externvar #endif #ifndef NULL #define NULL 0 #endif #ifndef NUL #define NUL '\0' #endif /* heap things */ #ifndef mnew #define mnew(Type) (Type*)malloc(sizeof(Type)) #define msave(Str) strcpy((char *)malloc(qss_strlen(Str)+1), (Str)) #define mnew_array(Type, Num) (Type*)malloc(sizeof(Type)*(Num)) #endif /* miscellaneous */ #ifndef M_Min #define M_Min(a, b) ((a) < (b) ? (a) : (b)) #define M_Max(a, b) ((a) > (b) ? (a) : (b)) #define M_Abs(a) ((a) < 0 ? -(a) : (a)) #define M_Xor(a, b) (((a) || (b)) && ( ! ((a) && (b)))) #endif /* Macro token concatenation */ #ifndef CAT_ #define ID_(x) x #ifdef __STDC__ #define CAT_(x,y) x ## y #else #define CAT_(x,y) ID_(x)y #endif #endif #ifndef StrMP_ #if defined (__STDC__) || defined(API_WIN32) #define StrMP_(x) (char *)#x #else #define StrMP_(x) (char *)NLS_("x") #endif #endif /* API Stuff */ /* Error States */ /* * CL58 - had to reintroduce apiErrorStates typedef, * because api.h is included by C (not C++) code which * uses apiErrorStates as a type name. */ enum apiErrorStates_ { DOORS_API_OK, DOORS_API_PARSE_BAD_DXL, DOORS_API_SEND_BAD_DXL, DOORS_API_CONNECT_FAILED, DOORS_API_ERROR }; typedef enum apiErrorStates_ apiErrorStates; #define apiInstall(proto,fn) apiInstallN(proto,StrMP_(fn),fn) #define BEGIN_FN(name,ins,outs) \ local int name API_ARGS((void)) { \ char* name__ = StrMP_(name); \ int inp_i_ = ins; \ int outp_i_ = ins; \ int inn_i_ = ins; \ int outn_i_ = outs; #define END_DECLS \ if (apiParCheck(name__,inn_i_,outn_i_,inp_i_)) ; else goto err_exit__ #define END_FN \ err_exit__: \ apiResCheck(name__,inp_i_,inn_i_,outp_i_,outn_i_); \ return (outn_i_ - inn_i_); } #define P_(t,x) \ t x = (t)apiPar(inp_i_--) #define RETURN_(x) \ apiReturn((datum)x,outp_i_--); /* for loop perm macros */ #define BEGIN_FOR_DO(name,ft,f,st,scan) \ local int name (char *pc) \ { \ char* loop; \ int irv = 0; \ st* scanp__; \ ft f; \ st scan; \ scanp__ = (st*)apiLoop(pc,&loop,(void **)&f,&irv); \ if (scanp__ == NULL) return irv; \ { #define PROCESS_DO(scan) \ {*scanp__ = scan;\ if (apiLoopBody(loop,&irv)) break;} #define END_FOR_DO \ } \ return apiLoopDone(loop,irv,pc); \ } /* Definitions */ #if API_CPLUSPLUS extern NLS_("C") { #endif API_EXTERN(void) apiError API_ARGS((char *format, ...)); API_EXTERN(void) apiWarn API_ARGS((char *format, ...)); API_EXTERN(int) apiParCheck API_ARGS((char *n, int ins, int outs, int ip)); API_EXTERN(void) apiResCheck API_ARGS((char *n, int ip, int in, int op, int on)); API_EXTERN(datum) apiPar API_ARGS((int ip)); API_EXTERN(void) apiReturn API_ARGS((long r, int op)); API_EXTERN(char*) apiLoop API_ARGS((char* pc, char** loop, void** fp, int* ret)); API_EXTERN(int) apiLoopBody API_ARGS((char* loop, int* irvp)); API_EXTERN(int) apiLoopDone API_ARGS((char* loop, int irv, char* pp)); API_EXTERN(void) apiMainProg API_ARGS((int argc, char* argv[], char* n, char* ext, char* include, void (*init)(void), void (*done)(void))); API_EXTERN(void) apiInitLibrary API_ARGS((char* n, char* ext, char* include)); API_EXTERN(void) apiFinishLibrary API_ARGS((void)); API_EXTERN(void) apiInstallN API_ARGS((char* proto, char* name, int (*)())); API_EXTERN(void) apiParse API_ARGS((char *format, ...)); API_EXTERN(void) apiConnect API_ARGS((char *s)); API_EXTERN(void) apiConnectSock API_ARGS((unsigned short portno, char* host)); API_EXTERN(void) apiConnectSockV2 API_ARGS((unsigned short portno, char* host)); API_EXTERN(void) apiSend API_ARGS((char *format, ...)); API_EXTERN(void) apiAuthenticatedSend API_ARGS((char *response, char *format, ...)); API_EXTERN(void) apiSendTimesout API_ARGS((int tmt, char *format, ...)); API_EXTERN(void) apiSendFile API_ARGS((char* f)); API_EXTERN(void) apiExitOnError API_ARGS((int onoff)); API_EXTERN(void) apiQuietError API_ARGS((int onoff)); API_EXTERN(int) apiGetErrorState API_ARGS((void)); API_EXTERN(void*) apiGetIPC API_ARGS((void)); API_EXTERN(int) apiSetIPC API_ARGS((void* newIPC)); API_EXTERN(void) apiDeleteIPC API_ARGS((void* newIPC)); API_EXTERN(void) apiFree API_ARGS((void*)); API_EXTERN(char*) apiAuthenticate API_ARGS((void)); #if API_CPLUSPLUS } #endif #endif /* DOORS_API_H */ ``` ```
c#调用go语言生成的dll传string不成功,急!
![图片说明](https://img-ask.csdn.net/upload/201907/30/1564488504_712964.png) c#代码 ``` using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Runtime.InteropServices; namespace test { [StructLayout(LayoutKind.Sequential)] struct GoString { public char[] str; public int length; }; class Program { //System.Runtime.InteropServices.MarshalDirectiveException:“方法的类型签名与 PInvoke 不兼容。” [DllImport("SearchMusic.dll", CharSet = CharSet.Unicode)] static extern GoString Search(GoString key,int apageNum, int pageSize); //这个函数能调用成功 [DllImport("SearchMusic.dll", EntryPoint = "Add")] static extern int Add(int a, int b); static void Main() { GoString str = new GoString(); StringBuilder sb = new StringBuilder("沙漠骆驼"); str.str= ("沙漠骆驼").ToCharArray(); str.length = str.str.Length; Search(str, 1, 10); } } } ``` go语言代码 ``` package main import ( "C" "fmt" "io/ioutil" "net/http" ) //Search : //export Search func Search(key string, pageNum int, pageSize int) { url := "https://c.y.qq.com/soso/fcgi-bin/client_search_cp?ct=24&qqmusic_ver=1298&new_json=1&remoteplace=txt.yqq.song&searchid=57152133376853167&t=0&aggr=1&cr=1&catZhida=1&lossless=0&flag_qc=0&g_tk=5381&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq.json&needNewCode=0&w=" + key + "&p=" + fmt.Sprintf("%d", pageNum) + "&n=" + fmt.Sprintf("%d", pageSize) resp, _ := http.Get(url) defer resp.Body.Close() body, _ := ioutil.ReadAll(resp.Body) json := string(body) fmt.Println(json) } //Add : //export Add func Add(a int, b int) int { return a + b } func main() { } ``` go生成dll时的.h文件 ``` /* Code generated by cmd/cgo; DO NOT EDIT. */ /* package command-line-arguments */ #line 1 "cgo-builtin-export-prolog" #include <stddef.h> /* for ptrdiff_t below */ #ifndef GO_CGO_EXPORT_PROLOGUE_H #define GO_CGO_EXPORT_PROLOGUE_H #ifndef GO_CGO_GOSTRING_TYPEDEF typedef struct { const char *p; ptrdiff_t n; } _GoString_; #endif #endif /* Start of preamble from import "C" comments. */ /* End of preamble from import "C" comments. */ /* Start of boilerplate cgo prologue. */ #line 1 "cgo-gcc-export-header-prolog" #ifndef GO_CGO_PROLOGUE_H #define GO_CGO_PROLOGUE_H typedef signed char GoInt8; typedef unsigned char GoUint8; typedef short GoInt16; typedef unsigned short GoUint16; typedef int GoInt32; typedef unsigned int GoUint32; typedef long long GoInt64; typedef unsigned long long GoUint64; typedef GoInt64 GoInt; typedef GoUint64 GoUint; typedef __SIZE_TYPE__ GoUintptr; typedef float GoFloat32; typedef double GoFloat64; typedef float _Complex GoComplex64; typedef double _Complex GoComplex128; /* static assertion to make sure the file is being used on architecture at least with matching size of GoInt. */ typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1]; #ifndef GO_CGO_GOSTRING_TYPEDEF typedef _GoString_ GoString; #endif typedef void *GoMap; typedef void *GoChan; typedef struct { void *t; void *v; } GoInterface; typedef struct { void *data; GoInt len; GoInt cap; } GoSlice; #endif /* End of boilerplate cgo prologue. */ #ifdef __cplusplus extern "C" { #endif //Search : extern void Search(GoString p0, GoInt p1, GoInt p2); //Add : extern GoInt Add(GoInt p0, GoInt p1); #ifdef __cplusplus } #endif ```
eclipse jni编程中自动生成的.h文件出现语法错误
/* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h> /* Header for class com_example_myimage_MyJNI */ #ifndef _Included_com_example_myimage_MyJNI #define _Included_com_example_myimage_MyJNI #ifdef __cplusplus extern "C" { #endif /* * Class: com_example_myimage_MyJNI * Method: getString * Signature: ()Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_com_example_myimage_MyJNI_getString (JNIEnv *, jobject); #ifdef __cplusplus } #endif #endif JNIEXPORT jstring JNICALL Java_com_example_myimage_MyJNI_getString (JNIEnv *, jobject);这里出现语法错误。JNIEnv类型无法识别
C语言图书管理系统中出现的问题
该系统是采用了细分各个功能模块,分别在main.c文件中调用。 开发环境是Win7,Netbeans8.0.2 这是main.c #include <stdio.h> #include <string.h> #include <stdlib.h> #include "bmenu.h" #include "search_allinformation.h" typedef struct bookinfo { char num[20]; /*图书编号*/ char name[40]; /*书名*/ char author[40]; /*作者*/ char publish [40]; /*出版社*/ double price; /*价格*/ } bi[40]; int w = 0; /*定义一个全局变量,用来记录bookinfo.txt文件中的数据个数*/ int main() { int i = 0; int choice1; FILE *fp; printf(" * ****************************** *\n"); printf(" * 欢迎进入图书馆信息管理系统 *\n"); printf(" * ****************************** *\n"); fp = fopen("E:\\BookInfo.txt", "r"); if (fp == NULL) { printf("Can not open the file !\n"); exit(0); } while (!feof(fp)) { fscanf(fp, "%s%s%s%s%lf", /*调用函数将文件中的数据读入结构变量中*/ &bi[i].num,&bi[i].name,&bi[i].author, &bi[i].publish, &bi[i].price); i++; } w = i - 1; fclose(fp); do { bmenu(); scanf("%d", &choice1); switch (choice1) { case 1: search_allinformation(bookinfo &bi); break; case 2: check_bookinformation(b); break; case 3: add_bookinformation(b); break; case 4: delete_bookinformation(b); break; case 5: borrow_book(b); break; case 0: break; } } while (choice1 != 0); printf("谢谢使用!\n"); return 0; } 这是bmenu.c #include <stdio.h> void bmenu() { printf("################################################################################"); printf(" 功能选项: \n"); printf(" 1:查看全部图书信息 \n"); printf(" 2:查找图书信息 \n"); printf(" 3:添加图书信息 \n"); printf(" 4:删除图书信息 \n"); printf(" 5:借阅图书 \n"); printf(" 0:退出系统 \n"); printf("################################################################################"); printf("请选择操作:"); } 这是bmenu.h #ifndef BMENU_H #define BMENU_H #ifdef __cplusplus extern "C" { #endif void bmenu(); #ifdef __cplusplus } #endif #endif /* BMENU_H */ 这是search_allinformation.c #include <stdio.h> typedef struct list { char num[20]; /*图书编号*/ char name[40]; /*书名*/ char author[40]; /*作者*/ char publish [40]; /*出版社*/ double price; /*价格*/ }; struct list b[40]; void search_allinformation(struct list b[],int w) { int i; int m = w; printf(" ####################################\n"); printf(" # 查看全部图书信息! #\n"); printf(" ####################################\n"); printf("图书的相关信息: 编号 书名 作者 出版社 价格\n"); for (i = 0; i < m; i++) { printf(" %s %s %s %s %.2f\n", /*将数据输出到屏幕中*/ b[i].num, b[i].name, b[i].author, b[i].publish, b[i].price); } printf("################################################################################\n"); } 这是search_allinformation.h #ifndef SEARCH_ALLINFORMATION_H #define SEARCH_ALLINFORMATION_H #ifdef __cplusplus extern "C" { #endif typedef struct list { char num[20]; /*图书编号*/ char name[40]; /*书名*/ char author[40]; /*作者*/ char publish [40]; /*出版社*/ double price; /*价格*/ }; struct list b[40]; void search_allinformation(struct list b[]); #ifdef __cplusplus } #endif #endif /* SEARCH_ALLINFORMATION_H */ 出现的问题如下:
未声明标识符?强制转化也不行
#include "stdafx.h" #include "afxmt.h" // SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的 // ATL 项目中进行定义,并允许与该项目共享文档代码。 #ifndef SHARED_HANDLERS #include "Porject1.h" #endif #include "Porject1Doc.h" #include "Porject1View.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CPorject1View IMPLEMENT_DYNCREATE(CPorject1View, CFormView) BEGIN_MESSAGE_MAP(CPorject1View, CFormView) ON_WM_CONTEXTMENU() ON_WM_RBUTTONUP() ON_BN_CLICKED(IDC_DATA_LINE, &CPorject1View::OnDataLine) ON_BN_CLICKED(IDC_END_DATA_LINE, &CPorject1View::OnEndThread) ON_WM_PAINT() ON_STN_CLICKED(IDC_DATA_ON_TIME, &CPorject1View::OnDataOnTime) ON_STN_CLICKED(IDC_DATA_ON_TIME_thread, &CPorject1View::OnStnClickedDataOnTimethread) END_MESSAGE_MAP() // CPorject1View 构造/析构 CPorject1View::CPorject1View() : CFormView(CPorject1View::IDD) { // TODO: 在此处添加构造代码 } CPorject1View::~CPorject1View() { } void CPorject1View::DoDataExchange(CDataExchange* pDX) { CFormView::DoDataExchange(pDX); } BOOL CPorject1View::PreCreateWindow(CREATESTRUCT& cs) { // TODO: 在此处通过修改 // CREATESTRUCT cs 来修改窗口类或样式 return CFormView::PreCreateWindow(cs); } void CPorject1View::OnInitialUpdate() { CFormView::OnInitialUpdate(); GetParentFrame()->RecalcLayout(); ResizeParentToFit(); } void CPorject1View::OnRButtonUp(UINT /* nFlags */, CPoint point) { ClientToScreen(&point); OnContextMenu(this, point); } void CPorject1View::OnContextMenu(CWnd* /* pWnd */, CPoint point) { #ifndef SHARED_HANDLERS theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE); #endif } // CPorject1View 诊断 #ifdef _DEBUG void CPorject1View::AssertValid() const { CFormView::AssertValid(); } void CPorject1View::Dump(CDumpContext& dc) const { CFormView::Dump(dc); } CPorject1Doc* CPorject1View::GetDocument() const // 非调试版本是内联的 { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPorject1Doc))); return (CPorject1Doc*)m_pDocument; } #endif //_DEBUG // CPorject1View 消息处理程序 CEvent EndPaintLine;//用来控制绘制线程结束的事件 POINT polyLine[31];//存放动态数据曲线数据值的数组 DWORD pLinePoints;//当前需绘制曲线的点数 int TimeSpan_GetData;//绘制动态曲线的时间间隔,具体系统中可在界面上加一微调按钮调整 CBrush * pBrushBlack = new CBrush; void CPorject1View::OnDataLine() { // TODO: 在此添加控件通知处理程序代码 //启动工作线程并画出绘制动态曲线的子窗口的背景矩形框 CWnd*pWnd = GetDlgItem(IDC_DATA_ON_TIME_thread); //获取绘制曲线文本框窗口指针 CDC * pDC = pWnd->GetDC(); CGdiObject * pOldBursh = pDC->SelectObject(pBrushBlack); pDC->Rectangle(0, 0, 300, 200); //用黑色绘制显示动态数据曲线的子窗口 pDC->SelectObject(pOldBursh); CWinThread * pThreadDataOnTime = AfxBeginThread(DataLineThread,(LPVOID )GetSafeHwnd(), THREAD_PRIORITY_NORMAL); } void CPorject1View::OnEndThread() { // TODO: 在此添加控件通知处理程序代码 EndPaintLine.SetEvent(); } void CPorject1View::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: 在此处添加消息处理程序代码 // 不为绘图消息调用 CFormView::OnPaint() CWnd * pWnd = GetDlgItem(IDC_DATA_ON_TIME_thread); //获取绘制曲线的文本框指针 pWnd->Invalidate(); pWnd->UpdateWindow(); CDC * pDC = pWnd->GetDC(); CGdiObject * pOldBrush = pDC->SelectObject(pBrushBlack); pDC->Rectangle(0, 0, 300, 200); //绘制图曲线的矩形区域 pDC->SelectObject(pOldBrush); } void CPorject1View::OnDataOnTime() { // TODO: 在此添加控件通知处理程序代码 } UINT DataLineThread(LPVOID lp) { CPen * pPenGreen = new CPen; CPen * pPenBlack = new CPen; CPen * pPenBKcolor = new CPen; CPen * pPenRed = new CPen; CPen * pPenBlue = new CPen; CBrush * pBrushBlack = new CBrush; pPenRed->CreatePen(PS_DOT, 1, RGB(255, 0, 0)); pPenBlue->CreatePen(PS_DOT, 1, RGB(10, 150, 255)); pPenBlack->CreatePen(PS_SOLID, 1, RGB(0, 0, 0)); pPenGreen->CreatePen(PS_SOLID, 1, RGB(0, 255, 0)); pPenBKcolor->CreatePen(PS_SOLID, 1, RGB(190, 190, 190)); pBrushBlack->CreateSolidBrush(RGB(0, 0, 0)); CWnd * pMainWnd = AfxGetMainWnd(); CWnd * pClient = pMainWnd->GetWindow(GW_CHILD); CWnd * pData = pClient->GetDlgItem(IDC_DATA_ON_TIME_thread); CDC * pDC = pData->GetDC(); BOOL runThread = TRUE; while (runThread) { CWnd * pWnd =pClient-> GetDlgItem(IDC_DATA_ON_TIME); CDC * pDC = pWnd->GetDC(); CGdiObject * pOldPen = pDC->SelectObject(pPenBlue); static int count_T = 0; pDC->SetBkColor(RGB(0, 0, 0)); for (int i = 0; i <= 30; i += 5) { if (300 - 10 * (i + count_T) >= 0) { pDC->MoveTo(300 - 10 * (i + count_T), 200); pDC->LineTo(300 - 10 * (i + count_T), 0); if ((i + count_T - 1) >= 0) { CGdiObject * pPenT = pDC->SelectObject(pPenBlack); pDC->MoveTo(300 - 10 * (i + count_T - 1), 200); pDC->LineTo(300 - 10 * (i + count_T - 1), 0); pDC->SelectObject(pPenT); } } pDC->SelectObject(pOldPen); count_T++; if (count_T == 5) count_T = 0; char tm[20]; _strtime(tm); pDC->SetBkColor(RGB(190, 190, 190)); pDC->TextOut(280, 205,_T("tm")); for (i = 0; i <= 20; i += 5) { pOldPen = pDC->SelectObject(pPenRed); pDC->SetBkColor(RGB(0, 0, 0)); pDC->MoveTo(0, i * 10); pDC->LineTo(300, i * 10); pDC->SelectObject(pOldPen); } if (pLinePoints >= 2) { pOldPen = pDC->SelectObject(pPenBlack); pDC->Polyline(polyLine, pLinePoints); pDC->SelectObject(pOldPen); } static int col = 0; int m_OnData; char mC[40]; if (col < 31) { for (int j = 0; j <= col; j++) polyLine[j].x = 300 - (col - j) * 10; m_OnData = rand()%200; polyLine[col].y = m_OnData; col++; pLinePoints++; } else { pLinePoints = 31; for (int t = 0; t < 30; t++) polyLine[t].y = polyLine[t + 1].y; m_OnData = rand()%200; polyLine[30].y = m_OnData; } itoa(m_OnData, mC, 10); pDC->SetBkColor(RGB(190, 190, 190)); pDC->TextOut(310, 35, _T("实时数据")); if (pLinePoints >= 2) { pOldPen = pDC->SelectObject(pPenGreen); pDC->Polyline(polyLine, pLinePoints); pDC->SetTextColor(RGB(0, 0, 0)); pDC->SelectObject(pOldPen); } int retCode = ::WaitForSingleObject(EndPaintLine.m_hObject, 0); if (retCode == WAIT_OBJECT_0) runThread = FALSE; ::Sleep(TimeSpan_GetData); } delete pPenRed; delete pPenBlue; delete pPenGreen; delete pPenBlack; delete pPenBKcolor; delete pBrushBlack; return 0; } } void CPorject1View::OnStnClickedDataOnTimethread() { // TODO: 在此添加控件通知处理程序代码 } error C2065: “DataLineThread”: 未声明的标识符
Java通过JNI调用第三方dll文件问题
因为我对C语言不熟悉,所以我不会在.cpp文件中实现Java生成头文件,**所以想请各位大侠帮我写一个.cpp文件**,下面是我用java生成的头文件: /* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h> /* Header for class test_CustomerShowDll */ #ifndef _Included_test_CustomerShowDll #define _Included_test_CustomerShowDll #ifdef __cplusplus extern "C" { #endif /* * Class: test_CustomerShowDll * Method: VC110_Init * Signature: ()Ljava/lang/Object; */ JNIEXPORT jobject JNICALL Java_test_CustomerShowDll_VC110_1Init (JNIEnv *, jobject); /* * Class: test_CustomerShowDll * Method: VC110_Cls * Signature: ()Ljava/lang/Object; */ JNIEXPORT jobject JNICALL Java_test_CustomerShowDll_VC110_1Cls (JNIEnv *, jobject); /* * Class: test_CustomerShowDll * Method: VC110_Display * Signature: (ILjava/lang/String;I)Ljava/lang/Object; */ JNIEXPORT jobject JNICALL Java_test_CustomerShowDll_VC110_1Display (JNIEnv *, jobject, jint, jstring, jint); #ifdef __cplusplus } #endif #endif 恳请各位大侠帮帮小弟,这对我来说很重要,跪谢!
orge 没有为 OgreMain.dll 加载符号&异常: 0xC0000005
在orge提供的**ExampleApplication.h**文件中 if (!setup())处: 0x77B0AF68 (msvcr90.dll) (Project1.exe 中)处有未经处理的异常: 0xC0000005: 读取位置 0x6766632E 时发生访问冲突。 查看堆栈: 下面的框架可能不正确和/或缺失,没有为 OgreMain.dll 加载符号 具体位置为: mRoot = OGRE_NEW Root(pluginsPath, mConfigPath + "ogre.cfg", mResourcePath + "Ogre.log"); setup()函数如下: ``` virtual bool setup(void) { String pluginsPath; // only use plugins.cfg if not static #ifndef OGRE_STATIC_LIB #if OGRE_DEBUG_MODE pluginsPath = mResourcePath + "plugins_d.cfg"; #else pluginsPath = mResourcePath + "plugins.cfg"; #endif #endif mRoot = OGRE_NEW Root(pluginsPath, mConfigPath + "ogre.cfg", mResourcePath + "Ogre.log"); mOverlaySystem = OGRE_NEW OverlaySystem(); #ifdef OGRE_STATIC_LIB mStaticPluginLoader.load(); #endif setupResources(); bool carryOn = configure(); if (!carryOn) return false; chooseSceneManager(); createCamera(); createViewports(); #ifdef INCLUDE_RTSHADER_SYSTEM // Initialize shader generator. carryOn = initializeShaderGenerator(mSceneMgr); if (!carryOn) return false; #endif // Set default mipmap level (NB some APIs ignore this) TextureManager::getSingleton().setDefaultNumMipmaps(5); // Create any resource listeners (for loading screens) createResourceListener(); // Load resources loadResources(); // Create the scene createScene(); createFrameListener(); return true; } ``` 第一次补充: 经断点调试发现没有执行Root的构造函数就已经异常
为什么 不能打印log 是因为要在cMakeLists中配置什么东西吗 请高手帮忙
/* DO NOT EDIT THIS FILE - it is machine generated */ #include <string.h> #include <jni.h> #include <android/log.h> #define TAG "JNI" #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__) /* Header for class com_wistrol_jnitest_MyJni */ #ifndef _Included_com_wistrol_jnitest_MyJni #define _Included_com_wistrol_jnitest_MyJni #ifdef __cplusplus extern "C" { #endif /* * Class: com_wistrol_jnitest_MyJni * Method: changeArray * Signature: ([I)[I */ JNIEXPORT jintArray JNICALL Java_com_wistrol_jnitest_MyJni_changeArray (JNIEnv * env, jclass jObject, jintArray jArray){ jsize length = (*env)->GetArrayLength(env,jArray); int* arrayPointer = (*env)->GetIntArrayElements(env,jArray,NULL); int i; for(i=0;i<length;i++){ *(arrayPointer + i) += 5; } LOGD("length=%d", length); return jArray; } #ifdef __cplusplus } #endif
C++中回调函数的实现以及代码错误
我是一个刚学C++的小白,基础比较差,但是现在有一个东西必须学习,就是回调函数。其实不太懂回调函数原理,我现在要写一个类之后封装成dll文件。最后写一个MFC程序调用这个dll文件。 内容就是需要写一个相机采集的简单步骤,需要MFC程序用回调函数的方式几首图像。接受图像就写成简单的文字就可以了。以下是我的代码: 类.h文件 #ifdef MYCAMDLL_EXPORTS #define MYCAMDLL_API __declspec(dllexport) #else #define MYCAMDLL_API __declspec(dllimport) #endif // //#ifndef MYCAMDLL_API //#define MYCAMDLL_API __declspec(dllimport) //#endif typedef void(CMyCamDll::*CallBackPtr)(void *, char *); // 此类是从 MyCamDll.dll 导出的 /* EXTERN_C */ class MYCAMDLL_API CMyCamDll { public: CMyCamDll(void); // TODO: 在此添加您的方法。 public: void OpenDiv(); void Start(); void Display(); void Stop(); void CloseDiv(); void call(); void setcallback(); private: CallBackPtr *callback; CMyCamDll *per; }; 类.cpp文件: #include "stdafx.h" #include "MyCamDll.h" #ifdef _DEBUG #define new DEBUG_NEW #endif CWinApp theApp; using namespace std; CMyCamDll::CMyCamDll() { } void CMyCamDll::call() { MessageBox(NULL, "图像显示", "显示图像中", NULL); } void CMyCamDll::setcallback() { callback = (CallBackPtr)(&CMyCamDll::call); per = this; } void CMyCamDll::OpenDiv() { MessageBox(NULL, "开启设备", "设备已启用", NULL); } void CMyCamDll::Start() { MessageBox(NULL, "采集图像", "已开始采集", NULL); } void CMyCamDll::Display() { MessageBox(NULL, "显示图像", "图像已显示", NULL); } void CMyCamDll::Stop() { MessageBox(NULL, "停止采集", "已停止采集", NULL); } void CMyCamDll::CloseDiv() { MessageBox(NULL, "关闭设备", "设备已关闭", NULL); (CallBackPtr)这里出现报错:IntelliSense: 不允许强制转换到类型 "CallBackPtr"
俄罗斯方块C语言 12列改为10列后出错,新人求助!
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <time.h> #include <conio.h> #include <windows.h> #ifdef _MSC_VER // M$的编译器要给予特殊照顾 #if _MSC_VER <= 1200 // VC6及以下版本 #error 你是不是还在用VC6?! #else // VC6以上版本 #if _MSC_VER >= 1600 // 据说VC10及以上版本有stdint.h了 #include <stdint.h> #else // VC10以下版本,自己定义int8_t和uint16_t typedef signed char int8_t; typedef unsigned short uint16_t; #endif #ifndef __cplusplus // 据说VC都没有stdbool.h,不用C++编译,自己定义bool typedef int bool; #define true 1 #define false 0 #endif #endif #else // 其他的编译器都好说 #include <stdint.h> #ifndef __cplusplus // 不用C++编译,需要stdbool.h里的bool #include <stdbool.h> #endif #endif // ============================================================================= // 7种方块的4旋转状态(4位为一行) static const uint16_t gs_uTetrisTable[7][4] = { { 0x00F0U, 0x2222U, 0x00F0U, 0x2222U }, // I型 { 0x0072U, 0x0262U, 0x0270U, 0x0232U }, // T型 { 0x0223U, 0x0074U, 0x0622U, 0x0170U }, // L型 { 0x0226U, 0x0470U, 0x0322U, 0x0071U }, // J型 { 0x0063U, 0x0264U, 0x0063U, 0x0264U }, // Z型 { 0x006CU, 0x0462U, 0x006CU, 0x0462U }, // S型 { 0x0660U, 0x0660U, 0x0660U, 0x0660U } // O型 }; // ============================================================================= // 初始状态的游戏池 // 每个元素表示游戏池的一行,下标大的是游戏池底部 // 两端各置2个1,底部2全置为1,便于进行碰撞检测 // 这样一来游戏池的宽度为12列 // 如果想要传统的10列,只需多填两个1即可(0xE007),当然显示相关部分也要随之改动 // 当某个元素为0xFFFFU时,说明该行已被填满 // 顶部4行用于给方块,不显示出来 // 再除去底部2行,显示出来的游戏池高度为22行 static const uint16_t gs_uInitialTetrisPool[28] = { 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xC003U, 0xFFFFU, 0xFFFFU }; #define COL_BEGIN 2 #define COL_END 14 #define ROW_BEGIN 4 #define ROW_END 26
关于C++6.0的图像水平镜像变换
关于C++6.0的图像水平镜像变换 ***头文件*** #ifdef MYDLL_EXPORTS #define MYDLL_API __declspec(dllexport) #else #define MYDLL_API __declspec(dllimport) #endif #ifndef LIB_H #define LIB_H struct image { unsigned char * ptr; int numcolors;//3---彩色(排序方式RGB);1----灰度或者黑白图像 int width; /* image width in pixels */ int height; /* image height in pixels */ }; #ifdef __cplusplus extern "C" { #endif //函数声明 MYDLL_API int imgfiletomat(char *filename,struct image *pimage);//-1表示读取图像文件错误;1表示读取正常 MYDLL_API void mattoimgfile(char *filename,struct image *pimage); MYDLL_API void imgshow(char *windowname,struct image *pimage); MYDLL_API int wait(int delay);//延迟delay毫秒数。若等于0,则无限制的等待按键事件 MYDLL_API int createwindow(char *windowname);//窗口的名字,它被用来区分不同的窗口,并被显示为窗口标题。 MYDLL_API void destroywindow(char *windowname);//要被销毁的窗口的名字。 MYDLL_API void destroyallwindows(void);//销毁所有窗口 #ifdef __cplusplus } #endif #endif ** *运行主程序* ** #include "mydll.h" #include <stdio.h> #include <stdlib.h> #include<math.h> #include<string.h> void main() { struct image img1; FILE *fp1; unsigned char *pdata; int temp; int i,j,k=0; int height,wide; fp1=fopen("D:\\学习\\imagetest\\imagedsp\\Debug\\1.txt","w"); imgfiletomat("D:\\学习\\imagetest\\imagedsp\\Debug\\1.jpg", &img1); createwindow("name1"); imgshow("name1",&img1); wait(0); //等待按键 height=img1.height; wide=img1.width; pdata=img1.ptr; for(i=0;i<height;i++) for(j=0;j<wide /2*3;j++) { temp=*(pdata+j); *(pdata+j)=*(pdata+j+3*wide-j/3*3*2-3); *(pdata+j+3*wide-j/3*3*2-3)=temp; } createwindow("name1"); imgshow("name1",&img1); wait(0); //等待按键 } 没有错误,但不知道为什么图像没有发生变化
c语言怎么生成 DLL?
自己在网上查了 N 久 怎么弄也不好使啊 !! 有两个文件 mynative.h 和 MyNative.c /* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h> /* Header for class MyNative */ #ifndef _Included_MyNative #define _Included_MyNative #ifdef __cplusplus extern "C" { #endif /* * Class: MyNative * Method: showParms0 * Signature: (Ljava/lang/String;IZ)V */ JNIEXPORT void JNICALL Java_MyNative_showParms0 (JNIEnv *, jobject, jstring, jint, jboolean); #ifdef __cplusplus } #endif #endif #include <stdio.h> #include "MyNative.h" JNIEXPORT void JNICALL Java_MyNative_showParms0 (JNIEnv *env, jobject obj, jstring s, jint i, jboolean b) { const char* szStr = (*env)->GetStringUTFChars( env, s, 0 ); printf( "String = [%s]\n", szStr ); printf( "int = %d\n", i ); printf( "boolean = %s\n", (b==JNI_TRUE ? "true" : "false") ); (*env)->ReleaseStringUTFChars( env, s, szStr ); } 我要把MyNative 编译成 DLL 怎么弄啊 网上有的说用VS 总是我是弄个半天也没弄出来啊 尽量说的清楚点吧 谢谢了 !
如何写一个托管和非托管下都能编译成功的C++结构体,方便在不同环境下调用?
不懂C++,请各位高手指点一下。 需求是需要封装一个动态库,方便C#调用C++对应结构体,该结构体也应用于静态库,代码如下: ``` //A.h #ifdef DOTNET #define TEST_STRUCT(name) [StructLayoutAttribute(LayoutKind::Sequential, Pack = 1)]\ typedef public ref struct name #else #define TEST_STRUCT(name) typedef struct name #endif ``` ``` TEST_STRUCT(A) { unsigned char Count; B* DataList; A() { Count = 0; DataList = NULL; } ~A() { if (DataList != NULL) { delete [] DataList; DataList = NULL; } } bool copy(char* input, unsigned long count, char* pMem, unsigned long ulMemCount) { DataList = new B[Count]; memcpy(DataList, &input[6], Count*8); return true; } }A ``` ``` 我创建了一个C++ 动态库工程 代码如下: ``` // TestCLI.h #include "..\A.h" #ifndef DOTNET #define DOTNET; #endif #pragma once ``` 然后在工程内引入A.h 编译时, ``` B* DataList; ``` 会报错。 应该如何改造呢? 补充一下,之所以要引用A.h,是想着两边用一套就可以满足,因为这个库是个协议库,后续要不断的往里面补充,为了方便,想着写一个.h, 然后引入两个工程中分别编译就可以了,不需要写两套那么麻烦。 有办法实现吗?
小白使用keil编程debug进入了harddefault,搞了半天没解决。求大佬帮下忙。
/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics. * All rights reserved.</center></h2> * * This software component is licensed by ST under BSD 3-Clause license, * the "License"; You may not use this file except in compliance with the * License. You may obtain a copy of the License at: * opensource.org/licenses/BSD-3-Clause * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "can.h" #include "usart.h" #include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ void CAN_SetTxMsg(void) { hcan.pTxMsg->ExtId=0x1314; //使用的扩展ID hcan.pTxMsg->IDE=CAN_ID_EXT; //扩展模式 hcan.pTxMsg->RTR=CAN_RTR_DATA; //发送的是数据 hcan.pTxMsg->DLC=8; //数据长度为2字节 hcan.pTxMsg->data[0]=0x01; hcan.pTxMsg->data[1]=0x02; hcan.pTxMsg->data[2]=0x03; hcan.pTxMsg->data[3]=0x04; hcan.pTxMsg->data[4]=0x05; hcan.pTxMsg->data[5]=0x06; hcan.pTxMsg->data[6]=0x07; hcan.pTxMsg->data[7]=0x08; } /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /** * @brief The application entry point. * @retval int */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_CAN_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ CAN_SetTxMsg(); HAL_CAN_AddTxMessage(&hcan,hcan.pTxMsg,hcan.pTxMsg->data,(uint32_t*)CAN_TX_MAILBOX0); HAL_CAN_ActivateNotification(&hcan,CAN_IT_RX_FIFO0_MSG_PENDING); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ } /** * @brief System Clock Configuration * @retval None */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; /** Initializes the CPU, AHB and APB busses clocks */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB busses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { Error_Handler(); } /** Enables the Clock Security System */ HAL_RCC_EnableCSS(); } /* USER CODE BEGIN 4 */ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan) { HAL_CAN_AddTxMessage(hcan,hcan->pTxMsg,hcan->pTxMsg->data,(uint32_t*)CAN_TX_MAILBOX0); HAL_CAN_ActivateNotification(hcan,CAN_IT_RX_FIFO0_MSG_PENDING); } /* USER CODE END 4 */ /** * @brief This function is executed in case of error occurrence. * @retval None */ void Error_Handler(void) { /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 这是我的主程序,debug总是在CAN_SetMsg()那里进入了hardfault.下面是定义的一些初始化结构体。 /** ****************************************************************************** * @file stm32f1xx_hal_can.h * @author MCD Application Team * @brief Header file of CAN HAL module. ****************************************************************************** * @attention * * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2> * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of STMicroelectronics nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef STM32F1xx_HAL_CAN_H #define STM32F1xx_HAL_CAN_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_hal_def.h" /** @addtogroup STM32F1xx_HAL_Driver * @{ */ #if defined (CAN1) /** @addtogroup CAN * @{ */ /* Exported types ------------------------------------------------------------*/ /** @defgroup CAN_Exported_Types CAN Exported Types * @{ */ /** * @brief HAL State structures definition */ typedef enum { HAL_CAN_STATE_RESET = 0x00U, /*!< CAN not yet initialized or disabled */ HAL_CAN_STATE_READY = 0x01U, /*!< CAN initialized and ready for use */ HAL_CAN_STATE_LISTENING = 0x02U, /*!< CAN receive process is ongoing */ HAL_CAN_STATE_SLEEP_PENDING = 0x03U, /*!< CAN sleep request is pending */ HAL_CAN_STATE_SLEEP_ACTIVE = 0x04U, /*!< CAN sleep mode is active */ HAL_CAN_STATE_ERROR = 0x05U /*!< CAN error state */ } HAL_CAN_StateTypeDef; /** * @brief CAN init structure definition */ typedef struct { uint32_t Prescaler; /*!< Specifies the length of a time quantum. This parameter must be a number between Min_Data = 1 and Max_Data = 1024. */ uint32_t Mode; /*!< Specifies the CAN operating mode. This parameter can be a value of @ref CAN_operating_mode */ uint32_t SyncJumpWidth; /*!< Specifies the maximum number of time quanta the CAN hardware is allowed to lengthen or shorten a bit to perform resynchronization. This parameter can be a value of @ref CAN_synchronisation_jump_width */ uint32_t TimeSeg1; /*!< Specifies the number of time quanta in Bit Segment 1. This parameter can be a value of @ref CAN_time_quantum_in_bit_segment_1 */ uint32_t TimeSeg2; /*!< Specifies the number of time quanta in Bit Segment 2. This parameter can be a value of @ref CAN_time_quantum_in_bit_segment_2 */ FunctionalState TimeTriggeredMode; /*!< Enable or disable the time triggered communication mode. This parameter can be set to ENABLE or DISABLE. */ FunctionalState AutoBusOff; /*!< Enable or disable the automatic bus-off management. This parameter can be set to ENABLE or DISABLE. */ FunctionalState AutoWakeUp; /*!< Enable or disable the automatic wake-up mode. This parameter can be set to ENABLE or DISABLE. */ FunctionalState AutoRetransmission; /*!< Enable or disable the non-automatic retransmission mode. This parameter can be set to ENABLE or DISABLE. */ FunctionalState ReceiveFifoLocked; /*!< Enable or disable the Receive FIFO Locked mode. This parameter can be set to ENABLE or DISABLE. */ FunctionalState TransmitFifoPriority;/*!< Enable or disable the transmit FIFO priority. This parameter can be set to ENABLE or DISABLE. */ } CAN_InitTypeDef; /** * @brief CAN filter configuration structure definition */ typedef struct { uint32_t FilterIdHigh; /*!< Specifies the filter identification number (MSBs for a 32-bit configuration, first one for a 16-bit configuration). This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. */ uint32_t FilterIdLow; /*!< Specifies the filter identification number (LSBs for a 32-bit configuration, second one for a 16-bit configuration). This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. */ uint32_t FilterMaskIdHigh; /*!< Specifies the filter mask number or identification number, according to the mode (MSBs for a 32-bit configuration, first one for a 16-bit configuration). This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. */ uint32_t FilterMaskIdLow; /*!< Specifies the filter mask number or identification number, according to the mode (LSBs for a 32-bit configuration, second one for a 16-bit configuration). This parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. */ uint32_t FilterFIFOAssignment; /*!< Specifies the FIFO (0 or 1U) which will be assigned to the filter. This parameter can be a value of @ref CAN_filter_FIFO */ uint32_t FilterBank; /*!< Specifies the filter bank which will be initialized. For single CAN instance(14 dedicated filter banks), this parameter must be a number between Min_Data = 0 and Max_Data = 13. For dual CAN instances(28 filter banks shared), this parameter must be a number between Min_Data = 0 and Max_Data = 27. */ uint32_t FilterMode; /*!< Specifies the filter mode to be initialized. This parameter can be a value of @ref CAN_filter_mode */ uint32_t FilterScale; /*!< Specifies the filter scale. This parameter can be a value of @ref CAN_filter_scale */ uint32_t FilterActivation; /*!< Enable or disable the filter. This parameter can be a value of @ref CAN_filter_activation */ uint32_t SlaveStartFilterBank; /*!< Select the start filter bank for the slave CAN instance. For single CAN instances, this parameter is meaningless. For dual CAN instances, all filter banks with lower index are assigned to master CAN instance, whereas all filter banks with greater index are assigned to slave CAN instance. This parameter must be a number between Min_Data = 0 and Max_Data = 27. */ } CAN_FilterTypeDef; /** * @brief CAN Tx message header structure definition */ typedef struct { uint32_t StdId; /*!< Specifies the standard identifier. This parameter must be a number between Min_Data = 0 and Max_Data = 0x7FF. */ uint32_t ExtId; /*!< Specifies the extended identifier. This parameter must be a number between Min_Data = 0 and Max_Data = 0x1FFFFFFF. */ uint32_t IDE; /*!< Specifies the type of identifier for the message that will be transmitted. This parameter can be a value of @ref CAN_identifier_type */ uint32_t RTR; /*!< Specifies the type of frame for the message that will be transmitted. This parameter can be a value of @ref CAN_remote_transmission_request */ uint32_t DLC; /*!< Specifies the length of the frame that will be transmitted. This parameter must be a number between Min_Data = 0 and Max_Data = 8. */ uint8_t data[8]; FunctionalState TransmitGlobalTime; /*!< Specifies whether the timestamp counter value captured on start of frame transmission, is sent in DATA6 and DATA7 replacing pData[6] and pData[7]. @note: Time Triggered Communication Mode must be enabled. @note: DLC must be programmed as 8 bytes, in order these 2 bytes are sent. This parameter can be set to ENABLE or DISABLE. */ } CAN_TxHeaderTypeDef; /** * @brief CAN Rx message header structure definition */ typedef struct { uint32_t StdId; /*!< Specifies the standard identifier. This parameter must be a number between Min_Data = 0 and Max_Data = 0x7FF. */ uint32_t ExtId; /*!< Specifies the extended identifier. This parameter must be a number between Min_Data = 0 and Max_Data = 0x1FFFFFFF. */ uint32_t IDE; /*!< Specifies the type of identifier for the message that will be transmitted. This parameter can be a value of @ref CAN_identifier_type */ uint32_t RTR; /*!< Specifies the type of frame for the message that will be transmitted. This parameter can be a value of @ref CAN_remote_transmission_request */ uint32_t DLC; /*!< Specifies the length of the frame that will be transmitted. This parameter must be a number between Min_Data = 0 and Max_Data = 8. */ uint8_t Data[8]; uint32_t Timestamp; /*!< Specifies the timestamp counter value captured on start of frame reception. @note: Time Triggered Communication Mode must be enabled. This parameter must be a number between Min_Data = 0 and Max_Data = 0xFFFF. */ uint32_t FilterMatchIndex; /*!< Specifies the index of matching acceptance filter element. This parameter must be a number between Min_Data = 0 and Max_Data = 0xFF. */ } CAN_RxHeaderTypeDef; /** * @brief CAN handle Structure definition */ typedef struct __CAN_HandleTypeDef { CAN_TypeDef *Instance; /*!< Register base address */ CAN_InitTypeDef Init; /*!< CAN required parameters */ CAN_TxHeaderTypeDef* pTxMsg; CAN_RxHeaderTypeDef* pRxMsg; HAL_LockTypeDef Lock; __IO HAL_CAN_StateTypeDef State; /*!< CAN communication state */ __IO uint32_t ErrorCode; /*!< CAN Error code. This parameter can be a value of @ref CAN_Error_Code */ } CAN_HandleTypeDef; /** * @} */ /* Exported constants --------------------------------------------------------*/ /** @defgroup CAN_Exported_Constants CAN Exported Constants * @{ */ /** @defgroup CAN_Error_Code CAN Error Code * @{ */ #define HAL_CAN_ERROR_NONE (0x00000000U) /*!< No error */ #define HAL_CAN_ERROR_EWG (0x00000001U) /*!< Protocol Error Warning */ #define HAL_CAN_ERROR_EPV (0x00000002U) /*!< Error Passive */ #define HAL_CAN_ERROR_BOF (0x00000004U) /*!< Bus-off error */ #define HAL_CAN_ERROR_STF (0x00000008U) /*!< Stuff error */ #define HAL_CAN_ERROR_FOR (0x00000010U) /*!< Form error */ #define HAL_CAN_ERROR_ACK (0x00000020U) /*!< Acknowledgment error */ #define HAL_CAN_ERROR_BR (0x00000040U) /*!< Bit recessive error */ #define HAL_CAN_ERROR_BD (0x00000080U) /*!< Bit dominant error */ #define HAL_CAN_ERROR_CRC (0x00000100U) /*!< CRC error */ #define HAL_CAN_ERROR_RX_FOV0 (0x00000200U) /*!< Rx FIFO0 overrun error */ #define HAL_CAN_ERROR_RX_FOV1 (0x00000400U) /*!< Rx FIFO1 overrun error */ #define HAL_CAN_ERROR_TX_ALST0 (0x00000800U) /*!< TxMailbox 0 transmit failure due to arbitration lost */ #define HAL_CAN_ERROR_TX_TERR0 (0x00001000U) /*!< TxMailbox 1 transmit failure due to tranmit error */ #define HAL_CAN_ERROR_TX_ALST1 (0x00002000U) /*!< TxMailbox 0 transmit failure due to arbitration lost */ #define HAL_CAN_ERROR_TX_TERR1 (0x00004000U) /*!< TxMailbox 1 transmit failure due to tranmit error */ #define HAL_CAN_ERROR_TX_ALST2 (0x00008000U) /*!< TxMailbox 0 transmit failure due to arbitration lost */ #define HAL_CAN_ERROR_TX_TERR2 (0x00010000U) /*!< TxMailbox 1 transmit failure due to tranmit error */ #define HAL_CAN_ERROR_TIMEOUT (0x00020000U) /*!< Timeout error */ #define HAL_CAN_ERROR_NOT_INITIALIZED (0x00040000U) /*!< Peripheral not initialized */ #define HAL_CAN_ERROR_NOT_READY (0x00080000U) /*!< Peripheral not ready */ #define HAL_CAN_ERROR_NOT_STARTED (0x00100000U) /*!< Peripheral not started */ #define HAL_CAN_ERROR_PARAM (0x00200000U) /*!< Parameter error */ #define HAL_CAN_ERROR_INTERNAL (0x00800000U) /*!< Internal error */ /** * @} */ /** @defgroup CAN_InitStatus CAN InitStatus * @{ */ #define CAN_INITSTATUS_FAILED (0x00000000U) /*!< CAN initialization failed */ #define CAN_INITSTATUS_SUCCESS (0x00000001U) /*!< CAN initialization OK */ /** * @} */ /** @defgroup CAN_operating_mode CAN Operating Mode * @{ */ #define CAN_MODE_NORMAL (0x00000000U) /*!< Normal mode */ #define CAN_MODE_LOOPBACK ((uint32_t)CAN_BTR_LBKM) /*!< Loopback mode */ #define CAN_MODE_SILENT ((uint32_t)CAN_BTR_SILM) /*!< Silent mode */ #define CAN_MODE_SILENT_LOOPBACK ((uint32_t)(CAN_BTR_LBKM | CAN_BTR_SILM)) /*!< Loopback combined with silent mode */ /** * @} */ /** @defgroup CAN_synchronisation_jump_width CAN Synchronization Jump Width * @{ */ #define CAN_SJW_1TQ (0x00000000U) /*!< 1 time quantum */ #define CAN_SJW_2TQ ((uint32_t)CAN_BTR_SJW_0) /*!< 2 time quantum */ #define CAN_SJW_3TQ ((uint32_t)CAN_BTR_SJW_1) /*!< 3 time quantum */ #define CAN_SJW_4TQ ((uint32_t)CAN_BTR_SJW) /*!< 4 time quantum */ /** * @} */ /** @defgroup CAN_time_quantum_in_bit_segment_1 CAN Time Quantum in Bit Segment 1 * @{ */ #define CAN_BS1_1TQ (0x00000000U) /*!< 1 time quantum */ #define CAN_BS1_2TQ ((uint32_t)CAN_BTR_TS1_0) /*!< 2 time quantum */ #define CAN_BS1_3TQ ((uint32_t)CAN_BTR_TS1_1) /*!< 3 time quantum */ #define CAN_BS1_4TQ ((uint32_t)(CAN_BTR_TS1_1 | CAN_BTR_TS1_0)) /*!< 4 time quantum */ #define CAN_BS1_5TQ ((uint32_t)CAN_BTR_TS1_2) /*!< 5 time quantum */ #define CAN_BS1_6TQ ((uint32_t)(CAN_BTR_TS1_2 | CAN_BTR_TS1_0)) /*!< 6 time quantum */ #define CAN_BS1_7TQ ((uint32_t)(CAN_BTR_TS1_2 | CAN_BTR_TS1_1)) /*!< 7 time quantum */ #define CAN_BS1_8TQ ((uint32_t)(CAN_BTR_TS1_2 | CAN_BTR_TS1_1 | CAN_BTR_TS1_0)) /*!< 8 time quantum */ #define CAN_BS1_9TQ ((uint32_t)CAN_BTR_TS1_3) /*!< 9 time quantum */ #define CAN_BS1_10TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_0)) /*!< 10 time quantum */ #define CAN_BS1_11TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_1)) /*!< 11 time quantum */ #define CAN_BS1_12TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_1 | CAN_BTR_TS1_0)) /*!< 12 time quantum */ #define CAN_BS1_13TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_2)) /*!< 13 time quantum */ #define CAN_BS1_14TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_2 | CAN_BTR_TS1_0)) /*!< 14 time quantum */ #define CAN_BS1_15TQ ((uint32_t)(CAN_BTR_TS1_3 | CAN_BTR_TS1_2 | CAN_BTR_TS1_1)) /*!< 15 time quantum */ #define CAN_BS1_16TQ ((uint32_t)CAN_BTR_TS1) /*!< 16 time quantum */ /** * @} */ /** @defgroup CAN_time_quantum_in_bit_segment_2 CAN Time Quantum in Bit Segment 2 * @{ */ #define CAN_BS2_1TQ (0x00000000U) /*!< 1 time quantum */ #define CAN_BS2_2TQ ((uint32_t)CAN_BTR_TS2_0) /*!< 2 time quantum */ #define CAN_BS2_3TQ ((uint32_t)CAN_BTR_TS2_1) /*!< 3 time quantum */ #define CAN_BS2_4TQ ((uint32_t)(CAN_BTR_TS2_1 | CAN_BTR_TS2_0)) /*!< 4 time quantum */ #define CAN_BS2_5TQ ((uint32_t)CAN_BTR_TS2_2) /*!< 5 time quantum */ #define CAN_BS2_6TQ ((uint32_t)(CAN_BTR_TS2_2 | CAN_BTR_TS2_0)) /*!< 6 time quantum */ #define CAN_BS2_7TQ ((uint32_t)(CAN_BTR_TS2_2 | CAN_BTR_TS2_1)) /*!< 7 time quantum */ #define CAN_BS2_8TQ ((uint32_t)CAN_BTR_TS2) /*!< 8 time quantum */ /** * @} */ /** @defgroup CAN_filter_mode CAN Filter Mode * @{ */ #define CAN_FILTERMODE_IDMASK (0x00000000U) /*!< Identifier mask mode */ #define CAN_FILTERMODE_IDLIST (0x00000001U) /*!< Identifier list mode */ /** * @} */ /** @defgroup CAN_filter_scale CAN Filter Scale * @{ */ #define CAN_FILTERSCALE_16BIT (0x00000000U) /*!< Two 16-bit filters */ #define CAN_FILTERSCALE_32BIT (0x00000001U) /*!< One 32-bit filter */ /** * @} */ /** @defgroup CAN_filter_activation CAN Filter Activation * @{ */ #define CAN_FILTER_DISABLE (0x00000000U) /*!< Disable filter */ #define CAN_FILTER_ENABLE (0x00000001U) /*!< Enable filter */ /** * @} */ /** @defgroup CAN_filter_FIFO CAN Filter FIFO * @{ */ #define CAN_FILTER_FIFO0 (0x00000000U) /*!< Filter FIFO 0 assignment for filter x */ #define CAN_FILTER_FIFO1 (0x00000001U) /*!< Filter FIFO 1 assignment for filter x */ /** * @} */ /** @defgroup CAN_identifier_type CAN Identifier Type * @{ */ #define CAN_ID_STD ((uint32_t)0x00000000) /*!< Standard Id */ #define CAN_ID_EXT ((uint32_t)0x00000004) /*!< Extended Id */ /** * @} */ /** @defgroup CAN_remote_transmission_request CAN Remote Transmission Request * @{ */ #define CAN_RTR_DATA ((uint32_t)0x00000000) /*!< Data frame */ #define CAN_RTR_REMOTE ((uint32_t)0x00000002) /*!< Remote frame */ /** * @} */ /** @defgroup CAN_receive_FIFO_number CAN Receive FIFO Number * @{ */ #define CAN_RX_FIFO0 (0x00000000U) /*!< CAN receive FIFO 0 */ #define CAN_RX_FIFO1 (0x00000001U) /*!< CAN receive FIFO 1 */ /** * @} */ /** @defgroup CAN_Tx_Mailboxes CAN Tx Mailboxes * @{ */ #define CAN_TX_MAILBOX0 (0x00000001U) /*!< Tx Mailbox 0 */ #define CAN_TX_MAILBOX1 (0x00000002U) /*!< Tx Mailbox 1 */ #define CAN_TX_MAILBOX2 (0x00000004U) /*!< Tx Mailbox 2 */ /** * @} */ /** @defgroup CAN_flags CAN Flags * @{ */ /* Transmit Flags */ #define CAN_FLAG_RQCP0 (0x00000500U) /*!< Request complete MailBox 0 flag */ #define CAN_FLAG_TXOK0 (0x00000501U) /*!< Transmission OK MailBox 0 flag */ #define CAN_FLAG_ALST0 (0x00000502U) /*!< Arbitration Lost MailBox 0 flag */ #define CAN_FLAG_TERR0 (0x00000503U) /*!< Transmission error MailBox 0 flag */ #define CAN_FLAG_RQCP1 (0x00000508U) /*!< Request complete MailBox1 flag */ #define CAN_FLAG_TXOK1 (0x00000509U) /*!< Transmission OK MailBox 1 flag */ #define CAN_FLAG_ALST1 (0x0000050AU) /*!< Arbitration Lost MailBox 1 flag */ #define CAN_FLAG_TERR1 (0x0000050BU) /*!< Transmission error MailBox 1 flag */ #define CAN_FLAG_RQCP2 (0x00000510U) /*!< Request complete MailBox2 flag */ #define CAN_FLAG_TXOK2 (0x00000511U) /*!< Transmission OK MailBox 2 flag */ #define CAN_FLAG_ALST2 (0x00000512U) /*!< Arbitration Lost MailBox 2 flag */ #define CAN_FLAG_TERR2 (0x00000513U) /*!< Transmission error MailBox 2 flag */ #define CAN_FLAG_TME0 (0x0000051AU) /*!< Transmit mailbox 0 empty flag */ #define CAN_FLAG_TME1 (0x0000051BU) /*!< Transmit mailbox 1 empty flag */ #define CAN_FLAG_TME2 (0x0000051CU) /*!< Transmit mailbox 2 empty flag */ #define CAN_FLAG_LOW0 (0x0000051DU) /*!< Lowest priority mailbox 0 flag */ #define CAN_FLAG_LOW1 (0x0000051EU) /*!< Lowest priority mailbox 1 flag */ #define CAN_FLAG_LOW2 (0x0000051FU) /*!< Lowest priority mailbox 2 flag */ /* Receive Flags */ #define CAN_FLAG_FF0 (0x00000203U) /*!< RX FIFO 0 Full flag */ #define CAN_FLAG_FOV0 (0x00000204U) /*!< RX FIFO 0 Overrun flag */ #define CAN_FLAG_FF1 (0x00000403U) /*!< RX FIFO 1 Full flag */ #define CAN_FLAG_FOV1 (0x00000404U) /*!< RX FIFO 1 Overrun flag */ /* Operating Mode Flags */ #define CAN_FLAG_INAK (0x00000100U) /*!< Initialization acknowledge flag */ #define CAN_FLAG_SLAK (0x00000101U) /*!< Sleep acknowledge flag */ #define CAN_FLAG_ERRI (0x00000102U) /*!< Error flag */ #define CAN_FLAG_WKU (0x00000103U) /*!< Wake up interrupt flag */ #define CAN_FLAG_SLAKI (0x00000104U) /*!< Sleep acknowledge interrupt flag */ /* Error Flags */ #define CAN_FLAG_EWG (0x00000300U) /*!< Error warning flag */ #define CAN_FLAG_EPV (0x00000301U) /*!< Error passive flag */ #define CAN_FLAG_BOF (0x00000302U) /*!< Bus-Off flag */ /** * @} */ /** @defgroup CAN_Interrupts CAN Interrupts * @{ */ /* Transmit Interrupt */ #define CAN_IT_TX_MAILBOX_EMPTY ((uint32_t)CAN_IER_TMEIE) /*!< Transmit mailbox empty interrupt */ /* Receive Interrupts */ #define CAN_IT_RX_FIFO0_MSG_PENDING ((uint32_t)CAN_IER_FMPIE0) /*!< FIFO 0 message pending interrupt */ #define CAN_IT_RX_FIFO0_FULL ((uint32_t)CAN_IER_FFIE0) /*!< FIFO 0 full interrupt */ #define CAN_IT_RX_FIFO0_OVERRUN ((uint32_t)CAN_IER_FOVIE0) /*!< FIFO 0 overrun interrupt */ #define CAN_IT_RX_FIFO1_MSG_PENDING ((uint32_t)CAN_IER_FMPIE1) /*!< FIFO 1 message pending interrupt */ #define CAN_IT_RX_FIFO1_FULL ((uint32_t)CAN_IER_FFIE1) /*!< FIFO 1 full interrupt */ #define CAN_IT_RX_FIFO1_OVERRUN ((uint32_t)CAN_IER_FOVIE1) /*!< FIFO 1 overrun interrupt */ /* Operating Mode Interrupts */ #define CAN_IT_WAKEUP ((uint32_t)CAN_IER_WKUIE) /*!< Wake-up interrupt */ #define CAN_IT_SLEEP_ACK ((uint32_t)CAN_IER_SLKIE) /*!< Sleep acknowledge interrupt */ /* Error Interrupts */ #define CAN_IT_ERROR_WARNING ((uint32_t)CAN_IER_EWGIE) /*!< Error warning interrupt */ #define CAN_IT_ERROR_PASSIVE ((uint32_t)CAN_IER_EPVIE) /*!< Error passive interrupt */ #define CAN_IT_BUSOFF ((uint32_t)CAN_IER_BOFIE) /*!< Bus-off interrupt */ #define CAN_IT_LAST_ERROR_CODE ((uint32_t)CAN_IER_LECIE) /*!< Last error code interrupt */ #define CAN_IT_ERROR ((uint32_t)CAN_IER_ERRIE) /*!< Error Interrupt */ /** * @} */ /** * @} */ /* Exported macros -----------------------------------------------------------*/ /** @defgroup CAN_Exported_Macros CAN Exported Macros * @{ */ /** @brief Reset CAN handle state * @param __HANDLE__ CAN handle. * @retval None */ #define __HAL_CAN_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_CAN_STATE_RESET) /** * @brief Enable the specified CAN interrupts. * @param __HANDLE__ CAN handle. * @param __INTERRUPT__ CAN Interrupt sources to enable. * This parameter can be any combination of @arg CAN_Interrupts * @retval None */ #define __HAL_CAN_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IER) |= (__INTERRUPT__)) /** * @brief Disable the specified CAN interrupts. * @param __HANDLE__ CAN handle. * @param __INTERRUPT__ CAN Interrupt sources to disable. * This parameter can be any combination of @arg CAN_Interrupts * @retval None */ #define __HAL_CAN_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IER) &= ~(__INTERRUPT__)) /** @brief Check if the specified CAN interrupt source is enabled or disabled. * @param __HANDLE__ specifies the CAN Handle. * @param __INTERRUPT__ specifies the CAN interrupt source to check. * This parameter can be a value of @arg CAN_Interrupts * @retval The state of __IT__ (TRUE or FALSE). */ #define __HAL_CAN_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IER) & (__INTERRUPT__)) /** @brief Check whether the specified CAN flag is set or not. * @param __HANDLE__ specifies the CAN Handle. * @param __FLAG__ specifies the flag to check. * This parameter can be one of @arg CAN_flags * @retval The state of __FLAG__ (TRUE or FALSE). */ #define __HAL_CAN_GET_FLAG(__HANDLE__, __FLAG__) \ ((((__FLAG__) >> 8U) == 5U)? ((((__HANDLE__)->Instance->TSR) & (1U << ((__FLAG__) & CAN_FLAG_MASK))) == (1U << ((__FLAG__) & CAN_FLAG_MASK))): \ (((__FLAG__) >> 8U) == 2U)? ((((__HANDLE__)->Instance->RF0R) & (1U << ((__FLAG__) & CAN_FLAG_MASK))) == (1U << ((__FLAG__) & CAN_FLAG_MASK))): \ (((__FLAG__) >> 8U) == 4U)? ((((__HANDLE__)->Instance->RF1R) & (1U << ((__FLAG__) & CAN_FLAG_MASK))) == (1U << ((__FLAG__) & CAN_FLAG_MASK))): \ (((__FLAG__) >> 8U) == 1U)? ((((__HANDLE__)->Instance->MSR) & (1U << ((__FLAG__) & CAN_FLAG_MASK))) == (1U << ((__FLAG__) & CAN_FLAG_MASK))): \ (((__FLAG__) >> 8U) == 3U)? ((((__HANDLE__)->Instance->ESR) & (1U << ((__FLAG__) & CAN_FLAG_MASK))) == (1U << ((__FLAG__) & CAN_FLAG_MASK))): 0U) /** @brief Clear the specified CAN pending flag. * @param __HANDLE__ specifies the CAN Handle. * @param __FLAG__ specifies the flag to check. * This parameter can be one of the following values: * @arg CAN_FLAG_RQCP0: Request complete MailBox 0 Flag * @arg CAN_FLAG_TXOK0: Transmission OK MailBox 0 Flag * @arg CAN_FLAG_ALST0: Arbitration Lost MailBox 0 Flag * @arg CAN_FLAG_TERR0: Transmission error MailBox 0 Flag * @arg CAN_FLAG_RQCP1: Request complete MailBox 1 Flag * @arg CAN_FLAG_TXOK1: Transmission OK MailBox 1 Flag * @arg CAN_FLAG_ALST1: Arbitration Lost MailBox 1 Flag * @arg CAN_FLAG_TERR1: Transmission error MailBox 1 Flag * @arg CAN_FLAG_RQCP2: Request complete MailBox 2 Flag * @arg CAN_FLAG_TXOK2: Transmission OK MailBox 2 Flag * @arg CAN_FLAG_ALST2: Arbitration Lost MailBox 2 Flag * @arg CAN_FLAG_TERR2: Transmission error MailBox 2 Flag * @arg CAN_FLAG_FF0: RX FIFO 0 Full Flag * @arg CAN_FLAG_FOV0: RX FIFO 0 Overrun Flag * @arg CAN_FLAG_FF1: RX FIFO 1 Full Flag * @arg CAN_FLAG_FOV1: RX FIFO 1 Overrun Flag * @arg CAN_FLAG_WKUI: Wake up Interrupt Flag * @arg CAN_FLAG_SLAKI: Sleep acknowledge Interrupt Flag * @retval None */ #define __HAL_CAN_CLEAR_FLAG(__HANDLE__, __FLAG__) \ ((((__FLAG__) >> 8U) == 5U)? (((__HANDLE__)->Instance->TSR) = (1U << ((__FLAG__) & CAN_FLAG_MASK))): \ (((__FLAG__) >> 8U) == 2U)? (((__HANDLE__)->Instance->RF0R) = (1U << ((__FLAG__) & CAN_FLAG_MASK))): \ (((__FLAG__) >> 8U) == 4U)? (((__HANDLE__)->Instance->RF1R) = (1U << ((__FLAG__) & CAN_FLAG_MASK))): \ (((__FLAG__) >> 8U) == 1U)? (((__HANDLE__)->Instance->MSR) = (1U << ((__FLAG__) & CAN_FLAG_MASK))): 0U) /** * @} */ /* Exported functions --------------------------------------------------------*/ /** @addtogroup CAN_Exported_Functions CAN Exported Functions * @{ */ /** @addtogroup CAN_Exported_Functions_Group1 Initialization and de-initialization functions * @brief Initialization and Configuration functions * @{ */ /* Initialization and de-initialization functions *****************************/ HAL_StatusTypeDef HAL_CAN_Init(CAN_HandleTypeDef *hcan); HAL_StatusTypeDef HAL_CAN_DeInit(CAN_HandleTypeDef *hcan); void HAL_CAN_MspInit(CAN_HandleTypeDef *hcan); void HAL_CAN_MspDeInit(CAN_HandleTypeDef *hcan); /** * @} */ /** @addtogroup CAN_Exported_Functions_Group2 Configuration functions * @brief Configuration functions * @{ */ /* Configuration functions ****************************************************/ HAL_StatusTypeDef HAL_CAN_ConfigFilter(CAN_HandleTypeDef *hcan, CAN_FilterTypeDef *sFilterConfig); /** * @} */ /** @addtogroup CAN_Exported_Functions_Group3 Control functions * @brief Control functions * @{ */ /* Control functions **********************************************************/ HAL_StatusTypeDef HAL_CAN_Start(CAN_HandleTypeDef *hcan); HAL_StatusTypeDef HAL_CAN_Stop(CAN_HandleTypeDef *hcan); HAL_StatusTypeDef HAL_CAN_RequestSleep(CAN_HandleTypeDef *hcan); HAL_StatusTypeDef HAL_CAN_WakeUp(CAN_HandleTypeDef *hcan); uint32_t HAL_CAN_IsSleepActive(CAN_HandleTypeDef *hcan); HAL_StatusTypeDef HAL_CAN_AddTxMessage(CAN_HandleTypeDef *hcan, CAN_TxHeaderTypeDef *pHeader, uint8_t aData[], uint32_t *pTxMailbox); HAL_StatusTypeDef HAL_CAN_AbortTxRequest(CAN_HandleTypeDef *hcan, uint32_t TxMailboxes); uint32_t HAL_CAN_GetTxMailboxesFreeLevel(CAN_HandleTypeDef *hcan); uint32_t HAL_CAN_IsTxMessagePending(CAN_HandleTypeDef *hcan, uint32_t TxMailboxes); uint32_t HAL_CAN_GetTxTimestamp(CAN_HandleTypeDef *hcan, uint32_t TxMailbox); HAL_StatusTypeDef HAL_CAN_GetRxMessage(CAN_HandleTypeDef *hcan, uint32_t RxFifo, CAN_RxHeaderTypeDef *pHeader, uint8_t aData[]); uint32_t HAL_CAN_GetRxFifoFillLevel(CAN_HandleTypeDef *hcan, uint32_t RxFifo); /** * @} */ /** @addtogroup CAN_Exported_Functions_Group4 Interrupts management * @brief Interrupts management * @{ */ /* Interrupts management ******************************************************/ HAL_StatusTypeDef HAL_CAN_ActivateNotification(CAN_HandleTypeDef *hcan, uint32_t ActiveITs); HAL_StatusTypeDef HAL_CAN_DeactivateNotification(CAN_HandleTypeDef *hcan, uint32_t InactiveITs); void HAL_CAN_IRQHandler(CAN_HandleTypeDef *hcan); /** * @} */ /** @addtogroup CAN_Exported_Functions_Group5 Callback functions * @brief Callback functions * @{ */ /* Callbacks functions ********************************************************/ void HAL_CAN_TxMailbox0CompleteCallback(CAN_HandleTypeDef *hcan); void HAL_CAN_TxMailbox1CompleteCallback(CAN_HandleTypeDef *hcan); void HAL_CAN_TxMailbox2CompleteCallback(CAN_HandleTypeDef *hcan); void HAL_CAN_TxMailbox0AbortCallback(CAN_HandleTypeDef *hcan); void HAL_CAN_TxMailbox1AbortCallback(CAN_HandleTypeDef *hcan); void HAL_CAN_TxMailbox2AbortCallback(CAN_HandleTypeDef *hcan); void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan); void HAL_CAN_RxFifo0FullCallback(CAN_HandleTypeDef *hcan); void HAL_CAN_RxFifo1MsgPendingCallback(CAN_HandleTypeDef *hcan); void HAL_CAN_RxFifo1FullCallback(CAN_HandleTypeDef *hcan); void HAL_CAN_SleepCallback(CAN_HandleTypeDef *hcan); void HAL_CAN_WakeUpFromRxMsgCallback(CAN_HandleTypeDef *hcan); void HAL_CAN_ErrorCallback(CAN_HandleTypeDef *hcan); /** * @} */ /** @addtogroup CAN_Exported_Functions_Group6 Peripheral State and Error functions * @brief CAN Peripheral State functions * @{ */ /* Peripheral State and Error functions ***************************************/ HAL_CAN_StateTypeDef HAL_CAN_GetState(CAN_HandleTypeDef *hcan); uint32_t HAL_CAN_GetError(CAN_HandleTypeDef *hcan); HAL_StatusTypeDef HAL_CAN_ResetError(CAN_HandleTypeDef *hcan); /** * @} */ /** * @} */ /* Private types -------------------------------------------------------------*/ /** @defgroup CAN_Private_Types CAN Private Types * @{ */ /** * @} */ /* Private variables ---------------------------------------------------------*/ /** @defgroup CAN_Private_Variables CAN Private Variables * @{ */ /** * @} */ /* Private constants ---------------------------------------------------------*/ /** @defgroup CAN_Private_Constants CAN Private Constants * @{ */ #define CAN_FLAG_MASK (0x000000FFU) /** * @} */ /* Private Macros -----------------------------------------------------------*/ /** @defgroup CAN_Private_Macros CAN Private Macros * @{ */ #define IS_CAN_MODE(MODE) (((MODE) == CAN_MODE_NORMAL) || \ ((MODE) == CAN_MODE_LOOPBACK)|| \ ((MODE) == CAN_MODE_SILENT) || \ ((MODE) == CAN_MODE_SILENT_LOOPBACK)) #define IS_CAN_SJW(SJW) (((SJW) == CAN_SJW_1TQ) || ((SJW) == CAN_SJW_2TQ) || \ ((SJW) == CAN_SJW_3TQ) || ((SJW) == CAN_SJW_4TQ)) #define IS_CAN_BS1(BS1) (((BS1) == CAN_BS1_1TQ) || ((BS1) == CAN_BS1_2TQ) || \ ((BS1) == CAN_BS1_3TQ) || ((BS1) == CAN_BS1_4TQ) || \ ((BS1) == CAN_BS1_5TQ) || ((BS1) == CAN_BS1_6TQ) || \ ((BS1) == CAN_BS1_7TQ) || ((BS1) == CAN_BS1_8TQ) || \ ((BS1) == CAN_BS1_9TQ) || ((BS1) == CAN_BS1_10TQ)|| \ ((BS1) == CAN_BS1_11TQ)|| ((BS1) == CAN_BS1_12TQ)|| \ ((BS1) == CAN_BS1_13TQ)|| ((BS1) == CAN_BS1_14TQ)|| \ ((BS1) == CAN_BS1_15TQ)|| ((BS1) == CAN_BS1_16TQ)) #define IS_CAN_BS2(BS2) (((BS2) == CAN_BS2_1TQ) || ((BS2) == CAN_BS2_2TQ) || \ ((BS2) == CAN_BS2_3TQ) || ((BS2) == CAN_BS2_4TQ) || \ ((BS2) == CAN_BS2_5TQ) || ((BS2) == CAN_BS2_6TQ) || \ ((BS2) == CAN_BS2_7TQ) || ((BS2) == CAN_BS2_8TQ)) #define IS_CAN_PRESCALER(PRESCALER) (((PRESCALER) >= 1U) && ((PRESCALER) <= 1024U)) #define IS_CAN_FILTER_ID_HALFWORD(HALFWORD) ((HALFWORD) <= 0xFFFFU) #if defined(CAN2) #define IS_CAN_FILTER_BANK_DUAL(BANK) ((BANK) <= 27U) #endif #define IS_CAN_FILTER_BANK_SINGLE(BANK) ((BANK) <= 13U) #define IS_CAN_FILTER_MODE(MODE) (((MODE) == CAN_FILTERMODE_IDMASK) || \ ((MODE) == CAN_FILTERMODE_IDLIST)) #define IS_CAN_FILTER_SCALE(SCALE) (((SCALE) == CAN_FILTERSCALE_16BIT) || \ ((SCALE) == CAN_FILTERSCALE_32BIT)) #define IS_CAN_FILTER_ACTIVATION(ACTIVATION) (((ACTIVATION) == CAN_FILTER_DISABLE) || \ ((ACTIVATION) == CAN_FILTER_ENABLE)) #define IS_CAN_FILTER_FIFO(FIFO) (((FIFO) == CAN_FILTER_FIFO0) || \ ((FIFO) == CAN_FILTER_FIFO1)) #define IS_CAN_TX_MAILBOX(TRANSMITMAILBOX) (((TRANSMITMAILBOX) == CAN_TX_MAILBOX0 ) || \ ((TRANSMITMAILBOX) == CAN_TX_MAILBOX1 ) || \ ((TRANSMITMAILBOX) == CAN_TX_MAILBOX2 )) #define IS_CAN_TX_MAILBOX_LIST(TRANSMITMAILBOX) ((TRANSMITMAILBOX) <= (CAN_TX_MAILBOX0 | CAN_TX_MAILBOX1 | CAN_TX_MAILBOX2)) #define IS_CAN_STDID(STDID) ((STDID) <= 0x7FFU) #define IS_CAN_EXTID(EXTID) ((EXTID) <= 0x1FFFFFFFU) #define IS_CAN_DLC(DLC) ((DLC) <= 8U) #define IS_CAN_IDTYPE(IDTYPE) (((IDTYPE) == CAN_ID_STD) || \ ((IDTYPE) == CAN_ID_EXT)) #define IS_CAN_RTR(RTR) (((RTR) == CAN_RTR_DATA) || ((RTR) == CAN_RTR_REMOTE)) #define IS_CAN_RX_FIFO(FIFO) (((FIFO) == CAN_RX_FIFO0) || ((FIFO) == CAN_RX_FIFO1)) #define IS_CAN_IT(IT) ((IT) <= (CAN_IT_TX_MAILBOX_EMPTY | CAN_IT_RX_FIFO0_MSG_PENDING | \ CAN_IT_RX_FIFO0_FULL | CAN_IT_RX_FIFO0_OVERRUN | \ CAN_IT_RX_FIFO1_MSG_PENDING | CAN_IT_RX_FIFO1_FULL | \ CAN_IT_RX_FIFO1_OVERRUN | CAN_IT_WAKEUP | \ CAN_IT_SLEEP_ACK | CAN_IT_ERROR_WARNING | \ CAN_IT_ERROR_PASSIVE | CAN_IT_BUSOFF | \ CAN_IT_LAST_ERROR_CODE | CAN_IT_ERROR)) /** * @} */ /* End of private macros -----------------------------------------------------*/ /** * @} */ #endif /* CAN1 */ /** * @} */ #ifdef __cplusplus } #endif #endif /* STM32F1xx_HAL_CAN_H */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 求大佬指点哪里错了。。
Java学习的正确打开方式
在博主认为,对于入门级学习java的最佳学习方法莫过于视频+博客+书籍+总结,前三者博主将淋漓尽致地挥毫于这篇博客文章中,至于总结在于个人,实际上越到后面你会发现学习的最好方式就是阅读参考官方文档其次就是国内的书籍,博客次之,这又是一个层次了,这里暂时不提后面再谈。博主将为各位入门java保驾护航,各位只管冲鸭!!!上天是公平的,只要不辜负时间,时间自然不会辜负你。 何谓学习?博主所理解的学习,它
大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了
大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、PDF搜索网站推荐 对于大部
linux系列之常用运维命令整理笔录
本博客记录工作中需要的linux运维命令,大学时候开始接触linux,会一些基本操作,可是都没有整理起来,加上是做开发,不做运维,有些命令忘记了,所以现在整理成博客,当然vi,文件操作等就不介绍了,慢慢积累一些其它拓展的命令,博客不定时更新 顺便拉下票,我在参加csdn博客之星竞选,欢迎投票支持,每个QQ或者微信每天都可以投5票,扫二维码即可,http://m234140.nofollow.ax.
Vue + Spring Boot 项目实战(十四):用户认证方案与完善的访问拦截
本篇文章主要讲解 token、session 等用户认证方案的区别并分析常见误区,以及如何通过前后端的配合实现完善的访问拦截,为下一步权限控制的实现打下基础。
比特币原理详解
一、什么是比特币 比特币是一种电子货币,是一种基于密码学的货币,在2008年11月1日由中本聪发表比特币白皮书,文中提出了一种去中心化的电子记账系统,我们平时的电子现金是银行来记账,因为银行的背后是国家信用。去中心化电子记账系统是参与者共同记账。比特币可以防止主权危机、信用风险。其好处不多做赘述,这一层面介绍的文章很多,本文主要从更深层的技术原理角度进行介绍。 二、问题引入  假设现有4个人
程序员接私活怎样防止做完了不给钱?
首先跟大家说明一点,我们做 IT 类的外包开发,是非标品开发,所以很有可能在开发过程中会有这样那样的需求修改,而这种需求修改很容易造成扯皮,进而影响到费用支付,甚至出现做完了项目收不到钱的情况。 那么,怎么保证自己的薪酬安全呢? 我们在开工前,一定要做好一些证据方面的准备(也就是“讨薪”的理论依据),这其中最重要的就是需求文档和验收标准。一定要让需求方提供这两个文档资料作为开发的基础。之后开发
网页实现一个简单的音乐播放器(大佬别看。(⊙﹏⊙))
今天闲着无事,就想写点东西。然后听了下歌,就打算写个播放器。 于是乎用h5 audio的加上js简单的播放器完工了。 欢迎 改进 留言。 演示地点跳到演示地点 html代码如下`&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;music&lt;/title&gt; &lt;meta charset="utf-8"&gt
Python十大装B语法
Python 是一种代表简单思想的语言,其语法相对简单,很容易上手。不过,如果就此小视 Python 语法的精妙和深邃,那就大错特错了。本文精心筛选了最能展现 Python 语法之精妙的十个知识点,并附上详细的实例代码。如能在实战中融会贯通、灵活使用,必将使代码更为精炼、高效,同时也会极大提升代码B格,使之看上去更老练,读起来更优雅。 1. for - else 什么?不是 if 和 else 才
数据库优化 - SQL优化
前面一篇文章从实例的角度进行数据库优化,通过配置一些参数让数据库性能达到最优。但是一些“不好”的SQL也会导致数据库查询变慢,影响业务流程。本文从SQL角度进行数据库优化,提升SQL运行效率。 判断问题SQL 判断SQL是否有问题时可以通过两个表象进行判断: 系统级别表象 CPU消耗严重 IO等待严重 页面响应时间过长
2019年11月中国大陆编程语言排行榜
2019年11月2日,我统计了某招聘网站,获得有效程序员招聘数据9万条。针对招聘信息,提取编程语言关键字,并统计如下: 编程语言比例 rank pl_ percentage 1 java 33.62% 2 c/c++ 16.42% 3 c_sharp 12.82% 4 javascript 12.31% 5 python 7.93% 6 go 7.25% 7
通俗易懂地给女朋友讲:线程池的内部原理
餐厅的约会 餐盘在灯光的照耀下格外晶莹洁白,女朋友拿起红酒杯轻轻地抿了一小口,对我说:“经常听你说线程池,到底线程池到底是个什么原理?”我楞了一下,心里想女朋友今天是怎么了,怎么突然问出这么专业的问题,但做为一个专业人士在女朋友面前也不能露怯啊,想了一下便说:“我先给你讲讲我前同事老王的故事吧!” 大龄程序员老王 老王是一个已经北漂十多年的程序员,岁数大了,加班加不动了,升迁也无望,于是拿着手里
经典算法(5)杨辉三角
写在前面: 我是 扬帆向海,这个昵称来源于我的名字以及女朋友的名字。我热爱技术、热爱开源、热爱编程。技术是开源的、知识是共享的。 这博客是对自己学习的一点点总结及记录,如果您对 Java、算法 感兴趣,可以关注我的动态,我们一起学习。 用知识改变命运,让我们的家人过上更好的生活。 目录一、杨辉三角的介绍二、杨辉三角的算法思想三、代码实现1.第一种写法2.第二种写法 一、杨辉三角的介绍 百度
腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹?
昨天,有网友私信我,说去阿里面试,彻底的被打击到了。问了为什么网上大量使用ThreadLocal的源码都会加上private static?他被难住了,因为他从来都没有考虑过这个问题。无独有偶,今天笔者又发现有网友吐槽了一道腾讯的面试题,我们一起来看看。 腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹? 在互联网职场论坛,一名程序员发帖求助到。二面腾讯,其中一个算法题:64匹
面试官:你连RESTful都不知道我怎么敢要你?
面试官:了解RESTful吗? 我:听说过。 面试官:那什么是RESTful? 我:就是用起来很规范,挺好的 面试官:是RESTful挺好的,还是自我感觉挺好的 我:都挺好的。 面试官:… 把门关上。 我:… 要干嘛?先关上再说。 面试官:我说出去把门关上。 我:what ?,夺门而去 文章目录01 前言02 RESTful的来源03 RESTful6大原则1. C-S架构2. 无状态3.统一的接
SQL-小白最佳入门sql查询一
一 说明 如果是初学者,建议去网上寻找安装Mysql的文章安装,以及使用navicat连接数据库,以后的示例基本是使用mysql数据库管理系统; 二 准备前提 需要建立一张学生表,列分别是id,名称,年龄,学生信息;本示例中文章篇幅原因SQL注释略; 建表语句: CREATE TABLE `student` ( `id` int(11) NOT NULL AUTO_INCREMENT, `
项目中的if else太多了,该怎么重构?
介绍 最近跟着公司的大佬开发了一款IM系统,类似QQ和微信哈,就是聊天软件。我们有一部分业务逻辑是这样的 if (msgType = "文本") { // dosomething } else if(msgType = "图片") { // doshomething } else if(msgType = "视频") { // doshomething } else { // dosho
漫话:什么是平衡(AVL)树?这应该是把AVL树讲的最好的文章了
这篇文章通过对话的形式,由浅入深带你读懂 AVL 树,看完让你保证理解 AVL 树的各种操作,如果觉得不错,别吝啬你的赞哦。 1、若它的左子树不为空,则左子树上所有的节点值都小于它的根节点值。 2、若它的右子树不为空,则右子树上所有的节点值均大于它的根节点值。 3、它的左右子树也分别可以充当为二叉查找树。 例如: 例如,我现在想要查找数值为14的节点。由于二叉查找树的特性,我们可...
“狗屁不通文章生成器”登顶GitHub热榜,分分钟写出万字形式主义大作
一、垃圾文字生成器介绍 最近在浏览GitHub的时候,发现了这样一个骨骼清奇的雷人项目,而且热度还特别高。 项目中文名:狗屁不通文章生成器 项目英文名:BullshitGenerator 根据作者的介绍,他是偶尔需要一些中文文字用于GUI开发时测试文本渲染,因此开发了这个废话生成器。但由于生成的废话实在是太过富于哲理,所以最近已经被小伙伴们给玩坏了。 他的文风可能是这样的: 你发现,
程序员:我终于知道post和get的区别
IT界知名的程序员曾说:对于那些月薪三万以下,自称IT工程师的码农们,其实我们从来没有把他们归为我们IT工程师的队伍。他们虽然总是以IT工程师自居,但只是他们一厢情愿罢了。 此话一出,不知激起了多少(码农)程序员的愤怒,却又无可奈何,于是码农问程序员。 码农:你知道get和post请求到底有什么区别? 程序员:你看这篇就知道了。 码农:你月薪三万了? 程序员:嗯。 码农:你是怎么做到的? 程序员:
《程序人生》系列-这个程序员只用了20行代码就拿了冠军
你知道的越多,你不知道的越多 点赞再看,养成习惯GitHub上已经开源https://github.com/JavaFamily,有一线大厂面试点脑图,欢迎Star和完善 前言 这一期不算《吊打面试官》系列的,所有没前言我直接开始。 絮叨 本来应该是没有这期的,看过我上期的小伙伴应该是知道的嘛,双十一比较忙嘛,要值班又要去帮忙拍摄年会的视频素材,还得搞个程序员一天的Vlog,还要写BU
开源并不是你认为的那些事
点击上方蓝字 关注我们开源之道导读所以 ————想要理清开源是什么?先要厘清开源不是什么,名正言顺是句中国的古代成语,概念本身的理解非常之重要。大部分生物多样性的起源,...
加快推动区块链技术和产业创新发展,2019可信区块链峰会在京召开
      11月8日,由中国信息通信研究院、中国通信标准化协会、中国互联网协会、可信区块链推进计划联合主办,科技行者协办的2019可信区块链峰会将在北京悠唐皇冠假日酒店开幕。   区块链技术被认为是继蒸汽机、电力、互联网之后,下一代颠覆性的核心技术。如果说蒸汽机释放了人类的生产力,电力解决了人类基本的生活需求,互联网彻底改变了信息传递的方式,区块链作为构造信任的技术有重要的价值。   1
程序员把地府后台管理系统做出来了,还有3.0版本!12月7号最新消息:已在开发中有github地址
第一幕:缘起 听说阎王爷要做个生死簿后台管理系统,我们派去了一个程序员…… 996程序员做的梦: 第一场:团队招募 为了应对地府管理危机,阎王打算找“人”开发一套地府后台管理系统,于是就在地府总经办群中发了项目需求。 话说还是中国电信的信号好,地府都是满格,哈哈!!! 经常会有外行朋友问:看某网站做的不错,功能也简单,你帮忙做一下? 而这次,面对这样的需求,这个程序员
网易云6亿用户音乐推荐算法
网易云音乐是音乐爱好者的集聚地,云音乐推荐系统致力于通过 AI 算法的落地,实现用户千人千面的个性化推荐,为用户带来不一样的听歌体验。 本次分享重点介绍 AI 算法在音乐推荐中的应用实践,以及在算法落地过程中遇到的挑战和解决方案。 将从如下两个部分展开: AI 算法在音乐推荐中的应用 音乐场景下的 AI 思考 从 2013 年 4 月正式上线至今,网易云音乐平台持续提供着:乐屏社区、UGC
【技巧总结】位运算装逼指南
位算法的效率有多快我就不说,不信你可以去用 10 亿个数据模拟一下,今天给大家讲一讲位运算的一些经典例子。不过,最重要的不是看懂了这些例子就好,而是要在以后多去运用位运算这些技巧,当然,采用位运算,也是可以装逼的,不信,你往下看。我会从最简单的讲起,一道比一道难度递增,不过居然是讲技巧,那么也不会太难,相信你分分钟看懂。 判断奇偶数 判断一个数是基于还是偶数,相信很多人都做过,一般的做法的代码如下
《C++ Primer》学习笔记(六):C++模块设计——函数
专栏C++学习笔记 《C++ Primer》学习笔记/习题答案 总目录 https://blog.csdn.net/TeFuirnever/article/details/100700212 —————————————————————————————————————————————————————— 《C++ Primer》习题参考答案:第6章 - C++模块设计——函数 文章目录专栏C+...
8年经验面试官详解 Java 面试秘诀
    作者 | 胡书敏 责编 | 刘静 出品 | CSDN(ID:CSDNnews) 本人目前在一家知名外企担任架构师,而且最近八年来,在多家外企和互联网公司担任Java技术面试官,前后累计面试了有两三百位候选人。在本文里,就将结合本人的面试经验,针对Java初学者、Java初级开发和Java开发,给出若干准备简历和准备面试的建议。   Java程序员准备和投递简历的实
面试官如何考察你的思维方式?
1.两种思维方式在求职面试中,经常会考察这种问题:北京有多少量特斯拉汽车? 某胡同口的煎饼摊一年能卖出多少个煎饼? 深圳有多少个产品经理? 一辆公交车里能装下多少个乒乓球? 一
so easy! 10行代码写个"狗屁不通"文章生成器
前几天,GitHub 有个开源项目特别火,只要输入标题就可以生成一篇长长的文章。背后实现代码一定很复杂吧,里面一定有很多高深莫测的机器学习等复杂算法不过,当我看了源代码之后这程序不到50
知乎高赞:中国有什么拿得出手的开源软件产品?(整理自本人原创回答)
知乎高赞:中国有什么拿得出手的开源软件产品? 在知乎上,有个问题问“中国有什么拿得出手的开源软件产品(在 GitHub 等社区受欢迎度较好的)?” 事实上,还不少呢~ 本人于2019.7.6进行了较为全面的 回答 - Bravo Yeung,获得该问题下回答中得最高赞(236赞和1枚专业勋章),对这些受欢迎的 Github 开源项目分类整理如下: 分布式计算、云平台相关工具类 1.SkyWalk
相关热词 c# 图片上传 c# gdi 占用内存 c#中遍历字典 c#控制台模拟dos c# 斜率 最小二乘法 c#进程延迟 c# mysql完整项目 c# grid 总行数 c# web浏览器插件 c# xml 生成xsd
立即提问