Projekt

Allgemein

Profil

Wiki » main.cpp

Maximilian Seesslen, 02.08.2024 17:48

 
1
//#include "mpeg.h"     /* include the header file generated with pycrc */
2
#include <stdlib.h>
3
#include <stdint.h>
4
#include <stdio.h>
5
#include <math.h>
6
// #include <intrin.h>
7
//#include <avx2intrin.h>
8
#include <unistd.h>
9
//#include <fmt::fmt>
10
#include <QDebug>
11
#include <sys/ioctl.h>
12
#include <stdio.h>
13

    
14

    
15
float sdd( float temp )
16
{
17
   float a ( 7.5 );
18
   float b ( 237.3 );
19
   float exp=( ( a * temp ) / ( b + temp ) );
20

    
21
   //printf("Exp: %g\n", exp );
22
   //printf("Pow: %g\n", pow( 10, exp ) );
23

    
24
   return( 6.1078 * pow( 10, exp ) );
25
}
26

    
27

    
28
float dd(float rel, float temp)
29
{
30
   return( rel / 100.0 * sdd( temp ) );
31
}
32

    
33

    
34
float absoluteHumidity(float rel, float temp)
35
{
36
   float mw ( 18.016 );     // kg/kmol (Molekulargewicht des Wasserdampfes)
37
   float ugc ( 8314.3 );   // J/(kmol*K) (universelle Gaskonstante)
38
   float TK = temp + 273.15;
39
   return(
40
       pow( 10, 5 ) * mw / ugc * dd(rel, temp) / TK
41
       );
42
}
43

    
44
void operator ""_km(long double)
45
{
46
   return;
47
}
48

    
49
void operator ""_m(unsigned long long v)
50
{
51
   return;
52
}
53

    
54
typedef long int lrtime_t;
55
typedef long int hrtime_t;
56
constexpr lrtime_t seconds( int sec)
57
{
58
   return( sec * 60 );
59
}
60

    
61
/*
62
constexpr hrtime_t seconds( int sec)
63
{
64
   return( sec * 60 * 60 );
65
}
66
*/
67

    
68
class CC1
69
{
70
   public:
71
      explicit CC1( int i1 )
72
      {};
73
};
74

    
75
extern int senseOfLife();
76

    
77

    
78
void __attribute__((optimize("O0"))) testStuff()
79
{
80
   int32_t i32;
81
   int16_t i16;
82

    
83
   i32 = INT16_MAX;
84
   i32++;
85
   i16 = i32;
86
   printf( "i16: 0x%X\n", i16 );
87
}
88

    
89
int main(int argc, const char *argv[])
90
{
91
   // 27°C; 54% -> 13.9038g/m³
92
   // 12, 10%
93
   //float f1=65536;
94
   float f1=32768;
95
   //f1++;
96
   //int16_t i16=f1;
97
   //int16_t i16=__SSAT(f1);
98
   // int16_t i16=__ssat(f1);
99
   //int16_t i16;
100
   //bool overflow = __builtin_mul_overflow(0.0, f1, &i16);
101

    
102
#if 0
103
   printf("float overflow: %d\n", i16);
104
   printf( "%g\n",  absoluteHumidity(10, 12) );
105
   printf( "Secs: %d\n",  seconds(10) );
106
   printf( "Sense of life: %d\n", senseOfLife() );
107
   printf( "\n" );
108
   1.23_km;
109
   CC1 c1 { 12 };
110
#endif
111

    
112
   uint32_t t1=0x7FFFFFFF;
113
   uint32_t t2=t1+10;
114

    
115
   printf("T1: %d\n", t1);
116
   printf("T2: %d\n", t2);
117

    
118
   printf("delta: %d\n", t2-t1); // delta is 10
119
   printf("delta: %d\n", t1-t2); // delta is -10
120

    
121
   uint64_t xt1=t1;
122
   uint64_t xt2=t2;
123
   printf("delta: %d\n", xt2-xt1);
124
   printf("delta: %d\n", xt1-xt2);
125
   printf("int: %d\n", sizeof(int));
126
   printf("int64: %d\n", sizeof(int64_t));
127

    
128
   float factor=2.3;
129
   int value=6000;
130
   int result=floor( value*factor );
131
   printf("Value1 = %.1lf\n", floor( value*factor ));
132
   printf("Result = %d\n", result);
133
   // printf("Multi: %d\n", (int)(value*factor) );
134

    
135
   testStuff();
136

    
137
   class CAnsi
138
   {
139
      int fade;
140
      int lines=0;
141
      int previousLines=0;
142
   public:
143
      void up(int n=1)
144
      {
145
         printf("\e[%dA", n);
146
      }
147
      void x(int n=0)
148
      {
149
         printf("\e[%dG", n);
150
      }
151
      void red()
152
      {
153
         printf("\e[38;2;255;0;0m");
154
      }
155
      void blue()
156
      {
157
         printf("\e[38;2;0;0;255m");
158
      }
159
      void reset()
160
      {
161
         printf("\e[0m");
162
      }
163
      void triggerFade()
164
      {
165

    
166
      }
167
      void eraseInLine()
168
      {
169
         printf("\e[0K");
170
      }
171
      void newLine()
172
      {
173
         printf("\n");
174
         lines++;
175

    
176
         eraseInLine();
177
         reset();
178
      }
179
      void finish()
180
      {
181
         x(1);
182
         for(int i1=0; i1<previousLines-lines; i1++)
183
         {
184
            eraseInLine();
185
            printf("\n");
186
         }
187
         for(int i1=0; i1<previousLines-lines; i1++)
188
         {
189
            up();
190
         }
191
         previousLines=lines;
192
      }
193
      void home()
194
      {
195
         for(int i1=0; i1<lines; i1++)
196
         {
197
            up();
198
         }
199
         eraseInLine();
200
         lines=0;
201
      }
202
      void cls()
203
      {
204
         fputs( "\e[2J\e[;H", stdout);
205
      }
206
      void initLoggingScreen(int start, int end)
207
      {
208
         printf("\e[22;52r\e[22;0H");
209
      }
210
      void setScrollArea(int start, int end)
211
      {
212
         // [s: save position
213
         // [u: restore
214
         // [20;0H move cursor
215
         //fputs("\e[s\e[4;20r\e[20;0H\n", stdout);
216
         // \033[22;52r\033[u
217

    
218
         fputs("\e[s\e[1;20r\e[1;1H", stdout);
219
         fputs("\e[20;1H", stdout);
220
         fputs("\e[1J", stdout);
221
         fputs("\e[1;1H", stdout);
222
         // fputs("\e[1;10;\"X\"K", stdout);
223
         fputs("\e[2;\"*\"J", stdout);
224
      }
225
      void gotoxy(int x, int y)
226
      {
227
         printf("\e[%d;%dH", y, x);
228
      }
229
      void loggingScreen(int start, int end)
230
      {
231
         // [s: save position
232
         // [u: restore
233
         // [20;0H move cursor
234
         //printf("\e[22;52r\e[u");
235
         printf("\e[22;52r\e[u");
236
         gotoxy(1, 52);
237
      }
238
   };
239

    
240
   CAnsi ansi;
241

    
242
   //struct ttysize ts;
243
   struct winsize w;
244
   ioctl(0, TIOCGWINSZ, &w);
245

    
246
   printf ("lines %d\n", w.ws_row);
247
   printf ("columns %d\n", w.ws_col);
248
   ansi.gotoxy(1,1);
249
   printf("X\n\n\n");
250
   ansi.gotoxy(w.ws_col,1);
251
   printf("X\n\n\n");
252
   exit(22);
253

    
254
   //printf("\n");
255
   //ansi.cls();
256
   ansi.initLoggingScreen(0, 0);
257
   printf("CANServer v1.1.1\n\n");
258

    
259
   for(int i1=0; i1<10; i1++)
260
   {
261

    
262
      ansi.home();
263
      ansi.setScrollArea(0,0);
264
      ansi.gotoxy(1, 1);
265

    
266
      //ansi.cls();
267
      //qWarning("This is a nice Warning2");
268
      //fflush(stderr);
269
      //fflush(stdout);
270
      printf("Hallooooooho!\n");
271
#if 0
272
      ansi.newLine();
273

    
274
      printf("Id");
275

    
276
      ansi.x(10);
277
      printf("counter");
278
      ansi.x(20);
279
      printf("target");
280
      ansi.newLine();
281
      printf("--------------------------------------------");
282
      ansi.newLine();
283

    
284
      printf("%d", i1);
285
      ansi.x(10);
286
      printf("%d", 100-i1);
287
      ansi.x(20);
288
      printf( "TCP Server" );
289
      ansi.newLine();
290

    
291
      ansi.red();
292
      printf("%d+1", i1);
293
      ansi.x(10);
294
      printf("%d", 100-i1);
295
      ansi.newLine();
296

    
297
      if(i1==5)
298
      {
299
         ansi.blue();
300
         printf("%d+1", i1);
301
         ansi.x(10);
302
         printf("%d", 100-i1);
303
         ansi.newLine();
304
      }
305
      printf("--------------------------------------------");
306
      ansi.newLine();
307
#if 0
308
      ansi.finish();
309
#endif
310
      //qWarning("Foooohuu");
311
#endif
312
      ansi.loggingScreen(0,0);
313

    
314
      printf("This is a nice Warning1 <%d-1>\n", i1);
315
      printf("This is a nice Warning1 <%d-2>\n", i1);
316
      printf("This is a nice Warning1 <%d-3>\n", i1);
317

    
318
      //fflush(stderr);
319
      //fflush(stdout);
320

    
321
      sleep(1);
322
      //ansi.home();
323
   }
324

    
325
   return(0);
326
}
327

    
328
//---fin----------------------------------------------------------------------
(1-1/3)