删除stm32代码

This commit is contained in:
kerwincui
2021-09-12 18:04:37 +08:00
parent 8d8c5b7d3b
commit abc22ba4bc
48 changed files with 0 additions and 5831 deletions

View File

@@ -1,727 +0,0 @@
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <float.h>
#include <limits.h>
#include <ctype.h>
#include "cJSON.h"
static const char *ep;
const char *cJSON_GetErrorPtr(void)
{return ep;}
static int cJSON_strcasecmp(const char *s1,const char *s2){
if (!s1) return (s1==s2)?0:1;if (!s2) return 1;
for(; tolower(*s1) == tolower(*s2); ++s1, ++s2) if(*s1 == 0) return 0;
return tolower(*(const unsigned char *)s1) - tolower(*(const unsigned char *)s2);
}
static void *(*cJSON_malloc)(size_t sz) = malloc;
static void (*cJSON_free)(void *ptr) = free;
static char* cJSON_strdup(const char* str){
size_t len;
char* copy;
len = strlen(str) + 1;
copy = (char *)cJSON_malloc(len);
if (!copy)
return 0;
memcpy(copy,str,len);
return copy;
}
void cJSON_InitHooks(cJSON_Hooks* hooks){
if (!hooks) { /* Reset hooks */
cJSON_malloc = malloc;
cJSON_free = free;
return;
}
cJSON_malloc = (hooks->malloc_fn)?hooks->malloc_fn:malloc;
cJSON_free = (hooks->free_fn)?hooks->free_fn:free;
}
/* Internal constructor. */
static cJSON *cJSON_New_Item(void){
cJSON* node = (cJSON*)cJSON_malloc(sizeof(cJSON));
if (node) memset(node,0,sizeof(cJSON));
return node;
}
/* Delete a cJSON structure. */
void cJSON_Delete(cJSON *c){
cJSON *next;
while (c)
{
next=c->next;
if (!(c->type&cJSON_IsReference) && c->child) cJSON_Delete(c->child);
if (!(c->type&cJSON_IsReference) && c->valuestring) cJSON_free(c->valuestring);
if (!(c->type&cJSON_StringIsConst) && c->string) cJSON_free(c->string);
cJSON_free(c);
c=next;
}
}
/* Parse the input text to generate a number, and populate the result into item. */
static const char *parse_number(cJSON *item,const char *num){
double n=0,sign=1,scale=0;int subscale=0,signsubscale=1;
if (*num=='-') sign=-1,num++; /* Has sign? */
if (*num=='0') num++; /* is zero */
if (*num>='1' && *num<='9') do n=(n*10.0)+(*num++ -'0'); while (*num>='0' && *num<='9'); /* Number? */
if (*num=='.' && num[1]>='0' && num[1]<='9') {num++; do n=(n*10.0)+(*num++ -'0'),scale--; while (*num>='0' && *num<='9');} /* Fractional part? */
if (*num=='e' || *num=='E') /* Exponent? */
{ num++;if (*num=='+') num++; else if (*num=='-') signsubscale=-1,num++; /* With sign? */
while (*num>='0' && *num<='9') subscale=(subscale*10)+(*num++ - '0'); /* Number? */
}
n=sign*n*pow(10.0,(scale+subscale*signsubscale)); /* number = +/- number.fraction * 10^+/- exponent */
item->valuedouble=n;
item->valueint=(int)n;
item->type=cJSON_Number;
return num;
}
static int pow2gt (int x) { --x; x|=x>>1; x|=x>>2; x|=x>>4; x|=x>>8; x|=x>>16; return x+1; }
typedef struct {char *buffer; int length; int offset; } printbuffer;
static char* ensure(printbuffer *p,int needed){
char *newbuffer;int newsize;
if (!p || !p->buffer) return 0;
needed+=p->offset;
if (needed<=p->length) return p->buffer+p->offset;
newsize=pow2gt(needed);
newbuffer=(char*)cJSON_malloc(newsize);
if (!newbuffer) {cJSON_free(p->buffer);p->length=0,p->buffer=0;return 0;}
if (newbuffer) memcpy(newbuffer,p->buffer,p->length);
cJSON_free(p->buffer);
p->length=newsize;
p->buffer=newbuffer;
return newbuffer+p->offset;
}
static int update(printbuffer *p){
char *str;
if (!p || !p->buffer) return 0;
str=p->buffer+p->offset;
return p->offset+strlen(str);
}
/* Render the number nicely from the given item into a string. */
static char *print_number(cJSON *item,printbuffer *p){
char *str=0;
double d=item->valuedouble;
if (d==0)
{
if (p) str=ensure(p,2);
else str=(char*)cJSON_malloc(2); /* special case for 0. */
if (str) strcpy(str,"0");
}
else if (fabs(((double)item->valueint)-d)<=DBL_EPSILON && d<=INT_MAX && d>=INT_MIN)
{
if (p) str=ensure(p,21);
else str=(char*)cJSON_malloc(21); /* 2^64+1 can be represented in 21 chars. */
if(str) sprintf(str,"%d",item->valueint);
}
else
{
if (p) str=ensure(p,64);
else str=(char*)cJSON_malloc(64); /* This is a nice tradeoff. */
if (str)
{
if (fabs(floor(d)-d)<=DBL_EPSILON && fabs(d)<1.0e60)sprintf(str,"%.0f",d);
else if (fabs(d)<1.0e-6 || fabs(d)>1.0e9) sprintf(str,"%e",d);
else sprintf(str,"%f",d);
}
}
return str;
}
static unsigned parse_hex4(const char *str){
unsigned h=0;
if (*str>='0' && *str<='9') h+=(*str)-'0'; else if (*str>='A' && *str<='F') h+=10+(*str)-'A'; else if (*str>='a' && *str<='f') h+=10+(*str)-'a'; else return 0;
h=h<<4;str++;
if (*str>='0' && *str<='9') h+=(*str)-'0'; else if (*str>='A' && *str<='F') h+=10+(*str)-'A'; else if (*str>='a' && *str<='f') h+=10+(*str)-'a'; else return 0;
h=h<<4;str++;
if (*str>='0' && *str<='9') h+=(*str)-'0'; else if (*str>='A' && *str<='F') h+=10+(*str)-'A'; else if (*str>='a' && *str<='f') h+=10+(*str)-'a'; else return 0;
h=h<<4;str++;
if (*str>='0' && *str<='9') h+=(*str)-'0'; else if (*str>='A' && *str<='F') h+=10+(*str)-'A'; else if (*str>='a' && *str<='f') h+=10+(*str)-'a'; else return 0;
return h;
}
/* Parse the input text into an unescaped cstring, and populate item. */
static const unsigned char firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
static const char *parse_string(cJSON *item,const char *str){
const char *ptr=str+1;char *ptr2;char *out;int len=0;unsigned uc,uc2;
if (*str!='\"') {ep=str;return 0;} /* not a string! */
while (*ptr!='\"' && *ptr && ++len) if (*ptr++ == '\\') ptr++; /* Skip escaped quotes. */
out=(char*)cJSON_malloc(len+1); /* 这大概是我们需要的长度. */
if (!out) return 0;
ptr=str+1;ptr2=out;
while (*ptr!='\"' && *ptr)
{
if (*ptr!='\\') *ptr2++=*ptr++;
else
{
ptr++;
switch (*ptr)
{
case 'b': *ptr2++='\b'; break;
case 'f': *ptr2++='\f'; break;
case 'n': *ptr2++='\n'; break;
case 'r': *ptr2++='\r'; break;
case 't': *ptr2++='\t'; break;
case 'u': /* transcode utf16 to utf8. */
uc=parse_hex4(ptr+1);ptr+=4; /* get the unicode char. */
if ((uc>=0xDC00 && uc<=0xDFFF) || uc==0) break; /* check for invalid. */
if (uc>=0xD800 && uc<=0xDBFF) /* UTF16 surrogate pairs. */
{
if (ptr[1]!='\\' || ptr[2]!='u') break; /* missing second-half of surrogate. */
uc2=parse_hex4(ptr+3);ptr+=6;
if (uc2<0xDC00 || uc2>0xDFFF) break; /* invalid second-half of surrogate. */
uc=0x10000 + (((uc&0x3FF)<<10) | (uc2&0x3FF));
}
len=4;if (uc<0x80) len=1;else if (uc<0x800) len=2;else if (uc<0x10000) len=3; ptr2+=len;
switch (len) {
case 4: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;
case 3: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;
case 2: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;
case 1: *--ptr2 =(uc | firstByteMark[len]);
}
ptr2+=len;
break;
default: *ptr2++=*ptr; break;
}
ptr++;
}
}
*ptr2=0;
if (*ptr=='\"') ptr++;
item->valuestring=out;
item->type=cJSON_String;
return ptr;
}
/* Render the cstring provided to an escaped version that can be printed. */
static char *print_string_ptr(const char *str,printbuffer *p){
const char *ptr;char *ptr2,*out;int len=0,flag=0;unsigned char token;
for (ptr=str;*ptr;ptr++) flag|=((*ptr>0 && *ptr<32)||(*ptr=='\"')||(*ptr=='\\'))?1:0;
if (!flag)
{
len=ptr-str;
if (p) out=ensure(p,len+3);
else out=(char*)cJSON_malloc(len+3);
if (!out) return 0;
ptr2=out;*ptr2++='\"';
strcpy(ptr2,str);
ptr2[len]='\"';
ptr2[len+1]=0;
return out;
}
if (!str)
{
if (p) out=ensure(p,3);
else out=(char*)cJSON_malloc(3);
if (!out) return 0;
strcpy(out,"\"\"");
return out;
}
ptr = str;
while ( (token==*ptr) && (++len) )
{
if (strchr("\"\\\b\f\n\r\t",token))
len++;
else if (token < 32) len+=5;
ptr++;
}
if (p) out=ensure(p,len+3);
else out=(char*)cJSON_malloc(len+3);
if (!out) return 0;
ptr2=out;ptr=str;
*ptr2++='\"';
while (*ptr)
{
if ((unsigned char)*ptr>31 && *ptr!='\"' && *ptr!='\\') *ptr2++=*ptr++;
else
{
*ptr2++='\\';
switch (token=*ptr++)
{
case '\\': *ptr2++='\\'; break;
case '\"': *ptr2++='\"'; break;
case '\b': *ptr2++='b'; break;
case '\f': *ptr2++='f'; break;
case '\n': *ptr2++='n'; break;
case '\r': *ptr2++='r'; break;
case '\t': *ptr2++='t'; break;
default: sprintf(ptr2,"u%04x",token);ptr2+=5; break; /* escape and print */
}
}
}
*ptr2++='\"';*ptr2++=0;
return out;
}
/* Invote print_string_ptr (which is useful) on an item. */
static char *print_string(cJSON *item,printbuffer *p) {return print_string_ptr(item->valuestring,p);}
/* Predeclare these prototypes. */
static const char *parse_value(cJSON *item,const char *value);
static char *print_value(cJSON *item,int depth,int fmt,printbuffer *p);
static const char *parse_array(cJSON *item,const char *value);
static char *print_array(cJSON *item,int depth,int fmt,printbuffer *p);
static const char *parse_object(cJSON *item,const char *value);
static char *print_object(cJSON *item,int depth,int fmt,printbuffer *p);
/* Utility to jump whitespace and cr/lf */
static const char *skip(const char *in)
{
while (in && *in && (unsigned char)*in<=32)
in++;
return in;
}
/* Parse an object - create a new root, and populate. */
cJSON *cJSON_ParseWithOpts(const char *value,const char **return_parse_end,int require_null_terminated){
const char *end=0;
cJSON *c=cJSON_New_Item();
ep=0;
if (!c) return 0; /* memory fail */
end=parse_value(c,skip(value));
if (!end) {cJSON_Delete(c);return 0;} /* parse failure. ep is set. */
/* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */
if (require_null_terminated) {end=skip(end);if (*end) {cJSON_Delete(c);ep=end;return 0;}}
if (return_parse_end) *return_parse_end=end;
return c;
}
/* Default options for cJSON_Parse */
cJSON *cJSON_Parse(const char *value) {return cJSON_ParseWithOpts(value,0,0);}
/* Render a cJSON item/entity/structure to text. */
char *cJSON_Print(cJSON *item) {return print_value(item,0,1,0);}
char *cJSON_PrintUnformatted(cJSON *item) {return print_value(item,0,0,0);}
char *cJSON_PrintBuffered(cJSON *item,int prebuffer,int fmt){
printbuffer p;
p.buffer = (char*)cJSON_malloc(prebuffer);
p.length = prebuffer;
p.offset = 0;
return print_value(item,0,fmt,&p);
// return p.buffer;
}
/* Parser core - when encountering text, process appropriately. */
static const char *parse_value(cJSON *item,const char *value){
if (!value) return 0; /* Fail on null. */
if (!strncmp(value,"null",4)) { item->type=cJSON_NULL; return value+4; }
if (!strncmp(value,"false",5)) { item->type=cJSON_False; return value+5; }
if (!strncmp(value,"true",4)) { item->type=cJSON_True; item->valueint=1; return value+4; }
if (*value=='\"') { return parse_string(item,value); }
if (*value=='-' || (*value>='0' && *value<='9')) { return parse_number(item,value); }
if (*value=='[') { return parse_array(item,value); }
if (*value=='{') { return parse_object(item,value); }
ep=value;return 0; /* failure. */
}
/* Render a value to text. */
static char *print_value(cJSON *item,int depth,int fmt,printbuffer *p){
char *out=0;
if (!item) return 0;
if (p)
{
switch ((item->type)&255)
{
case cJSON_NULL: {out=ensure(p,5); if (out) strcpy(out,"null"); break;}
case cJSON_False: {out=ensure(p,6); if (out) strcpy(out,"false"); break;}
case cJSON_True: {out=ensure(p,5); if (out) strcpy(out,"true"); break;}
case cJSON_Number: out=print_number(item,p);break;
case cJSON_String: out=print_string(item,p);break;
case cJSON_Array: out=print_array(item,depth,fmt,p);break;
case cJSON_Object: out=print_object(item,depth,fmt,p);break;
}
}
else
{
switch ((item->type)&255)
{
case cJSON_NULL: out=cJSON_strdup("null"); break;
case cJSON_False: out=cJSON_strdup("false");break;
case cJSON_True: out=cJSON_strdup("true"); break;
case cJSON_Number: out=print_number(item,0); break;
case cJSON_String: out=print_string(item,0); break;
case cJSON_Array: out=print_array(item,depth,fmt,0); break;
case cJSON_Object: out=print_object(item,depth,fmt,0);break;
}
}
return out;
}
/* Build an array from input text. */
static const char *parse_array(cJSON *item,const char *value){
cJSON *child;
if (*value!='[') {ep=value;return 0;} /* not an array! */
item->type=cJSON_Array;
value=skip(value+1);
if (*value==']') return value+1; /* empty array. */
item->child=child = cJSON_New_Item();
if (!item->child) return 0; /* memory fail */
value=skip(parse_value(child,skip(value))); /* skip any spacing, get the value. */
if (!value) return 0;
while (*value==',')
{
cJSON *new_item;
new_item = cJSON_New_Item();
if (!new_item)
return 0; /* memory fail */
child->next=new_item;new_item->prev=child;child=new_item;
value=skip(parse_value(child,skip(value+1)));
if (!value)
return 0; /* memory fail */
}
if (*value==']') return value+1; /* end of array */
ep=value;return 0; /* malformed. */
}
/* Render an array to text */
static char *print_array(cJSON *item,int depth,int fmt,printbuffer *p){
char **entries;
char *out=0,*ptr,*ret;int len=5;
cJSON *child=item->child;
int numentries=0,i=0,fail=0;
size_t tmplen=0;
/* How many entries in the array? */
while (child) numentries++,child=child->next;
/* Explicitly handle numentries==0 */
if (!numentries)
{
if (p) out=ensure(p,3);
else out=(char*)cJSON_malloc(3);
if (out) strcpy(out,"[]");
return out;
}
if (p)
{
/* Compose the output array. */
i=p->offset;
ptr=ensure(p,1);if (!ptr) return 0; *ptr='['; p->offset++;
child=item->child;
while (child && !fail)
{
print_value(child,depth+1,fmt,p);
p->offset=update(p);
if (child->next) {len=fmt?2:1;ptr=ensure(p,len+1);if (!ptr) return 0;*ptr++=',';if(fmt)*ptr++=' ';*ptr=0;p->offset+=len;}
child=child->next;
}
ptr=ensure(p,2);if (!ptr) return 0; *ptr++=']';*ptr=0;
out=(p->buffer)+i;
}
else
{
/* Allocate an array to hold the values for each */
entries=(char**)cJSON_malloc(numentries*sizeof(char*));
if (!entries) return 0;
memset(entries,0,numentries*sizeof(char*));
/* Retrieve all the results: */
child=item->child;
while (child && !fail)
{
ret=print_value(child,depth+1,fmt,0);
entries[i++]=ret;
if (ret) len+=strlen(ret)+2+(fmt?1:0); else fail=1;
child=child->next;
}
/* If we didn't fail, try to malloc the output string */
if (!fail) out=(char*)cJSON_malloc(len);
/* If that fails, we fail. */
if (!out) fail=1;
/* Handle failure. */
if (fail)
{
for (i=0;i<numentries;i++) if (entries[i]) cJSON_free(entries[i]);
cJSON_free(entries);
return 0;
}
/* Compose the output array. */
*out='[';
ptr=out+1;*ptr=0;
for (i=0;i<numentries;i++)
{
tmplen=strlen(entries[i]);memcpy(ptr,entries[i],tmplen);ptr+=tmplen;
if (i!=numentries-1) {*ptr++=',';if(fmt)*ptr++=' ';*ptr=0;}
cJSON_free(entries[i]);
}
cJSON_free(entries);
*ptr++=']';*ptr++=0;
}
return out;
}
/* Build an object from the text. */
static const char *parse_object(cJSON *item,const char *value){
cJSON *child;
if (*value!='{') {ep=value;return 0;} /* not an object! */
item->type=cJSON_Object;
value=skip(value+1);
if (*value=='}') return value+1; /* empty array. */
item->child=child=cJSON_New_Item();
if (!item->child) return 0;
value=skip(parse_string(child,skip(value)));
if (!value) return 0;
child->string=child->valuestring;child->valuestring=0;
if (*value!=':') {ep=value;return 0;} /* fail! */
value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */
if (!value) return 0;
while (*value==',')
{
cJSON *new_item;
new_item=cJSON_New_Item();
if (!new_item)
return 0; /* memory fail */
child->next=new_item;new_item->prev=child;child=new_item;
value=skip(parse_string(child,skip(value+1)));
if (!value)
return 0;
child->string=child->valuestring;child->valuestring=0;
if (*value!=':')
{ep=value;return 0;} /* fail! */
value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */
if (!value)
return 0;
}
if (*value=='}') return value+1; /* end of array */
ep=value;return 0; /* malformed. */
}
/* Render an object to text. */
static char *print_object(cJSON *item,int depth,int fmt,printbuffer *p){
char **entries=0,**names=0;
char *out=0,*ptr,*ret,*str;int len=7,i=0,j;
cJSON *child=item->child;
int numentries=0,fail=0;
size_t tmplen=0;
/* Count the number of entries. */
while (child) numentries++,child=child->next;
/* Explicitly handle empty object case */
if (!numentries)
{
if (p) out=ensure(p,fmt?depth+4:3);
else out=(char*)cJSON_malloc(fmt?depth+4:3);
if (!out) return 0;
ptr=out;*ptr++='{';
if (fmt) {*ptr++='\n';for (i=0;i<depth-1;i++) *ptr++='\t';}
*ptr++='}';*ptr++=0;
return out;
}
if (p)
{
/* Compose the output: */
i=p->offset;
len=fmt?2:1; ptr=ensure(p,len+1); if (!ptr) return 0;
*ptr++='{'; if (fmt) *ptr++='\n'; *ptr=0; p->offset+=len;
child=item->child;depth++;
while (child)
{
if (fmt)
{
ptr=ensure(p,depth); if (!ptr) return 0;
for (j=0;j<depth;j++) *ptr++='\t';
p->offset+=depth;
}
print_string_ptr(child->string,p);
p->offset=update(p);
len=fmt?2:1;
ptr=ensure(p,len); if (!ptr) return 0;
*ptr++=':';if (fmt) *ptr++='\t';
p->offset+=len;
print_value(child,depth,fmt,p);
p->offset=update(p);
len=(fmt?1:0)+(child->next?1:0);
ptr=ensure(p,len+1); if (!ptr) return 0;
if (child->next) *ptr++=',';
if (fmt) *ptr++='\n';*ptr=0;
p->offset+=len;
child=child->next;
}
ptr=ensure(p,fmt?(depth+1):2); if (!ptr) return 0;
if (fmt) for (i=0;i<depth-1;i++) *ptr++='\t';
*ptr++='}';*ptr=0;
out=(p->buffer)+i;
}
else
{
/* Allocate space for the names and the objects */
entries=(char**)cJSON_malloc(numentries*sizeof(char*));
if (!entries) return 0;
names=(char**)cJSON_malloc(numentries*sizeof(char*));
if (!names) {cJSON_free(entries);return 0;}
memset(entries,0,sizeof(char*)*numentries);
memset(names,0,sizeof(char*)*numentries);
/* Collect all the results into our arrays: */
child=item->child;depth++;if (fmt) len+=depth;
while (child)
{
names[i]=str=print_string_ptr(child->string,0);
entries[i++]=ret=print_value(child,depth,fmt,0);
if (str && ret) len+=strlen(ret)+strlen(str)+2+(fmt?2+depth:0); else fail=1;
child=child->next;
}
/* Try to allocate the output string */
if (!fail) out=(char*)cJSON_malloc(len);
if (!out) fail=1;
/* Handle failure */
if (fail)
{
for (i=0;i<numentries;i++) {if (names[i]) cJSON_free(names[i]);if (entries[i]) cJSON_free(entries[i]);}
cJSON_free(names);cJSON_free(entries);
return 0;
}
/* Compose the output: */
*out='{';ptr=out+1;if (fmt)*ptr++='\n';*ptr=0;
for (i=0;i<numentries;i++)
{
if (fmt) for (j=0;j<depth;j++) *ptr++='\t';
tmplen=strlen(names[i]);memcpy(ptr,names[i],tmplen);ptr+=tmplen;
*ptr++=':';if (fmt) *ptr++='\t';
strcpy(ptr,entries[i]);ptr+=strlen(entries[i]);
if (i!=numentries-1) *ptr++=',';
if (fmt) *ptr++='\n';*ptr=0;
cJSON_free(names[i]);cJSON_free(entries[i]);
}
cJSON_free(names);cJSON_free(entries);
if (fmt) for (i=0;i<depth-1;i++) *ptr++='\t';
*ptr++='}';*ptr++=0;
}
return out;
}
/* 获取数组大小/项/对象项 */
int cJSON_GetArraySize(cJSON *array) {cJSON *c=array->child;int i=0;while(c)i++,c=c->next;return i;}
cJSON *cJSON_GetArrayItem(cJSON *array,int item) {cJSON *c=array->child; while (c && item>0) item--,c=c->next; return c;}
cJSON *cJSON_GetObjectItem(cJSON *object,const char *string) {cJSON *c=object->child; while (c && cJSON_strcasecmp(c->string,string)) c=c->next; return c;}
/* Utility for array list handling. */
static void suffix_object(cJSON *prev,cJSON *item) {prev->next=item;item->prev=prev;}
/* Utility for handling references. */
static cJSON *create_reference(cJSON *item) {cJSON *ref=cJSON_New_Item();if (!ref) return 0;memcpy(ref,item,sizeof(cJSON));ref->string=0;ref->type|=cJSON_IsReference;ref->next=ref->prev=0;return ref;}
/* Add item to array/object. */
void cJSON_AddItemToArray(cJSON *array, cJSON *item) {cJSON *c=array->child;if (!item) return; if (!c) {array->child=item;} else {while (c && c->next) c=c->next; suffix_object(c,item);}}
void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item) {if (!item) return; if (item->string) cJSON_free(item->string);item->string=cJSON_strdup(string);cJSON_AddItemToArray(object,item);}
void cJSON_AddItemToObjectCS(cJSON *object,const char *string,cJSON *item) {if (!item) return; if (!(item->type&cJSON_StringIsConst) && item->string) cJSON_free(item->string);item->string=(char*)string;item->type|=cJSON_StringIsConst;cJSON_AddItemToArray(object,item);}
void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) {cJSON_AddItemToArray(array,create_reference(item));}
void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item) {cJSON_AddItemToObject(object,string,create_reference(item));}
cJSON *cJSON_DetachItemFromArray(cJSON *array,int which) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return 0;
if (c->prev) c->prev->next=c->next;if (c->next) c->next->prev=c->prev;if (c==array->child) array->child=c->next;c->prev=c->next=0;return c;}
void cJSON_DeleteItemFromArray(cJSON *array,int which) {cJSON_Delete(cJSON_DetachItemFromArray(array,which));}
cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string) {int i=0;cJSON *c=object->child;while (c && cJSON_strcasecmp(c->string,string)) i++,c=c->next;if (c) return cJSON_DetachItemFromArray(object,i);return 0;}
void cJSON_DeleteItemFromObject(cJSON *object,const char *string) {cJSON_Delete(cJSON_DetachItemFromObject(object,string));}
/* Replace array/object items with new ones. */
void cJSON_InsertItemInArray(cJSON *array,int which,cJSON *newitem) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) {cJSON_AddItemToArray(array,newitem);return;}
newitem->next=c;newitem->prev=c->prev;c->prev=newitem;if (c==array->child) array->child=newitem; else newitem->prev->next=newitem;}
void cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return;
newitem->next=c->next;newitem->prev=c->prev;if (newitem->next) newitem->next->prev=newitem;
if (c==array->child) array->child=newitem; else newitem->prev->next=newitem;c->next=c->prev=0;cJSON_Delete(c);}
void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem){int i=0;cJSON *c=object->child;while(c && cJSON_strcasecmp(c->string,string))i++,c=c->next;if(c){newitem->string=cJSON_strdup(string);cJSON_ReplaceItemInArray(object,i,newitem);}}
/* Create basic types: */
cJSON *cJSON_CreateNull(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_NULL;return item;}
cJSON *cJSON_CreateTrue(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_True;return item;}
cJSON *cJSON_CreateFalse(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_False;return item;}
cJSON *cJSON_CreateBool(int b) {cJSON *item=cJSON_New_Item();if(item)item->type=b?cJSON_True:cJSON_False;return item;}
cJSON *cJSON_CreateNumber(double num) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_Number;item->valuedouble=num;item->valueint=(int)num;}return item;}
cJSON *cJSON_CreateString(const char *string) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_String;item->valuestring=cJSON_strdup(string);}return item;}
cJSON *cJSON_CreateArray(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_Array;return item;}
cJSON *cJSON_CreateObject(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_Object;return item;}
/* Create Arrays: */
cJSON *cJSON_CreateIntArray(const int *numbers,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateNumber(numbers[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
cJSON *cJSON_CreateFloatArray(const float *numbers,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateNumber(numbers[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
cJSON *cJSON_CreateDoubleArray(const double *numbers,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateNumber(numbers[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
cJSON *cJSON_CreateStringArray(const char **strings,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateString(strings[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
/* Duplication */
cJSON *cJSON_Duplicate(cJSON *item,int recurse){
cJSON *newitem,*cptr,*nptr=0,*newchild;
/* Bail on bad ptr */
if (!item) return 0;
/* Create new item */
newitem=cJSON_New_Item();
if (!newitem) return 0;
/* Copy over all vars */
newitem->type=item->type&(~cJSON_IsReference),newitem->valueint=item->valueint,newitem->valuedouble=item->valuedouble;
if (item->valuestring) {newitem->valuestring=cJSON_strdup(item->valuestring); if (!newitem->valuestring) {cJSON_Delete(newitem);return 0;}}
if (item->string) {newitem->string=cJSON_strdup(item->string); if (!newitem->string) {cJSON_Delete(newitem);return 0;}}
/* If non-recursive, then we're done! */
if (!recurse) return newitem;
/* Walk the ->next chain for the child. */
cptr=item->child;
while (cptr)
{
newchild=cJSON_Duplicate(cptr,1); /* Duplicate (with recurse) each item in the ->next chain */
if (!newchild) {cJSON_Delete(newitem);return 0;}
if (nptr) {nptr->next=newchild,newchild->prev=nptr;nptr=newchild;} /* If newitem->child already set, then crosswire ->prev and ->next and move on */
else {newitem->child=newchild;nptr=newchild;} /* Set newitem->child and move to it */
cptr=cptr->next;
}
return newitem;
}
void cJSON_Minify(char *json){
char *into=json;
while (*json)
{
if (*json==' ') json++;
else if (*json=='\t') json++; /* Whitespace characters. */
else if (*json=='\r') json++;
else if (*json=='\n') json++;
else if (*json=='/' && json[1]=='/') while (*json && *json!='\n') json++; /* double-slash comments, to end of line. */
else if (*json=='/' && json[1]=='*') {while (*json && !(*json=='*' && json[1]=='/')) json++;json+=2;} /* multiline comments. */
else if (*json=='\"'){*into++=*json++;while (*json && *json!='\"'){if (*json=='\\') *into++=*json++;*into++=*json++;}*into++=*json++;} /* string literals, which are \" sensitive. */
else *into++=*json++; /* All other characters. */
}
*into=0; /* and null-terminate. */
}

View File

@@ -1,126 +0,0 @@
#ifndef _cJSON_H_
#define _cJSON_H_
#ifdef __cplusplus
extern "C"
{
#endif
/* cJSON Types: */
#define cJSON_False 0
#define cJSON_True 1
#define cJSON_NULL 2
#define cJSON_Number 3
#define cJSON_String 4
#define cJSON_Array 5
#define cJSON_Object 6
#define cJSON_IsReference 256
#define cJSON_StringIsConst 512
/* The cJSON structure: */
typedef struct cJSON {
struct cJSON *next,*prev; /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
struct cJSON *child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
int type; /* The type of the item, as above. */
char *valuestring; /* The item's string, if type==cJSON_String */
int valueint; /* The item's number, if type==cJSON_Number */
double valuedouble; /* The item's number, if type==cJSON_Number */
char *string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
} cJSON;
typedef struct cJSON_Hooks {
void *(*malloc_fn)(size_t sz);
void (*free_fn)(void *ptr);
} cJSON_Hooks;
/* 向cJSON提供malloc、realloc和free函数 */
extern void cJSON_InitHooks(cJSON_Hooks* hooks);
/* 提供一个JSON块然后返回一个可以查询的cJSON对象。完成后调用cJSON_Delete */
extern cJSON *cJSON_Parse(const char *value);
/* 将cJSON实体呈现为用于传输/存储的文本。完成后释放char* */
extern char *cJSON_Print(cJSON *item);
/* 将cJSON实体呈现为用于传输/存储的文本而不进行任何格式化。完成后释放char* */
extern char *cJSON_PrintUnformatted(cJSON *item);
/* 使用缓冲策略将cJSON实体呈现为文本。预缓冲是对最终大小的猜测。猜测减少了重新分配。fmt=0表示无格式,=1表示有格式 */
extern char *cJSON_PrintBuffered(cJSON *item,int prebuffer,int fmt);
/* 删除一个cJSON实体和所有子实体 */
extern void cJSON_Delete(cJSON *c);
/* 返回数组(或对象)中的项数 */
extern int cJSON_GetArraySize(cJSON *array);
/* 从数组“数组”中检索项目编号“项目”。如果不成功返回NULL */
extern cJSON *cJSON_GetArrayItem(cJSON *array,int item);
/* 从对象中获取项目“string”。不区分大小写 */
extern cJSON *cJSON_GetObjectItem(cJSON *object,const char *string);
/* 用于分析失败的语法。这将返回一个指向解析错误的指针。你可能需要回头看几个字才能理解它。当cJSON_Parse()返回0时定义。当cJSON_Parse()成功时为0 */
extern const char *cJSON_GetErrorPtr(void);
/* 这些调用创建适当类型的cJSON项 */
extern cJSON *cJSON_CreateNull(void);
extern cJSON *cJSON_CreateTrue(void);
extern cJSON *cJSON_CreateFalse(void);
extern cJSON *cJSON_CreateBool(int b);
extern cJSON *cJSON_CreateNumber(double num);
extern cJSON *cJSON_CreateString(const char *string);
extern cJSON *cJSON_CreateArray(void);
extern cJSON *cJSON_CreateObject(void);
/* 这些实用程序创建一个计数项数组 */
extern cJSON *cJSON_CreateIntArray(const int *numbers,int count);
extern cJSON *cJSON_CreateFloatArray(const float *numbers,int count);
extern cJSON *cJSON_CreateDoubleArray(const double *numbers,int count);
extern cJSON *cJSON_CreateStringArray(const char **strings,int count);
/* 向指定的数组/对象追加项 */
extern void cJSON_AddItemToArray(cJSON *array, cJSON *item);
extern void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item);
extern void cJSON_AddItemToObjectCS(cJSON *object,const char *string,cJSON *item); /* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object */
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
extern void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
extern void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item);
/* 从数组/对象中删除/分离项 */
extern cJSON *cJSON_DetachItemFromArray(cJSON *array,int which);
extern void cJSON_DeleteItemFromArray(cJSON *array,int which);
extern cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string);
extern void cJSON_DeleteItemFromObject(cJSON *object,const char *string);
/* Update array items. */
extern void cJSON_InsertItemInArray(cJSON *array,int which,cJSON *newitem); /* Shifts pre-existing items to the right. */
extern void cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem);
extern void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
/* 复制一个cJSON项目 */
extern cJSON *cJSON_Duplicate(cJSON *item,int recurse);
/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
need to be released. With recurse!=0, it will duplicate any children connected to the item.
The item->next and ->prev pointers are always zero on return from Duplicate. */
/* ParseWithOpts允许您要求(并检查)JSON是否以null结尾并检索指向解析后的最终字节的指针 */
extern cJSON *cJSON_ParseWithOpts(const char *value,const char **return_parse_end,int require_null_terminated);
extern void cJSON_Minify(char *json);
/* 用于快速创建内容的宏 */
#define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull())
#define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue())
#define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse())
#define cJSON_AddBoolToObject(object,name,b) cJSON_AddItemToObject(object, name, cJSON_CreateBool(b))
#define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n))
#define cJSON_AddStringToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s))
/* 在分配整数值时也需要将其传播到valuedouble */
#define cJSON_SetIntValue(object,val) ((object)?(object)->valueint=(object)->valuedouble=(val):(val))
#define cJSON_SetNumberValue(object,val) ((object)?(object)->valueint=(object)->valuedouble=(val):(val))
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,40 +0,0 @@
#include "uart1_receive.h"
void BSP_UART1ReceiveInfor(void)
{
if(UART1ReadFlag&0x8000)
{
UART1ReadFlag = 0;
memset((void *)UART1ReadBuf,0,sizeof(UART1ReadBuf));
}
}

View File

@@ -1,27 +0,0 @@
#ifndef _UART1_RECEIVE_H_
#define _UART1_RECEIVE_H_
#include "stm32f10x.h"
#include "bsp_uart1.h"
#include "bsp_timer3.h"
#include "bsp_port.h"
void Sys_Usart1RecMessage(void);
#endif

View File

@@ -1,81 +0,0 @@
#include "uart2_receive.h"
uint8_t txLen = 0;
uint8_t txBuf[20] = {0};
static uint8_t Server_CheckSum(uint8_t * buf)
{
uint8_t len = 0,i = 0;
uint16_t CheckSum = 0;
len = buf[2] - 2;
for( i = 0; i < len; i++)
CheckSum += buf[i+2];
return (uint8_t)CheckSum;
}
void Server_Protocol(void)
{
if(UART2ReadFlag&0x8000)
{
if(UART2ReadBuf[0]==0xAA && UART2ReadBuf[1]==0xBB)
{
// 校验和
switch(UART2ReadBuf[3])
{
case 0x90 : { } break; // 返回配网结果
case 0x91 : { DevParam.Server = UART2ReadBuf[8]; } break; // 返回网络状态
case 0x94 : { } break; // 返回上报属性结果
case 0x95 : { } break; // 返回上报事件结果
case 0x96 : { } break; // 下发控制
case 0x97 : { } break; // 下发获取状态
default : break;
}
}
UART2ReadFlag = 0;
memset((void *)UART2ReadBuf,0,sizeof(UART2ReadBuf));
}
// 间隔2秒上报设备状态
if( (DevParam.Server==2) && (DevParam.ServerUpdateTime>=2000) )
{
txLen = 0;
txBuf[txLen++] = 0xAA; txBuf[txLen++] = 0xBB;
txBuf[txLen++] = 0x00; // 数据长度,帧头后有效数据长度
txBuf[txLen++] = 0x84; // 上报属性
txBuf[txLen++] = 0x01; txBuf[txLen++] = 0x02; txBuf[txLen++] = 0x03; txBuf[txLen++] = 0x04; // 客户端ID
/////////参数////////
txBuf[txLen++] = 0x01; txBuf[txLen++] = 0x01;
txBuf[txLen++] = 0x01; txBuf[txLen++] = 0x01;
///////////////////////
txBuf[txLen++] = 0x00; // 校验和
txBuf[txLen++] = 0x5F; // 帧尾
txBuf[2] = txLen-2; // 数据长度
txBuf[txLen-2] = Server_CheckSum(txBuf);// 校验和
// 发送
ESP8266_SendData( txBuf, txLen);
DevParam.ServerUpdateTime = 0;
}
}

View File

@@ -1,21 +0,0 @@
#ifndef _UART2_RECEIVE_H_
#define _UART2_RECEIVE_H_
#include "stm32f10x.h"
#include "bsp_timer3.h"
#include "bsp_uart2.h"
#endif

View File

@@ -1,28 +0,0 @@
#include "uart3_receive.h"
void BSP_UART3ReceiveInfor(void)
{
// Sys_Usart3RecComplete(System_1ms);
// if(Usart3ReadFlag&0x8000)
// {
// Sys_Usart3SendStr("uart3:");
// Sys_Usart3SendData(Usart3ReadBuf,(Usart3ReadFlag&(~(1<<15))));
//
// Usart3ReadFlag = 0;
// memset((void *)Usart3ReadBuf,0,sizeof(Usart3ReadBuf));
// }
}

View File

@@ -1,24 +0,0 @@
#ifndef _UART3_RECEIVE_H_
#define _UART3_RECEIVE_H_
#include "stm32f10x.h"
#include "bsp_timer3.h"
#include "bsp_uart3.h"
void BSP_UART3ReceiveInfor(void);
#endif

View File

@@ -1,18 +0,0 @@
#include "basic_data.h"
uint8_t UART1ReadBuf[500] = {0};
uint16_t UART1ReadFlag = 0;
uint8_t UART2ReadBuf[500] = {0};
uint16_t UART2ReadFlag = 0;
uint8_t UART3ReadBuf[500] = {0};
uint16_t UART3ReadFlag = 0;
DevParam_t DevParam = {0};

View File

@@ -1,74 +0,0 @@
#ifndef _BASIC_DATA_H_
#define _BASIC_DATA_H_
#include "stm32f10x.h"
#define Device_LCD 1
#define MQTT_SCode 1
//#define MQTT_AT 1
extern uint8_t UART1ReadBuf[500];
extern uint16_t UART1ReadFlag;
extern uint8_t UART2ReadBuf[500];
extern uint16_t UART2ReadFlag;
extern uint8_t UART3ReadBuf[500];
extern uint16_t UART3ReadFlag;
typedef enum
{
RunPhase_Standby = 0x01,
RunPhase_Runing = 0x02,
RunPhase_Close = 0x03
}RunPhase_E;
typedef struct
{
uint16_t U3GetTime;
uint8_t BatCheck; // 电池检测
float BatVoltage; // 电池电压
uint8_t BatSOC; // 电池SOC
uint8_t ShortBatSOC;// 显示电池SOC
uint8_t BatCharging;// 电池充电中
uint16_t BatInforGetTime; // 电池信息获取时间
uint16_t BatIconRefreshTime;// 电池图标刷新时间
uint16_t AirInforGetTime; // 空气信息获取时间
uint8_t ServerRelay; // 服务器继电器
uint8_t ServerRed;
uint16_t ESP8266SendTime;
uint16_t MQTTSendTime;
// 运行阶段
RunPhase_E RunPhase;
RunPhase_E ShortRunPhase;
uint8_t SideBeat; // 侧边标识
uint16_t SideBeatTime; // 侧边跳动时间
uint16_t Server;
uint16_t ServerUpdateTime;
uint16_t ShowPM1_0;
uint16_t ShowPM2_5;
uint16_t ShowPM10;
uint16_t PM1_0;
uint16_t PM2_5;
uint16_t PM10;
uint16_t tes;
}DevParam_t;
extern DevParam_t DevParam;
#endif

View File

@@ -1,70 +0,0 @@
#include "bsp_adc.h"
void BSP_ADCInit(void)
{
ADC_InitTypeDef ADC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOA, ENABLE);
RCC_ADCCLKConfig(RCC_PCLK2_Div6);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA,&GPIO_InitStructure);
ADC_DeInit(ADC1);
/* ADC1 configuration ------------------------------------------------------*/
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 1;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_Cmd(ADC1, ENABLE);
ADC_ResetCalibration(ADC1);
while(ADC_GetResetCalibrationStatus(ADC1));
ADC_StartCalibration(ADC1);
while(ADC_GetCalibrationStatus(ADC1));
ADC_SoftwareStartConvCmd(ADC1,ENABLE);
}
float ADC_GetSimpleData(void)
{
float SimpleVoltage = 0;
uint8_t x = 0;
uint32_t total = 0;
for( x = 0;x < 5; x++)
{
// 开启转换,等待DMA传输结束
ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_239Cycles5 );
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC )){}//等待转换结束
total += ADC_GetConversionValue(ADC1);
Delay_ms(2);
}
total = (uint32_t)(total/5);
SimpleVoltage = (float)total*3.3/4096.0*2.0;
return SimpleVoltage;
}

View File

@@ -1,17 +0,0 @@
#ifndef _BSP_ADC_H_
#define _BSP_ADC_H_
#include "stm32f10x.h"
#include "string.h"
#include "bsp_port.h"
#include "bsp_timer3.h"
#include "basic_data.h"
void BSP_ADCInit(void);
float ADC_GetSimpleData(void);
#endif

View File

@@ -1,53 +0,0 @@
#include "bsp_clock.h"
static uint8_t fac_us = 0;
static uint16_t fac_ms = 0;
//功能systick初始化
void BSP_ClockInit(void)
{
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); //选择外部时钟 HCLK/8
fac_us=SystemCoreClock/8000000;//为系统时钟的1/8
fac_ms = (uint16_t)fac_us*1000;
}
//功能:毫秒级延时,最多1864ms
void Delay_ms(uint32_t nms)
{
uint32_t temp = 0;
SysTick->LOAD=(uint32_t)nms*fac_ms;//时间加载(SysTick->LOAD为24bit)
SysTick->VAL =0x00; //清空计数器
SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ; //开始倒数
do
{
temp=SysTick->CTRL;
}
while( (temp&0x01) && (!(temp&(1<<16))) );//等待时间到达
SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk; //关闭计数器
SysTick->VAL =0X00; //清空计数器
}
//功能微秒级延时最多1800ms
void Delay_us(uint32_t nus)
{
uint32_t temp;
SysTick->LOAD=nus*fac_us; //时间加载
SysTick->VAL=0x00; //清空计数器
SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ; //开始倒数
do
{
temp=SysTick->CTRL;
}
while( (temp&0x01) && (!(temp&(1<<16))) );//等待时间到达
SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk; //关闭计数器
SysTick->VAL =0X00; //清空计数器
}

View File

@@ -1,12 +0,0 @@
#ifndef _BSP_CLOCK_H_
#define _BSP_CLOCK_H_
#include "stm32f10x.h"
void Delay_ms(uint32_t nms);
void Delay_us(uint32_t nus);
void BSP_ClockInit(void);
#endif

View File

@@ -1,74 +0,0 @@
#include "bsp_port.h"
// 禁用JTAG引脚,保留SWD引脚
void Sys_DisableJTAGEnableSWD(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); //开启AFIO时钟
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable,ENABLE); //禁止JTAG功能
}
// PM 初始化
void BSP_PowerInit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_12|GPIO_Pin_13;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStructure);
Power_PMD4(0); Power_3V3(0); Power_LCD(0);
// 唤醒/正在充电指示/充电完成
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_14;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOC,&GPIO_InitStructure);
/* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* 配置P[A|B|C|D|E]0为中断源 */
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
GPIO_Init(GPIOC,&GPIO_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource15);
EXTI_InitStructure.EXTI_Line = EXTI15_10_IRQn;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //下降沿中断
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
void EXTI15_10_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line15) != RESET)
{
EXTI_ClearITPendingBit(EXTI_Line15);
if(DevParam.RunPhase == 0)
{
BSP_Restart();
}
}
}
// mcu 重新启动
void BSP_Restart(void){
__set_FAULTMASK(1);
NVIC_SystemReset();
}

View File

@@ -1,34 +0,0 @@
#ifndef _BSP_PORT_H_
#define _BSP_PORT_H_
#include "stm32f10x.h"
#include "bsp_clock.h"
#include "bsp_timer3.h"
#include "basic_data.h"
// 禁用JTAG引脚,保留SWD引脚
void Sys_DisableJTAGEnableSWD(void);
#define Power_PMD4(x) (x)?GPIO_SetBits(GPIOB,GPIO_Pin_1) :GPIO_ResetBits(GPIOB,GPIO_Pin_1) // PM2.5
#define Power_LCD(x) (x)?GPIO_SetBits(GPIOB,GPIO_Pin_12):GPIO_ResetBits(GPIOB,GPIO_Pin_12)// LCD
#define Power_3V3(x) (x)?GPIO_SetBits(GPIOB,GPIO_Pin_13):GPIO_ResetBits(GPIOB,GPIO_Pin_13)// 3.3V
#define Read_BatCharging() GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13)// 电池充电中状态,低电平有效
#define Read_BatComplete() GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_14)// 电池充电完成状态,低电平有效
#define Read_BootKey() GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_15)// 开机按键
void BSP_PowerInit(void);
void Dev_ReadIndicate(void);
// 重启
void BSP_Restart(void);
#endif

View File

@@ -1,126 +0,0 @@
#include "bsp_timer3.h"
/*如果Period=N*10那么每隔N毫秒中断一次。*/
void BSP_Timer3Init(void){
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //时钟使能
TIM_TimeBaseStructure.TIM_Period = 9; //设置在下一个更新事件装入活动的自动重装载寄存器周期的值 计数到N*10为Nms
TIM_TimeBaseStructure.TIM_Prescaler =(7200-1); //设置用来作为TIMx时钟频率除数的预分频值 10Khz的计数频率
TIM_TimeBaseStructure.TIM_ClockDivision = 0; //设置时钟分割:TDTS = Tck_tim
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIM向上计数模式
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); //根据TIM_TimeBaseInitStruct中指定的参数初始化TIMx的时间基数单位
TIM_ITConfig( //使能或者失能指定的TIM中断
TIM3, //TIM3
TIM_IT_Update| //TIM 中断源
TIM_IT_Trigger,//TIM 触发中断源
ENABLE //使能
);
/*配置中断优先级*/
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; //TIM3中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //先占优先级0级
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //从优先级3级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道被使能
NVIC_Init(&NVIC_InitStructure);//根据NVIC_InitStruct中指定的参数初始化外设NVIC寄存器
TIM_Cmd(TIM3, ENABLE); //使能TIMx外设
}
uint16_t UART2Count = 0;
uint8_t UART2RecTime = 0;
uint16_t UART3Count = 0;
uint8_t UART3RecTime = 0;
void TIM3_IRQHandler(void) //TIM3中断服务程序
{
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)//检查指定的TIM中断发生与否
{
TIM_ClearITPendingBit(TIM3,TIM_IT_Update); //清除TIMx的中断标志位
// 串口2接收判断
if((UART2ReadFlag!=0)&&(!(UART2ReadFlag&0x8000)))
{
if(UART2RecTime<=200)
UART2RecTime++;
if(UART2RecTime >= 20)
{
if(UART2Count == UART2ReadFlag)
{
UART2ReadFlag |= (1 << 15);
UART2Count = 0;
UART2RecTime = 0;
}
else
{
UART2Count = UART2ReadFlag;
UART2RecTime = 0;
}
}
}
else { UART2RecTime = 0; UART2Count = 0; }
// 串口3接收判断
if((UART3ReadFlag!=0)&&(!(UART3ReadFlag&0x8000)))
{
if(UART3RecTime <= 100)
UART3RecTime++;
if(UART3RecTime >= 20)
{
if(UART3Count == UART3ReadFlag)
{
UART3ReadFlag |= (1 << 15);
UART3Count = 0;
UART3RecTime = 0;
}
else
{
UART3Count = UART3ReadFlag;
UART3RecTime = 0;
}
}
}
else { UART3RecTime = 0; UART3Count = 0; }
// 空气信息获取时间
if(DevParam.AirInforGetTime<65000)
DevParam.AirInforGetTime++;
// 电池图标刷新时间
if(DevParam.BatIconRefreshTime<65000)
DevParam.BatIconRefreshTime++;
// 电池信息获取时间
if(DevParam.BatInforGetTime<65000)
DevParam.BatInforGetTime++;
// 侧边跳动时间
if(DevParam.SideBeatTime<65000)
DevParam.SideBeatTime++;
// 上报到服务器状态时间
if(DevParam.ServerUpdateTime<65000)
DevParam.ServerUpdateTime++;
// 发送时间
if(DevParam.ESP8266SendTime<65000)
DevParam.ESP8266SendTime++;
// 发送时间
if(DevParam.MQTTSendTime<65000)
DevParam.MQTTSendTime++;
}
}

View File

@@ -1,15 +0,0 @@
#ifndef _BSP_TIMER3_H_
#define _BSP_TIMER3_H_
#include "stm32f10x.h"
#include "bsp_uart3.h"
#include "esp8266_uart2.h"
#include "basic_data.h"
void BSP_Timer3Init(void);
#endif

View File

@@ -1,2 +0,0 @@
#include "bsp_tool.h"

View File

@@ -1,11 +0,0 @@
#ifndef _BSP_TOOL_H_
#define _BSP_TOOL_H_
#include "stm32f10x.h"
#include "bsp_clock.h"
#include "basic_data.h"
#endif

View File

@@ -1,107 +0,0 @@
#include "bsp_uart1.h"
void BSP_UART1SendStr(char *ch){
uint16_t i = 0,j = 0;
j = strlen(ch);
for(i = 0;i < j;i++)
{
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET){};
USART_SendData(USART1,ch[i]);
}
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET);
}
// 发送数据
void BSP_UART1SendData(uint8_t *ch,uint16_t len){
uint16_t i;
for(i = 0;i < len;i++)
{
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET){};
USART_SendData(USART1,ch[i]);
}
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET);
}
void BSP_UART1Init(uint32_t bound){
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
//使能USART1,GPIOA
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA,ENABLE);
//USART1_TX GPIOA.9
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//USART1_RX GPIOA.10初始化
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//Usart1 NVIC 配置
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority= 3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//USART 初始化设置
USART_InitStructure.USART_BaudRate = bound;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1,&USART_InitStructure);
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
USART_Cmd(USART1, ENABLE);
}
// 读取USARTx->SR能避免莫名其妙的错误
uint8_t Usart1ReadBuf[100] = {0};
uint16_t Usart1ReadFlag = 0;
void USART1_IRQHandler(void){
uint8_t res = 0;
if(USART_GetITStatus(USART1,USART_IT_RXNE) != RESET)
{
res =USART_ReceiveData(USART1);
// 是否存在数据没有处理
if( (Usart1ReadFlag&0x8000)==0 )
{
Usart1ReadBuf[Usart1ReadFlag] = res;
Usart1ReadFlag++;
// 判断是否接收结束
if(Usart1ReadFlag>=90)
{
Usart1ReadFlag |= (1 << 15);
}
}
}
//溢出-如果发生溢出需要先读SR,再读DR,则可清除不断入中断的问题
if( USART_GetFlagStatus(USART1,USART_FLAG_ORE)==SET )
{
USART_ReceiveData(USART1);
USART_ClearFlag(USART1,USART_FLAG_ORE);
}
USART_ClearFlag(USART1,USART_IT_RXNE);
}

View File

@@ -1,22 +0,0 @@
#ifndef _BSP_UART1_H_
#define _BSP_UART1_H_
#include "stm32f10x.h"
#include "bsp_clock.h"
#include "stdio.h"
#include "string.h"
#include "stdarg.h"
#include "bsp_timer3.h"
void Sys_SendLog(const char *fmt, ...);
// 判断串口01接收完成
void BSP_UART1RecComplete(uint64_t Std_1ms);
void BSP_UART1SendStr(char *ch);
void BSP_UART1SendData(uint8_t *ch,uint16_t len);
void BSP_UART1Init(uint32_t bound);
#endif

View File

@@ -1,114 +0,0 @@
#include "bsp_uart2.h"
// 串口2 PA2 TX PA3 RX
void Dev_UART2SendStr(uint8_t* tbuf, uint16_t tlen, uint8_t tByte){
uint16_t i = 0,j = 0;
if(tlen > 0)
j = tlen;
else
j = strlen((const char*)tbuf);
for( i = 0; i < j; i++)
{
if((tByte>0)&&(i==2))
{
while(USART_GetFlagStatus(USART2, USART_FLAG_TC)==RESET){};
USART_SendData(USART2, tByte);
}
while(USART_GetFlagStatus(USART2, USART_FLAG_TC)==RESET){};
USART_SendData(USART2, tbuf[i]);
}
while(USART_GetFlagStatus(USART2, USART_FLAG_TC)==RESET);
}
// 发送数据
void Dev_UART2SendData(uint8_t *ch,uint16_t len){
uint16_t i = 0;
for(i = 0;i < len;i++)
{
while(USART_GetFlagStatus(USART2,USART_FLAG_TC)==RESET){};
USART_SendData(USART2,ch[i]);
}
while(USART_GetFlagStatus(USART2,USART_FLAG_TC)==RESET);
}
void BSP_UART2Init(uint32_t bound)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
//使能USART,GPIO
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// NVIC 配置
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority= 3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
// USART 配置
USART_InitStructure.USART_BaudRate = bound;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART2, &USART_InitStructure);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);//开启串口接受中断
USART_Cmd(USART2, ENABLE); //使能串口
}
/*读取USARTx->SR能避免莫名其妙的错误*/
void USART2_IRQHandler(void)
{
uint8_t res = 0;
if(USART_GetITStatus(USART2, USART_IT_RXNE)!=RESET)
{
res = USART_ReceiveData(USART2);
// 是否存在数据没有处理
if((UART2ReadFlag&0x8000)==0)
{
UART2ReadBuf[UART2ReadFlag++] = res;
if(UART2ReadFlag>=480)
{
UART2ReadFlag |= (1 << 15);
}
}
}
/*溢出-如果发生溢出需要先读SR,再读DR寄存器则可清除不断入中断的问题*/
if( USART_GetFlagStatus(USART2, USART_FLAG_ORE)==SET )
{
USART_ReceiveData(USART2);
USART_ClearFlag(USART2, USART_FLAG_ORE);
}
USART_ClearFlag(USART2, USART_IT_RXNE);
}

View File

@@ -1,19 +0,0 @@
#ifndef _BSP_UART2_H_
#define _BSP_UART2_H_
#include "stm32f10x.h"
#include "bsp_clock.h"
#include "stdio.h"
#include "string.h"
#include "stdarg.h"
#include "bsp_timer3.h"
#include "basic_data.h"
void Dev_UART2SendStr(uint8_t* tbuf, uint16_t tlen, uint8_t tByte);
void Dev_UART2SendData(uint8_t *ch, uint16_t len);
void BSP_UART2Init(uint32_t bound);
#endif

View File

@@ -1,106 +0,0 @@
#include "bsp_uart3.h"
// 串口3 PB10 TX PB11 RX
void BSP_UART3SendStr(char *ch){
uint16_t i = 0,j = 0;
j = strlen(ch);
for(i = 0;i < j;i++)
{
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)==RESET){};
USART_SendData(USART3,ch[i]);
}
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)==RESET);
}
// 发送数据
void BSP_UART3SendData(uint8_t *ch,uint16_t len){
uint16_t i = 0;
for(i = 0;i < len;i++)
{
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)==RESET){};
USART_SendData(USART3,ch[i]);
}
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)==RESET);
}
void BSP_UART3Init(uint32_t bound){
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
//使能USART3,GPIOB
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
//USART3_TX GPIOB10
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//USART3_RX GPIOB11
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//Usart3 NVIC 配置
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority= 3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//USART 初始化设置
USART_InitStructure.USART_BaudRate = bound;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART3, &USART_InitStructure);
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);//开启串口接受中断
USART_Cmd(USART3, ENABLE); //使能串口
}
// 读取USARTx->SR能避免莫名其妙的错误
void USART3_IRQHandler(void)
{
uint8_t res = 0;
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)
{
res = USART_ReceiveData(USART3);
// 是否存在数据没有处理
if( (UART3ReadFlag&0x8000)==0 )
{
UART3ReadBuf[UART3ReadFlag++] = res;
if(UART3ReadFlag>=59)
{
UART3ReadFlag |= (1 << 15);
}
}
}
//溢出-如果发生溢出需要先读SR,再读DR寄存器则可清除不断入中断的问题
if( USART_GetFlagStatus(USART3,USART_FLAG_ORE)==SET )
{
USART_ReceiveData(USART3);
USART_ClearFlag(USART3,USART_FLAG_ORE);
}
USART_ClearFlag(USART3,USART_IT_RXNE);
}

View File

@@ -1,18 +0,0 @@
#ifndef _BSP_UART3_H_
#define _BSP_UART3_H_
#include "stm32f10x.h"
#include "bsp_clock.h"
#include "stdio.h"
#include "string.h"
#include "basic_data.h"
// 判断串口03接收完成
void BSP_UART3SendStr(char *ch);
void BSP_UART3SendData(uint8_t *ch,uint16_t len);
void BSP_UART3Init(uint32_t bound);
#endif

View File

@@ -1,66 +0,0 @@
#include "main.h"
/************************
ESP8266 UART2
PMD4 UART3
************************/
int main()
{
BSP_ClockInit();
BSP_Timer3Init();
// 电源控制部分
BSP_PowerInit();
Delay_ms(200);
// 电池电压ADC
BSP_ADCInit();
// LCD
#ifdef Device_LCD
Delay_ms(1000);
SimLCD_Init();
DevParam.AirInforGetTime = 3000;
DevParam.BatIconRefreshTime= 3000;
DevParam.BatInforGetTime = 3000;
DevParam.SideBeatTime = 3000;
DevParam.ShowPM1_0 = 200;
DevParam.ShowPM2_5 = 200;
DevParam.ShowPM10 = 200;
#endif
while(1)
{
// 网络配网部分
//ESP8266_NetWorkFlow();
// 网络数据接收处理
ESP8266_NetReceiveInfor();
// 电池,获取电池信息
Bat_GetWorkInfor();
// 读取电路板状态
Dev_ScanExtIndicate();
// 切换工作模式
Dev_SwitchWorkMode();
// 系统正常运行处理流程
if(DevParam.RunPhase == RunPhase_Runing)
{
// 显示部分,侧边跳动
Show_BroadSideBeat();
// PMD4获取空气信息
PMD4_GetAirInfor();
}
// 显示部分,电池图标刷新
Show_BatIconRefresh();
}
}

View File

@@ -1,28 +0,0 @@
#ifndef _MAIN_H_
#define _MAIN_H_
#include "stm32f10x.h"
#include "bsp_clock.h"
#include "bsp_timer3.h"
#include "bsp_port.h"
#include "bsp_tool.h"
#include "bsp_adc.h"
#include "pm_uart3.h"
#include "uart2_receive.h"
#include "simulation_lcd.h"
#include "esp8266_work.h"
#include "dev_work.h"
#include "battery.h"
#endif

View File

@@ -1,333 +0,0 @@
#include "mqtt.h"
/* 数据采用大端模式,高字节先发
UTF-8 "长度 + 字符串"
控制报文包含:固定包头+可变包头+有效负载
固定包头 byte1报文类型bit7-4+类型标识bit3-0 + byte2剩余长度包含可变包头和有效负载长度最大128字节
两个字节的计算方式:
两个字节的计算方式:剩余长度=(Byte1-128)+Byte2*128
*/
/***计算剩余字节数***/
uint8_t by[4] = {0};
uint8_t MQTTSCode_CalcSurplusByte(uint32_t str){
uint8_t i = 0;
do
{
by[i] = str%128;
str = str/128;
if(str > 0)
{
by[i] = by[i] | 128;
i++;
}
} while(str > 0);
return i;
}
MQTT_ConnectData_t MQTT_ConnectData;
static uint8_t StringData[500] = {0};
static uint8_t StringLen = 0;
static uint16_t waittime = 200;
static uint16_t NewSite = 0;
// 连接服务器
uint8_t MQTTSCode_Connect(void) {
waittime = 500;
memset((void *)StringData, 0, sizeof(StringData));
/*固定包头*/
StringData[0] = (uint8_t)(CONNECT<<4) + 0;// 固定帧头
StringData[1] = 0x00;// 剩余长度值
/***可变包头***/
// 协议名
StringData[2] = 0x00;
StringData[3] = 0x04;
StringData[4] = 'M';
StringData[5] = 'Q';
StringData[6] = 'T';
StringData[7] = 'T';
// 协议版本V3.1.1
StringData[8] = 0x04;
/* 连接标识 使能用户名和密码校验,不使用遗嘱,不保留会话
* 1bit 清理会话
* 2bit 遗嘱标识
* 3bit 遗嘱QoS
* 4bit 遗嘱QoS
* 5bit 遗嘱保留
* 6bit 用户名标识
* 7bit 密码标识
*/
StringData[9] = 0xC2;
// 保活时间
StringData[10] = (uint8_t)(MQTT_ConnectData.keepAlive>>8);
StringData[11] = (uint8_t)(MQTT_ConnectData.keepAlive>>0);
// 客户端ID
NewSite = 12;
StringLen = strlen((const char*)MQTT_ConnectData.clientID);
StringData[NewSite] = (uint8_t)(StringLen>>8);
StringData[NewSite+1] = (uint8_t)(StringLen>>0);
memcpy( &StringData[NewSite+2], MQTT_ConnectData.clientID, StringLen);
NewSite = NewSite + 2 + StringLen;
// 用户名
StringLen = strlen((const char*)MQTT_ConnectData.username);
StringData[NewSite] = (uint8_t)(StringLen>>8);
StringData[NewSite+1]= (uint8_t)(StringLen>>0);
memcpy( &StringData[NewSite+2], MQTT_ConnectData.username, StringLen);
NewSite = NewSite + 2 + StringLen;
// 密码
StringLen = strlen((const char*)MQTT_ConnectData.password);
StringData[NewSite] = (uint8_t)(StringLen>>8);
StringData[NewSite+1] = (uint8_t)(StringLen>>0);
memcpy( &StringData[NewSite+2], MQTT_ConnectData.password, StringLen);
NewSite = NewSite + 2 + StringLen;
// 剩余长度
if(NewSite < 127)
StringData[1] = NewSite - 2;
else
return 1;
UART2ReadFlag = 0;
memset((void *)UART2ReadBuf, 0, sizeof(UART2ReadBuf));
Dev_UART2SendStr(StringData, NewSite, 0);
// 等待回应
if(waittime) {
while(--waittime)
{
Delay_ms(10);
if(UART2ReadFlag&0x8000)
{
if(((UART2ReadBuf[0]>>4)==CONNACK)&&(UART2ReadBuf[1]==2))
{
if(UART2ReadBuf[3]==0){
UART2ReadFlag = 0;
return 0;
}
else{
UART2ReadFlag = 0;
while(1);
}
}
}
}
if(waittime==0)
return 1;
}
return 1;
}
// 订阅 服务质量
uint8_t MQTTSCode_Subscribe(char *topic, uint8_t qos, uint8_t bsf) {
waittime = 500;
memset((void *)StringData, 0, sizeof(StringData));
/*固定包头*/
StringData[0] = (uint8_t)(SUBSCRIBE<<4) + (uint8_t)(1<<1);// 固定帧头
StringData[1] = 0x00;// 剩余长度值
/*可变包头*/
// 报文标识符
NewSite = 2;
StringData[NewSite] = (uint8_t)(bsf>>8);
StringData[NewSite+1] = (uint8_t)(bsf>>0);
NewSite = NewSite + 2;
// 有效负载
// 主题
StringLen = strlen((const char*)topic);
StringData[NewSite] = (uint8_t)(StringLen>>8);
StringData[NewSite+1] = (uint8_t)(StringLen>>0);
memcpy( &StringData[NewSite+2], topic, StringLen);
NewSite = NewSite + 2 + StringLen;
// 服务质量
StringData[NewSite] = (uint8_t)(qos>>0);
NewSite = NewSite + 1;
// 剩余长度
if(NewSite < 127)
StringData[1] = NewSite - 2;
else
return 1;
UART2ReadFlag = 0;
memset((void *)UART2ReadBuf, 0, sizeof(UART2ReadBuf));
Dev_UART2SendStr(StringData, NewSite, 0);
if(waittime) {
while(--waittime)
{
Delay_ms(10);
if(UART2ReadFlag&0x8000)
{
if((UART2ReadBuf[0]>>4)==SUBACK)
{
UART2ReadFlag = 0;
return 0;
}
}
}
if(waittime==0)
return 1;
}
return 1;
}
// 发布暂定负载小于100字节
// qos 0最多发送一次1至少分发一次2只分发一次
uint16_t wait = 0;
uint16_t byte1 = 0,byte2 = 0;
uint8_t MQTTSCode_Publish(char *topic, char *payload, uint16_t payloadLen, uint8_t dup, uint8_t qos, uint16_t bsf) {
waittime = 500;
memset((void *)StringData, 0, sizeof(StringData));
/*固定包头*/
StringData[0] = (uint8_t)(PUBLISH<<4) + (uint8_t)(dup<<3) + (uint8_t)(qos<<1);// 固定帧头
StringData[1] = 0x00;// 剩余长度值
/*可变包头*/
// 主题名
NewSite = 2;
StringLen = strlen((const char*)topic);
StringData[NewSite] = (uint8_t)(StringLen>>8);
StringData[NewSite+1] = (uint8_t)(StringLen>>0);
memcpy( &StringData[NewSite+2], topic, StringLen);
NewSite = NewSite + 2 + StringLen;
// 报文标识符
if((qos==1) || (qos==2)) {
StringData[NewSite] = (uint8_t)(bsf>>8);
StringData[NewSite+1] = (uint8_t)(bsf>>0);
NewSite = NewSite + 2;
}
// 有效负载
StringLen = payloadLen;
if(StringLen > 0) {
memcpy( &StringData[NewSite], payload, StringLen);
NewSite = NewSite + StringLen;
}
// 剩余长度
byte1 = 0;
byte2 = 0;
if(NewSite <= 129) {
StringData[1] = NewSite - 2;
}
else
{
wait = NewSite - 2;
byte1 = wait%128;
wait = wait/128;
if(wait > 0)
{
byte1 = byte1 | 128;
byte2 = wait%128;
StringData[1] = byte1;
}
}
UART2ReadFlag = 0;
memset((void *)UART2ReadBuf, 0, sizeof(UART2ReadBuf));
Dev_UART2SendStr(StringData, NewSite, byte2);
// 没有回复消息
if((qos==1)||(qos==2)) {
if(waittime) {
while(--waittime)
{
Delay_ms(10);
if(UART2ReadFlag&0x8000)
{
if(((UART2ReadBuf[0]>>4)==PUBACK)&&(UART2ReadBuf[1]==2)&&(qos==1))
{
UART2ReadFlag = 0;
return 0;
}
// if(((UART2ReadBuf[0]>>4)==PUBREC)&&(UART2ReadBuf[1]==2)&&(qos==2))
// {
// UART2ReadFlag = 0;
// return 0;
// }
}
}
}
if(waittime==0)
return 1;
}
else
{
return 0;
}
return 1;
}
// 心跳 服务质量
uint8_t MQTTSCode_KeepAlive(void) {
waittime = 500;
memset((void *)StringData, 0, sizeof(StringData));
/*固定包头*/
StringData[0] = (uint8_t)(PINGREQ<<4) + 0;// 固定帧头
StringData[1] = 0x00;
NewSite = 2;
// 剩余长度
if(NewSite < 127)
StringData[1] = NewSite - 2;
else
return 1;
UART2ReadFlag = 0;
memset((void *)UART2ReadBuf, 0, sizeof(UART2ReadBuf));
Dev_UART2SendStr(StringData, NewSite, 0);
if(waittime) {
while(--waittime)
{
Delay_ms(10);
if(UART2ReadFlag&0x8000)
{
if((UART2ReadBuf[0]>>4)==PINGRESP)
{
UART2ReadFlag = 0;
return 0;
}
}
}
if(waittime==0)
return 1;
}
return 1;
}
// 断开连接
uint8_t MQTTSCode_DisConnect(void) {
memset((void *)StringData, 0, sizeof(StringData));
/*固定包头*/
StringData[0] = (uint8_t)(DISCONNECT<<4) + 0;// 固定帧头
StringData[1] = 0x00; // 剩余长度值
NewSite = 2;
// 剩余长度
if(NewSite < 127)
StringData[1] = NewSite - 2;
else
return 1;
UART2ReadFlag = 0;
memset((void *)UART2ReadBuf, 0, sizeof(UART2ReadBuf));
Dev_UART2SendStr(StringData, NewSite, 0);
// 断开网络连接
return 0;
}

View File

@@ -1,56 +0,0 @@
#ifndef _MQTT_H_
#define _MQTT_H_
#include "stm32f10x.h"
#include "esp8266_uart2.h"
#include "stdio.h"
#include "string.h"
#include "stdarg.h"
#include "cJSON.h"
typedef enum
{
CONNECT = 1,
CONNACK = 2,
PUBLISH = 3,
PUBACK = 4,
PUBREC = 5,
PUBREL = 6,
PUBCOMP = 7,
SUBSCRIBE = 8,
SUBACK = 9,
UNSUBSCRIBE = 10,
UNSUBACK = 11,
PINGREQ = 12,
PINGRESP = 13,
DISCONNECT = 14
}msgTypes;
typedef struct
{
unsigned short keepAlive;
char clientID[50];
char username[50];
char password[50];
} MQTT_ConnectData_t;
extern MQTT_ConnectData_t MQTT_ConnectData;
uint8_t MQTTSCode_Connect(void);
/*订阅 服务质量*/
uint8_t MQTTSCode_Subscribe(char *topic, uint8_t qos, uint8_t bsf);
/*发布暂定负载小于100字节*/
uint8_t MQTTSCode_Publish(char *topic, char *payload, uint16_t payloadLen, uint8_t dup, uint8_t qos, uint16_t bsf);
uint8_t MQTTSCode_KeepAlive(void); // 心跳 服务质量
uint8_t MQTTSCode_DisConnect(void);// 断开连接
#endif

View File

@@ -1,219 +0,0 @@
#include "battery.h"
/*电池,获取电池信息*/
void Bat_GetWorkInfor(void)
{
/***读取正在充电指示***/
if(Read_BatCharging()==0)
DevParam.BatCharging = 1;
else
DevParam.BatCharging = 0;
if(DevParam.BatInforGetTime >= 300)
{
if(DevParam.BatCheck < 100)
DevParam.BatCheck++;
/***获取电池电压***/
DevParam.BatVoltage = ADC_GetSimpleData();
if(DevParam.BatVoltage >= 3.58) {
/***转换电池容量***/
if(DevParam.BatVoltage>=4.16)
DevParam.ShortBatSOC = 100;
else if(DevParam.BatVoltage>=4.08)
DevParam.ShortBatSOC = 90;
else if(DevParam.BatVoltage>=3.97)
DevParam.ShortBatSOC = 80;
else if(DevParam.BatVoltage>=3.90)
DevParam.ShortBatSOC = 70;
else if(DevParam.BatVoltage>=3.84)
DevParam.ShortBatSOC = 60;
else if(DevParam.BatVoltage>=3.79)
DevParam.ShortBatSOC = 50;
else if(DevParam.BatVoltage>=3.76)
DevParam.ShortBatSOC = 40;
else if(DevParam.BatVoltage>=3.73)
DevParam.ShortBatSOC = 30;
else if(DevParam.BatVoltage>=3.71)
DevParam.ShortBatSOC = 20;
else if(DevParam.BatVoltage>=3.65)
DevParam.ShortBatSOC = 10;
}
else
{
DevParam.ShortBatSOC = 0;
}
DevParam.BatInforGetTime = 0;
}
}
/*显示部分,电池图标外形刷新*/
void Show_BatIconShapeRefresh(void)
{
#ifdef Device_LCD
// 电池外形
SimLCD_PointColor = SimLCDColor_WHITE;
SimLCD_DrawLine( 200, 9, 222, 9);
SimLCD_DrawLine( 200, 21, 222, 21);
SimLCD_DrawLine( 200, 9, 200, 21);
SimLCD_DrawLine( 222, 9, 222, 21);
SimLCD_DrawLine( 197, 13, 200, 13); // 上横线
SimLCD_DrawLine( 197, 13, 197, 17); // 中横线
SimLCD_DrawLine( 197, 17, 200, 17); // 下横线
#endif
}
/*显示部分,电池图标刷新*/
void Show_BatIconRefresh(void)
{
if((DevParam.BatIconRefreshTime>=500)&&(DevParam.BatCheck>=2)&&(DevParam.RunPhase!=0))
{
#ifdef Device_LCD
uint8_t i = 0;
uint16_t FontColor = 0;
if( (DevParam.BatCharging==1)&&(DevParam.RunPhase!=0) )
{// 充电中,电池图标变成绿色
FontColor = SimLCDColor_GREEN;
}
else if(DevParam.RunPhase==RunPhase_Runing)
{// 其他,电池图标变成白色
FontColor = SimLCDColor_WHITE;
}
// 显示SOC
if(DevParam.ShortBatSOC!=DevParam.BatSOC)
{
if( DevParam.ShortBatSOC >= 80 ) {
SimLCD_PointColor = FontColor;
for( i = 12; i < 19; i++)
SimLCD_DrawLine( 202, i, 205, i);
for( i = 12; i < 19; i++)
SimLCD_DrawLine( 207, i, 210, i);
for( i = 12; i < 19; i++)
SimLCD_DrawLine( 212, i, 215, i);
for( i = 12; i < 19; i++)
SimLCD_DrawLine( 217, i, 220, i);
}
else if( DevParam.ShortBatSOC >= 60 ) {
SimLCD_PointColor = SimLCDColor_BLACK;
for( i = 12; i < 19; i++)
SimLCD_DrawLine( 202, i, 205, i);
SimLCD_PointColor = FontColor;
for( i = 12; i < 19; i++)
SimLCD_DrawLine( 207, i, 210, i);
for( i = 12; i < 19; i++)
SimLCD_DrawLine( 212, i, 215, i);
for( i = 12; i < 19; i++)
SimLCD_DrawLine( 217, i, 220, i);
}
else if( DevParam.ShortBatSOC >= 40 ) {
SimLCD_PointColor = SimLCDColor_BLACK;
for( i = 12; i < 19; i++)
SimLCD_DrawLine( 202, i, 205, i);
for( i = 12; i < 19; i++)
SimLCD_DrawLine( 207, i, 210, i);
SimLCD_PointColor = FontColor;
for( i = 12; i < 19; i++)
SimLCD_DrawLine( 212, i, 215, i);
for( i = 12; i < 19; i++)
SimLCD_DrawLine( 217, i, 220, i);
}
else if( DevParam.ShortBatSOC >= 20 ) {
SimLCD_PointColor = SimLCDColor_BLACK;
for( i = 12; i < 19; i++)
SimLCD_DrawLine( 202, i, 205, i);
for( i = 12; i < 19; i++)
SimLCD_DrawLine( 207, i, 210, i);
for( i = 12; i < 19; i++)
SimLCD_DrawLine( 212, i, 215, i);
SimLCD_PointColor = FontColor;
for( i = 12; i < 19; i++)
SimLCD_DrawLine( 217, i, 220, i);
}
else if( DevParam.ShortBatSOC >= 1 ) {
SimLCD_PointColor = SimLCDColor_BLACK;
for( i = 12; i < 19; i++)
SimLCD_DrawLine( 202, i, 205, i);
for( i = 12; i < 19; i++)
SimLCD_DrawLine( 207, i, 210, i);
for( i = 12; i < 19; i++)
SimLCD_DrawLine( 212, i, 215, i);
for( i = 12; i < 19; i++)
SimLCD_DrawLine( 217, i, 220, i);
}
Power_LCD(1);
DevParam.BatSOC =DevParam.ShortBatSOC;
}
#endif
DevParam.BatIconRefreshTime = 0;
}
}
/*显示部分,侧边跳动*/
void Show_BroadSideBeat(void)
{
if(DevParam.SideBeatTime>=2000)
{
#ifdef Device_LCD
uint8_t i = 0;
if(DevParam.SideBeat==1) {
SimLCD_PointColor = SimLCDColor_CYAN;
for(i = 0; i < 13; i++)
SimLCD_DrawLine( 0, i, 32, i);
DevParam.SideBeat = 2;
}
else if(DevParam.SideBeat==2) {
SimLCD_PointColor = SimLCDColor_CYAN;
for(i = 15; i < 28; i++)
SimLCD_DrawLine( 0, i, 24, i);
DevParam.SideBeat = 3;
}
else if(DevParam.SideBeat==3) {
SimLCD_PointColor = SimLCDColor_CYAN;
for(i = 30; i < 43; i++)
SimLCD_DrawLine( 0, i, 16, i);
DevParam.SideBeat = 4;
}
else if(DevParam.SideBeat==4) {
SimLCD_PointColor = SimLCDColor_CYAN;
for(i = 45; i < 58; i++)
SimLCD_DrawLine( 0, i, 8, i);
DevParam.SideBeat = 5;
}
else if(DevParam.SideBeat==5) {
SimLCD_PointColor = SimLCDColor_BLACK;
for(i = 0; i < 13; i++)
SimLCD_DrawLine( 0, i, 32, i);
for(i = 15; i < 28; i++)
SimLCD_DrawLine( 0, i, 24, i);
for(i = 30; i < 43; i++)
SimLCD_DrawLine( 0, i, 16, i);
for(i = 45; i < 58; i++)
SimLCD_DrawLine( 0, i, 8, i);
DevParam.SideBeat = 1;
}
#endif
DevParam.SideBeatTime = 0;
}
}

View File

@@ -1,31 +0,0 @@
#ifndef _BATTERY_H_
#define _BATTERY_H_
#include "stm32f10x.h"
#include "bsp_timer3.h"
#include "bsp_port.h"
#include "bsp_adc.h"
#include "simulation_lcd.h"
/*电池,获取电池信息*/
void Bat_GetWorkInfor(void);
/*显示部分,电池图标外形刷新*/
void Show_BatIconShapeRefresh(void);
/*显示部分,电池图标刷新*/
void Show_BatIconRefresh(void);
/*显示部分,侧边跳动*/
void Show_BroadSideBeat(void);
#endif

View File

@@ -1,134 +0,0 @@
#include "dev_work.h"
void Dev_ScanExtIndicate(void) {
/*开机检测*/
if(DevParam.RunPhase==0)
{
if(Read_BootKey())
{
Delay_ms(200);
if(Read_BootKey())
{
Power_3V3(1);
while(Read_BootKey());
DevParam.ShortRunPhase = RunPhase_Runing;
}
}
else
{
DevParam.ShortRunPhase = RunPhase_Standby;
}
}
// 待机模式
if(DevParam.RunPhase==RunPhase_Standby)
{
if(Read_BootKey())
{
Delay_ms(200);
if(Read_BootKey())
{
while(Read_BootKey());
DevParam.ShortRunPhase = RunPhase_Runing;
}
}
}
// 运行模式
if(DevParam.RunPhase==RunPhase_Runing) {
if(Read_BootKey())
{
Delay_ms(200);
if(Read_BootKey())
{
while(Read_BootKey());
// 关机/进入待机状态
if(DevParam.BatCharging)
DevParam.ShortRunPhase = RunPhase_Standby;
else
DevParam.ShortRunPhase = RunPhase_Close;
}
}
}
}
/*切换工作模式*/
void Dev_SwitchWorkMode(void)
{
if(DevParam.RunPhase!=DevParam.ShortRunPhase)
{
if(DevParam.ShortRunPhase == RunPhase_Runing)
{
// 显示初始化
#ifdef Device_LCD
Power_3V3(1);
Power_LCD(0);
/*显示部分,基础外形刷新*/
Show_BasicShapeRefresh();
/*显示部分,电池图标外形刷新*/
if(DevParam.RunPhase == 0)
Show_BatIconShapeRefresh();
#endif
// 侧边跳动初始化
DevParam.SideBeat = 1;
/*空气检测仪初始化*/
PMD4_Init();
Power_LCD(1);
DevParam.RunPhase = RunPhase_Runing;
}
if(DevParam.ShortRunPhase == RunPhase_Standby)
{
Power_PMD4(0);
#ifdef Device_LCD
Power_LCD(0);
if(DevParam.RunPhase==0)
{
/*显示部分,电池图标外形刷新*/
Show_BatIconShapeRefresh();
Power_LCD(1);
}
else if(DevParam.RunPhase==RunPhase_Runing)
{
// 进行清屏操作
SimLCD_Clear(SimLCDColor_BLACK);
/*显示部分,电池图标外形刷新*/
Show_BatIconShapeRefresh();
// 数据部分清零
DevParam.BatSOC = 0;
Power_LCD(1);
}
#endif
DevParam.RunPhase = RunPhase_Standby;
}
// 关机模式
if(DevParam.ShortRunPhase == RunPhase_Close)
{
Delay_ms(1000);
Power_PMD4(0);
Power_LCD(0);
Power_3V3(0);
DevParam.RunPhase = RunPhase_Close;
while(1);
}
}
}

View File

@@ -1,29 +0,0 @@
#ifndef _DEV_WORK_H_
#define _DEV_WORK_H_
#include "stm32f10x.h"
#include "bsp_timer3.h"
#include "bsp_port.h"
#include "bsp_adc.h"
#include "simulation_lcd.h"
#include "battery.h"
#include "pm_uart3.h"
void Dev_ScanExtIndicate(void);
void Dev_SwitchWorkMode(void);
#endif

View File

@@ -1,251 +0,0 @@
#include "esp8266_uart2.h"
//检测应答命令
static uint8_t* ESP8266_CheckCMD(uint8_t *str){
char *strx = 0;
if(UART2ReadFlag&0x8000)
{
UART2ReadBuf[UART2ReadFlag&0x7FFF] = 0;//添加结束符
strx = strstr((const char*)UART2ReadBuf,(const char*)str);
}
return (uint8_t*)strx;
}
//cmd:发送的命令字符串
//ack:期待的应答结果,如果为空,则表示不需要等待应答
//返回值:0,发送成功 1,发送失败
uint8_t ESP8266_SendCMD(uint8_t *cmd,uint8_t *ack,uint16_t waittime) {
UART2ReadFlag = 0;
memset((void *)UART2ReadBuf, 0, sizeof(UART2ReadBuf));
Dev_UART2SendStr(cmd, 0, 0);
if(ack&&waittime)
{
while(--waittime)
{
Delay_ms(10);
if(UART2ReadFlag&0x8000)
{
if(ESP8266_CheckCMD(ack))
{
UART2ReadFlag = 0;
return 0;
}
else
{
UART2ReadFlag = 0;
return 1;
}
}
}
if(waittime==0)
{
return 1;
}
}
return 1;
}
uint8_t ESP8266_SendStr(char* fmt,...){
uint8_t tbuf[300] = {0};
uint16_t i = 0,j = 0;
va_list ap;
va_start(ap, fmt);
vsprintf((char*)tbuf, fmt, ap);
va_end(ap);
j = strlen((const char*)tbuf);
for( i = 0; i < j; i++)
{
while(USART_GetFlagStatus(USART2, USART_FLAG_TC)==RESET){}
USART_SendData(USART2, tbuf[i]);
}
while(USART_GetFlagStatus(USART2, USART_FLAG_TC)==RESET){}
return 0;
}
uint8_t ESP8266_SendData(uint8_t *tbuf, uint16_t len){
uint16_t i = 0;
for( i = 0; i < len; i++)
{
while(USART_GetFlagStatus(USART2, USART_FLAG_TC)==RESET){}
USART_SendData(USART2, tbuf[i]);
}
while(USART_GetFlagStatus(USART2, USART_FLAG_TC)==RESET){}
return 0;
}
// STA模式下获取本地IP
void ESP8266_GetLocalIP(uint8_t* ipbuf){
uint8_t *p,*p1;
if(ESP8266_SendCMD( (uint8_t *)"AT+CIFSR\r\n", (uint8_t *)"OK", 50))
{
ipbuf[0] = 0;
return;
}
p = ESP8266_CheckCMD((uint8_t *)"\"");
p1 = (uint8_t *)strstr((const char*)(p+1),"\"");
*p1=0;
sprintf((char*)ipbuf,"%s",p+1);
}
//退出透传模式 0,退出成功; 1,退出失败
uint8_t ESP8266_QuitTrans(void){
while(USART_GetFlagStatus(USART2,USART_FLAG_TC)==RESET){};
USART_SendData(USART2, '+');
Delay_ms(15);
while(USART_GetFlagStatus(USART2,USART_FLAG_TC)==RESET){};
USART_SendData(USART2, '+');
Delay_ms(15);
while(USART_GetFlagStatus(USART2,USART_FLAG_TC)==RESET){};
USART_SendData(USART2, '+');
Delay_ms(500); //等待500ms
return ESP8266_SendCMD((uint8_t *)"AT\r\n",(uint8_t *)"OK",20);//退出透传判断
}
//获取连接状态 0,未连接;1,连接成功.
uint8_t ESP8266_ConstaCheck(void){
while(ESP8266_SendCMD((uint8_t *)"AT+CIPSTATUS\r\n",(uint8_t *)"OK",50));
return 0;
}
uint8_t ESP8266_APInit(char *name, char *password){
uint8_t Sbuf[60] ={0};
// UART2
BSP_UART2Init(115200);
Delay_ms(1000);
Delay_ms(1000);
while(ESP8266_SendCMD((uint8_t *)"AT\r\n",(uint8_t *)"OK",200))
{//退出透传
ESP8266_QuitTrans();
//关闭透传模式
ESP8266_SendCMD((uint8_t *)"AT+CIPMODE=0\r\n",(uint8_t *)"OK",200);
Delay_ms(1000);
}
// 关闭回显
while(ESP8266_SendCMD((uint8_t *)"ATE0\r\n",(uint8_t *)"OK",200));
// 设置波特率
while(ESP8266_SendCMD((uint8_t *)"AT+UART=115200,8,1,0,0\r\n",(uint8_t *)"OK",200));
Delay_ms(10);
// 设置WIFI AP模式
while(ESP8266_SendCMD((uint8_t *)"AT+CWMODE=2\r\n",(uint8_t *)"OK",200));
while(ESP8266_SendCMD((uint8_t *)"AT+RST\r\n",(uint8_t *)"OK",200));
// 延时4秒等待重启成功
Delay_ms(1000);
Delay_ms(1000);
Delay_ms(1000);
Delay_ms(1000);
memset(Sbuf, 0 , sizeof(Sbuf));
sprintf((char*)Sbuf, "AT+CWSAP=\"%s\",\"%s\",1,4\r\n", name, password);
while(ESP8266_SendCMD(Sbuf, (uint8_t *)"OK", 1000));
#ifdef TCP_Mode
#endif
#ifdef UDP_Mode
while(ESP8266_SendCMD((uint8_t *)"AT+CIPMUX=0\r\n",(uint8_t *)"OK",200));
while(ESP8266_SendCMD((uint8_t *)"AT+CIPSTART=\"UDP\",\"255.255.255.255\",60156,42254,0\r\n",(uint8_t *)"OK",500));
while(ESP8266_SendCMD((uint8_t *)"AT+CIPMODE=1\r\n",(uint8_t *)"OK",300));
while(ESP8266_SendCMD((uint8_t *)"AT+CIPSEND\r\n",(uint8_t *)"OK",200));
#endif
UART2ReadFlag = 0;
memset((void *)UART2ReadBuf, 0, sizeof(UART2ReadBuf));
return 0;
}
uint8_t ESP8266_STAConnect(char *name, char *password){
uint8_t Sbuf[60] ={0};
memset(Sbuf, 0 , sizeof(Sbuf));
sprintf((char*)Sbuf,"AT+CWJAP=\"%s\",\"%s\"\r\n", name, password);
if(ESP8266_SendCMD( Sbuf, (uint8_t *)"WIFI GOT IP", 100)){
return 1;
}
else
{
#ifdef MQTT_AT
#elif MQTT_SCode
#elif TCP_Mode
while(ESP8266_SendCMD((uint8_t *)"AT+CIPMUX=0\r\n",(uint8_t *)"OK",200));
while(ESP8266_SendCMD((uint8_t *)"AT+CIPSTART=\"TCP\",\"192.168.0.102\",8086\r\n",(uint8_t *)"OK",200));
while(ESP8266_SendCMD((uint8_t *)"AT+CIPMODE=1\r\n",(uint8_t *)"OK",200));
while(ESP8266_SendCMD((uint8_t *)"AT+CIPSEND\r\n",(uint8_t *)"OK",20));
#elif UDP_Mode
while(ESP8266_SendCMD((uint8_t *)"AT+CIPMUX=0\r\n",(uint8_t *)"OK",200));
while(ESP8266_SendCMD((uint8_t *)"AT+CIPSTART=\"UDP\",\"192.168.1.6\",8086,8086,0\r\n",(uint8_t *)"OK",200));
while(ESP8266_SendCMD((uint8_t *)"AT+CIPMODE=1\r\n",(uint8_t *)"OK",200));
while(ESP8266_SendCMD((uint8_t *)"AT+CIPSEND\r\n",(uint8_t *)"OK",20));
#endif
UART2ReadFlag = 0;
memset((void *)UART2ReadBuf, 0, sizeof(UART2ReadBuf));
return 0;
}
}
uint8_t ESP8266_STAInit(void){
// 初始化串口
BSP_UART2Init(115200);
// 延时2秒等待串口初始化完成
Delay_ms(1000);
Delay_ms(1000);
while(ESP8266_SendCMD((uint8_t *)"AT\r\n",(uint8_t *)"OK",200))
{
//退出透传
ESP8266_QuitTrans();
//关闭透传模式
ESP8266_SendCMD((uint8_t *)"AT+CIPMODE=0\r\n",(uint8_t *)"OK",200);
Delay_ms(800);
}
// 关闭回显
while(ESP8266_SendCMD((uint8_t *)"ATE0\r\n",(uint8_t *)"OK",200));
// 设置波特率
while(ESP8266_SendCMD((uint8_t *)"AT+UART=115200,8,1,0,0\r\n",(uint8_t *)"OK",200));
Delay_ms(10);
// 设置WIFI STA模式
while(ESP8266_SendCMD((uint8_t *)"AT+CWMODE=1\r\n",(uint8_t *)"OK",200));
while(ESP8266_SendCMD((uint8_t *)"AT+RST\r\n",(uint8_t *)"OK",200));
Delay_ms(1000);
Delay_ms(1000);
Delay_ms(1000);
return 1;
}

View File

@@ -1,24 +0,0 @@
#ifndef _ESP8266_UART2_H_
#define _ESP8266_UART2_H_
#include "stm32f10x.h"
#include "bsp_uart2.h"
#include "stdio.h"
#include "string.h"
#include "stdarg.h"
//#define TCP_Mode 1
#define UDP_Mode 1
uint8_t ESP8266_SendStr(char* fmt,...);
uint8_t ESP8266_SendCMD(uint8_t *cmd,uint8_t *ack,uint16_t waittime);
uint8_t ESP8266_SendData(uint8_t *tbuf, uint16_t len);
uint8_t ESP8266_APInit(char *name, char *password);
uint8_t ESP8266_STAInit(void);
uint8_t ESP8266_STAConnect(char *name, char *password);
#endif

View File

@@ -1,362 +0,0 @@
#include "esp8266_work.h"
/*************************************************************
配网流程
1、将无线设备初始化为AP模式默认设置为
2、AT+CWJAP="CMCC-LI","092413131li"
// 配置 MQTT 用户属性
// AT+MQTTUSERCFG=0,1,"8bf209cd00704760b7a60b2f71be9d8c","test","12345678",0,0,""
// 配置 MQTT 连接属性
// AT+MQTTCONNCFG=0,120,0,"","",0,0
// 连接/查询 MQTT Broker
// AT+MQTTCONN=0,"106.12.9.213",1883,0
// 发布主题
// {"deviceNum":"E8DB84933056","categoryId":2,"firmwareVersion":"1.0","ownerId":"1"}
// AT+MQTTPUB=0,"device_info","{\"deviceNum\":\"E8DB8493312\"\\,\"categoryId\":1\\,\"firmwareVersion\":\"1.0\"\\,\"ownerId\":\"1\"}",0,0
// AT+MQTTPUB=0,"device_info","{\"deviceNum\":\"E8DB8493312\"\\,\"categoryId\":1\\,\"firmwareVersion\":\"1.0\"\\,\"ownerId\":\"1\"}",0,0\r\n
// 订阅/查询主题
// AT+MQTTSUB=0,"status/set/E8DB84933056",0
// 取消订阅
// AT+MQTTUNSUB=0,"status/set/E8DB84933050"
// 关闭连接, 释放资源
// AT+MQTTCLEAN=0
************************************************************/
uint8_t NetWorkFlow = 1;
uint8_t Wssid[20] = "";
uint8_t Wpassword[20] = "";
#ifdef MQTT_SCode
char MQTT_ServerIP[20] = "106.12.9.213";
uint32_t MQTT_ServerPort = 1883;
static char MQTT_DeviceID[20] = "E8DB84933299";
static char MQTT_ClientID[100] = "user";
static char MQTT_Username[20] = "test";
static char MQTT_Password[20] = "123456";
#elif MQTT_AT
char MQTT_ServerIP[20] = "106.12.9.213";
uint32_t MQTT_ServerPort = 1883;
static char MQTT_DeviceID[20] = "E8DB84933299";
static char MQTT_ClientID[100] = "user";
static char MQTT_Username[20] = "test";
static char MQTT_Password[20] = "123456";
#endif
uint8_t PublishData[500] = {0};
int len = 0;
void ESP8266_NetWorkFlow(void) {
// 第一步初始化为AP
if(NetWorkFlow == 1) {
ESP8266_APInit("XiaoYi_IOT_AirBox", "asdqwe9867");
NetWorkFlow = 2;
}
// 第二步持续发送UDP广播
else if(NetWorkFlow == 2) {
if(DevParam.ESP8266SendTime >= 2000)
{
ESP8266_SendStr("{\"code\":0,\"msg\":\"start connect\"}");
DevParam.ESP8266SendTime = 0;
}
}
// 第三步,返回接受成功信息
else if(NetWorkFlow == 3) {
ESP8266_SendStr("{\"code\":1,\"msg\":\"getWifiInfo:success\"}");
NetWorkFlow = 4;
}
// 第四步,连接家庭无线
else if(NetWorkFlow == 4) {
ESP8266_STAInit();
while(ESP8266_STAConnect((char *)Wssid, (char *)Wpassword));
NetWorkFlow = 5;
}
// 第五步配置MQTT
else if(NetWorkFlow == 5) {
/*********模拟MQTT指令**************/
#ifdef MQTT_SCode
MQTT_ConnectData.keepAlive = 120; // 心跳包,单位秒
strcpy( MQTT_ConnectData.clientID, MQTT_ClientID);// 客户端ID
strcpy( MQTT_ConnectData.username, MQTT_Username);// 用户名
strcpy( MQTT_ConnectData.password, MQTT_Password);// 密码
/***连接服务器***/
while(ESP8266_SendCMD((uint8_t *)"AT+CIPMUX=0\r\n",(uint8_t *)"OK",200));
memset((void *)PublishData, 0, sizeof(PublishData));
sprintf((char *)PublishData,"AT+CIPSTART=\"TCP\",\"%s\",%d\r\n", MQTT_ServerIP, MQTT_ServerPort);
while(ESP8266_SendCMD((uint8_t *)PublishData, (uint8_t *)"OK", 500));
while(ESP8266_SendCMD((uint8_t *)"AT+CIPMODE=1\r\n",(uint8_t *)"OK",200));
while(ESP8266_SendCMD((uint8_t *)"AT+CIPSEND\r\n",(uint8_t *)"OK",200));
/***登录服务器***/
while(MQTTSCode_Connect());
/***订阅服务器对状态设置***/
memset((void *)PublishData, 0, sizeof(PublishData));
sprintf((char *)PublishData,"status/set/%s", MQTT_DeviceID);
while(MQTTSCode_Subscribe((char *)PublishData, 0, 12));
#endif
/********************************/
/*********AT指令*****************/
#ifdef MQTT_AT
// 1配置 MQTT 用户属性
memset((void *)PublishData, 0, sizeof(PublishData));
sprintf((char *)PublishData,"AT+MQTTUSERCFG=0,1,\"%s\",\"%s\",\"%s\",0,0,\"\"\r\n",\
MQTT_ClientID, MQTT_Username, MQTT_Password);
while(ESP8266_SendCMD((uint8_t *)PublishData, (uint8_t *)"OK", 500));
// 2配置 MQTT 连接属性
memset((void *)PublishData, 0, sizeof(PublishData));
sprintf((char *)PublishData,"AT+MQTTCONNCFG=0,120,0,\"\",\"\",0,0\r\n");
while(ESP8266_SendCMD((uint8_t *)PublishData, (uint8_t *)"OK", 500));
// 3连接/查询服务器
//memset((void *)PublishData, 0, sizeof(PublishData));
//sprintf((char *)PublishData,"AT+MQTTCONN=0,\"%s\",1883,0\r\n",\
// MQTT_ServerIP);
//while(ESP8266_SendCMD((uint8_t *)"AT+MQTTCONN?\r\n", (uint8_t *)"OK", 500));
while(ESP8266_SendCMD((uint8_t *)"AT+MQTTCONN=0,\"106.12.9.213\",1883,0\r\n", (uint8_t *)"OK", 300));
// 4发布注册设备信息Publish
//memset((void *)PublishData, 0, sizeof(PublishData));
//sprintf((char *)PublishData,"AT+MQTTPUB=0,\"%s\",\"{\\\"deviceNum\\\":\\\"%s\\\"\\,\\\"categoryId\\\":1\\,\\\"firmwareVersion\\\":\\\"1.0\\\"\\,\\\"ownerId\\\":\\\"1\\\"}\",0,0\r\n",\
// "device_info" ,MQTT_DeviceID);
//while(ESP8266_SendCMD(PublishData, (uint8_t *)"OK", 500));
// 发布设备上线(设备状态)
memset((void *)PublishData, 0, sizeof(PublishData));
sprintf((char *)PublishData,"AT+MQTTPUB=0,\"%s\",\"{\\\"deviceNum\\\":\\\"%s\\\"\\,\\\"isOnline\\\":1\\,\\\"rssi\\\":-73\\,\\\"airTemperature\\\":%d\\,\\\"remark\\\":\\\"\\\"}\",0,0\r\n",\
"status" ,MQTT_DeviceID, DevParam.BatSOC);
while(ESP8266_SendCMD(PublishData, (uint8_t *)"OK", 500));
// 发布设备遗嘱
// memset((void *)PublishData, 0, sizeof(PublishData));
// sprintf((char *)PublishData,"AT+MQTTPUB=0,\"offline\",\"{\\\"deviceNum\\\":\\\"%s\\\"\\,\\\"isOnline\\\":0\\,\\\"remark\\\":\\\"\\\"}\",0,0\r\n",\
// MQTT_DeviceID);
// while(ESP8266_SendCMD(PublishData, (uint8_t *)"OK", 500));
// 发布设备配置
memset((void *)PublishData, 0, sizeof(PublishData));
sprintf((char *)PublishData,"AT+MQTTPUB=0,\"status\",\"{\\\"deviceNum\\\":\\\"%s\\\"\\,\\\"isReset\\\":0\\,\\\"remark\\\":\\\"\\\"}\",0,0\r\n",\
MQTT_DeviceID);
while(ESP8266_SendCMD(PublishData, (uint8_t *)"OK", 500));
// 5订阅
// // 更新设备设置状态
// memset((void *)PublishData, 0, sizeof(PublishData));
// sprintf((char *)PublishData,"AT+MQTTSUB=0,\"status\\\/set\\\/%s\", MQTT_DeviceID);
// while(ESP8266_SendCMD((uint8_t *)PublishData, (uint8_t *)"OK", 500));
// 订阅获取设备状态
memset((void *)PublishData, 0, sizeof(PublishData));
sprintf((char *)PublishData,"AT+MQTTSUB=0,\"status\\/set\\/%s\",0\r\n", MQTT_DeviceID);
while(ESP8266_SendCMD((uint8_t *)PublishData, (uint8_t *)"OK", 500));
// // 更新设备配置
// memset((void *)PublishData, 0, sizeof(PublishData));
// sprintf((char *)PublishData,"AT+MQTTSUB=0,\"setting/set/%s\",\"\",0,0\r\n", MQTT_DeviceID);
// while(ESP8266_SendCMD((uint8_t *)PublishData, (uint8_t *)"OK", 500));
// // 获取设备配置
// memset((void *)PublishData, 0, sizeof(PublishData));
// sprintf((char *)PublishData,"AT+MQTTSUB=0,\"setting/get/%s\",\"\",0,0\r\n", MQTT_DeviceID);
// while(ESP8266_SendCMD((uint8_t *)PublishData, (uint8_t *)"OK", 200));
#endif
NetWorkFlow = 10;
/********************************/
}
// 第十步,发布消息
else if(NetWorkFlow == 10) {
/********************************/
#ifdef MQTT_SCode
if(DevParam.MQTTSendTime >= 2000)
{
// 定时发布设备状态
memset((void *)PublishData, 0, sizeof(PublishData));
len = sprintf((char *)PublishData,"{\"deviceNum\":\"%s\",\"isOnline\":1,\"airTemperature\":%d,\"remark\":\"\"}",\
MQTT_DeviceID, DevParam.tes);
if(len > 0)
{
while(MQTTSCode_Publish("status", (char *)PublishData, len, 0, 1, 10));
memset((void *)UART2ReadBuf, 0, sizeof(UART2ReadBuf));
}
DevParam.MQTTSendTime = 0;
}
#endif
/********************************/
/********************************/
#ifdef MQTT_AT
if(DevParam.MQTTSendTime >= 5000) {
// 定时发布设备状态
memset((void *)PublishData, 0, sizeof(PublishData));
sprintf((char *)PublishData,"AT+MQTTPUB=0,\"%s\",\"{\\\"deviceNum\\\":\\\"%s\\\"\\,\\\"isOnline\\\":1\\,\\\"rssi\\\":-73\\,\\\"airTemperature\\\":%d\\,\\\"remark\\\":\\\"\\\"}\",0,0\r\n",\
"status" ,MQTT_DeviceID, DevParam.BatSOC);
while(ESP8266_SendCMD(PublishData, (uint8_t *)"OK", 500));
memset((void *)UART2ReadBuf, 0, sizeof(UART2ReadBuf));
DevParam.MQTTSendTime = 0;
}
#endif
/********************************/
}
}
char mystrstr(char *haystack, char *needle) {
uint16_t i = 0,j = 0;
for(i = 0;;i++)
{
if(haystack[i]==needle[0])
{
for(j = 0;;j++)
{
if(haystack[i+j]==needle[j])
{
if(needle[j+1] == '\0')
return 1;
}
else
break;
}
}
if((haystack[i]=='\r') && (haystack[i+1]=='\n'))
{
return 0;
}
}
}
cJSON *root = NULL;
char JsonString[500] = {0};
uint16_t i = 0,j = 0,slen = 0;
void ESP8266_NetReceiveInfor(void) {
if(UART2ReadFlag&0x8000)
{
// 配网解析
if(NetWorkFlow == 2) {
// {"port":60156,"ssid":"xxx","password":"xxxx"}
if(UART2ReadBuf[0] == '{') {
memset(JsonString, 0, sizeof(JsonString));
for(i = 0;;i++)
{
JsonString[i] = UART2ReadBuf[i];
if(UART2ReadBuf[i] == '}')
{
// 解析数据
root = cJSON_Parse((char *)JsonString);
if(root == NULL)
{
memset((void *)UART2ReadBuf, 0, sizeof(UART2ReadBuf));
UART3ReadFlag = 0;
return;
}
// Nport = cJSON_GetObjectItem(root, "port")->valuedouble;
// if(Nport==60156)
// {
sprintf((char *)Wssid, "%s",cJSON_GetObjectItem(root, "ssid")->valuestring);
sprintf((char *)Wpassword,"%s",cJSON_GetObjectItem(root, "password")->valuestring);
// 进入无线第三步
NetWorkFlow = 3;
// }
cJSON_Delete(root);
break;
}
}
}
}
// 服务器解析
if(NetWorkFlow == 10) {
#ifdef MQTT_SCode
slen = UART2ReadFlag&(~(1 << 15));
UART2ReadBuf[slen] = 0x0D;
UART2ReadBuf[slen+1] = 0x0A;
/**********设置状态*********/
memset((void *)PublishData, 0, sizeof(PublishData));
sprintf((char *)PublishData,"status/set/%s", MQTT_DeviceID);
if(mystrstr((char *)UART2ReadBuf, (char *)PublishData)==1) {
memset(JsonString, 0, sizeof(JsonString));
for(i = 0;;i++)
{
if(UART2ReadBuf[i]=='{')
{
for(j = 0;;j++)
{
JsonString[j] = UART2ReadBuf[j+i];
if( (UART2ReadBuf[j+i]=='}') && (UART2ReadBuf[j+i+1]==0x0D) && (UART2ReadBuf[j+i+2]==0x0A))
{
// 解析数据
root = cJSON_Parse((char *)JsonString);
if(root == NULL)
{
memset((void *)UART2ReadBuf, 0, sizeof(UART2ReadBuf));
UART3ReadFlag = 0;
return;
}
DevParam.ServerRelay= cJSON_GetObjectItem(root, "relayStatus")->valuedouble;
DevParam.ServerRed = cJSON_GetObjectItem(root, "red")->valuedouble;
cJSON_Delete(root);
memset((void *)UART2ReadBuf, 0, sizeof(UART2ReadBuf));
UART3ReadFlag = 0;
return;
}
}
}
}
}
#endif
#ifdef MQTT_AT
// 首先判断
if(strstr((const char*)UART2ReadBuf,(const char*)"+MQTTSUBRECV")) {
memset((void *)PublishData, 0, sizeof(PublishData));
sprintf((char *)PublishData,"status/set/%s", MQTT_DeviceID);
if(strstr((const char*)UART2ReadBuf,(const char*)PublishData))
{
memset(JsonString, 0, sizeof(JsonString));
for(i = 0;;i++)
{
if(UART2ReadBuf[i]=='{')
{
for(j = 0;;j++)
{
JsonString[j] = UART2ReadBuf[j+i];
if( (UART2ReadBuf[j+i]=='}') && (UART2ReadBuf[j+i+1]==0x0D) && (UART2ReadBuf[j+i+2]==0x0A))
{
// 解析数据
root = cJSON_Parse((char *)JsonString);
if(root == NULL)
{
memset((void *)UART2ReadBuf, 0, sizeof(UART2ReadBuf));
UART3ReadFlag = 0;
return;
}
DevParam.ServerRelay= cJSON_GetObjectItem(root, "relayStatus")->valuedouble;
DevParam.ServerRed = cJSON_GetObjectItem(root, "red")->valuedouble;
cJSON_Delete(root);
memset((void *)UART2ReadBuf, 0, sizeof(UART2ReadBuf));
UART3ReadFlag = 0;
return;
}
}
}
}
}
}
#endif
}
memset((void *)UART2ReadBuf, 0, sizeof(UART2ReadBuf));
UART2ReadFlag = 0;
}
}

View File

@@ -1,22 +0,0 @@
#ifndef _ESP8266_WORK_H_
#define _ESP8266_WORK_H_
#include "stm32f10x.h"
#include "esp8266_uart2.h"
#include "stdio.h"
#include "string.h"
#include "stdarg.h"
#include "cJSON.h"
#include "mqtt.h"
void ESP8266_NetWorkFlow(void);
void ESP8266_NetReceiveInfor(void);
#endif

View File

@@ -1,198 +0,0 @@
#include "pm_uart3.h"
// 校验
// 校验正确--0xff 校验错误--0x00
uint8_t PMD4_CheckSum(uint8_t *data) {
uint8_t i = 0, result = 0;
uint16_t sum = 0;
if( (data[0] == 0x42) && (data[1] == 0x4d) )
{
for(i = 0; i < 30; i++)
{
sum += data[i];
}
if( sum == ((data[30]<<8) + data[31]) )
{
result = 0xff;
}
}
return result;
}
// PM 初始化
void PMD4_Init(void) {
Power_PMD4(1);
Delay_ms(200);
BSP_UART3Init(9600);
Delay_ms(200);
}
// 请求获取空气信息
void PMD4_ReqGetAirInfor(uint8_t Code) {
uint16_t sum = 0;
uint8_t data[20] = {0};
uint8_t i = 0;
data[0] = 0x42;
data[1] = 0x4d;
data[2] = Code;
data[3] = 0x00;
data[4] = 0x00;
for(i = 0; i < 5; i++)
{
sum += data[i];
}
data[5] = (uint8_t)(sum>>8);
data[6] = (uint8_t)(sum>>0);
BSP_UART3SendData(data, 7);
}
/*PMD4获取空气信息*/
void PMD4_GetAirInfor(void)
{
#ifdef Device_LCD
uint16_t x = 0, y = 0;
uint8_t i = 0;
#endif
if(UART3ReadFlag&0x8000)
{
if( PMD4_CheckSum(UART3ReadBuf)==0xff)
{
DevParam.PM1_0 = (uint16_t)(UART3ReadBuf[4]<<8) + (uint16_t)(UART3ReadBuf[5]<<0);
DevParam.PM2_5 = (uint16_t)(UART3ReadBuf[6]<<8) + (uint16_t)(UART3ReadBuf[7]<<0);
DevParam.PM10 = (uint16_t)(UART3ReadBuf[8]<<8) + (uint16_t)(UART3ReadBuf[9]<<0);
}
UART3ReadFlag = 0;
memset((void *)UART3ReadBuf, 0, sizeof(UART3ReadBuf));
}
if(DevParam.AirInforGetTime >= 2000)
{
//PMD4_ReqGetAirInfor(0xE2);
DevParam.AirInforGetTime = 0;
}
/**********显示实时空气信息*****************/
#ifdef Device_LCD
// PM1.0
if(DevParam.ShowPM1_0 != DevParam.PM1_0)
{
x = (uint16_t)(SimLCD.width/2/2-20);
y = 260;
// 1
i = (uint8_t)(DevParam.PM1_0/100);
SimLCD_NewShowChar( (x+8), y, (i + 16));
// 1
i = (uint8_t)(DevParam.PM1_0/10%10);
SimLCD_NewShowChar( (x+16), y, (i + 16));
// 0
i = (uint8_t)(DevParam.PM1_0%10);
SimLCD_NewShowChar( (x+24), y, (i + 16));
DevParam.ShowPM1_0 = DevParam.PM1_0;
}
// PM2.5
if(DevParam.ShowPM2_5 != DevParam.PM2_5)
{
x = (uint16_t)(SimLCD.width/2-20);
y = 80;
// 1
i = (uint8_t)(DevParam.PM2_5/100);
SimLCD_NewShowChar( (x+8), y, (i + 16));
// 1
i = (uint8_t)(DevParam.PM2_5/10%10);
SimLCD_NewShowChar( (x+16), y, (i + 16));
// 0
i = (uint8_t)(DevParam.PM2_5%10);
SimLCD_NewShowChar( (x+24), y, (i + 16));
DevParam.ShowPM2_5 = DevParam.PM2_5;
}
// PM10
if(DevParam.PM10 != DevParam.ShowPM10)
{
x = (uint16_t)(SimLCD.width/2/2*3-16);
y = 260;
// 1
i = (uint8_t)(DevParam.PM10/100);
SimLCD_NewShowChar( (x+8), y, (i + 16));
// 1
i = (uint8_t)(DevParam.PM10/10%10);
SimLCD_NewShowChar( (x+16), y, (i + 16));
// 0
i = (uint8_t)(DevParam.PM10%10);
SimLCD_NewShowChar( (x+24), y, (i + 16));
DevParam.ShowPM10 = DevParam.PM10;
}
#endif
}
/*显示部分,基础外形刷新*/
void Show_BasicShapeRefresh(void) {
#ifdef Device_LCD
uint16_t x = 0, y = 0;
// 画上边内圆
x = (uint16_t)(SimLCD.width/2);
y = (uint16_t)(SimLCD.height/3) + 10;
// 填充圆环 r0外圆 r1内圆
SimLCD_PointColor = SimLCDColor_CYAN;
SimLCD_FillTorus( x, y, 100, 90);
// 画下边两个圆
x = (uint16_t)(SimLCD.width/2/2*3);
y = (uint16_t)(SimLCD.height/3*2) + (uint16_t)(SimLCD.height/3/2);
// 填充圆环 r0外圆 r1内圆
SimLCD_PointColor = SimLCDColor_YELLOW;
SimLCD_FillTorus( x, y, 50, 45);
x = (uint16_t)(SimLCD.width/2/2);
y = (uint16_t)(SimLCD.height/3*2) + (uint16_t)(SimLCD.height/3/2);
SimLCD_PointColor = SimLCDColor_LIGHTGREEN;
SimLCD_FillTorus( x, y, 50, 45);
// 显示字符串 PM2.5 ug/m3 PM1.0 PM10
x = (uint16_t)(SimLCD.width/2-24);
y = 40;
SimLCD_Show_PM2_5( x, y);
x = (uint16_t)(SimLCD.width/2-20);
y = 180;
SimLCD_Show_ug_m3( x, y);
x = (uint16_t)(SimLCD.width/2/2-20);
y = 230;
SimLCD_Show_PM1_0( x, y);
x = (uint16_t)(SimLCD.width/2/2*3-16);
y = 230;
SimLCD_Show_PM10( x, y);
#endif
}

View File

@@ -1,28 +0,0 @@
#ifndef _PM_UART3_H_
#define _PM_UART3_H_
#include "stm32f10x.h"
#include "bsp_uart3.h"
#include "bsp_timer3.h"
#include "bsp_port.h"
#include "simulation_lcd.h"
void PMD4_Init(void);
/*PMD4获取空气信息*/
void PMD4_GetAirInfor(void);
/*显示部分,基础外形刷新*/
void Show_BasicShapeRefresh(void);
#endif

View File

@@ -1,270 +0,0 @@
#ifndef _SIMULATION_FONT_H_
#define _SIMULATION_FONT_H_
//常用ASCII表
//偏移量32
//ASCII字符集: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
//PC2LCD2002取模方式设置阴码+逐列式+顺向+C51格式
//总共3个字符集12*12、16*16和24*24用户可以自行新增其他分辨率的字符集。
//每个字符所占用的字节数为:(size/8+((size%8)?1:0))*(size/2),其中size:是字库生成时的点阵大小(12/16/24...)
const unsigned char Simulation_Asc1206[95][12]={
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",0*/
{0x00,0x00,0x00,0x00,0x3F,0x40,0x00,0x00,0x00,0x00,0x00,0x00},/*"!",1*/
{0x00,0x00,0x30,0x00,0x40,0x00,0x30,0x00,0x40,0x00,0x00,0x00},/*""",2*/
{0x09,0x00,0x0B,0xC0,0x3D,0x00,0x0B,0xC0,0x3D,0x00,0x09,0x00},/*"#",3*/
{0x18,0xC0,0x24,0x40,0x7F,0xE0,0x22,0x40,0x31,0x80,0x00,0x00},/*"$",4*/
{0x18,0x00,0x24,0xC0,0x1B,0x00,0x0D,0x80,0x32,0x40,0x01,0x80},/*"%",5*/
{0x03,0x80,0x1C,0x40,0x27,0x40,0x1C,0x80,0x07,0x40,0x00,0x40},/*"&",6*/
{0x10,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",7*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x80,0x20,0x40,0x40,0x20},/*"(",8*/
{0x00,0x00,0x40,0x20,0x20,0x40,0x1F,0x80,0x00,0x00,0x00,0x00},/*")",9*/
{0x09,0x00,0x06,0x00,0x1F,0x80,0x06,0x00,0x09,0x00,0x00,0x00},/*"*",10*/
{0x04,0x00,0x04,0x00,0x3F,0x80,0x04,0x00,0x04,0x00,0x00,0x00},/*"+",11*/
{0x00,0x10,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*",",12*/
{0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x00,0x00},/*"-",13*/
{0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*".",14*/
{0x00,0x20,0x01,0xC0,0x06,0x00,0x38,0x00,0x40,0x00,0x00,0x00},/*"/",15*/
{0x1F,0x80,0x20,0x40,0x20,0x40,0x20,0x40,0x1F,0x80,0x00,0x00},/*"0",16*/
{0x00,0x00,0x10,0x40,0x3F,0xC0,0x00,0x40,0x00,0x00,0x00,0x00},/*"1",17*/
{0x18,0xC0,0x21,0x40,0x22,0x40,0x24,0x40,0x18,0x40,0x00,0x00},/*"2",18*/
{0x10,0x80,0x20,0x40,0x24,0x40,0x24,0x40,0x1B,0x80,0x00,0x00},/*"3",19*/
{0x02,0x00,0x0D,0x00,0x11,0x00,0x3F,0xC0,0x01,0x40,0x00,0x00},/*"4",20*/
{0x3C,0x80,0x24,0x40,0x24,0x40,0x24,0x40,0x23,0x80,0x00,0x00},/*"5",21*/
{0x1F,0x80,0x24,0x40,0x24,0x40,0x34,0x40,0x03,0x80,0x00,0x00},/*"6",22*/
{0x30,0x00,0x20,0x00,0x27,0xC0,0x38,0x00,0x20,0x00,0x00,0x00},/*"7",23*/
{0x1B,0x80,0x24,0x40,0x24,0x40,0x24,0x40,0x1B,0x80,0x00,0x00},/*"8",24*/
{0x1C,0x00,0x22,0xC0,0x22,0x40,0x22,0x40,0x1F,0x80,0x00,0x00},/*"9",25*/
{0x00,0x00,0x00,0x00,0x08,0x40,0x00,0x00,0x00,0x00,0x00,0x00},/*":",26*/
{0x00,0x00,0x00,0x00,0x04,0x60,0x00,0x00,0x00,0x00,0x00,0x00},/*";",27*/
{0x00,0x00,0x04,0x00,0x0A,0x00,0x11,0x00,0x20,0x80,0x40,0x40},/*"<",28*/
{0x09,0x00,0x09,0x00,0x09,0x00,0x09,0x00,0x09,0x00,0x00,0x00},/*"=",29*/
{0x00,0x00,0x40,0x40,0x20,0x80,0x11,0x00,0x0A,0x00,0x04,0x00},/*">",30*/
{0x18,0x00,0x20,0x00,0x23,0x40,0x24,0x00,0x18,0x00,0x00,0x00},/*"?",31*/
{0x1F,0x80,0x20,0x40,0x27,0x40,0x29,0x40,0x1F,0x40,0x00,0x00},/*"@",32*/
{0x00,0x40,0x07,0xC0,0x39,0x00,0x0F,0x00,0x01,0xC0,0x00,0x40},/*"A",33*/
{0x20,0x40,0x3F,0xC0,0x24,0x40,0x24,0x40,0x1B,0x80,0x00,0x00},/*"B",34*/
{0x1F,0x80,0x20,0x40,0x20,0x40,0x20,0x40,0x30,0x80,0x00,0x00},/*"C",35*/
{0x20,0x40,0x3F,0xC0,0x20,0x40,0x20,0x40,0x1F,0x80,0x00,0x00},/*"D",36*/
{0x20,0x40,0x3F,0xC0,0x24,0x40,0x2E,0x40,0x30,0xC0,0x00,0x00},/*"E",37*/
{0x20,0x40,0x3F,0xC0,0x24,0x40,0x2E,0x00,0x30,0x00,0x00,0x00},/*"F",38*/
{0x0F,0x00,0x10,0x80,0x20,0x40,0x22,0x40,0x33,0x80,0x02,0x00},/*"G",39*/
{0x20,0x40,0x3F,0xC0,0x04,0x00,0x04,0x00,0x3F,0xC0,0x20,0x40},/*"H",40*/
{0x20,0x40,0x20,0x40,0x3F,0xC0,0x20,0x40,0x20,0x40,0x00,0x00},/*"I",41*/
{0x00,0x60,0x20,0x20,0x20,0x20,0x3F,0xC0,0x20,0x00,0x20,0x00},/*"J",42*/
{0x20,0x40,0x3F,0xC0,0x24,0x40,0x0B,0x00,0x30,0xC0,0x20,0x40},/*"K",43*/
{0x20,0x40,0x3F,0xC0,0x20,0x40,0x00,0x40,0x00,0x40,0x00,0xC0},/*"L",44*/
{0x3F,0xC0,0x3C,0x00,0x03,0xC0,0x3C,0x00,0x3F,0xC0,0x00,0x00},/*"M",45*/
{0x20,0x40,0x3F,0xC0,0x0C,0x40,0x23,0x00,0x3F,0xC0,0x20,0x00},/*"N",46*/
{0x1F,0x80,0x20,0x40,0x20,0x40,0x20,0x40,0x1F,0x80,0x00,0x00},/*"O",47*/
{0x20,0x40,0x3F,0xC0,0x24,0x40,0x24,0x00,0x18,0x00,0x00,0x00},/*"P",48*/
{0x1F,0x80,0x21,0x40,0x21,0x40,0x20,0xE0,0x1F,0xA0,0x00,0x00},/*"Q",49*/
{0x20,0x40,0x3F,0xC0,0x24,0x40,0x26,0x00,0x19,0xC0,0x00,0x40},/*"R",50*/
{0x18,0xC0,0x24,0x40,0x24,0x40,0x22,0x40,0x31,0x80,0x00,0x00},/*"S",51*/
{0x30,0x00,0x20,0x40,0x3F,0xC0,0x20,0x40,0x30,0x00,0x00,0x00},/*"T",52*/
{0x20,0x00,0x3F,0x80,0x00,0x40,0x00,0x40,0x3F,0x80,0x20,0x00},/*"U",53*/
{0x20,0x00,0x3E,0x00,0x01,0xC0,0x07,0x00,0x38,0x00,0x20,0x00},/*"V",54*/
{0x38,0x00,0x07,0xC0,0x3C,0x00,0x07,0xC0,0x38,0x00,0x00,0x00},/*"W",55*/
{0x20,0x40,0x39,0xC0,0x06,0x00,0x39,0xC0,0x20,0x40,0x00,0x00},/*"X",56*/
{0x20,0x00,0x38,0x40,0x07,0xC0,0x38,0x40,0x20,0x00,0x00,0x00},/*"Y",57*/
{0x30,0x40,0x21,0xC0,0x26,0x40,0x38,0x40,0x20,0xC0,0x00,0x00},/*"Z",58*/
{0x00,0x00,0x00,0x00,0x7F,0xE0,0x40,0x20,0x40,0x20,0x00,0x00},/*"[",59*/
{0x00,0x00,0x70,0x00,0x0C,0x00,0x03,0x80,0x00,0x40,0x00,0x00},/*"\",60*/
{0x00,0x00,0x40,0x20,0x40,0x20,0x7F,0xE0,0x00,0x00,0x00,0x00},/*"]",61*/
{0x00,0x00,0x20,0x00,0x40,0x00,0x20,0x00,0x00,0x00,0x00,0x00},/*"^",62*/
{0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10},/*"_",63*/
{0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"`",64*/
{0x00,0x00,0x02,0x80,0x05,0x40,0x05,0x40,0x03,0xC0,0x00,0x40},/*"a",65*/
{0x20,0x00,0x3F,0xC0,0x04,0x40,0x04,0x40,0x03,0x80,0x00,0x00},/*"b",66*/
{0x00,0x00,0x03,0x80,0x04,0x40,0x04,0x40,0x06,0x40,0x00,0x00},/*"c",67*/
{0x00,0x00,0x03,0x80,0x04,0x40,0x24,0x40,0x3F,0xC0,0x00,0x40},/*"d",68*/
{0x00,0x00,0x03,0x80,0x05,0x40,0x05,0x40,0x03,0x40,0x00,0x00},/*"e",69*/
{0x00,0x00,0x04,0x40,0x1F,0xC0,0x24,0x40,0x24,0x40,0x20,0x00},/*"f",70*/
{0x00,0x00,0x02,0xE0,0x05,0x50,0x05,0x50,0x06,0x50,0x04,0x20},/*"g",71*/
{0x20,0x40,0x3F,0xC0,0x04,0x40,0x04,0x00,0x03,0xC0,0x00,0x40},/*"h",72*/
{0x00,0x00,0x04,0x40,0x27,0xC0,0x00,0x40,0x00,0x00,0x00,0x00},/*"i",73*/
{0x00,0x10,0x00,0x10,0x04,0x10,0x27,0xE0,0x00,0x00,0x00,0x00},/*"j",74*/
{0x20,0x40,0x3F,0xC0,0x01,0x40,0x07,0x00,0x04,0xC0,0x04,0x40},/*"k",75*/
{0x20,0x40,0x20,0x40,0x3F,0xC0,0x00,0x40,0x00,0x40,0x00,0x00},/*"l",76*/
{0x07,0xC0,0x04,0x00,0x07,0xC0,0x04,0x00,0x03,0xC0,0x00,0x00},/*"m",77*/
{0x04,0x40,0x07,0xC0,0x04,0x40,0x04,0x00,0x03,0xC0,0x00,0x40},/*"n",78*/
{0x00,0x00,0x03,0x80,0x04,0x40,0x04,0x40,0x03,0x80,0x00,0x00},/*"o",79*/
{0x04,0x10,0x07,0xF0,0x04,0x50,0x04,0x40,0x03,0x80,0x00,0x00},/*"p",80*/
{0x00,0x00,0x03,0x80,0x04,0x40,0x04,0x50,0x07,0xF0,0x00,0x10},/*"q",81*/
{0x04,0x40,0x07,0xC0,0x02,0x40,0x04,0x00,0x04,0x00,0x00,0x00},/*"r",82*/
{0x00,0x00,0x06,0x40,0x05,0x40,0x05,0x40,0x04,0xC0,0x00,0x00},/*"s",83*/
{0x00,0x00,0x04,0x00,0x1F,0x80,0x04,0x40,0x00,0x40,0x00,0x00},/*"t",84*/
{0x04,0x00,0x07,0x80,0x00,0x40,0x04,0x40,0x07,0xC0,0x00,0x40},/*"u",85*/
{0x04,0x00,0x07,0x00,0x04,0xC0,0x01,0x80,0x06,0x00,0x04,0x00},/*"v",86*/
{0x06,0x00,0x01,0xC0,0x07,0x00,0x01,0xC0,0x06,0x00,0x00,0x00},/*"w",87*/
{0x04,0x40,0x06,0xC0,0x01,0x00,0x06,0xC0,0x04,0x40,0x00,0x00},/*"x",88*/
{0x04,0x10,0x07,0x10,0x04,0xE0,0x01,0x80,0x06,0x00,0x04,0x00},/*"y",89*/
{0x00,0x00,0x04,0x40,0x05,0xC0,0x06,0x40,0x04,0x40,0x00,0x00},/*"z",90*/
{0x00,0x00,0x00,0x00,0x04,0x00,0x7B,0xE0,0x40,0x20,0x00,0x00},/*"{",91*/
{0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xF0,0x00,0x00,0x00,0x00},/*"|",92*/
{0x00,0x00,0x40,0x20,0x7B,0xE0,0x04,0x00,0x00,0x00,0x00,0x00},/*"}",93*/
{0x40,0x00,0x80,0x00,0x40,0x00,0x20,0x00,0x20,0x00,0x40,0x00},/*"~",94*/
};
const unsigned char Simulation_Asc1608[95][16]={
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",0*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xCC,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00},/*"!",1*/
{0x00,0x00,0x08,0x00,0x30,0x00,0x60,0x00,0x08,0x00,0x30,0x00,0x60,0x00,0x00,0x00},/*""",2*/
{0x02,0x20,0x03,0xFC,0x1E,0x20,0x02,0x20,0x03,0xFC,0x1E,0x20,0x02,0x20,0x00,0x00},/*"#",3*/
{0x00,0x00,0x0E,0x18,0x11,0x04,0x3F,0xFF,0x10,0x84,0x0C,0x78,0x00,0x00,0x00,0x00},/*"$",4*/
{0x0F,0x00,0x10,0x84,0x0F,0x38,0x00,0xC0,0x07,0x78,0x18,0x84,0x00,0x78,0x00,0x00},/*"%",5*/
{0x00,0x78,0x0F,0x84,0x10,0xC4,0x11,0x24,0x0E,0x98,0x00,0xE4,0x00,0x84,0x00,0x08},/*"&",6*/
{0x08,0x00,0x68,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",7*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xE0,0x18,0x18,0x20,0x04,0x40,0x02,0x00,0x00},/*"(",8*/
{0x00,0x00,0x40,0x02,0x20,0x04,0x18,0x18,0x07,0xE0,0x00,0x00,0x00,0x00,0x00,0x00},/*")",9*/
{0x02,0x40,0x02,0x40,0x01,0x80,0x0F,0xF0,0x01,0x80,0x02,0x40,0x02,0x40,0x00,0x00},/*"*",10*/
{0x00,0x80,0x00,0x80,0x00,0x80,0x0F,0xF8,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x00},/*"+",11*/
{0x00,0x01,0x00,0x0D,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*",",12*/
{0x00,0x00,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80},/*"-",13*/
{0x00,0x00,0x00,0x0C,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*".",14*/
{0x00,0x00,0x00,0x06,0x00,0x18,0x00,0x60,0x01,0x80,0x06,0x00,0x18,0x00,0x20,0x00},/*"/",15*/
{0x00,0x00,0x07,0xF0,0x08,0x08,0x10,0x04,0x10,0x04,0x08,0x08,0x07,0xF0,0x00,0x00},/*"0",16*/
{0x00,0x00,0x08,0x04,0x08,0x04,0x1F,0xFC,0x00,0x04,0x00,0x04,0x00,0x00,0x00,0x00},/*"1",17*/
{0x00,0x00,0x0E,0x0C,0x10,0x14,0x10,0x24,0x10,0x44,0x11,0x84,0x0E,0x0C,0x00,0x00},/*"2",18*/
{0x00,0x00,0x0C,0x18,0x10,0x04,0x11,0x04,0x11,0x04,0x12,0x88,0x0C,0x70,0x00,0x00},/*"3",19*/
{0x00,0x00,0x00,0xE0,0x03,0x20,0x04,0x24,0x08,0x24,0x1F,0xFC,0x00,0x24,0x00,0x00},/*"4",20*/
{0x00,0x00,0x1F,0x98,0x10,0x84,0x11,0x04,0x11,0x04,0x10,0x88,0x10,0x70,0x00,0x00},/*"5",21*/
{0x00,0x00,0x07,0xF0,0x08,0x88,0x11,0x04,0x11,0x04,0x18,0x88,0x00,0x70,0x00,0x00},/*"6",22*/
{0x00,0x00,0x1C,0x00,0x10,0x00,0x10,0xFC,0x13,0x00,0x1C,0x00,0x10,0x00,0x00,0x00},/*"7",23*/
{0x00,0x00,0x0E,0x38,0x11,0x44,0x10,0x84,0x10,0x84,0x11,0x44,0x0E,0x38,0x00,0x00},/*"8",24*/
{0x00,0x00,0x07,0x00,0x08,0x8C,0x10,0x44,0x10,0x44,0x08,0x88,0x07,0xF0,0x00,0x00},/*"9",25*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x0C,0x03,0x0C,0x00,0x00,0x00,0x00,0x00,0x00},/*":",26*/
{0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*";",27*/
{0x00,0x00,0x00,0x80,0x01,0x40,0x02,0x20,0x04,0x10,0x08,0x08,0x10,0x04,0x00,0x00},/*"<",28*/
{0x02,0x20,0x02,0x20,0x02,0x20,0x02,0x20,0x02,0x20,0x02,0x20,0x02,0x20,0x00,0x00},/*"=",29*/
{0x00,0x00,0x10,0x04,0x08,0x08,0x04,0x10,0x02,0x20,0x01,0x40,0x00,0x80,0x00,0x00},/*">",30*/
{0x00,0x00,0x0E,0x00,0x12,0x00,0x10,0x0C,0x10,0x6C,0x10,0x80,0x0F,0x00,0x00,0x00},/*"?",31*/
{0x03,0xE0,0x0C,0x18,0x13,0xE4,0x14,0x24,0x17,0xC4,0x08,0x28,0x07,0xD0,0x00,0x00},/*"@",32*/
{0x00,0x04,0x00,0x3C,0x03,0xC4,0x1C,0x40,0x07,0x40,0x00,0xE4,0x00,0x1C,0x00,0x04},/*"A",33*/
{0x10,0x04,0x1F,0xFC,0x11,0x04,0x11,0x04,0x11,0x04,0x0E,0x88,0x00,0x70,0x00,0x00},/*"B",34*/
{0x03,0xE0,0x0C,0x18,0x10,0x04,0x10,0x04,0x10,0x04,0x10,0x08,0x1C,0x10,0x00,0x00},/*"C",35*/
{0x10,0x04,0x1F,0xFC,0x10,0x04,0x10,0x04,0x10,0x04,0x08,0x08,0x07,0xF0,0x00,0x00},/*"D",36*/
{0x10,0x04,0x1F,0xFC,0x11,0x04,0x11,0x04,0x17,0xC4,0x10,0x04,0x08,0x18,0x00,0x00},/*"E",37*/
{0x10,0x04,0x1F,0xFC,0x11,0x04,0x11,0x00,0x17,0xC0,0x10,0x00,0x08,0x00,0x00,0x00},/*"F",38*/
{0x03,0xE0,0x0C,0x18,0x10,0x04,0x10,0x04,0x10,0x44,0x1C,0x78,0x00,0x40,0x00,0x00},/*"G",39*/
{0x10,0x04,0x1F,0xFC,0x10,0x84,0x00,0x80,0x00,0x80,0x10,0x84,0x1F,0xFC,0x10,0x04},/*"H",40*/
{0x00,0x00,0x10,0x04,0x10,0x04,0x1F,0xFC,0x10,0x04,0x10,0x04,0x00,0x00,0x00,0x00},/*"I",41*/
{0x00,0x03,0x00,0x01,0x10,0x01,0x10,0x01,0x1F,0xFE,0x10,0x00,0x10,0x00,0x00,0x00},/*"J",42*/
{0x10,0x04,0x1F,0xFC,0x11,0x04,0x03,0x80,0x14,0x64,0x18,0x1C,0x10,0x04,0x00,0x00},/*"K",43*/
{0x10,0x04,0x1F,0xFC,0x10,0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x0C,0x00,0x00},/*"L",44*/
{0x10,0x04,0x1F,0xFC,0x1F,0x00,0x00,0xFC,0x1F,0x00,0x1F,0xFC,0x10,0x04,0x00,0x00},/*"M",45*/
{0x10,0x04,0x1F,0xFC,0x0C,0x04,0x03,0x00,0x00,0xE0,0x10,0x18,0x1F,0xFC,0x10,0x00},/*"N",46*/
{0x07,0xF0,0x08,0x08,0x10,0x04,0x10,0x04,0x10,0x04,0x08,0x08,0x07,0xF0,0x00,0x00},/*"O",47*/
{0x10,0x04,0x1F,0xFC,0x10,0x84,0x10,0x80,0x10,0x80,0x10,0x80,0x0F,0x00,0x00,0x00},/*"P",48*/
{0x07,0xF0,0x08,0x18,0x10,0x24,0x10,0x24,0x10,0x1C,0x08,0x0A,0x07,0xF2,0x00,0x00},/*"Q",49*/
{0x10,0x04,0x1F,0xFC,0x11,0x04,0x11,0x00,0x11,0xC0,0x11,0x30,0x0E,0x0C,0x00,0x04},/*"R",50*/
{0x00,0x00,0x0E,0x1C,0x11,0x04,0x10,0x84,0x10,0x84,0x10,0x44,0x1C,0x38,0x00,0x00},/*"S",51*/
{0x18,0x00,0x10,0x00,0x10,0x04,0x1F,0xFC,0x10,0x04,0x10,0x00,0x18,0x00,0x00,0x00},/*"T",52*/
{0x10,0x00,0x1F,0xF8,0x10,0x04,0x00,0x04,0x00,0x04,0x10,0x04,0x1F,0xF8,0x10,0x00},/*"U",53*/
{0x10,0x00,0x1E,0x00,0x11,0xE0,0x00,0x1C,0x00,0x70,0x13,0x80,0x1C,0x00,0x10,0x00},/*"V",54*/
{0x1F,0xC0,0x10,0x3C,0x00,0xE0,0x1F,0x00,0x00,0xE0,0x10,0x3C,0x1F,0xC0,0x00,0x00},/*"W",55*/
{0x10,0x04,0x18,0x0C,0x16,0x34,0x01,0xC0,0x01,0xC0,0x16,0x34,0x18,0x0C,0x10,0x04},/*"X",56*/
{0x10,0x00,0x1C,0x00,0x13,0x04,0x00,0xFC,0x13,0x04,0x1C,0x00,0x10,0x00,0x00,0x00},/*"Y",57*/
{0x08,0x04,0x10,0x1C,0x10,0x64,0x10,0x84,0x13,0x04,0x1C,0x04,0x10,0x18,0x00,0x00},/*"Z",58*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFE,0x40,0x02,0x40,0x02,0x40,0x02,0x00,0x00},/*"[",59*/
{0x00,0x00,0x30,0x00,0x0C,0x00,0x03,0x80,0x00,0x60,0x00,0x1C,0x00,0x03,0x00,0x00},/*"\",60*/
{0x00,0x00,0x40,0x02,0x40,0x02,0x40,0x02,0x7F,0xFE,0x00,0x00,0x00,0x00,0x00,0x00},/*"]",61*/
{0x00,0x00,0x00,0x00,0x20,0x00,0x40,0x00,0x40,0x00,0x40,0x00,0x20,0x00,0x00,0x00},/*"^",62*/
{0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01},/*"_",63*/
{0x00,0x00,0x40,0x00,0x40,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"`",64*/
{0x00,0x00,0x00,0x98,0x01,0x24,0x01,0x44,0x01,0x44,0x01,0x44,0x00,0xFC,0x00,0x04},/*"a",65*/
{0x10,0x00,0x1F,0xFC,0x00,0x88,0x01,0x04,0x01,0x04,0x00,0x88,0x00,0x70,0x00,0x00},/*"b",66*/
{0x00,0x00,0x00,0x70,0x00,0x88,0x01,0x04,0x01,0x04,0x01,0x04,0x00,0x88,0x00,0x00},/*"c",67*/
{0x00,0x00,0x00,0x70,0x00,0x88,0x01,0x04,0x01,0x04,0x11,0x08,0x1F,0xFC,0x00,0x04},/*"d",68*/
{0x00,0x00,0x00,0xF8,0x01,0x44,0x01,0x44,0x01,0x44,0x01,0x44,0x00,0xC8,0x00,0x00},/*"e",69*/
{0x00,0x00,0x01,0x04,0x01,0x04,0x0F,0xFC,0x11,0x04,0x11,0x04,0x11,0x00,0x18,0x00},/*"f",70*/
{0x00,0x00,0x00,0xD6,0x01,0x29,0x01,0x29,0x01,0x29,0x01,0xC9,0x01,0x06,0x00,0x00},/*"g",71*/
{0x10,0x04,0x1F,0xFC,0x00,0x84,0x01,0x00,0x01,0x00,0x01,0x04,0x00,0xFC,0x00,0x04},/*"h",72*/
{0x00,0x00,0x01,0x04,0x19,0x04,0x19,0xFC,0x00,0x04,0x00,0x04,0x00,0x00,0x00,0x00},/*"i",73*/
{0x00,0x00,0x00,0x03,0x00,0x01,0x01,0x01,0x19,0x01,0x19,0xFE,0x00,0x00,0x00,0x00},/*"j",74*/
{0x10,0x04,0x1F,0xFC,0x00,0x24,0x00,0x40,0x01,0xB4,0x01,0x0C,0x01,0x04,0x00,0x00},/*"k",75*/
{0x00,0x00,0x10,0x04,0x10,0x04,0x1F,0xFC,0x00,0x04,0x00,0x04,0x00,0x00,0x00,0x00},/*"l",76*/
{0x01,0x04,0x01,0xFC,0x01,0x04,0x01,0x00,0x01,0xFC,0x01,0x04,0x01,0x00,0x00,0xFC},/*"m",77*/
{0x01,0x04,0x01,0xFC,0x00,0x84,0x01,0x00,0x01,0x00,0x01,0x04,0x00,0xFC,0x00,0x04},/*"n",78*/
{0x00,0x00,0x00,0xF8,0x01,0x04,0x01,0x04,0x01,0x04,0x01,0x04,0x00,0xF8,0x00,0x00},/*"o",79*/
{0x01,0x01,0x01,0xFF,0x00,0x85,0x01,0x04,0x01,0x04,0x00,0x88,0x00,0x70,0x00,0x00},/*"p",80*/
{0x00,0x00,0x00,0x70,0x00,0x88,0x01,0x04,0x01,0x04,0x01,0x05,0x01,0xFF,0x00,0x01},/*"q",81*/
{0x01,0x04,0x01,0x04,0x01,0xFC,0x00,0x84,0x01,0x04,0x01,0x00,0x01,0x80,0x00,0x00},/*"r",82*/
{0x00,0x00,0x00,0xCC,0x01,0x24,0x01,0x24,0x01,0x24,0x01,0x24,0x01,0x98,0x00,0x00},/*"s",83*/
{0x00,0x00,0x01,0x00,0x01,0x00,0x07,0xF8,0x01,0x04,0x01,0x04,0x00,0x00,0x00,0x00},/*"t",84*/
{0x01,0x00,0x01,0xF8,0x00,0x04,0x00,0x04,0x00,0x04,0x01,0x08,0x01,0xFC,0x00,0x04},/*"u",85*/
{0x01,0x00,0x01,0x80,0x01,0x70,0x00,0x0C,0x00,0x10,0x01,0x60,0x01,0x80,0x01,0x00},/*"v",86*/
{0x01,0xF0,0x01,0x0C,0x00,0x30,0x01,0xC0,0x00,0x30,0x01,0x0C,0x01,0xF0,0x01,0x00},/*"w",87*/
{0x00,0x00,0x01,0x04,0x01,0x8C,0x00,0x74,0x01,0x70,0x01,0x8C,0x01,0x04,0x00,0x00},/*"x",88*/
{0x01,0x01,0x01,0x81,0x01,0x71,0x00,0x0E,0x00,0x18,0x01,0x60,0x01,0x80,0x01,0x00},/*"y",89*/
{0x00,0x00,0x01,0x84,0x01,0x0C,0x01,0x34,0x01,0x44,0x01,0x84,0x01,0x0C,0x00,0x00},/*"z",90*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x3E,0xFC,0x40,0x02,0x40,0x02},/*"{",91*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00},/*"|",92*/
{0x00,0x00,0x40,0x02,0x40,0x02,0x3E,0xFC,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"}",93*/
{0x00,0x00,0x60,0x00,0x80,0x00,0x80,0x00,0x40,0x00,0x40,0x00,0x20,0x00,0x20,0x00},/*"~",94*/
};
const unsigned char Simulation_Asc3636[5][36]= {
{0x00,0x00,0x00,0x0F,0xFF,0xF8,0x0F,0xFF,0xF8,0x0C,0x0C,0x00,0x0C,0x0C,0x00,0x0C,0x0C,0x00,0x04,0x0C,0x00,0x06,0x0C,0x00,0x06,0x1C,0x00,0x03,0xF8,0x00,0x01,0xF0,
0x00,0x00,0x00,0x00},/*"P",0*/
{0x00,0x00,0x00,0x0F,0xFF,0xF8,0x0F,0xFF,0xF8,0x0F,0xF0,0x00,0x00,0xFF,0x80,0x00,0x07,0xF8,0x00,0x07,0xF8,0x01,0xFF,0x00,0x0F,0xE0,0x00,0x0F,0xFF,0xF8,0x0F,0xFF,
0xF8,0x00,0x00,0x00},/*"M",1*/
{0x00,0x00,0x00,0x01,0x80,0x10,0x07,0x80,0x70,0x06,0x00,0xF0,0x0C,0x01,0xD0,0x0C,0x03,0x90,0x0C,0x07,0x10,0x0E,0x1C,0x10,0x07,0xF8,0x10,0x03,0xE0,0x10,0x00,0x00,
0x10,0x00,0x00,0x00},/*"2",2*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00},/*".",3*/
{0x00,0x00,0x80,0x00,0x38,0xE0,0x07,0xF8,0x70,0x07,0xB0,0x10,0x04,0x20,0x18,0x04,0x20,0x18,0x04,0x30,0x18,0x04,0x30,0x30,0x04,0x3C,0xF0,0x04,0x1F,0xE0,0x00,0x03,
0x00,0x00,0x00,0x00},/*"5",4*/
};
const unsigned char Simulation_Asc3838[10][90]= {
{0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFC,0x00,0x00,
0x00,0x3F,0xFF,0xC0,0x00,0x00,0x7F,0xFF,0xF0,0x00,
0x00,0xFC,0x01,0xF8,0x00,0x01,0xE0,0x00,0x78,0x00,
0x03,0xC0,0x00,0x1C,0x00,0x03,0x80,0x00,0x1C,0x00,
0x03,0x00,0x00,0x0E,0x00,0x03,0x00,0x00,0x0E,0x00,
0x03,0x80,0x00,0x1C,0x00,0x03,0xC0,0x00,0x3C,0x00,
0x01,0xF0,0x00,0x78,0x00,0x00,0xFF,0xFF,0xF0,0x00,
0x00,0x7F,0xFF,0xE0,0x00,0x00,0x0F,0xFF,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"0",0*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00,0x70,
0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x01,0xFF,0xFF,0xFC,0x00,0x03,0xFF,0xFF,0xFC,0x00,0x03,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"1",1*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x70,0x00,0x1C,0x00,0x00,0xF8,0x00,0x3C,0x00,0x01,0xE0,0x00,0x7C,0x00,0x03,0xC0,0x00,0xFC,0x00,0x03,0x80,
0x01,0xEC,0x00,0x03,0x80,0x03,0xCC,0x00,0x03,0x80,0x0F,0x0C,0x00,0x03,0x80,0x1E,0x0C,0x00,0x03,0x80,0x3C,0x0C,0x00,0x03,0x80,0xF8,0x0C,0x00,0x01,0xE7,0xE0,0x0C,
0x00,0x01,0xFF,0xC0,0x0C,0x00,0x00,0xFF,0x00,0x0C,0x00,0x00,0x18,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"2",2*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x30,0x00,0xE0,0x00,0x00,0x70,0x00,0xF0,0x00,0x01,0xF0,0x00,0x78,0x00,0x01,0xC0,0x00,0x3C,0x00,0x03,0x80,
0x00,0x1C,0x00,0x03,0x80,0x60,0x0C,0x00,0x03,0x00,0xE0,0x0C,0x00,0x03,0x00,0xE0,0x0C,0x00,0x03,0x80,0xE0,0x1C,0x00,0x03,0x81,0xF0,0x1C,0x00,0x01,0xE7,0xB8,0x78,
0x00,0x01,0xFF,0x3F,0xF8,0x00,0x00,0xFE,0x1F,0xF0,0x00,0x00,0x18,0x07,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"3",3*/
{0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x07,0x80,0x00,0x00,0x00,0x1F,0x80,0x00,0x00,0x00,0x3F,0x80,0x00,0x00,0x00,0x7B,0x80,0x00,0x00,0x01,0xE3,0x80,0x00,0x00,0x03,
0xC3,0x80,0x00,0x00,0x0F,0x83,0x80,0x00,0x00,0x1E,0x03,0x80,0x00,0x00,0x7C,0x03,0x80,0x00,0x00,0xF0,0x03,0x80,0x00,0x03,0xFF,0xFF,0xFC,0x00,0x03,0xFF,0xFF,0xFC,
0x00,0x03,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x00,0x00,0x00},/*"4",4*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0xE0,0x00,0x00,0x07,0xE0,0xF0,0x00,0x00,0xFF,0xE0,0x78,0x00,0x03,0xFF,0xC0,0x1C,0x00,0x03,0xF1,0x80,0x1C,0x00,0x03,0x83,
0x80,0x0E,0x00,0x03,0x83,0x80,0x0E,0x00,0x03,0x83,0x80,0x0E,0x00,0x03,0x83,0x80,0x0C,0x00,0x03,0x83,0x80,0x1C,0x00,0x03,0x81,0xC0,0x3C,0x00,0x03,0x81,0xE0,0x78,
0x00,0x03,0x80,0xFF,0xF8,0x00,0x03,0x80,0x7F,0xE0,0x00,0x00,0x00,0x1F,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"5",5*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x3F,0xE0,0x00,0x00,0x00,0xFF,0xF0,0x00,0x00,0x03,0xF8,0xF8,0x00,0x00,0x07,0xE0,0x3C,0x00,0x00,0x1F,
0xC0,0x1C,0x00,0x00,0x3F,0x80,0x0C,0x00,0x00,0xF9,0x80,0x0E,0x00,0x01,0xF1,0x80,0x0E,0x00,0x03,0xC1,0x80,0x0E,0x00,0x03,0x01,0xC0,0x0C,0x00,0x02,0x01,0xC0,0x1C,
0x00,0x00,0x00,0xE0,0x7C,0x00,0x00,0x00,0xFF,0xF8,0x00,0x00,0x00,0x7F,0xF0,0x00,0x00,0x00,0x1F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00},/*"6",6*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x03,0x80,0x00,0x1C,0x00,0x03,0x80,
0x00,0xFC,0x00,0x03,0x80,0x07,0xFC,0x00,0x03,0x80,0x1F,0xE0,0x00,0x03,0x80,0x7F,0x00,0x00,0x03,0x81,0xF8,0x00,0x00,0x03,0x87,0xE0,0x00,0x00,0x03,0x9F,0x00,0x00,
0x00,0x03,0xFC,0x00,0x00,0x00,0x03,0xF0,0x00,0x00,0x00,0x03,0xE0,0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"7",7*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xE0,0x00,0x00,0x7E,0x1F,0xF0,0x00,0x00,0xFF,0xBF,0xF8,0x00,0x01,0xE7,0xF8,0x3C,0x00,0x03,0x81,0xF0,0x1C,0x00,0x03,0x80,
0xE0,0x0C,0x00,0x03,0x80,0xE0,0x0E,0x00,0x03,0x00,0xE0,0x0E,0x00,0x03,0x80,0xE0,0x0E,0x00,0x03,0x80,0xE0,0x0C,0x00,0x03,0x81,0xF0,0x1C,0x00,0x01,0xE7,0xB8,0x3C,
0x00,0x00,0xFF,0x3F,0xF8,0x00,0x00,0x7E,0x1F,0xF0,0x00,0x00,0x00,0x0F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"8",8*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xC0,0x00,0x00,0x00,0x7F,0xE0,0x00,0x00,0x00,0xFF,0xF0,0x00,0x00,0x01,0xE0,0x78,0x00,0x00,0x03,0xC0,0x38,0x06,0x00,0x03,0x80,
0x18,0x1E,0x00,0x03,0x80,0x18,0x7E,0x00,0x03,0x80,0x19,0xF8,0x00,0x03,0x80,0x1F,0xE0,0x00,0x03,0x80,0x3F,0xC0,0x00,0x03,0xC0,0x7F,0x00,0x00,0x01,0xE1,0xFC,0x00,
0x00,0x00,0xFF,0xF0,0x00,0x00,0x00,0x7F,0xC0,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"9",9*/
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,206 +0,0 @@
#ifndef _SIMULATION_LCD_H_
#define _SIMULATION_LCD_H_
#include "stm32f10x.h"
#include "bsp_clock.h"
#include "stdlib.h"
typedef struct
{
uint16_t width; // LCD 宽度
uint16_t height; // LCD 高度
uint16_t id; // LCD ID
uint8_t dir; // 横屏还是竖屏控制0竖屏1横屏。
uint8_t wramcmd; // 开始写gram指令
uint8_t setxcmd; // 设置x坐标指令
uint8_t setycmd; // 设置y坐标指令
}SimLCD_t;
extern SimLCD_t SimLCD; //管理LCD重要参数
//LCD的画笔颜色和背景色
extern uint16_t SimLCD_PointColor;// 画笔颜色
extern uint16_t SimLCD_BackColor;// 背景色
//扫描方向定义
#define SimLCD_L2R_U2D 0 //从左到右,从上到下
#define SimLCD_L2R_D2U 1 //从左到右,从下到上
#define SimLCD_R2L_U2D 2 //从右到左,从上到下
#define SimLCD_R2L_D2U 3 //从右到左,从下到上
#define SimLCD_U2D_L2R 4 //从上到下,从左到右
#define SimLCD_U2D_R2L 5 //从上到下,从右到左
#define SimLCD_D2U_L2R 6 //从下到上,从左到右
#define SimLCD_D2U_R2L 7 //从下到上,从右到左
// 默认的扫描方向
#define SimLCD_DefScanDir SimLCD_L2R_U2D
void SimLCD_Init(void);
void SimLCD_Clear(uint16_t color);
void SimLCD_DrawPoint(uint16_t x, uint16_t y);
uint16_t SimLCD_ReadPoint(uint16_t x, uint16_t y);
void SimLCD_Fill(uint16_t sx,uint16_t sy,uint16_t ex,uint16_t ey,uint16_t color);
void SimLCD_ColorFill(uint16_t sx,uint16_t sy,uint16_t ex,uint16_t ey,uint16_t *color);
void SimLCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
void SimLCD_DrawCircle(uint16_t x0,uint16_t y0,uint8_t r);
void SimLCD_DrawRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
void SimLCD_ShowNum(uint16_t x,uint16_t y,uint32_t num,uint8_t len,uint8_t size);
void SimLCD_ShowxNum(uint16_t x,uint16_t y,uint32_t num,uint8_t len,uint8_t size,uint8_t mode);
void SimLCD_ShowString(uint16_t x,uint16_t y,uint16_t width,uint16_t height,uint8_t size,uint8_t *p);
void SimLCD_FillTorus(uint16_t x0,uint16_t y0,uint16_t r0,uint16_t r1);
void SimLCD_Show_PM2_5(uint16_t x, uint16_t y);
void SimLCD_Show_ug_m3(uint16_t x, uint16_t y);
void SimLCD_Show_PM1_0(uint16_t x, uint16_t y);
void SimLCD_Show_PM10(uint16_t x, uint16_t y);
void SimLCD_NewShowChar(uint16_t x, uint16_t y, uint16_t ziti);
void SimLCD_NewShowNum32(uint16_t x, uint16_t y, uint16_t ziti);
//画笔颜色
#define SimLCDColor_WHITE 0xFFFF
#define SimLCDColor_BLACK 0x0000
#define SimLCDColor_BLUE 0x001F
#define SimLCDColor_BRED 0XF81F
#define SimLCDColor_GRED 0XFFE0
#define SimLCDColor_GBLUE 0X07FF
#define SimLCDColor_RED 0xF800
#define SimLCDColor_MAGENTA 0xF81F
#define SimLCDColor_GREEN 0x07E0
#define SimLCDColor_CYAN 0x7FFF
#define SimLCDColor_YELLOW 0xFFE0
#define SimLCDColor_BROWN 0XBC40 //棕色
#define SimLCDColor_BRRED 0XFC07 //棕红色
#define SimLCDColor_GRAY 0X8430 //灰色
//GUI颜色
#define SimLCDColor_DARKBLUE 0X01CF //深蓝色
#define SimLCDColor_LIGHTBLUE 0X7D7C //浅蓝色
#define SimLCDColor_GRAYBLUE 0X5458 //灰蓝色
//以上三色为PANEL的颜色
#define SimLCDColor_LIGHTGREEN 0X841F //浅绿色
//#define SimLCDColor_LIGHTGRAY 0XEF5B //浅灰色(PANNEL)
#define SimLCDColor_LGRAY 0XC618 //浅灰色(PANNEL),窗体背景色
#define SimLCDColor_LGRAYBLUE 0XA651 //浅灰蓝色(中间层颜色)
#define SimLCDColor_LBBLUE 0X2B12 //浅棕蓝色(选择条目的反色)
//9320/9325 LCD寄存器
#define SimLCD_R0 0x00
#define SimLCD_R1 0x01
#define SimLCD_R2 0x02
#define SimLCD_R3 0x03
#define SimLCD_R4 0x04
#define SimLCD_R5 0x05
#define SimLCD_R6 0x06
#define SimLCD_R7 0x07
#define SimLCD_R8 0x08
#define SimLCD_R9 0x09
#define SimLCD_R10 0x0A
#define SimLCD_R12 0x0C
#define SimLCD_R13 0x0D
#define SimLCD_R14 0x0E
#define SimLCD_R15 0x0F
#define SimLCD_R16 0x10
#define SimLCD_R17 0x11
#define SimLCD_R18 0x12
#define SimLCD_R19 0x13
#define SimLCD_R20 0x14
#define SimLCD_R21 0x15
#define SimLCD_R22 0x16
#define SimLCD_R23 0x17
#define SimLCD_R24 0x18
#define SimLCD_R25 0x19
#define SimLCD_R26 0x1A
#define SimLCD_R27 0x1B
#define SimLCD_R28 0x1C
#define SimLCD_R29 0x1D
#define SimLCD_R30 0x1E
#define SimLCD_R31 0x1F
#define SimLCD_R32 0x20
#define SimLCD_R33 0x21
#define SimLCD_R34 0x22
#define SimLCD_R36 0x24
#define SimLCD_R37 0x25
#define SimLCD_R40 0x28
#define SimLCD_R41 0x29
#define SimLCD_R43 0x2B
#define SimLCD_R45 0x2D
#define SimLCD_R48 0x30
#define SimLCD_R49 0x31
#define SimLCD_R50 0x32
#define SimLCD_R51 0x33
#define SimLCD_R52 0x34
#define SimLCD_R53 0x35
#define SimLCD_R54 0x36
#define SimLCD_R55 0x37
#define SimLCD_R56 0x38
#define SimLCD_R57 0x39
#define SimLCD_R59 0x3B
#define SimLCD_R60 0x3C
#define SimLCD_R61 0x3D
#define SimLCD_R62 0x3E
#define SimLCD_R63 0x3F
#define SimLCD_R64 0x40
#define SimLCD_R65 0x41
#define SimLCD_R66 0x42
#define SimLCD_R67 0x43
#define SimLCD_R68 0x44
#define SimLCD_R69 0x45
#define SimLCD_R70 0x46
#define SimLCD_R71 0x47
#define SimLCD_R72 0x48
#define SimLCD_R73 0x49
#define SimLCD_R74 0x4A
#define SimLCD_R75 0x4B
#define SimLCD_R76 0x4C
#define SimLCD_R77 0x4D
#define SimLCD_R78 0x4E
#define SimLCD_R79 0x4F
#define SimLCD_R80 0x50
#define SimLCD_R81 0x51
#define SimLCD_R82 0x52
#define SimLCD_R83 0x53
#define SimLCD_R96 0x60
#define SimLCD_R97 0x61
#define SimLCD_R106 0x6A
#define SimLCD_R118 0x76
#define SimLCD_R128 0x80
#define SimLCD_R129 0x81
#define SimLCD_R130 0x82
#define SimLCD_R131 0x83
#define SimLCD_R132 0x84
#define SimLCD_R133 0x85
#define SimLCD_R134 0x86
#define SimLCD_R135 0x87
#define SimLCD_R136 0x88
#define SimLCD_R137 0x89
#define SimLCD_R139 0x8B
#define SimLCD_R140 0x8C
#define SimLCD_R141 0x8D
#define SimLCD_R143 0x8F
#define SimLCD_R144 0x90
#define SimLCD_R145 0x91
#define SimLCD_R146 0x92
#define SimLCD_R147 0x93
#define SimLCD_R148 0x94
#define SimLCD_R149 0x95
#define SimLCD_R150 0x96
#define SimLCD_R151 0x97
#define SimLCD_R152 0x98
#define SimLCD_R153 0x99
#define SimLCD_R154 0x9A
#define SimLCD_R157 0x9D
#define SimLCD_R192 0xC0
#define SimLCD_R193 0xC1
#define SimLCD_R229 0xE5
#endif

View File

@@ -1,116 +0,0 @@
#include "stmflash.h"
//读取指定地址的半字(16位数据)
//faddr:读地址(此地址必须为2的倍数!!)
//返回值:对应数据.
u16 STMFLASH_ReadHalfWord(u32 faddr)
{
return *(vu16*)faddr;
}
#if STM32_FLASH_WREN //如果使能了写
//不检查的写入
//WriteAddr:起始地址
//pBuffer:数据指针
//NumToWrite:半字(16位)数
void STMFLASH_Write_NoCheck(u32 WriteAddr,u16 *pBuffer,u16 NumToWrite)
{
u16 i;
for(i=0;i<NumToWrite;i++)
{
FLASH_ProgramHalfWord(WriteAddr,pBuffer[i]);
WriteAddr+=2;//地址增加2.
}
}
//从指定地址开始写入指定长度的数据
//WriteAddr:起始地址(此地址必须为2的倍数!!)
//pBuffer:数据指针
//NumToWrite:半字(16位)数(就是要写入的16位数据的个数.)
#if STM32_FLASH_SIZE<256
#define STM_SECTOR_SIZE 1024 //字节
#else
#define STM_SECTOR_SIZE 2048
#endif
u16 STMFLASH_BUF[STM_SECTOR_SIZE/2];//最多是2K字节
void STMFLASH_Write(u32 WriteAddr,u16 *pBuffer,u16 NumToWrite)
{
u32 secpos; //扇区地址
u16 secoff; //扇区内偏移地址(16位字计算)
u16 secremain; //扇区内剩余地址(16位字计算)
u16 i;
u32 offaddr; //去掉0X08000000后的地址
if(WriteAddr<STM32_FLASH_BASE||(WriteAddr>=(STM32_FLASH_BASE+1024*STM32_FLASH_SIZE)))return;//非法地址
FLASH_Unlock(); //解锁
offaddr=WriteAddr-STM32_FLASH_BASE; //实际偏移地址.
secpos=offaddr/STM_SECTOR_SIZE; //扇区地址 0~127 for STM32F103RBT6
secoff=(offaddr%STM_SECTOR_SIZE)/2; //在扇区内的偏移(2个字节为基本单位.)
secremain=STM_SECTOR_SIZE/2-secoff; //扇区剩余空间大小
if(NumToWrite<=secremain)secremain=NumToWrite;//不大于该扇区范围
while(1)
{
STMFLASH_Read(secpos*STM_SECTOR_SIZE+STM32_FLASH_BASE,STMFLASH_BUF,STM_SECTOR_SIZE/2);//读出整个扇区的内容
for(i=0;i<secremain;i++)//校验数据
{
if(STMFLASH_BUF[secoff+i]!=0XFFFF)break;//需要擦除
}
if(i<secremain)//需要擦除
{
FLASH_ErasePage(secpos*STM_SECTOR_SIZE+STM32_FLASH_BASE);//擦除这个扇区
for(i=0;i<secremain;i++)//复制
{
STMFLASH_BUF[i+secoff]=pBuffer[i];
}
STMFLASH_Write_NoCheck(secpos*STM_SECTOR_SIZE+STM32_FLASH_BASE,STMFLASH_BUF,STM_SECTOR_SIZE/2);//写入整个扇区
}else STMFLASH_Write_NoCheck(WriteAddr,pBuffer,secremain);//写已经擦除了的,直接写入扇区剩余区间.
if(NumToWrite==secremain)break;//写入结束了
else//写入未结束
{
secpos++; //扇区地址增1
secoff=0; //偏移位置为0
pBuffer+=secremain; //指针偏移
WriteAddr+=secremain; //写地址偏移
NumToWrite-=secremain; //字节(16位)数递减
if(NumToWrite>(STM_SECTOR_SIZE/2))secremain=STM_SECTOR_SIZE/2;//下一个扇区还是写不完
else secremain=NumToWrite;//下一个扇区可以写完了
}
};
FLASH_Lock();//上锁
}
#endif
//从指定地址开始读出指定长度的数据
//ReadAddr:起始地址
//pBuffer:数据指针
//NumToWrite:半字(16位)数
void STMFLASH_Read(u32 ReadAddr,u16 *pBuffer,u16 NumToRead)
{
u16 i;
for(i=0;i<NumToRead;i++)
{
pBuffer[i]=STMFLASH_ReadHalfWord(ReadAddr);//读取2个字节.
ReadAddr+=2;//偏移2个字节.
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
//WriteAddr:起始地址
//WriteData:要写入的数据
void Test_Write(u32 WriteAddr,u16 WriteData)
{
STMFLASH_Write(WriteAddr,&WriteData,1);//写入一个字
}

View File

@@ -1,44 +0,0 @@
#ifndef __STMFLASH_H__
#define __STMFLASH_H__
#include "stm32f10x.h"
#include "bsp_clock.h"
//////////////////////////////////////////////////////////////////////////////////////////////////////
//用户根据自己的需要设置
#define STM32_FLASH_SIZE 512 //所选STM32的FLASH容量大小(单位为K)
#define STM32_FLASH_WREN 1 //使能FLASH写入(0不是能;1使能)
//////////////////////////////////////////////////////////////////////////////////////////////////////
//FLASH起始地址
#define STM32_FLASH_BASE 0x08000000 //STM32 FLASH的起始地址
//FLASH解锁键值
u16 STMFLASH_ReadHalfWord(u32 faddr); //读出半字
void STMFLASH_WriteLenByte(u32 WriteAddr,u32 DataToWrite,u16 Len); //指定地址开始写入指定长度的数据
u32 STMFLASH_ReadLenByte(u32 ReadAddr,u16 Len); //指定地址开始读取指定长度数据
void STMFLASH_Write(u32 WriteAddr,u16 *pBuffer,u16 NumToWrite); //从指定地址开始写入指定长度的数据
void STMFLASH_Read(u32 ReadAddr,u16 *pBuffer,u16 NumToRead); //从指定地址开始读出指定长度的数据
//测试写入
void Test_Write(u32 WriteAddr,u16 WriteData);
#endif

View File

@@ -1,77 +0,0 @@
/**
******************************************************************************
* @file Project/STM32F10x_StdPeriph_Template/stm32f10x_conf.h
* @author MCD Application Team
* @version V3.5.0
* @date 08-April-2011
* @brief Library configuration file.
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32F10x_CONF_H
#define __STM32F10x_CONF_H
/* Includes ------------------------------------------------------------------*/
/* Uncomment/Comment the line below to enable/disable peripheral header file inclusion */
#include "stm32f10x_adc.h"
#include "stm32f10x_bkp.h"
#include "stm32f10x_can.h"
#include "stm32f10x_cec.h"
#include "stm32f10x_crc.h"
#include "stm32f10x_dac.h"
#include "stm32f10x_dbgmcu.h"
#include "stm32f10x_dma.h"
#include "stm32f10x_exti.h"
#include "stm32f10x_flash.h"
#include "stm32f10x_fsmc.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_i2c.h"
#include "stm32f10x_iwdg.h"
#include "stm32f10x_pwr.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_rtc.h"
#include "stm32f10x_sdio.h"
#include "stm32f10x_spi.h"
#include "stm32f10x_tim.h"
#include "stm32f10x_usart.h"
#include "stm32f10x_wwdg.h"
#include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Uncomment the line below to expanse the "assert_param" macro in the
Standard Peripheral Library drivers code */
/* #define USE_FULL_ASSERT 1 */
/* Exported macro ------------------------------------------------------------*/
#ifdef USE_FULL_ASSERT
/**
* @brief The assert_param macro is used for function's parameters check.
* @param expr: If expr is false, it calls assert_failed function which reports
* the name of the source file and the source line number of the call
* that failed. If expr is true, it returns no value.
* @retval None
*/
#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */
void assert_failed(uint8_t* file, uint32_t line);
#else
#define assert_param(expr) ((void)0)
#endif /* USE_FULL_ASSERT */
#endif /* __STM32F10x_CONF_H */
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/

View File

@@ -1,160 +0,0 @@
/**
******************************************************************************
* @file Project/STM32F10x_StdPeriph_Template/stm32f10x_it.c
* @author MCD Application Team
* @version V3.5.0
* @date 08-April-2011
* @brief Main Interrupt Service Routines.
* This file provides template for all exceptions handler and
* peripherals interrupt service routine.
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_it.h"
/** @addtogroup STM32F10x_StdPeriph_Template
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/******************************************************************************/
/* Cortex-M3 Processor Exceptions Handlers */
/******************************************************************************/
/**
* @brief This function handles NMI exception.
* @param None
* @retval None
*/
void NMI_Handler(void)
{
}
/**
* @brief This function handles Hard Fault exception.
* @param None
* @retval None
*/
void HardFault_Handler(void)
{
/* Go to infinite loop when Hard Fault exception occurs */
while (1)
{
}
}
/**
* @brief This function handles Memory Manage exception.
* @param None
* @retval None
*/
void MemManage_Handler(void)
{
/* Go to infinite loop when Memory Manage exception occurs */
while (1)
{
}
}
/**
* @brief This function handles Bus Fault exception.
* @param None
* @retval None
*/
void BusFault_Handler(void)
{
/* Go to infinite loop when Bus Fault exception occurs */
while (1)
{
}
}
/**
* @brief This function handles Usage Fault exception.
* @param None
* @retval None
*/
void UsageFault_Handler(void)
{
/* Go to infinite loop when Usage Fault exception occurs */
while (1)
{
}
}
/**
* @brief This function handles SVCall exception.
* @param None
* @retval None
*/
void SVC_Handler(void)
{
}
/**
* @brief This function handles Debug Monitor exception.
* @param None
* @retval None
*/
void DebugMon_Handler(void)
{
}
/**
* @brief This function handles PendSVC exception.
* @param None
* @retval None
*/
void PendSV_Handler(void)
{
}
/**
* @brief This function handles SysTick Handler.
* @param None
* @retval None
*/
void SysTick_Handler(void)
{
}
/******************************************************************************/
/* STM32F10x Peripherals Interrupt Handlers */
/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */
/* available peripheral interrupt handler's name please refer to the startup */
/* file (startup_stm32f10x_xx.s). */
/******************************************************************************/
/**
* @brief This function handles PPP interrupt request.
* @param None
* @retval None
*/
/*void PPP_IRQHandler(void)
{
}*/
/**
* @}
*/
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/

View File

@@ -1,54 +0,0 @@
/**
******************************************************************************
* @file Project/STM32F10x_StdPeriph_Template/stm32f10x_it.h
* @author MCD Application Team
* @version V3.5.0
* @date 08-April-2011
* @brief This file contains the headers of the interrupt handlers.
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32F10x_IT_H
#define __STM32F10x_IT_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void NMI_Handler(void);
void HardFault_Handler(void);
void MemManage_Handler(void);
void BusFault_Handler(void);
void UsageFault_Handler(void);
void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
#ifdef __cplusplus
}
#endif
#endif /* __STM32F10x_IT_H */
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/