PLC 16 in / 8 rev / an in-out / CAN

Dependencies:   PCAL955x mbed mbed-rtos AT45

Committer:
Oleg_B
Date:
Fri Feb 12 10:55:27 2021 +0000
Revision:
2:439534d6bb89
Parent:
src/can.cpp@0:d05a7158dbad
files move to f

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Oleg_B 0:d05a7158dbad 1
Oleg_B 0:d05a7158dbad 2 #include <mbed.h>
Oleg_B 0:d05a7158dbad 3 #include "rtos.h"
Oleg_B 0:d05a7158dbad 4 #include "can.h"
Oleg_B 0:d05a7158dbad 5 #include "ext_vars.h"
Oleg_B 0:d05a7158dbad 6
Oleg_B 0:d05a7158dbad 7
Oleg_B 0:d05a7158dbad 8 //-------------хранение полученного сообщения --------------
Oleg_B 0:d05a7158dbad 9 //
Oleg_B 0:d05a7158dbad 10 // [b1 b2 b3 b4]
Oleg_B 0:d05a7158dbad 11 // -----------------
Oleg_B 0:d05a7158dbad 12 // r_mess id[0] -> r_mess_data [ 0 1 2 3] - новое сообщение
Oleg_B 0:d05a7158dbad 13 // r_mess id[1] -> r_mess_data [ 4 5 6 7] - новое сообщение
Oleg_B 0:d05a7158dbad 14 // r_mess id[2] -> r_mess_data [ 8 9 10 11] - новое сообщение
Oleg_B 0:d05a7158dbad 15 // r_mess id[3] -> r_mess_data [12 13 14 15] - новое сообщение
Oleg_B 0:d05a7158dbad 16 // r_mess id[4] -> r_mess_data [16 17 18 19] - новое сообщение
Oleg_B 0:d05a7158dbad 17 // r_mess id[5] -> r_mess_data [20 21 22 23] - новое сообщение
Oleg_B 0:d05a7158dbad 18 // r_mess id[6] -> r_mess_data [24 25 26 27] - новое сообщение
Oleg_B 0:d05a7158dbad 19 // r_mess id[7] -> r_mess_data [28 29 30 31] - новое сообщение
Oleg_B 0:d05a7158dbad 20 // r_mess id[8] -> r_mess_data [32 33 34 35] - новое сообщение
Oleg_B 0:d05a7158dbad 21 // r_mess id[9] -> r_mess_data [36 37 38 39] - новое сообщение
Oleg_B 0:d05a7158dbad 22
Oleg_B 0:d05a7158dbad 23
Oleg_B 0:d05a7158dbad 24 //--------- очередь сообщений на отправку ------------------
Oleg_B 0:d05a7158dbad 25 //
Oleg_B 0:d05a7158dbad 26 // [b1 b2 b3 b4]
Oleg_B 0:d05a7158dbad 27 // -----------------
Oleg_B 0:d05a7158dbad 28 // w_mess id[0] -> w_mess_data [ 0 1 2 3] - новое сообщение
Oleg_B 0:d05a7158dbad 29 // w_mess id[1] -> w_mess_data [ 4 5 6 7] - новое сообщение
Oleg_B 0:d05a7158dbad 30 // w_mess id[2] -> w_mess_data [ 8 9 10 11] - новое сообщение
Oleg_B 0:d05a7158dbad 31 // w_mess id[3] -> w_mess_data [12 13 14 15] - новое сообщение
Oleg_B 0:d05a7158dbad 32 // w_mess id[4] -> w_mess_data [16 17 18 19] - новое сообщение
Oleg_B 0:d05a7158dbad 33 // w_mess id[5] -> w_mess_data [20 21 22 23] - новое сообщение
Oleg_B 0:d05a7158dbad 34 // w_mess id[6] -> w_mess_data [24 25 26 27] - новое сообщение
Oleg_B 0:d05a7158dbad 35 // w_mess id[7] -> w_mess_data [28 29 30 31] - новое сообщение
Oleg_B 0:d05a7158dbad 36 // w_mess id[8] -> w_mess_data [32 33 34 35] - новое сообщение
Oleg_B 0:d05a7158dbad 37 // w_mess id[9] -> w_mess_data [36 37 38 39] - новое сообщение
Oleg_B 0:d05a7158dbad 38
Oleg_B 0:d05a7158dbad 39
Oleg_B 0:d05a7158dbad 40
Oleg_B 0:d05a7158dbad 41
Oleg_B 0:d05a7158dbad 42 // помещаем в очередь полученное сообщение
Oleg_B 0:d05a7158dbad 43 int can_save_rd(int id, char b1, char b2, char b3, char b4)
Oleg_B 0:d05a7158dbad 44 {
Oleg_B 0:d05a7158dbad 45 int res = 0 ;
Oleg_B 0:d05a7158dbad 46 for(int i=0; i<9; i++){
Oleg_B 0:d05a7158dbad 47 if( r_mess_id[i]==0 && res==0){
Oleg_B 0:d05a7158dbad 48 r_mess_id[i] = id;
Oleg_B 0:d05a7158dbad 49 r_mess_data[i*3+i+0] = b1;
Oleg_B 0:d05a7158dbad 50 r_mess_data[i*3+i+1] = b2;
Oleg_B 0:d05a7158dbad 51 r_mess_data[i*3+i+2] = b3;
Oleg_B 0:d05a7158dbad 52 r_mess_data[i*3+i+3] = b4;
Oleg_B 0:d05a7158dbad 53 res = 1;
Oleg_B 0:d05a7158dbad 54 }
Oleg_B 0:d05a7158dbad 55 }
Oleg_B 0:d05a7158dbad 56 return res;
Oleg_B 0:d05a7158dbad 57 }
Oleg_B 0:d05a7158dbad 58
Oleg_B 0:d05a7158dbad 59
Oleg_B 0:d05a7158dbad 60 // помещаем в очередь сообщения для отправки
Oleg_B 0:d05a7158dbad 61 int can_save_wr(int id, char b1, char b2, char b3, char b4)
Oleg_B 0:d05a7158dbad 62 {
Oleg_B 0:d05a7158dbad 63 int res = 0 ;
Oleg_B 0:d05a7158dbad 64 for(int i=0; i<9; i++){
Oleg_B 0:d05a7158dbad 65 if( w_mess_id[i]==0 && res==0){
Oleg_B 0:d05a7158dbad 66 w_mess_id[i] = id;
Oleg_B 0:d05a7158dbad 67 w_mess_data[i*3+i+0] = b1;
Oleg_B 0:d05a7158dbad 68 w_mess_data[i*3+i+1] = b2;
Oleg_B 0:d05a7158dbad 69 w_mess_data[i*3+i+2] = b3;
Oleg_B 0:d05a7158dbad 70 w_mess_data[i*3+i+3] = b4;
Oleg_B 0:d05a7158dbad 71 res = 1;
Oleg_B 0:d05a7158dbad 72 }
Oleg_B 0:d05a7158dbad 73 }
Oleg_B 0:d05a7158dbad 74 return res;
Oleg_B 0:d05a7158dbad 75 }
Oleg_B 0:d05a7158dbad 76
Oleg_B 0:d05a7158dbad 77 // выбираем сообщение из очереди для обработки
Oleg_B 0:d05a7158dbad 78 // и помещаем в раб. переменные
Oleg_B 0:d05a7158dbad 79 int can_select_rd()
Oleg_B 0:d05a7158dbad 80 {
Oleg_B 0:d05a7158dbad 81 int res = 0;
Oleg_B 0:d05a7158dbad 82
Oleg_B 0:d05a7158dbad 83 r_id=0;
Oleg_B 0:d05a7158dbad 84 r_b1=0;
Oleg_B 0:d05a7158dbad 85 r_b2=0;
Oleg_B 0:d05a7158dbad 86 r_b3=0;
Oleg_B 0:d05a7158dbad 87 r_b4=0;
Oleg_B 0:d05a7158dbad 88
Oleg_B 0:d05a7158dbad 89 for(int i=0; i<9; i++){
Oleg_B 0:d05a7158dbad 90 if( r_mess_id[i] != 0 && res==0 ) {
Oleg_B 0:d05a7158dbad 91 r_id = r_mess_id[i] ;
Oleg_B 0:d05a7158dbad 92 r_b1 = r_mess_data[i*3+i+0];
Oleg_B 0:d05a7158dbad 93 r_b2 = r_mess_data[i*3+i+1];
Oleg_B 0:d05a7158dbad 94 r_b3 = r_mess_data[i*3+i+2];
Oleg_B 0:d05a7158dbad 95 r_b4 = r_mess_data[i*3+i+3];
Oleg_B 0:d05a7158dbad 96 r_mess_id[i] = 0 ;
Oleg_B 0:d05a7158dbad 97 res=1;
Oleg_B 0:d05a7158dbad 98 }
Oleg_B 0:d05a7158dbad 99 }
Oleg_B 0:d05a7158dbad 100 return res;
Oleg_B 0:d05a7158dbad 101 }
Oleg_B 0:d05a7158dbad 102
Oleg_B 0:d05a7158dbad 103
Oleg_B 0:d05a7158dbad 104
Oleg_B 0:d05a7158dbad 105
Oleg_B 0:d05a7158dbad 106 // выбираем сообщение из очереди для отправки
Oleg_B 0:d05a7158dbad 107 // и помещаем в раб. переменные
Oleg_B 0:d05a7158dbad 108 int can_select_wr()
Oleg_B 0:d05a7158dbad 109 {
Oleg_B 0:d05a7158dbad 110
Oleg_B 0:d05a7158dbad 111 int res = 0;
Oleg_B 0:d05a7158dbad 112
Oleg_B 0:d05a7158dbad 113 w_id=0;
Oleg_B 0:d05a7158dbad 114 w_b1=0;
Oleg_B 0:d05a7158dbad 115 w_b2=0;
Oleg_B 0:d05a7158dbad 116 w_b3=0;
Oleg_B 0:d05a7158dbad 117 w_b4=0;
Oleg_B 0:d05a7158dbad 118
Oleg_B 0:d05a7158dbad 119 for(int i=0; i<9; i++){
Oleg_B 0:d05a7158dbad 120 if( w_mess_id[i] != 0 && res==0 ) {
Oleg_B 0:d05a7158dbad 121 w_id = w_mess_id[i] ;
Oleg_B 0:d05a7158dbad 122 w_b1 = w_mess_data[i*3+i+0];
Oleg_B 0:d05a7158dbad 123 w_b2 = w_mess_data[i*3+i+1];
Oleg_B 0:d05a7158dbad 124 w_b3 = w_mess_data[i*3+i+2];
Oleg_B 0:d05a7158dbad 125 w_b4 = w_mess_data[i*3+i+3];
Oleg_B 0:d05a7158dbad 126 w_mess_id[i] = 0 ;
Oleg_B 0:d05a7158dbad 127 res=1;
Oleg_B 0:d05a7158dbad 128 }
Oleg_B 0:d05a7158dbad 129 }
Oleg_B 0:d05a7158dbad 130
Oleg_B 0:d05a7158dbad 131 return res;
Oleg_B 0:d05a7158dbad 132 }
Oleg_B 0:d05a7158dbad 133
Oleg_B 0:d05a7158dbad 134
Oleg_B 0:d05a7158dbad 135
Oleg_B 0:d05a7158dbad 136
Oleg_B 0:d05a7158dbad 137
Oleg_B 0:d05a7158dbad 138
Oleg_B 0:d05a7158dbad 139
Oleg_B 0:d05a7158dbad 140
Oleg_B 0:d05a7158dbad 141
Oleg_B 0:d05a7158dbad 142