function evaluation & CV & ...
This commit is contained in:
1 parent
7e487f38cf
commit
47101afbf8
3 files changed
+568
-84
No files matched your search
@@ -31,6 +31,7 @@ target_link_libraries(
|
||||
hello_multicore
|
||||
pico_stdlib
|
||||
hardware_pio
|
||||
hardware_pwm
|
||||
pico_multicore
|
||||
)
|
||||
|
||||
|
||||
@@ -1,8 +1,345 @@
|
||||
#define CV_1 5 //Adresse - Die Basisadresse enthält die Lokadresse. Ist CV#1 gleich 0, verlässt der Decoder den Digitalbetrieb und wechselt in den Alternativ-Betrieb (Analog-Betrieb). Normalerweise wird beim Schreiben der CV1 im Decoder automatisch CV19 (Mehrfachtraktionsadresse) und in CV29 das Bit 5 (Verwendung der erweiterten Adresse; Bit 5 bei Zählung ab 0) gelöscht.
|
||||
#define CV_2 0 //U_min - Definiert die Fahrspannung, die bei niedrigster Fahrstufe am Motor anliegt.
|
||||
#define CV_3 5 //Beschleunigungsrate - Definiert die Länge der Wartezeit, die beim Beschleunigen jeweils vor dem Hochschalten zur nächst höheren Fahrstufe vergeht.
|
||||
#define CV_4 5 //Bremsrate - Definiert die Länge der Wartezeit, die beim Bremsen jeweils vor dem Herunterschalten zur nächst niedrigen Fahrstufe vergeht.
|
||||
#define CV_5 255 //U_max - Definiert die Fahrspannung, die bei höchster Fahrstufe am Motor anliegt.
|
||||
#define CV_6 127 //U_mid - Definiert die Fahrspannung, die bei mittlerer Fahrstufe am Motor anliegt.
|
||||
#define CV_8 1 //Versionsnummer - Gibt die Versionsnummer der Decoder-Software an.
|
||||
#define CV_9 5 //PWM-Periode - Definiert die Frequenz der Pulsweitenmodulation.
|
||||
#define CV_1 5 //Address - Basic Address
|
||||
#define CV_2 0 //V_min - Minimum Speed
|
||||
#define CV_3 5 //Beschleunigungsrate - Definiert die Länge der Wartezeit, die beim Beschleunigen jeweils vor dem Hochschalten zur nächst höheren Fahrstufe vergeht.
|
||||
#define CV_4 5 //Bremsrate - Definiert die Länge der Wartezeit, die beim Bremsen jeweils vor dem Herunterschalten zur nächst niedrigen Fahrstufe vergeht.
|
||||
#define CV_5 255 //V_max - Maximum Speed
|
||||
#define CV_6 127 //V_mid - Middle Speed
|
||||
#define CV_7 13 //Version No. - Decoder-Software version
|
||||
#define CV_8 13 //Manufacturer - Manufacturer Identification (13 == "Public Domain & Do-It-Yourself Decoders").
|
||||
#define CV_9 5 //PWM-Period - Defines the Motor PWM-Period
|
||||
const uint8_t CV_FUNCTION_ARRAY [256] = {
|
||||
//F0 forward
|
||||
0b11111111, //byte 0 - CV_257
|
||||
0b11111111, //byte 1 - CV_258
|
||||
0b11111111, //byte 2 - CV_259
|
||||
0b11111111, //byte 3 - CV_260
|
||||
//F0 reverse
|
||||
0b11111111, //byte 0 - CV_261
|
||||
0b11111111, //byte 1 - CV_262
|
||||
0b11111111, //byte 2 - CV_263
|
||||
0b11111111, //byte 3 - CV_264
|
||||
//F1 forward
|
||||
0b11111111, //byte 0 - CV_265
|
||||
0b11111111, //byte 1 - CV_266
|
||||
0b11111111, //byte 2 - CV_267
|
||||
0b11111111, //byte 3 - CV_268
|
||||
//F1 reverse
|
||||
0b11111111, //byte 0 - CV_269
|
||||
0b11111111, //byte 1 - CV_270
|
||||
0b11111111, //byte 2 - CV_271
|
||||
0b11111111, //byte 3 - CV_272
|
||||
//F2 forward
|
||||
0b11111111, //byte 0 - CV_273
|
||||
0b11111111, //byte 1 - CV_274
|
||||
0b11111111, //byte 2 - CV_275
|
||||
0b11111111, //byte 3 - CV_276
|
||||
//F2 reverse
|
||||
0b11111111, //byte 0 - CV_277
|
||||
0b11111111, //byte 1 - CV_278
|
||||
0b11111111, //byte 2 - CV_279
|
||||
0b11111111, //byte 3 - CV_280
|
||||
//F3 forward
|
||||
0b11111111, //byte 0 - CV_281
|
||||
0b11111111, //byte 1 - CV_282
|
||||
0b11111111, //byte 2 - CV_283
|
||||
0b11111111, //byte 3 - CV_284
|
||||
//F3 reverse
|
||||
0b11111111, //byte 0 - CV_285
|
||||
0b11111111, //byte 1 - CV_286
|
||||
0b11111111, //byte 2 - CV_287
|
||||
0b11111111, //byte 3 - CV_288
|
||||
//F4 forward
|
||||
0b11111111, //byte 0 - CV_289
|
||||
0b11111111, //byte 1 - CV_290
|
||||
0b11111111, //byte 2 - CV_291
|
||||
0b11111111, //byte 3 - CV_292
|
||||
//F4 reverse
|
||||
0b11111111, //byte 0 - CV_293
|
||||
0b11111111, //byte 1 - CV_294
|
||||
0b11111111, //byte 2 - CV_295
|
||||
0b11111111, //byte 3 - CV_296
|
||||
//F5 forward
|
||||
0b11111111, //byte 0 - CV_297
|
||||
0b11111111, //byte 1 - CV_298
|
||||
0b11111111, //byte 2 - CV_299
|
||||
0b11111111, //byte 3 - CV_300
|
||||
//F5 reverse
|
||||
0b11111111, //byte 0 - CV_301
|
||||
0b11111111, //byte 1 - CV_302
|
||||
0b11111111, //byte 2 - CV_303
|
||||
0b11111111, //byte 3 - CV_304
|
||||
//F6 forward
|
||||
0b11111111, //byte 0 - CV_305
|
||||
0b11111111, //byte 1 - CV_306
|
||||
0b11111111, //byte 2 - CV_307
|
||||
0b11111111, //byte 3 - CV_308
|
||||
//F6 reverse
|
||||
0b11111111, //byte 0 - CV_309
|
||||
0b11111111, //byte 1 - CV_310
|
||||
0b11111111, //byte 2 - CV_311
|
||||
0b11111111, //byte 3 - CV_312
|
||||
//F7 forward
|
||||
0b11111111, //byte 0 - CV_313
|
||||
0b11111111, //byte 1 - CV_314
|
||||
0b11111111, //byte 2 - CV_315
|
||||
0b11111111, //byte 3 - CV_316
|
||||
//F7 reverse
|
||||
0b11111111, //byte 0 - CV_317
|
||||
0b11111111, //byte 1 - CV_318
|
||||
0b11111111, //byte 2 - CV_319
|
||||
0b11111111, //byte 3 - CV_320
|
||||
//F8 forward
|
||||
0b11111111, //byte 0 - CV_321
|
||||
0b11111111, //byte 1 - CV_322
|
||||
0b11111111, //byte 2 - CV_323
|
||||
0b11111111, //byte 3 - CV_324
|
||||
//F8 reverse
|
||||
0b11111111, //byte 0 - CV_325
|
||||
0b11111111, //byte 1 - CV_326
|
||||
0b11111111, //byte 2 - CV_327
|
||||
0b11111111, //byte 3 - CV_328
|
||||
//F9 forward
|
||||
0b11111111, //byte 0 - CV_329
|
||||
0b11111111, //byte 1 - CV_330
|
||||
0b11111111, //byte 2 - CV_331
|
||||
0b11111111, //byte 3 - CV_332
|
||||
//F9 reverse
|
||||
0b11111111, //byte 0 - CV_333
|
||||
0b11111111, //byte 1 - CV_334
|
||||
0b11111111, //byte 2 - CV_335
|
||||
0b11111111, //byte 3 - CV_336
|
||||
//F10 forward
|
||||
0b11111111, //byte 0 - CV_337
|
||||
0b11111111, //byte 1 - CV_338
|
||||
0b11111111, //byte 2 - CV_339
|
||||
0b11111111, //byte 3 - CV_340
|
||||
//F10 reverse
|
||||
0b11111111, //byte 0 - CV_341
|
||||
0b11111111, //byte 1 - CV_342
|
||||
0b11111111, //byte 2 - CV_343
|
||||
0b11111111, //byte 3 - CV_344
|
||||
//F11 forward
|
||||
0b11111111, //byte 0 - CV_345
|
||||
0b11111111, //byte 1 - CV_346
|
||||
0b11111111, //byte 2 - CV_347
|
||||
0b11111111, //byte 3 - CV_348
|
||||
//F11 reverse
|
||||
0b11111111, //byte 0 - CV_349
|
||||
0b11111111, //byte 1 - CV_350
|
||||
0b11111111, //byte 2 - CV_351
|
||||
0b11111111, //byte 3 - CV_352
|
||||
//F12 forward
|
||||
0b11111111, //byte 0 - CV_353
|
||||
0b11111111, //byte 1 - CV_354
|
||||
0b11111111, //byte 2 - CV_355
|
||||
0b11111111, //byte 3 - CV_356
|
||||
//F12 reverse
|
||||
0b11111111, //byte 0 - CV_357
|
||||
0b11111111, //byte 1 - CV_358
|
||||
0b11111111, //byte 2 - CV_359
|
||||
0b11111111, //byte 3 - CV_360
|
||||
//F13 forward
|
||||
0b11111111, //byte 0 - CV_361
|
||||
0b11111111, //byte 1 - CV_362
|
||||
0b11111111, //byte 2 - CV_363
|
||||
0b11111111, //byte 3 - CV_364
|
||||
//F13 reverse
|
||||
0b11111111, //byte 0 - CV_365
|
||||
0b11111111, //byte 1 - CV_366
|
||||
0b11111111, //byte 2 - CV_367
|
||||
0b11111111, //byte 3 - CV_368
|
||||
//F14 forward
|
||||
0b11111111, //byte 0 - CV_369
|
||||
0b11111111, //byte 1 - CV_370
|
||||
0b11111111, //byte 2 - CV_371
|
||||
0b11111111, //byte 3 - CV_372
|
||||
//F14 reverse
|
||||
0b11111111, //byte 0 - CV_373
|
||||
0b11111111, //byte 1 - CV_374
|
||||
0b11111111, //byte 2 - CV_375
|
||||
0b11111111, //byte 3 - CV_376
|
||||
//F15 forward
|
||||
0b11111111, //byte 0 - CV_377
|
||||
0b11111111, //byte 1 - CV_378
|
||||
0b11111111, //byte 2 - CV_379
|
||||
0b11111111, //byte 3 - CV_380
|
||||
//F15 reverse
|
||||
0b11111111, //byte 0 - CV_381
|
||||
0b11111111, //byte 1 - CV_382
|
||||
0b11111111, //byte 2 - CV_383
|
||||
0b11111111, //byte 3 - CV_384
|
||||
//F16 forward
|
||||
0b11111111, //byte 0 - CV_385
|
||||
0b11111111, //byte 1 - CV_386
|
||||
0b11111111, //byte 2 - CV_387
|
||||
0b11111111, //byte 3 - CV_388
|
||||
//F16 reverse
|
||||
0b11111111, //byte 0 - CV_389
|
||||
0b11111111, //byte 1 - CV_390
|
||||
0b11111111, //byte 2 - CV_391
|
||||
0b11111111, //byte 3 - CV_392
|
||||
//F17 forward
|
||||
0b11111111, //byte 0 - CV_393
|
||||
0b11111111, //byte 1 - CV_394
|
||||
0b11111111, //byte 2 - CV_395
|
||||
0b11111111, //byte 3 - CV_396
|
||||
//F17 reverse
|
||||
0b11111111, //byte 0 - CV_397
|
||||
0b11111111, //byte 1 - CV_398
|
||||
0b11111111, //byte 2 - CV_399
|
||||
0b11111111, //byte 3 - CV_400
|
||||
//F18 forward
|
||||
0b11111111, //byte 0 - CV_401
|
||||
0b11111111, //byte 1 - CV_402
|
||||
0b11111111, //byte 2 - CV_403
|
||||
0b11111111, //byte 3 - CV_404
|
||||
//F18 reverse
|
||||
0b11111111, //byte 0 - CV_405
|
||||
0b11111111, //byte 1 - CV_406
|
||||
0b11111111, //byte 2 - CV_407
|
||||
0b11111111, //byte 3 - CV_408
|
||||
//F19 forward
|
||||
0b11111111, //byte 0 - CV_409
|
||||
0b11111111, //byte 1 - CV_410
|
||||
0b11111111, //byte 2 - CV_411
|
||||
0b11111111, //byte 3 - CV_412
|
||||
//F19 reverse
|
||||
0b11111111, //byte 0 - CV_413
|
||||
0b11111111, //byte 1 - CV_414
|
||||
0b11111111, //byte 2 - CV_415
|
||||
0b11111111, //byte 3 - CV_416
|
||||
//F20 forward
|
||||
0b11111111, //byte 0 - CV_417
|
||||
0b11111111, //byte 1 - CV_418
|
||||
0b11111111, //byte 2 - CV_419
|
||||
0b11111111, //byte 3 - CV_420
|
||||
//F20 reverse
|
||||
0b11111111, //byte 0 - CV_421
|
||||
0b11111111, //byte 1 - CV_422
|
||||
0b11111111, //byte 2 - CV_423
|
||||
0b11111111, //byte 3 - CV_424
|
||||
//F21 forward
|
||||
0b11111111, //byte 0 - CV_425
|
||||
0b11111111, //byte 1 - CV_426
|
||||
0b11111111, //byte 2 - CV_427
|
||||
0b11111111, //byte 3 - CV_428
|
||||
//F21 reverse
|
||||
0b11111111, //byte 0 - CV_429
|
||||
0b11111111, //byte 1 - CV_430
|
||||
0b11111111, //byte 2 - CV_431
|
||||
0b11111111, //byte 3 - CV_432
|
||||
//F22 forward
|
||||
0b11111111, //byte 0 - CV_433
|
||||
0b11111111, //byte 1 - CV_434
|
||||
0b11111111, //byte 2 - CV_435
|
||||
0b11111111, //byte 3 - CV_436
|
||||
//F22 reverse
|
||||
0b11111111, //byte 0 - CV_437
|
||||
0b11111111, //byte 1 - CV_438
|
||||
0b11111111, //byte 2 - CV_439
|
||||
0b11111111, //byte 3 - CV_440
|
||||
//F23 forward
|
||||
0b11111111, //byte 0 - CV_441
|
||||
0b11111111, //byte 1 - CV_442
|
||||
0b11111111, //byte 2 - CV_443
|
||||
0b11111111, //byte 3 - CV_444
|
||||
//F23 reverse
|
||||
0b11111111, //byte 0 - CV_445
|
||||
0b11111111, //byte 1 - CV_446
|
||||
0b11111111, //byte 2 - CV_447
|
||||
0b11111111, //byte 3 - CV_448
|
||||
//F24 forward
|
||||
0b11111111, //byte 0 - CV_449
|
||||
0b11111111, //byte 1 - CV_450
|
||||
0b11111111, //byte 2 - CV_451
|
||||
0b11111111, //byte 3 - CV_452
|
||||
//F24 reverse
|
||||
0b11111111, //byte 0 - CV_453
|
||||
0b11111111, //byte 1 - CV_454
|
||||
0b11111111, //byte 2 - CV_455
|
||||
0b11111111, //byte 3 - CV_456
|
||||
//F25 forward
|
||||
0b11111111, //byte 0 - CV_457
|
||||
0b11111111, //byte 1 - CV_458
|
||||
0b11111111, //byte 2 - CV_459
|
||||
0b11111111, //byte 3 - CV_460
|
||||
//F25 reverse
|
||||
0b11111111, //byte 0 - CV_461
|
||||
0b11111111, //byte 1 - CV_462
|
||||
0b11111111, //byte 2 - CV_463
|
||||
0b11111111, //byte 3 - CV_464
|
||||
//F26 forward
|
||||
0b11111111, //byte 0 - CV_465
|
||||
0b11111111, //byte 1 - CV_466
|
||||
0b11111111, //byte 2 - CV_467
|
||||
0b11111111, //byte 3 - CV_468
|
||||
//F26 reverse
|
||||
0b11111111, //byte 0 - CV_469
|
||||
0b11111111, //byte 1 - CV_470
|
||||
0b11111111, //byte 2 - CV_471
|
||||
0b11111111, //byte 3 - CV_472
|
||||
//F27 forward
|
||||
0b11111111, //byte 0 - CV_473
|
||||
0b11111111, //byte 1 - CV_474
|
||||
0b11111111, //byte 2 - CV_475
|
||||
0b11111111, //byte 3 - CV_476
|
||||
//F27 reverse
|
||||
0b11111111, //byte 0 - CV_477
|
||||
0b11111111, //byte 1 - CV_478
|
||||
0b11111111, //byte 2 - CV_479
|
||||
0b11111111, //byte 3 - CV_480
|
||||
//F28 forward
|
||||
0b11111111, //byte 0 - CV_481
|
||||
0b11111111, //byte 1 - CV_482
|
||||
0b11111111, //byte 2 - CV_483
|
||||
0b11111111, //byte 3 - CV_484
|
||||
//F28 reverse
|
||||
0b11111111, //byte 0 - CV_485
|
||||
0b11111111, //byte 1 - CV_486
|
||||
0b11111111, //byte 2 - CV_487
|
||||
0b11111111, //byte 3 - CV_488
|
||||
//F29 forward
|
||||
0b11111111, //byte 0 - CV_489
|
||||
0b11111111, //byte 1 - CV_490
|
||||
0b11111111, //byte 2 - CV_491
|
||||
0b11111111, //byte 3 - CV_492
|
||||
//F29 reverse
|
||||
0b11111111, //byte 0 - CV_493
|
||||
0b11111111, //byte 1 - CV_494
|
||||
0b11111111, //byte 2 - CV_495
|
||||
0b11111111, //byte 3 - CV_496
|
||||
//F30 forward
|
||||
0b11111111, //byte 0 - CV_497
|
||||
0b11111111, //byte 1 - CV_498
|
||||
0b11111111, //byte 2 - CV_499
|
||||
0b11111111, //byte 3 - CV_500
|
||||
//F30 reverse
|
||||
0b11111111, //byte 0 - CV_501
|
||||
0b11111111, //byte 1 - CV_502
|
||||
0b11111111, //byte 2 - CV_503
|
||||
0b11111111, //byte 3 - CV_504
|
||||
//F31 forward
|
||||
0b11111111, //byte 0 - CV_505
|
||||
0b11111111, //byte 1 - CV_506
|
||||
0b11111111, //byte 2 - CV_507
|
||||
0b11111111, //byte 3 - CV_508
|
||||
//F31 reverse
|
||||
0b11111111, //byte 0 - CV_509
|
||||
0b11111111, //byte 1 - CV_510
|
||||
0b11111111, //byte 2 - CV_511
|
||||
0b11111111, //byte 3 - CV_512
|
||||
};
|
||||
// #define CV_33 0b00000001 //F0 (Licht) vorwärts (MSB) A8 - A1 (LSB)
|
||||
// #define CV_34 0b00000010 //F0 (Licht) rückwärts (MSB) A8 - A1 (LSB)
|
||||
// #define CV_35 0b00000100 //F1 (MSB) A8 - A1 (LSB)
|
||||
// #define CV_36 0b00001000 //F2 (MSB) A8 - A1 (LSB)
|
||||
// #define CV_37 0b00010000 //F3 (MSB) A8 - A1 (LSB)
|
||||
// #define CV_38 0b00000100 //F4 (MSB) A11 - A4 (LSB)
|
||||
// #define CV_39 0b00001000 //F5 (MSB) A11 - A4 (LSB)
|
||||
// #define CV_40 0b00010000 //F6 (MSB) A11 - A4 (LSB)
|
||||
// #define CV_41 0b00100000 //F7 (MSB) A11 - A4 (LSB)
|
||||
// #define CV_42 0b01000000 //F8 (MSB) A11 - A4 (LSB)
|
||||
// #define CV_43 0b00010000 //F9 (MSB) A14 - A9 (LSB)
|
||||
// #define CV_44 0b00100000 //F10 (MSB) A14 - A9 (LSB)
|
||||
// #define CV_45 0b01000000 //F11 (MSB) A14 - A9 (LSB)
|
||||
// #define CV_46 0b10000000 //F12 (MSB) A14 - A9 (LSB)
|
||||
+222
-76
@@ -5,6 +5,7 @@
|
||||
#include "pico/multicore.h"
|
||||
#include "hardware/gpio.h"
|
||||
#include "hardware/pio.h"
|
||||
#include "hardware/pwm.h"
|
||||
#include "pwm.pio.h"
|
||||
#include "automat.h"
|
||||
#include "CV.h"
|
||||
@@ -20,12 +21,52 @@
|
||||
(byte & 0x02 ? '1' : '0'), \
|
||||
(byte & 0x01 ? '1' : '0')
|
||||
|
||||
#define SIZE 128
|
||||
bool bitarray[SIZE] = {false};
|
||||
uint8_t bytearray[13] = {0};
|
||||
#define SIZE_BIT_ARRAY 128
|
||||
#define SIZE_BYTE_ARRAY 13
|
||||
#define SIZE_FUNCTION_BIT_ARRAY 68
|
||||
bool bit_array[SIZE_BIT_ARRAY] = {false};
|
||||
bool function_bit_array[SIZE_FUNCTION_BIT_ARRAY] = {false};
|
||||
uint8_t byte_array[SIZE_BYTE_ARRAY] = {0};
|
||||
uint8_t index_new = 0;
|
||||
uint8_t index_old;
|
||||
|
||||
|
||||
bool get_current_direction(){
|
||||
return false;
|
||||
}
|
||||
|
||||
void emergency_break(){
|
||||
printf("EMERGENCY BREAK");
|
||||
}
|
||||
|
||||
void set_speed(uint8_t speed, bool direction)
|
||||
{
|
||||
printf("Speed: %d\nDirection: %d", speed, direction);
|
||||
}
|
||||
|
||||
void set_outputs()
|
||||
{
|
||||
for (uint8_t i = 0; i < SIZE_FUNCTION_BIT_ARRAY; i++)
|
||||
{
|
||||
if (function_bit_array[i])
|
||||
{
|
||||
uint8_t mask = 0b00000001;
|
||||
for (uint8_t j = 0; j < 8; j++)
|
||||
{
|
||||
uint8_t bit_value = (mask&CV_FUNCTION_ARRAY[i])>>j;
|
||||
//gpio_put(j,bit_value);
|
||||
printf("GPIO: %d set to: %d\n",j,bit_value);
|
||||
mask = mask << 1;
|
||||
}
|
||||
|
||||
}
|
||||
// bool current_bit = function_bit_array[i];
|
||||
// uint8_t current_CV = CV_FUNCTION_ARRAY[i];
|
||||
// printf("GPIO: %d - %d ; ",i,function_bit_array[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
bool readBit()
|
||||
{
|
||||
busy_wait_us_32(87);
|
||||
@@ -33,25 +74,35 @@ bool readBit()
|
||||
}
|
||||
|
||||
void writeBit(bool bit){
|
||||
index_old = (index_new+SIZE-1)%SIZE;
|
||||
bitarray[index_old] = bit;
|
||||
index_old = (index_new+SIZE_BIT_ARRAY-1)%SIZE_BIT_ARRAY;
|
||||
bit_array[index_old] = bit;
|
||||
}
|
||||
|
||||
uint8_t read8bit(int index){
|
||||
uint8_t retval = 0;
|
||||
for (int i =0 ; i < 8; i++){
|
||||
retval <<= 1;
|
||||
retval |= bitarray[index%SIZE];
|
||||
retval |= bit_array[index%SIZE_BIT_ARRAY];
|
||||
index--;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
void parse_to_function_bit_array(uint8_t bit_index_offset,uint8_t input_byte,uint8_t count)
|
||||
{
|
||||
uint8_t mask = 0b00000001;
|
||||
for (uint8_t i = 0; i < count; i++)
|
||||
{
|
||||
function_bit_array[i+bit_index_offset] = (input_byte&mask)>>i;
|
||||
mask = mask<<1;
|
||||
}
|
||||
}
|
||||
|
||||
void convert_array (int8_t number_of_bytes){
|
||||
//start of transmission -> byte_n(addressbyte) -> ... -> byte_0(error detection byte) -> end of transmission
|
||||
for (int i = 0; i < number_of_bytes; i++)
|
||||
{
|
||||
bytearray[i] = read8bit(index_new + 8 + i*9);
|
||||
byte_array[i] = read8bit(index_new + 8 + i*9);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +112,7 @@ bool error_detection(int8_t number_of_bytes)
|
||||
uint8_t exor_byte = 0;
|
||||
for (int i = 0; i < number_of_bytes; i++)
|
||||
{
|
||||
exor_byte = exor_byte^bytearray[i];
|
||||
exor_byte = exor_byte^byte_array[i];
|
||||
}
|
||||
if(exor_byte == 0b00000000){
|
||||
return true;
|
||||
@@ -71,9 +122,9 @@ bool error_detection(int8_t number_of_bytes)
|
||||
|
||||
// Returns true for long address
|
||||
bool long_address(uint8_t number_of_bytes){
|
||||
if (bitarray[(index_new-1+(9*number_of_bytes))%SIZE]) //most significant bit of first received byte
|
||||
if (bit_array[(index_new-1+(9*number_of_bytes))%SIZE_BIT_ARRAY]) //most significant bit of first received byte
|
||||
{
|
||||
if (bitarray[(index_new-2+(9*number_of_bytes))%SIZE]) //second most significant bit of first received byte
|
||||
if (bit_array[(index_new-2+(9*number_of_bytes))%SIZE_BIT_ARRAY]) //second most significant bit of first received byte
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -86,115 +137,210 @@ bool address_evaluation(uint8_t number_of_bytes){
|
||||
if(long_address(number_of_bytes))
|
||||
{
|
||||
//start of transmission -> address_byte_1 -> address_byte_0 -> ... -> end of transmission
|
||||
uint8_t address_byte_1 = (bytearray[number_of_bytes-1])-192; //remove long address identifier bits
|
||||
uint8_t address_byte_0 = (bytearray[number_of_bytes-2]);
|
||||
uint8_t address_byte_1 = (byte_array[number_of_bytes-1])-192; //remove long address identifier bits
|
||||
uint8_t address_byte_0 = (byte_array[number_of_bytes-2]);
|
||||
read_address = (address_byte_1<<8)+address_byte_0;
|
||||
printf("long address: %d ,was read. \n", read_address);
|
||||
printf("long address: %d, was read. \n", read_address);
|
||||
}
|
||||
else
|
||||
{
|
||||
//start of transmission -> address_byte_0 -> ... -> end of transmission
|
||||
read_address = (bytearray[number_of_bytes-1]);
|
||||
printf("short address: %d ,was read. \n",read_address);
|
||||
read_address = (byte_array[number_of_bytes-1]);
|
||||
printf("short address: %d, was read. \n",read_address);
|
||||
}
|
||||
if (CV_1 == read_address) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void command_evaluation(uint8_t number_of_bytes){
|
||||
void instruction_evaluation(uint8_t number_of_bytes){
|
||||
uint8_t command_byte_n;
|
||||
//start of transmission -> ... -> command_byte_n -> ... -> command_byte_0 -> ... -> end of transmission
|
||||
if (long_address(number_of_bytes))
|
||||
{
|
||||
command_byte_n = bytearray[number_of_bytes-3];
|
||||
}
|
||||
else
|
||||
{
|
||||
command_byte_n = bytearray[number_of_bytes-2];
|
||||
}
|
||||
if (command_byte_n>>5 == 0b00000001) // 001X-XXXX (001 Advanced Operation Instructions)
|
||||
{
|
||||
switch (command_byte_n)
|
||||
{
|
||||
case 0b00111100: // 0011-1100 (Speed, Direction and Functions)
|
||||
/* code */
|
||||
printf("0011-1100 (Speed, Direction and Functions) \n");
|
||||
break;
|
||||
case 0b00111111: // 0011-1111 (128 Speed Step Control)
|
||||
/*... */
|
||||
printf("0011-1111 (128 Speed Step Control) \n");
|
||||
uint8_t command_byte_index;
|
||||
// start of transmission -> ... -> command_byte_n -> ... -> command_byte_0 -> ... -> end of transmission
|
||||
if (long_address(number_of_bytes))
|
||||
{
|
||||
command_byte_index = number_of_bytes-3;
|
||||
}
|
||||
else
|
||||
{
|
||||
command_byte_index = number_of_bytes-2;
|
||||
}
|
||||
command_byte_n = byte_array[command_byte_index];
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (command_byte_n>>6 == 0b00000010) // 10XX-XXXX (Function Group Instruction)
|
||||
{
|
||||
if (command_byte_n>>5 == 0b00000100) // Functions F0-F4
|
||||
{
|
||||
/*...........*/
|
||||
if (command_byte_n>>6 == 0b00000001) // 01XX-XXXX (Basic Speed and Direction Instruction)
|
||||
{
|
||||
if (command_byte_n<<4>>4 == 0b00000001) // 01XX-0001 (Emergency Break)
|
||||
{
|
||||
emergency_break();
|
||||
}
|
||||
if (command_byte_n<<4>>4 == 0b00000000) // 01XX-0000 (Normal Break)
|
||||
{
|
||||
set_speed(0 , 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("01XX-XXXX - Basic Speed \n"); //01XX-XXXX - Basic Speed (26 Steps)
|
||||
uint8_t mask = 0b01111111;
|
||||
uint8_t speed = ((command_byte_n & mask)-1)*4; //Max speed step is equivalent to step 104 of 128 speed step
|
||||
mask = 0b00100000;
|
||||
uint8_t direction = (command_byte_n&mask)>>5;
|
||||
set_speed(speed, direction);
|
||||
}
|
||||
}
|
||||
if (command_byte_n>>5 == 0b00000001) // 001X-XXXX (Advanced Operation Instructions)
|
||||
{
|
||||
switch (command_byte_n)
|
||||
{
|
||||
case 0b00111100: // 0011-1100 (Speed, Direction and Functions) - 3 to 6 Byte length
|
||||
printf("0011-1100 (Speed, Direction and Functions) \n");
|
||||
switch (command_byte_index) //command_byte_index == Instruction Byte Length
|
||||
{ //Switch case could be replaced with for loop...
|
||||
case 6:
|
||||
//F0 - F7
|
||||
parse_to_function_bit_array(0,byte_array[command_byte_index-2],8);
|
||||
//F8-F15
|
||||
parse_to_function_bit_array(8,byte_array[command_byte_index-3],8);
|
||||
//F16-F23
|
||||
parse_to_function_bit_array(16,byte_array[command_byte_index-4],8);
|
||||
//F24-F31
|
||||
parse_to_function_bit_array(24,byte_array[command_byte_index-5],8);
|
||||
//...
|
||||
goto speed_128;
|
||||
break;
|
||||
case 5:
|
||||
//F0 - F7
|
||||
parse_to_function_bit_array(0,byte_array[command_byte_index-2],8);
|
||||
//F8-F15
|
||||
parse_to_function_bit_array(8,byte_array[command_byte_index-3],8);
|
||||
//F16-F23
|
||||
parse_to_function_bit_array(16,byte_array[command_byte_index-4],8);
|
||||
//...
|
||||
goto speed_128;
|
||||
break;
|
||||
case 4:
|
||||
//F0 - F7
|
||||
parse_to_function_bit_array(0,byte_array[command_byte_index-2],8);
|
||||
//F8-F15
|
||||
parse_to_function_bit_array(8,byte_array[command_byte_index-3],8);
|
||||
//...
|
||||
goto speed_128;
|
||||
break;
|
||||
case 3:
|
||||
//F0 - F7
|
||||
parse_to_function_bit_array(0,byte_array[command_byte_index-2],8);
|
||||
//...
|
||||
goto speed_128;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0b00111111: // 0011-1111 (128 Speed Step Control) - 2 Byte length
|
||||
speed_128:
|
||||
printf("0011-1111 (128 Speed Step Control) \n");
|
||||
uint8_t command_byte_n_minus1 = byte_array[command_byte_index-1];
|
||||
uint8_t mask = 0b01111111;
|
||||
uint8_t speed = (command_byte_n_minus1 & mask)-1;
|
||||
uint8_t direction = command_byte_n_minus1>>7;
|
||||
set_speed(speed , direction);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (command_byte_n>>6 == 0b00000010) // 10XX-XXXX (Function Group Instruction)
|
||||
{
|
||||
if (command_byte_n>>5 == 0b00000100) // Functions F0-F4
|
||||
{
|
||||
parse_to_function_bit_array(0,command_byte_n>>4,1); //F0
|
||||
parse_to_function_bit_array(1,command_byte_n,4); //F1-F4
|
||||
printf("Functions F0-F4 \n");
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (command_byte_n>>4)
|
||||
{
|
||||
case 0b00001011: // Functions F5-F8
|
||||
/* code */
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (command_byte_n>>4)
|
||||
{
|
||||
case 0b00001011: // Functions F5-F8
|
||||
printf("Functions F5-F8 \n");
|
||||
parse_to_function_bit_array(5,command_byte_n,4);
|
||||
break;
|
||||
case 0b00001010: // Functions F9-F12
|
||||
case 0b00001010: // Functions F9-F12
|
||||
printf("Functions F9-F12 \n");
|
||||
/* code */
|
||||
parse_to_function_bit_array(9,command_byte_n,4);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (command_byte_n>>5 == 0b00000110) //Feature Expansion Instruction 110X-XXXX
|
||||
{
|
||||
switch (command_byte_n)
|
||||
{
|
||||
case 0b11011110: // F13-F20
|
||||
parse_to_function_bit_array(13,byte_array[command_byte_index-1],8);
|
||||
break;
|
||||
case 0b11011111: // F21-F28
|
||||
parse_to_function_bit_array(21,byte_array[command_byte_index-1],8);
|
||||
break;
|
||||
case 0b11011000: // F29-F36
|
||||
parse_to_function_bit_array(29,byte_array[command_byte_index-1],8);
|
||||
break;
|
||||
case 0b11011001: // F37-F44
|
||||
parse_to_function_bit_array(37,byte_array[command_byte_index-1],8);
|
||||
break;
|
||||
case 0b11011010: // F45-F52
|
||||
parse_to_function_bit_array(45,byte_array[command_byte_index-1],8);
|
||||
break;
|
||||
case 0b11011011: // F53-F60
|
||||
parse_to_function_bit_array(53,byte_array[command_byte_index-1],8);
|
||||
break;
|
||||
case 0b11011100: // F61-F68
|
||||
parse_to_function_bit_array(61,byte_array[command_byte_index-1],8);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
set_outputs();
|
||||
}
|
||||
|
||||
|
||||
void gpio_callback_rise(unsigned int gpio, long unsigned int events) {
|
||||
writeBit(readBit());
|
||||
bool * s = bitarray;
|
||||
int fsm_result = fsm_main(s, index_new, SIZE ); //fsm_main returns number of bytes if it finds valid bit sequence otherwise it returns -1
|
||||
bool * s = bit_array;
|
||||
int fsm_result = fsm_main(s, index_new, SIZE_BIT_ARRAY ); //fsm_main returns number of bytes if it finds valid bit sequence otherwise it returns -1
|
||||
if(fsm_result != -1){
|
||||
convert_array(fsm_result); //converts bitarray to bytearray for easier handling
|
||||
if(error_detection(fsm_result)){ //Returns true if exor equals 0b00000000 matches with CV
|
||||
convert_array(fsm_result); //converts bit_array to byte_array for easier handling
|
||||
if(error_detection(fsm_result)){ //Returns true if the XOR verification was error-free
|
||||
printf("no error :-)\n");
|
||||
if(address_evaluation(fsm_result)){ //Returns true if address matches with CV
|
||||
if(address_evaluation(fsm_result)){ //Returns true if address matches with CV
|
||||
printf("address matches :-)\n");
|
||||
command_evaluation(fsm_result);
|
||||
instruction_evaluation(fsm_result); //
|
||||
}
|
||||
else printf("ADDRESS DOES NOT MATCH!\n");
|
||||
}
|
||||
else printf("ERROR DETECED!\n");
|
||||
printf("\n");
|
||||
|
||||
/*for (int i = 0; i < fsm_result; i++)
|
||||
for (int i = 0; i < fsm_result; i++)
|
||||
{
|
||||
printf("\nBYTE_%d: ",i);
|
||||
for (int j = 0; j < 8; j++)
|
||||
{
|
||||
printf("%d",bitarray[(index_new-j+8+(9*i))%SIZE]);
|
||||
printf("%d",bit_array[(index_new-j+8+(9*i))%SIZE_BIT_ARRAY]);
|
||||
}
|
||||
}
|
||||
printf("\nPaketgroesse: %d\n",fsm_result);
|
||||
printf("\n");
|
||||
printf(BYTE_TO_BINARY_PATTERN"\n",BYTE_TO_BINARY(error_detection(fsm_result, index_new)));
|
||||
*/
|
||||
// printf(BYTE_TO_BINARY_PATTERN"\n",BYTE_TO_BINARY(error_detection(fsm_result, index_new)));
|
||||
|
||||
}
|
||||
index_new = index_old;
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
int main() {
|
||||
stdio_init_all();
|
||||
gpio_init(17);
|
||||
gpio_set_dir(17, GPIO_IN);
|
||||
|
||||
Reference in new issue
Block a user