APservice/tslib.h

169 lines
5.9 KiB
C
Executable File

#ifndef TSLIB_H
#define TSLIB_H
#include <stdint.h>
#include <QByteArray>
typedef uint8_t UCHAR;
typedef uint16_t UINT;
typedef uint32_t ULONG;
#define LOWBYTE false
#define HIGHBYTE true
uint16_t uchar2uint(char Highbyte, char Lowbyte);
uint16_t uchar2uint(uint8_t Highbyte, uint8_t Lowbyte);
uint32_t uchar2ulong(uint8_t Highbyte, uint8_t MHbyte, uint8_t MLbyte, uint8_t Lowbyte);
uint8_t uint2uchar(uint16_t uival, bool getHighB);
void delay(uint16_t MilliSec);
#define MITSEK 1
#define OHNESEK 0
#define HourSys12h 1
#define HourSys24h 0
void GetTimeString(uint8_t hours, uint8_t minutes, uint8_t seconds, uint8_t System12h, uint8_t ShowSec, uint8_t *buf);
// generate time as ascii string from integers hours/minutes/seconds
// System12h=0: 24h system =1: 12h System
// ShowSec=0: String has 5 digits (hh:mm) =1: String has 8 digits (hh:mm:ss)
// return String in *buf // 12 byte für buf!
#define DateFormatDeutsch 0
#define DateFormatAmerica 1
#define UsePointSeperator 0
#define UseSlashSeperator 1
void GetDateString(uint8_t day, uint8_t month, uint8_t yearhigh, uint8_t yearlow, uint8_t format, uint8_t sep, uint8_t *buf);
// generate date as ascii string from integers day/month/year
// yearhigh in europe always 20 (not in arabia)
// format= 0: dd.mm.yyyy (deutsch)
// 1: mm.dd.yyyy (amerika)
// 2: yyyy.mm.dd (Iran, Dubai)
// 3: dd.yyyy.mm
// 4: mm.yyyy.dd
// 5: yyyy.dd.mm
// sep: 0: use . as seperator 1: use / as seperator
// return String in *buf // 11 byte für buf!
void GetShortDateString(uint8_t day, uint8_t month, uint8_t yearlow, uint8_t format, uint8_t sep, uint8_t *buf);
// generate date as ascii string from integers day/month/year
// format= 0: dd.mm.yy (deutsch)
// 1: mm.dd.yy (amerika)
// 2: yy.mm.dd (Iran, Dubai)
// 3: dd.yy.mm
// 4: mm.yy.dd
// 5: yy.dd.mm
// sep: 0: use . as seperator 1: use / as seperator
// return String in *buf // 11byte für buf!
uint16_t tslib_strlen(char *buf);
void tslib_strclr(char *buf, char clrsign, uint16_t len);
void tslib_strclr(uint8_t *buf, char clrsign, uint16_t len);
void tslib_strcpy(char *srcbuf, char *destbuf, uint16_t len);
void tslib_strcpy(char *srcbuf, uint8_t *destbuf, uint16_t len);
void tslib_strcpy(uint8_t *srcbuf, uint8_t *destbuf, uint16_t len);
uint16_t tslib_calcCrcCcitt(uint16_t BufLength, uint8_t *buf);
bool tslib_isDecAsciiNumber(char sign);
bool tslib_isHexAsciiNumber(char sign);
int tslib_getMinimum(int val1, int val2);
void tslib_text2array(QByteArray text, char *aray, uint16_t maxArayLen);
// usage: tslib_text2array("my text", ctmp, 50);
bool tslib_strComp(uint8_t *buf, char *compStr);
bool tslib_plausiChkTime(uint8_t hour, uint8_t min, uint8_t sec );
// retval: true: time is OK
bool tslib_plausiChkDate(uint8_t year, uint8_t month, uint8_t dom );
// retval: true: time is OK
UCHAR swl_LengthCurrentMonth(UCHAR month, UCHAR year);
// return nr of days for this month, respecting leap years
UINT swl_GetDaysOfaCompleteYear(UCHAR year);
// year: 0=2000 4=2004 99=2099
// retval: 365 or 366 (leap year)
UINT swl_GetDaysOfYear(UCHAR year, UCHAR month, UCHAR day);
// number of days of momentary year from 1. Jan until
// (inclusive) given date with respect to leap years
// year: 0..99 month=1..12 day=1..31
unsigned long swl_getNrOfDaysSince2000Jan1(UCHAR thisYear, UCHAR thisMonth, UCHAR thisDay);
// till today
unsigned long swl_getNrOfHoursSince_Midnight2000Jan1(UCHAR thisYear, UCHAR thisMonth, UCHAR thisDay, UCHAR hoursNow);
unsigned long swl_getNrOfMinutesSince_Midnight2000Jan1(UCHAR thisYear, \
UCHAR thisMonth, UCHAR thisDay, UCHAR hoursNow, UCHAR minuteNow);
unsigned long swl_getNrOfSecondsSince_Midnight2000Jan1(UCHAR thisYear, \
UCHAR thisMonth, UCHAR thisDay, UCHAR hoursNow, UCHAR minuteNow, UCHAR secondNow);
char swl_isLeap(UCHAR year);
UCHAR swl_getNextLeapYear(UCHAR year);
UCHAR swl_getLastLeapYear(UCHAR year);
UCHAR swl_hoursOfThisWeek(UCHAR dow, UCHAR hoursNow);
// always calculate from monday 0 o'clock
// dow: 1=monday 7=sunday
UINT swl_minutesOfThisWeek(UCHAR dow, UCHAR hoursNow, UCHAR minutesNow);
// always calculate from monday 0 o'clock
// dow: 1=monday 7=sunday
UINT swl_hoursOfThisMonth(UCHAR thisDay, UCHAR hoursNow);
UINT swl_minutesOfThisMonth(UCHAR thisDay, UCHAR hoursNow, UCHAR minutesNow);
UINT swl_GetHoursOfYear(UCHAR year, UCHAR month, UCHAR day, UCHAR hourNow);
ULONG swl_GetMinutesOfYear(UCHAR year, UCHAR month, UCHAR day, UCHAR hourNow, UCHAR minutesNow);
UCHAR swl_weekday(UCHAR year, UCHAR month, UCHAR dayOfMonth);
// return 1...7 = monday...sunday, starting from 1.1.2000
QString swl_int2str(int val);
QString swl_hex2str(double val);
void swl_text2ui8buf(QString text, uint8_t *outbuf, uint16_t length);
// copy text byte-by-byte to outbuf
QString swl_ulong2str(uint32_t val);
QString swl_long2str(long val);
uint16_t swl_str2uint(QString myIntStr);
uint32_t swl_str2ulong(QString myIntStr);
QString swl_labelAndValToStr(QString label, uint32_t val);
QString swl_8valInaRowToStr(QString label, uint8_t val[8]);
QString swl_8valInaRowToStr(QString label, uint16_t val[8]);
QString swl_8intsInaRowToStr(QString label, int val[8]);
QString swl_centToEuroString(uint32_t amount_in_cent);
#endif // TSLIB_H
// qDebug << QDateTime::currentDateTime().toString(Qt::ISODateWithMs) << QByteArray((const char*)dataSendBuf,dataBufLen).toHex(':');