Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
51ad293c94 | ||
|
|
b26c97e136 | ||
|
|
6a76239f40 | ||
|
|
584c263eaa | ||
|
|
42db319ae9 | ||
|
|
81cebe6472 | ||
|
|
732b91caef | ||
|
|
35263d8595 | ||
|
|
15de286b3f | ||
|
|
4b22b19ab6 | ||
|
|
77b927d1fc |
@@ -3,17 +3,16 @@ EESchema-LIBRARY Version 2.4
|
|||||||
#
|
#
|
||||||
# 000_my_lib:DSN-MINI-360
|
# 000_my_lib:DSN-MINI-360
|
||||||
#
|
#
|
||||||
DEF 000_my_lib:DSN-MINI-360 MOD 0 40 Y Y 1 F P
|
DEF 000_my_lib:DSN-MINI-360 MOD 0 40 N Y 1 F N
|
||||||
F0 "MOD" 350 -50 50 H V C CNN
|
F0 "MOD" 350 -50 50 H V C CNN
|
||||||
F1 "000_my_lib:DSN-MINI-360" 200 350 50 H V C CNN
|
F1 "000_my_lib:DSN-MINI-360" 200 350 50 H V C CNN
|
||||||
F2 "" 250 150 50 H I C CNN
|
F2 "" 250 150 50 H I C CNN
|
||||||
F3 "" 250 150 50 H I C CNN
|
F3 "" 250 150 50 H I C CNN
|
||||||
DRAW
|
DRAW
|
||||||
S 0 300 450 0 0 0 0 f
|
S 0 300 400 0 0 0 0 f
|
||||||
X GND ~ -100 50 100 R 50 50 1 1 P
|
X GND GND 200 -100 100 U 50 50 1 1 P
|
||||||
X GND ~ 550 50 100 L 50 50 1 1 P
|
X IN IN -100 250 100 R 50 50 1 1 P
|
||||||
X IN ~ -100 250 100 R 50 50 1 1 P
|
X OUT OUT 500 250 100 L 50 50 1 1 P
|
||||||
X OUT ~ 550 250 100 L 50 50 1 1 P
|
|
||||||
ENDDRAW
|
ENDDRAW
|
||||||
ENDDEF
|
ENDDEF
|
||||||
#
|
#
|
||||||
|
|||||||
+5386
-7950
File diff suppressed because it is too large
Load Diff
+245
-21
@@ -1,29 +1,10 @@
|
|||||||
update=Date
|
update=Tue Sep 3 03:50:31 2019
|
||||||
version=1
|
version=1
|
||||||
last_client=kicad
|
last_client=kicad
|
||||||
[general]
|
[general]
|
||||||
version=1
|
version=1
|
||||||
RootSch=
|
RootSch=
|
||||||
BoardNm=
|
BoardNm=
|
||||||
[pcbnew]
|
|
||||||
version=1
|
|
||||||
LastNetListRead=
|
|
||||||
UseCmpFile=1
|
|
||||||
PadDrill=0.600000000000
|
|
||||||
PadDrillOvalY=0.600000000000
|
|
||||||
PadSizeH=1.500000000000
|
|
||||||
PadSizeV=1.500000000000
|
|
||||||
PcbTextSizeV=1.500000000000
|
|
||||||
PcbTextSizeH=1.500000000000
|
|
||||||
PcbTextThickness=0.300000000000
|
|
||||||
ModuleTextSizeV=1.000000000000
|
|
||||||
ModuleTextSizeH=1.000000000000
|
|
||||||
ModuleTextSizeThickness=0.150000000000
|
|
||||||
SolderMaskClearance=0.000000000000
|
|
||||||
SolderMaskMinWidth=0.000000000000
|
|
||||||
DrawSegmentWidth=0.200000000000
|
|
||||||
BoardOutlineThickness=0.100000000000
|
|
||||||
ModuleOutlineThickness=0.150000000000
|
|
||||||
[cvpcb]
|
[cvpcb]
|
||||||
version=1
|
version=1
|
||||||
NetIExt=net
|
NetIExt=net
|
||||||
@@ -37,7 +18,250 @@ PageLayoutDescrFile=
|
|||||||
PlotDirectoryName=images/
|
PlotDirectoryName=images/
|
||||||
SubpartIdSeparator=0
|
SubpartIdSeparator=0
|
||||||
SubpartFirstId=65
|
SubpartFirstId=65
|
||||||
NetFmtName=
|
NetFmtName=Pcbnew
|
||||||
SpiceAjustPassiveValues=0
|
SpiceAjustPassiveValues=0
|
||||||
LabSize=50
|
LabSize=50
|
||||||
ERC_TestSimilarLabels=1
|
ERC_TestSimilarLabels=1
|
||||||
|
[pcbnew]
|
||||||
|
version=1
|
||||||
|
PageLayoutDescrFile=
|
||||||
|
LastNetListRead=CANNode.net
|
||||||
|
CopperLayerCount=4
|
||||||
|
BoardThickness=1.6
|
||||||
|
AllowMicroVias=0
|
||||||
|
AllowBlindVias=0
|
||||||
|
RequireCourtyardDefinitions=0
|
||||||
|
ProhibitOverlappingCourtyards=1
|
||||||
|
MinTrackWidth=0.1524
|
||||||
|
MinViaDiameter=0.6858
|
||||||
|
MinViaDrill=0.3302
|
||||||
|
MinMicroViaDiameter=0.2
|
||||||
|
MinMicroViaDrill=0.09999999999999999
|
||||||
|
MinHoleToHole=0.25
|
||||||
|
TrackWidth1=0.3
|
||||||
|
TrackWidth2=0.175
|
||||||
|
TrackWidth3=0.2
|
||||||
|
TrackWidth4=0.25
|
||||||
|
TrackWidth5=0.3
|
||||||
|
TrackWidth6=0.4
|
||||||
|
TrackWidth7=0.6
|
||||||
|
TrackWidth8=0.8
|
||||||
|
TrackWidth9=1.6
|
||||||
|
ViaDiameter1=0.6858
|
||||||
|
ViaDrill1=0.3302
|
||||||
|
dPairWidth1=0.2
|
||||||
|
dPairGap1=0.175
|
||||||
|
dPairViaGap1=0.25
|
||||||
|
SilkLineWidth=0.15
|
||||||
|
SilkTextSizeV=1
|
||||||
|
SilkTextSizeH=1
|
||||||
|
SilkTextSizeThickness=0.15
|
||||||
|
SilkTextItalic=0
|
||||||
|
SilkTextUpright=1
|
||||||
|
CopperLineWidth=0.2
|
||||||
|
CopperTextSizeV=1.5
|
||||||
|
CopperTextSizeH=1.5
|
||||||
|
CopperTextThickness=0.3
|
||||||
|
CopperTextItalic=0
|
||||||
|
CopperTextUpright=1
|
||||||
|
EdgeCutLineWidth=0.2
|
||||||
|
CourtyardLineWidth=0.05
|
||||||
|
OthersLineWidth=0.15
|
||||||
|
OthersTextSizeV=1
|
||||||
|
OthersTextSizeH=1
|
||||||
|
OthersTextSizeThickness=0.15
|
||||||
|
OthersTextItalic=0
|
||||||
|
OthersTextUpright=1
|
||||||
|
SolderMaskClearance=0.2
|
||||||
|
SolderMaskMinWidth=0.25
|
||||||
|
SolderPasteClearance=0
|
||||||
|
SolderPasteRatio=0
|
||||||
|
[pcbnew/Layer.F.Cu]
|
||||||
|
Name=F.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=1
|
||||||
|
[pcbnew/Layer.In1.Cu]
|
||||||
|
Name=In1.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=1
|
||||||
|
[pcbnew/Layer.In2.Cu]
|
||||||
|
Name=In2.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=1
|
||||||
|
[pcbnew/Layer.In3.Cu]
|
||||||
|
Name=In3.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.In4.Cu]
|
||||||
|
Name=In4.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.In5.Cu]
|
||||||
|
Name=In5.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.In6.Cu]
|
||||||
|
Name=In6.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.In7.Cu]
|
||||||
|
Name=In7.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.In8.Cu]
|
||||||
|
Name=In8.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.In9.Cu]
|
||||||
|
Name=In9.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.In10.Cu]
|
||||||
|
Name=In10.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.In11.Cu]
|
||||||
|
Name=In11.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.In12.Cu]
|
||||||
|
Name=In12.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.In13.Cu]
|
||||||
|
Name=In13.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.In14.Cu]
|
||||||
|
Name=In14.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.In15.Cu]
|
||||||
|
Name=In15.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.In16.Cu]
|
||||||
|
Name=In16.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.In17.Cu]
|
||||||
|
Name=In17.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.In18.Cu]
|
||||||
|
Name=In18.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.In19.Cu]
|
||||||
|
Name=In19.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.In20.Cu]
|
||||||
|
Name=In20.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.In21.Cu]
|
||||||
|
Name=In21.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.In22.Cu]
|
||||||
|
Name=In22.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.In23.Cu]
|
||||||
|
Name=In23.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.In24.Cu]
|
||||||
|
Name=In24.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.In25.Cu]
|
||||||
|
Name=In25.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.In26.Cu]
|
||||||
|
Name=In26.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.In27.Cu]
|
||||||
|
Name=In27.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.In28.Cu]
|
||||||
|
Name=In28.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.In29.Cu]
|
||||||
|
Name=In29.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.In30.Cu]
|
||||||
|
Name=In30.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Layer.B.Cu]
|
||||||
|
Name=B.Cu
|
||||||
|
Type=0
|
||||||
|
Enabled=1
|
||||||
|
[pcbnew/Layer.B.Adhes]
|
||||||
|
Enabled=1
|
||||||
|
[pcbnew/Layer.F.Adhes]
|
||||||
|
Enabled=1
|
||||||
|
[pcbnew/Layer.B.Paste]
|
||||||
|
Enabled=1
|
||||||
|
[pcbnew/Layer.F.Paste]
|
||||||
|
Enabled=1
|
||||||
|
[pcbnew/Layer.B.SilkS]
|
||||||
|
Enabled=1
|
||||||
|
[pcbnew/Layer.F.SilkS]
|
||||||
|
Enabled=1
|
||||||
|
[pcbnew/Layer.B.Mask]
|
||||||
|
Enabled=1
|
||||||
|
[pcbnew/Layer.F.Mask]
|
||||||
|
Enabled=1
|
||||||
|
[pcbnew/Layer.Dwgs.User]
|
||||||
|
Enabled=1
|
||||||
|
[pcbnew/Layer.Cmts.User]
|
||||||
|
Enabled=1
|
||||||
|
[pcbnew/Layer.Eco1.User]
|
||||||
|
Enabled=1
|
||||||
|
[pcbnew/Layer.Eco2.User]
|
||||||
|
Enabled=1
|
||||||
|
[pcbnew/Layer.Edge.Cuts]
|
||||||
|
Enabled=1
|
||||||
|
[pcbnew/Layer.Margin]
|
||||||
|
Enabled=1
|
||||||
|
[pcbnew/Layer.B.CrtYd]
|
||||||
|
Enabled=1
|
||||||
|
[pcbnew/Layer.F.CrtYd]
|
||||||
|
Enabled=1
|
||||||
|
[pcbnew/Layer.B.Fab]
|
||||||
|
Enabled=1
|
||||||
|
[pcbnew/Layer.F.Fab]
|
||||||
|
Enabled=1
|
||||||
|
[pcbnew/Layer.Rescue]
|
||||||
|
Enabled=0
|
||||||
|
[pcbnew/Netclasses]
|
||||||
|
[pcbnew/Netclasses/Default]
|
||||||
|
Name=Default
|
||||||
|
Clearance=0.175
|
||||||
|
TrackWidth=0.3
|
||||||
|
ViaDiameter=0.6858
|
||||||
|
ViaDrill=0.3302
|
||||||
|
uViaDiameter=0.3
|
||||||
|
uViaDrill=0.1
|
||||||
|
dPairWidth=0.2
|
||||||
|
dPairGap=0.175
|
||||||
|
dPairViaGap=0.25
|
||||||
|
[pcbnew/Netclasses/1]
|
||||||
|
Name=Power
|
||||||
|
Clearance=0.2
|
||||||
|
TrackWidth=0.5
|
||||||
|
ViaDiameter=1.25
|
||||||
|
ViaDrill=0.5
|
||||||
|
uViaDiameter=0.65
|
||||||
|
uViaDrill=0.2
|
||||||
|
dPairWidth=0.2
|
||||||
|
dPairGap=0.25
|
||||||
|
dPairViaGap=0.25
|
||||||
|
|||||||
+742
-483
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
Before Width: | Height: | Size: 424 KiB |
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
Before Width: | Height: | Size: 371 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 721 KiB |
@@ -0,0 +1,44 @@
|
|||||||
|
EESchema-LIBRARY Version 2.4
|
||||||
|
#encoding utf-8
|
||||||
|
#
|
||||||
|
# MAX481E
|
||||||
|
#
|
||||||
|
DEF MAX481E U 0 20 Y Y 1 F N
|
||||||
|
F0 "U" -240 450 50 H V C CNN
|
||||||
|
F1 "MAX481E" 30 450 50 H V L CNN
|
||||||
|
F2 "" 0 -700 50 H I C CNN
|
||||||
|
F3 "" 0 50 50 H I C CNN
|
||||||
|
ALIAS MAX483E MAX485E MAX487E MAX1487E MAX3485 MAX3483 MAX3486
|
||||||
|
$FPLIST
|
||||||
|
DIP*W7.62mm*
|
||||||
|
SOIC*3.9x4.9mm*P1.27mm*
|
||||||
|
$ENDFPLIST
|
||||||
|
DRAW
|
||||||
|
C -12 -145 14 0 1 10 F
|
||||||
|
C -1 59 14 0 1 10 F
|
||||||
|
C 65 75 14 0 1 10 F
|
||||||
|
S -300 400 300 -500 0 1 10 f
|
||||||
|
S 50 125 50 125 0 1 0 N
|
||||||
|
P 2 0 1 10 -160 -200 -75 -200 N
|
||||||
|
P 2 0 1 10 -160 100 -50 100 N
|
||||||
|
P 2 0 1 10 -50 -126 -50 -136 N
|
||||||
|
P 2 0 1 10 -25 -200 210 -200 N
|
||||||
|
P 3 0 1 10 -160 -100 -50 -100 -50 -125 N
|
||||||
|
P 3 0 1 10 0 50 0 0 -160 0 N
|
||||||
|
P 3 0 1 10 50 125 150 125 150 -200 N
|
||||||
|
P 3 0 1 10 100 75 100 -150 0 -150 N
|
||||||
|
P 4 0 1 10 -75 -125 -75 -225 25 -175 -75 -125 N
|
||||||
|
P 4 0 1 10 -50 100 50 150 50 50 -50 100 N
|
||||||
|
P 4 0 1 10 75 75 175 75 175 100 210 100 N
|
||||||
|
X RO 1 -400 100 100 R 50 50 1 1 O
|
||||||
|
X ~RE 2 -400 0 100 R 50 50 1 1 I
|
||||||
|
X DE 3 -400 -100 100 R 50 50 1 1 I
|
||||||
|
X DI 4 -400 -200 100 R 50 50 1 1 I
|
||||||
|
X GND 5 0 -600 100 U 50 50 1 1 W
|
||||||
|
X A 6 400 -200 100 L 50 50 1 1 B
|
||||||
|
X B 7 400 100 100 L 50 50 1 1 B
|
||||||
|
X VCC 8 0 500 100 D 50 50 1 1 W
|
||||||
|
ENDDRAW
|
||||||
|
ENDDEF
|
||||||
|
#
|
||||||
|
#End Library
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
EESchema-LIBRARY Version 2.4
|
||||||
|
#encoding utf-8
|
||||||
|
#
|
||||||
|
# PCA9306
|
||||||
|
#
|
||||||
|
DEF PCA9306 U 0 40 Y Y 1 F N
|
||||||
|
F0 "U" -300 450 50 H V L CNN
|
||||||
|
F1 "PCA9306" 200 450 50 H V L CNN
|
||||||
|
F2 "" -400 350 50 H I C CNN
|
||||||
|
F3 "" -300 450 50 H I C CNN
|
||||||
|
$FPLIST
|
||||||
|
SSOP*2.95x2.8mm*P0.65mm*
|
||||||
|
VSSOP*2.3x2mm*P0.5mm*
|
||||||
|
X2SON*1.4x1mm*P0.35mm*
|
||||||
|
$ENDFPLIST
|
||||||
|
DRAW
|
||||||
|
S -300 400 300 -400 0 1 10 f
|
||||||
|
X GND 1 0 -500 100 U 50 50 1 1 W
|
||||||
|
X VREF1 2 -100 500 100 D 50 50 1 1 W
|
||||||
|
X SCL1 3 -400 -100 100 R 50 50 1 1 B
|
||||||
|
X SDA1 4 -400 0 100 R 50 50 1 1 B
|
||||||
|
X SDA2 5 400 0 100 L 50 50 1 1 B
|
||||||
|
X SCL2 6 400 -100 100 L 50 50 1 1 B
|
||||||
|
X VREF2 7 100 500 100 D 50 50 1 1 W
|
||||||
|
X EN 8 400 100 100 L 50 50 1 1 I
|
||||||
|
ENDDRAW
|
||||||
|
ENDDEF
|
||||||
|
#
|
||||||
|
#End Library
|
||||||
+61
-40
@@ -1,4 +1,4 @@
|
|||||||
#include <Arduino.h>
|
// #include <Arduino.h>
|
||||||
|
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
// CANNode for Teensy 3.1/3.2
|
// CANNode for Teensy 3.1/3.2
|
||||||
@@ -14,7 +14,9 @@
|
|||||||
|
|
||||||
// For Node definition:
|
// For Node definition:
|
||||||
|
|
||||||
#include "Node_2_def.h"
|
#include "Node_1_def.h" // Dachstuhl
|
||||||
|
//#include "Node_2_def.h" // Werkstatt
|
||||||
|
//#include "Node_3_def.h" // Keller
|
||||||
|
|
||||||
// Metro ticks in ms
|
// Metro ticks in ms
|
||||||
#define METRO_CAN_tick 1
|
#define METRO_CAN_tick 1
|
||||||
@@ -64,13 +66,15 @@ FlexCAN CANbus(CAN_speed);
|
|||||||
// FLEXCAN0_MCR &= ~FLEXCAN_MCR_SRX_DIS;
|
// FLEXCAN0_MCR &= ~FLEXCAN_MCR_SRX_DIS;
|
||||||
// OneWire
|
// OneWire
|
||||||
uint8_t addr[8];
|
uint8_t addr[8];
|
||||||
|
uint8_t data[8];
|
||||||
uint8_t buffer[DS2406_BUF_LEN];
|
uint8_t buffer[DS2406_BUF_LEN];
|
||||||
uint8_t readout,trig_event,event_idx,tmp;
|
uint8_t readout,recheck,trig_event,event_idx,tmp;
|
||||||
OneWire OW_1(OW_pin);
|
OneWire OW_1(OW_pin);
|
||||||
|
|
||||||
telegram_comp_t mesg_comp;
|
telegram_comp_t mesg_comp;
|
||||||
|
|
||||||
static CAN_message_t txmsg,rxmsg;
|
static CAN_message_t global_txmsg,rxmsg;
|
||||||
|
CAN_message_t txmsg;
|
||||||
static uint8_t hex[17] = "0123456789abcdef";
|
static uint8_t hex[17] = "0123456789abcdef";
|
||||||
|
|
||||||
int txCount,rxCount;
|
int txCount,rxCount;
|
||||||
@@ -131,19 +135,27 @@ uint32_t forgeid(uint8_t prio, uint8_t dst, uint8_t cmd, uint8_t type=0){
|
|||||||
// Type: 0: SINGLE, 1: FIRST, 2: CONT, 3: LAST
|
// Type: 0: SINGLE, 1: FIRST, 2: CONT, 3: LAST
|
||||||
return (prio<<26)+(type<<24)+(dst<<16)+(NODE_ID<<8)+cmd;
|
return (prio<<26)+(type<<24)+(dst<<16)+(NODE_ID<<8)+cmd;
|
||||||
}
|
}
|
||||||
int CAN_send(uint8_t prio, uint8_t dst, uint8_t cmd, uint8_t data[], uint8_t type=0){
|
|
||||||
|
int CAN_send(uint8_t prio, uint8_t dst, uint8_t cmd, uint8_t* data, uint8_t data_size, uint8_t type=0){
|
||||||
|
txmsg.ext = 1;
|
||||||
|
txmsg.timeout = 100;
|
||||||
txmsg.id = forgeid(prio, dst, cmd, type);
|
txmsg.id = forgeid(prio, dst, cmd, type);
|
||||||
txmsg.len = sizeof(data);
|
txmsg.len = data_size;
|
||||||
for (uint8_t i = 0; i < txmsg.len; i++) { txmsg.buf[i] = data[i]; }
|
for (uint8_t i = 0; i < txmsg.len; i++) { txmsg.buf[i] = data[i]; }
|
||||||
CANbus.write(txmsg);
|
return CANbus.write(txmsg);
|
||||||
|
// txmsg.buf[0]++;
|
||||||
|
// txmsg.len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CAN_send(uint8_t prio, uint8_t dst, uint8_t cmd, uint8_t data, uint8_t type=0){
|
int CAN_send(uint8_t prio, uint8_t dst, uint8_t cmd, uint8_t data, uint8_t type=0){
|
||||||
|
txmsg.ext = 1;
|
||||||
|
txmsg.timeout = 100;
|
||||||
txmsg.id = forgeid(prio, dst, cmd, type);
|
txmsg.id = forgeid(prio, dst, cmd, type);
|
||||||
//txmsg.len = sizeof(data);
|
|
||||||
txmsg.len = 1;
|
txmsg.len = 1;
|
||||||
txmsg.buf[0] = data;
|
txmsg.buf[0] = data;
|
||||||
CANbus.write(txmsg);
|
return CANbus.write(txmsg);
|
||||||
|
// txmsg.buf[0]++;
|
||||||
|
// txmsg.len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -164,16 +176,18 @@ void send_event (uint8_t trig_event){
|
|||||||
|
|
||||||
for (uint8_t e_idx = 0; tx_events[e_idx].tag != 0; e_idx++)
|
for (uint8_t e_idx = 0; tx_events[e_idx].tag != 0; e_idx++)
|
||||||
if ( tx_events[e_idx].tag == trig_event ) {
|
if ( tx_events[e_idx].tag == trig_event ) {
|
||||||
|
txmsg.ext = 1;
|
||||||
|
txmsg.timeout = 100;
|
||||||
txmsg.id = event2id(tx_events[e_idx]);
|
txmsg.id = event2id(tx_events[e_idx]);
|
||||||
txmsg.len = 1;
|
txmsg.len = 1;
|
||||||
// txmsg.timeout = 100;
|
|
||||||
txmsg.buf[0]= tx_events[e_idx].data;
|
txmsg.buf[0]= tx_events[e_idx].data;
|
||||||
CANbus.write(txmsg);
|
CANbus.write(txmsg);
|
||||||
Serial.print(F("Sending to CAN ID: "));
|
Serial.print(F("Sending to CAN ID: "));
|
||||||
Serial.print(txmsg.id);
|
Serial.print(txmsg.id);
|
||||||
Serial.print(F("DATA: "));
|
Serial.print(F("DATA: "));
|
||||||
Serial.println(txmsg.buf[0]);
|
Serial.println(txmsg.buf[0]);
|
||||||
txmsg.len = 0;
|
// txmsg.buf[0]++;
|
||||||
|
// txmsg.len = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,20 +219,14 @@ for (uint8_t i = 0; action_map[i].tag != 0 ; i++) {
|
|||||||
}
|
}
|
||||||
bool new_state = digitalRead(outputs[action_map[i].outputs_idx].address);
|
bool new_state = digitalRead(outputs[action_map[i].outputs_idx].address);
|
||||||
if ( old_state == new_state) {
|
if ( old_state == new_state) {
|
||||||
switch ( new_state ) {
|
data[0]=action_map[i].outputs_idx;
|
||||||
case 0:
|
data[1]=new_state ^ outputs[action_map[i].outputs_idx].invert;
|
||||||
CAN_send(NOTIFY, 0xFF, OFF, action_map[i].outputs_idx);
|
CAN_send(NOTIFY, 0x0, STATE_OUT, data, 2);
|
||||||
case 1:
|
|
||||||
CAN_send(NOTIFY, 0xFF, ON, action_map[i].outputs_idx);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
switch ( new_state ) {
|
data[0]=action_map[i].outputs_idx;
|
||||||
case 0:
|
data[1]=new_state ^ outputs[action_map[i].outputs_idx].invert;
|
||||||
CAN_send(NOTIFY, 0xFF, T_OFF, action_map[i].outputs_idx);
|
CAN_send(NOTIFY, 0x0, NEWSTATE_OUT, data, 2);
|
||||||
case 1:
|
|
||||||
CAN_send(NOTIFY, 0xFF, T_ON, action_map[i].outputs_idx);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -237,8 +245,6 @@ void setup(void)
|
|||||||
pinMode(CAN_RS_PIN,OUTPUT);
|
pinMode(CAN_RS_PIN,OUTPUT);
|
||||||
digitalWrite(CAN_RS_PIN,0);
|
digitalWrite(CAN_RS_PIN,0);
|
||||||
CANbus.begin();
|
CANbus.begin();
|
||||||
txmsg.ext = 1;
|
|
||||||
txmsg.timeout = 100;
|
|
||||||
|
|
||||||
// outputs
|
// outputs
|
||||||
for (size_t i = 0; outputs[i].type != NOP; i++) {
|
for (size_t i = 0; outputs[i].type != NOP; i++) {
|
||||||
@@ -294,11 +300,10 @@ void loop(void)
|
|||||||
}
|
}
|
||||||
if (new_owd) {
|
if (new_owd) {
|
||||||
// send new ID to all
|
// send new ID to all
|
||||||
CAN_send(NOTIFY, 0xFF, NEW_TWID, addr);
|
|
||||||
Serial.print("Found a device: ");
|
Serial.print("Found a device: ");
|
||||||
print_OW_Device(addr);
|
print_OW_Device(addr);
|
||||||
|
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
CAN_send(NOTIFY, 0x0, NEW_TWID, addr, sizeof(addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -324,19 +329,29 @@ void loop(void)
|
|||||||
}
|
}
|
||||||
// if ((switches_state[s_idx] != readout) && (readout != 255 )) {
|
// if ((switches_state[s_idx] != readout) && (readout != 255 )) {
|
||||||
if (switches_state[s_idx] != readout) {
|
if (switches_state[s_idx] != readout) {
|
||||||
|
delay(1);
|
||||||
|
recheck = read_DS2406(switches[s_idx].addr);
|
||||||
|
if (readout == recheck) {
|
||||||
tmp = readout ^ switches_state[s_idx];
|
tmp = readout ^ switches_state[s_idx];
|
||||||
switches_state[s_idx] = readout;
|
switches_state[s_idx] = readout;
|
||||||
action[0] = tmp & 0x08;
|
action[0] = tmp & 0x08;
|
||||||
action[1] = tmp & 0x04;
|
action[1] = tmp & 0x04;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (action[0]) {
|
if (action[0]) {
|
||||||
Serial.print("pioA of switch ");
|
Serial.print("pioA of switch ");
|
||||||
Serial.print(switches[s_idx].nick);
|
Serial.print(switches[s_idx].nick);
|
||||||
if (readout & 0x08) {
|
if (readout & 0x08) {
|
||||||
Serial.println(F(" is now OFF"));
|
Serial.println(F(" is now OFF"));
|
||||||
|
data[0]=switches[s_idx].nick;
|
||||||
|
data[1]=0;
|
||||||
|
CAN_send(NOTIFY, 0x0, STATE_IN, data, 2);
|
||||||
send_event(switches[s_idx].event_tag[0]);
|
send_event(switches[s_idx].event_tag[0]);
|
||||||
} else {
|
} else {
|
||||||
Serial.println(F(" is now ON"));
|
Serial.println(F(" is now ON"));
|
||||||
|
data[0]=switches[s_idx].nick;
|
||||||
|
data[1]=1;
|
||||||
|
CAN_send(NOTIFY, 0x0, STATE_IN, data, 2);
|
||||||
send_event(switches[s_idx].event_tag[1]);
|
send_event(switches[s_idx].event_tag[1]);
|
||||||
}
|
}
|
||||||
action[0] = 0;
|
action[0] = 0;
|
||||||
@@ -346,9 +361,15 @@ void loop(void)
|
|||||||
Serial.print(switches[s_idx].nick);
|
Serial.print(switches[s_idx].nick);
|
||||||
if (readout & 0x04) {
|
if (readout & 0x04) {
|
||||||
Serial.println(F(" is now OFF"));
|
Serial.println(F(" is now OFF"));
|
||||||
|
data[0]=switches[s_idx].nick;
|
||||||
|
data[1]=2;
|
||||||
|
CAN_send(NOTIFY, 0x0, STATE_IN, data, 2);
|
||||||
send_event(switches[s_idx].event_tag[2]);
|
send_event(switches[s_idx].event_tag[2]);
|
||||||
} else {
|
} else {
|
||||||
Serial.println(F(" is now ON"));
|
Serial.println(F(" is now ON"));
|
||||||
|
data[0]=switches[s_idx].nick;
|
||||||
|
data[1]=3;
|
||||||
|
CAN_send(NOTIFY, 0x0, STATE_IN, data, 2);
|
||||||
send_event(switches[s_idx].event_tag[3]);
|
send_event(switches[s_idx].event_tag[3]);
|
||||||
}
|
}
|
||||||
action[1] = 0;
|
action[1] = 0;
|
||||||
@@ -397,18 +418,18 @@ void loop(void)
|
|||||||
}
|
}
|
||||||
rxCount = 0;
|
rxCount = 0;
|
||||||
}
|
}
|
||||||
txTimer = 100;//milliseconds
|
// txTimer = 10;//milliseconds
|
||||||
if (txmsg.len != 0){
|
// if (txmsg.len != 0){
|
||||||
Serial.print("PUT=");
|
// Serial.print("PUT=");
|
||||||
Serial.print(txmsg.id,HEX);
|
// Serial.print(txmsg.id,HEX);
|
||||||
for (uint8_t i=0; i<txmsg.len; i++){
|
// for (uint8_t i=0; i<txmsg.len; i++){
|
||||||
Serial.print(":");
|
// Serial.print(":");
|
||||||
Serial.print(txmsg.buf[i],HEX);
|
// Serial.print(txmsg.buf[i],HEX);
|
||||||
}
|
// }
|
||||||
Serial.print("\n");
|
// Serial.print("\n");
|
||||||
CANbus.write(txmsg);
|
// CANbus.write(txmsg);
|
||||||
txmsg.buf[0]++;
|
// txmsg.buf[0]++;
|
||||||
txmsg.len = 0;
|
// txmsg.len = 0;
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
enum out_type { GPIO, PWM, OW, I2C, SPI, WS2811, DMX, NOP };
|
enum out_type { GPIO, PWM, OW, I2C, SPI, WS2811, DMX, NOP };
|
||||||
enum event_type { LOCAL, SEND};
|
enum event_type { LOCAL, SEND};
|
||||||
|
|
||||||
enum cmd_type { OFF, ON, VALUE, TOGGLE, T_OFF, T_ON, BIN_DUMP, NEW_TWID };
|
enum cmd_type { OFF, ON, VALUE, TOGGLE, STATE_OUT, STATE_IN, NEWSTATE_OUT, NEWSTATE_IN, BIN_DUMP, NEW_TWID };
|
||||||
enum telegram_prio { ALERT, EVENT, NOTIFY, INFO };
|
enum telegram_prio { ALERT, EVENT, NOTIFY, INFO };
|
||||||
|
|
||||||
typedef struct CAN_telegram_t {
|
typedef struct CAN_telegram_t {
|
||||||
|
|||||||
+2
-1
@@ -31,7 +31,8 @@ static OW_switch_t switches[N_SWITCHES] PROGMEM={
|
|||||||
// nick, addr[8], event_tag[pioA_FALL, pioA_RISE, pioB_FALL, pioB_RISE]
|
// nick, addr[8], event_tag[pioA_FALL, pioA_RISE, pioB_FALL, pioB_RISE]
|
||||||
{ 255, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }, { 0, 0, 0, 0 } },
|
{ 255, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }, { 0, 0, 0, 0 } },
|
||||||
{ 21, { 0x12, 0x86, 0xB4, 0x54, 0x0, 0x0, 0x0, 0x5F }, { 23, 23, 37, 37 } }, // Flur
|
{ 21, { 0x12, 0x86, 0xB4, 0x54, 0x0, 0x0, 0x0, 0x5F }, { 23, 23, 37, 37 } }, // Flur
|
||||||
{ 22, { 0x12, 0xC7, 0x2F, 0xCF, 0x0, 0x0, 0x0, 0xAF }, { 22, 22, 21, 21 } }, // WZ
|
{ 22, { 0x12, 0xCE, 0x6E, 0xCA, 0x0, 0x0, 0x0, 0x9C }, { 22, 22, 21, 21 } }, // WZ
|
||||||
|
// { 22, { 0x12, 0xC7, 0x2F, 0xCF, 0x0, 0x0, 0x0, 0xAF }, { 22, 22, 21, 21 } }, // WZ
|
||||||
// { 22, { 0x12, 0x5E, 0xFF, 0x55, 0x0, 0x0, 0x0, 0x2C }, { 21, 21, 22, 22 } }, // WZ
|
// { 22, { 0x12, 0x5E, 0xFF, 0x55, 0x0, 0x0, 0x0, 0x2C }, { 21, 21, 22, 22 } }, // WZ
|
||||||
{ 0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }, { 0, 0, 0, 0 } }
|
{ 0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }, { 0, 0, 0, 0 } }
|
||||||
};
|
};
|
||||||
|
|||||||
+8
-11
@@ -19,8 +19,8 @@
|
|||||||
#define RELAY4 22
|
#define RELAY4 22
|
||||||
#define RELAY5 17
|
#define RELAY5 17
|
||||||
#define RELAY6 16
|
#define RELAY6 16
|
||||||
#define RELAY7 9
|
#define RELAY7 19
|
||||||
#define RELAY8 10
|
#define RELAY8 18
|
||||||
|
|
||||||
// OneWire
|
// OneWire
|
||||||
#define OW_pin 14
|
#define OW_pin 14
|
||||||
@@ -35,6 +35,8 @@ static OW_switch_t switches[N_SWITCHES] PROGMEM={
|
|||||||
//{ 21, { 0x12, 0x86, 0xB4, 0x54, 0x0, 0x0, 0x0, 0x5F }, { 3, 3, 4, 4 } },
|
//{ 21, { 0x12, 0x86, 0xB4, 0x54, 0x0, 0x0, 0x0, 0x5F }, { 3, 3, 4, 4 } },
|
||||||
{ 22, { 0x12, 0x84, 0xAD, 0x4F, 0x0, 0x0, 0x0, 0x12 }, { 1, 1, 2, 2 } }, // EZ -> Küche
|
{ 22, { 0x12, 0x84, 0xAD, 0x4F, 0x0, 0x0, 0x0, 0x12 }, { 1, 1, 2, 2 } }, // EZ -> Küche
|
||||||
// { 31, { 0x12, 0x88, 0xDD, 0x53, 0x0, 0x0, 0x0, 0x28 }, { 210, 211, 220, 221 } }, // Roldenschalter (A - UP, B - DOWN)
|
// { 31, { 0x12, 0x88, 0xDD, 0x53, 0x0, 0x0, 0x0, 0x28 }, { 210, 211, 220, 221 } }, // Roldenschalter (A - UP, B - DOWN)
|
||||||
|
{ 31, { 0x12, 0x8F, 0xE2, 0x86 ,0x0, 0x0, 0x0, 0xC6}, { 220, 221, 210, 211 } } // Roldenschalter (A - UP, B - DOWN)
|
||||||
|
|
||||||
};
|
};
|
||||||
static uint8_t switches_state[N_SWITCHES];
|
static uint8_t switches_state[N_SWITCHES];
|
||||||
static outputs_t outputs[N_OUTPUTS] PROGMEM={
|
static outputs_t outputs[N_OUTPUTS] PROGMEM={
|
||||||
@@ -45,13 +47,8 @@ static outputs_t outputs[N_OUTPUTS] PROGMEM={
|
|||||||
{ GPIO, 22, 0, true }, // 3
|
{ GPIO, 22, 0, true }, // 3
|
||||||
{ GPIO, 17, 0, true }, // 4
|
{ GPIO, 17, 0, true }, // 4
|
||||||
{ GPIO, 16, 0, true }, // 5
|
{ GPIO, 16, 0, true }, // 5
|
||||||
<<<<<<< HEAD
|
|
||||||
{ GPIO, 9, 255, true }, // 6
|
|
||||||
{ GPIO, 10, 0, true }, // 7
|
|
||||||
=======
|
|
||||||
{ GPIO, 19, 0, true }, // 6
|
{ GPIO, 19, 0, true }, // 6
|
||||||
{ GPIO, 18, 0, true }, // 7
|
{ GPIO, 18, 0, true }, // 7
|
||||||
>>>>>>> led
|
|
||||||
{ NOP, 0xFF, 0, 0 }
|
{ NOP, 0xFF, 0, 0 }
|
||||||
};
|
};
|
||||||
static uint8_t outputs_state[N_OUTPUTS];
|
static uint8_t outputs_state[N_OUTPUTS];
|
||||||
@@ -72,10 +69,10 @@ static event_t tx_events[N_EVENTS] PROGMEM={
|
|||||||
{ 8, 0x03, 0x03, TOGGLE, 0x08},
|
{ 8, 0x03, 0x03, TOGGLE, 0x08},
|
||||||
{ 11, 0x03, 0x01, ON, 0x01},
|
{ 11, 0x03, 0x01, ON, 0x01},
|
||||||
{ 12, 0x03, 0x01, ON, 0x02},
|
{ 12, 0x03, 0x01, ON, 0x02},
|
||||||
{ 210, 0x03, 0xff, OFF, 0x06},
|
{ 210, 0x03, 0x03, OFF, 0x04},
|
||||||
{ 211, 0x03, 0xff, ON, 0x06},
|
{ 211, 0x03, 0x03, ON, 0x04},
|
||||||
{ 220, 0x03, 0xff, OFF, 0x07},
|
{ 220, 0x03, 0x03, OFF, 0x05},
|
||||||
{ 221, 0x03, 0xff, ON, 0x07},
|
{ 221, 0x03, 0x03, ON, 0x05},
|
||||||
{ 255, 0x03, 0xff, OFF, 0x09},
|
{ 255, 0x03, 0xff, OFF, 0x09},
|
||||||
{ 254, 0x03, 0xff, ON, 0x09},
|
{ 254, 0x03, 0xff, ON, 0x09},
|
||||||
{ 10, 0x03, 0xff, TOGGLE, 0x01},
|
{ 10, 0x03, 0xff, TOGGLE, 0x01},
|
||||||
|
|||||||
Executable
+85
@@ -0,0 +1,85 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
from __future__ import absolute_import, print_function
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import argparse
|
||||||
|
import socket
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
import can
|
||||||
|
from can import Bus, BusState, Logger
|
||||||
|
|
||||||
|
import paho.mqtt.client as mqtt
|
||||||
|
|
||||||
|
def decon(msg_id):
|
||||||
|
msg_prio=msg_id>>26
|
||||||
|
msg_type=(msg_id>>24) & 0x03
|
||||||
|
msg_dst=(msg_id>>16) & 0xFF
|
||||||
|
msg_src=(msg_id>>8) & 0xFF
|
||||||
|
msg_cmd=msg_id & 0xFF
|
||||||
|
print("prio: ", hex(msg_prio),"type: ", hex(msg_type)," dst: ", hex(msg_dst)," src: ", hex(msg_src)," cmd: ",hex(msg_cmd))
|
||||||
|
return [msg_prio, msg_type, msg_dst, msg_src, msg_cmd]
|
||||||
|
|
||||||
|
def on_connect(mcp_mqtt, userdata, flags, rc):
|
||||||
|
print("Connected with result code "+str(rc))
|
||||||
|
|
||||||
|
# Subscribing in on_connect() means that if we lose the connection and
|
||||||
|
# reconnect then subscriptions will be renewed.
|
||||||
|
mcp_mqtt.subscribe("can/raw")
|
||||||
|
mcp_mqtt.subscribe("ctest/#")
|
||||||
|
|
||||||
|
def on_message(mcp_mqtt, userdata, msg):
|
||||||
|
local_bus=userdata
|
||||||
|
topic=msg.topic
|
||||||
|
print("data Received topic: ", topic)
|
||||||
|
m_decode=str(msg.payload.decode("utf-8","ignore"))
|
||||||
|
print("data Received",m_decode)
|
||||||
|
msg_id=int(m_decode.split('#')[0],16)
|
||||||
|
|
||||||
|
msg_data=int(m_decode.split('#')[1],16)
|
||||||
|
print(msg_data)
|
||||||
|
m = can.Message(arbitration_id=msg_id,
|
||||||
|
data=[msg_data],
|
||||||
|
extended_id=True)
|
||||||
|
try:
|
||||||
|
local_bus.send(m)
|
||||||
|
except BaseException as e:
|
||||||
|
logging.error("Error sending can message {%s}: %s" % (m, e))
|
||||||
|
print("data sent to CAN",m)
|
||||||
|
def main():
|
||||||
|
verbosity = 2
|
||||||
|
|
||||||
|
logging_level_name = ['critical', 'error', 'warning', 'info', 'debug', 'subdebug'][min(5, verbosity)]
|
||||||
|
can.set_logging_level(logging_level_name)
|
||||||
|
|
||||||
|
can_filters = []
|
||||||
|
config = {"can_filters": can_filters, "single_handle": True}
|
||||||
|
config["interface"] = "socketcan"
|
||||||
|
config["bitrate"] = 125000
|
||||||
|
bus = Bus("can1", **config)
|
||||||
|
|
||||||
|
print('Connected to {}: {}'.format(bus.__class__.__name__, bus.channel_info))
|
||||||
|
print('Can Logger (Started on {})\n'.format(datetime.now()))
|
||||||
|
|
||||||
|
mcp_mqtt = mqtt.Client()
|
||||||
|
mcp_mqtt.on_connect = on_connect
|
||||||
|
mcp_mqtt.on_message = on_message
|
||||||
|
mcp_mqtt.user_data_set(bus)
|
||||||
|
mcp_mqtt.connect("mcp", 1883, 60)
|
||||||
|
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
mcp_mqtt.loop_start()
|
||||||
|
msg = bus.recv(1)
|
||||||
|
if msg is not None:
|
||||||
|
de=decon(msg.arbitration_id)
|
||||||
|
m= { "prio": hex(de[0]), "type": hex(de[1]), "dst": hex(de[2]), "src": hex(de[3]), "cmd": hex(de[4]), "data": "".join("%02x" % b for b in msg.data) }
|
||||||
|
print(m)
|
||||||
|
mcp_mqtt.publish("can/rx", str(m))
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
|
bus.shutdown()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Executable
+63
@@ -0,0 +1,63 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
|
||||||
|
from __future__ import absolute_import, print_function
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import argparse
|
||||||
|
import socket
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
import can
|
||||||
|
from can import Bus, BusState, Logger
|
||||||
|
|
||||||
|
|
||||||
|
def decon(msg_id):
|
||||||
|
msg_prio=msg_id>>26
|
||||||
|
msg_type=(msg_id>>24) & 0x03
|
||||||
|
msg_dst=(msg_id>>16) & 0xFF
|
||||||
|
msg_src=(msg_id>>8) & 0xFF
|
||||||
|
msg_cmd=msg_id & 0xFF
|
||||||
|
print("prio: ", hex(msg_prio),"type: ", hex(msg_type)," dst: ", hex(msg_dst)," src: ", hex(msg_src)," cmd: ",hex(msg_cmd))
|
||||||
|
return [msg_prio, msg_type, msg_dst, msg_src, msg_cmd]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
verbosity = 2
|
||||||
|
|
||||||
|
logging_level_name = ['critical', 'error', 'warning', 'info', 'debug', 'subdebug'][min(5, verbosity)]
|
||||||
|
can.set_logging_level(logging_level_name)
|
||||||
|
|
||||||
|
can_filters = []
|
||||||
|
config = {"can_filters": can_filters, "single_handle": True}
|
||||||
|
config["interface"] = "socketcan"
|
||||||
|
config["bitrate"] = 125000
|
||||||
|
bus = Bus("can1", **config)
|
||||||
|
|
||||||
|
print('Connected to {}: {}'.format(bus.__class__.__name__, bus.channel_info))
|
||||||
|
print('Can Logger (Started on {})\n'.format(datetime.now()))
|
||||||
|
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
msg = bus.recv(1)
|
||||||
|
if msg is not None:
|
||||||
|
de=decon(msg.arbitration_id)
|
||||||
|
m= { "prio": hex(de[0]), "type": hex(de[1]), "dst": hex(de[2]), "src": hex(de[3]), "cmd": hex(de[4]), "target": hex(msg.data[0]) }
|
||||||
|
if de[2] is 3 and msg.data[0] is 3 and de[1] is 0 and de[3] is 3 and de[4] is 3 :
|
||||||
|
print(m)
|
||||||
|
m = can.Message(arbitration_id=0x0C030900,
|
||||||
|
data=[3],
|
||||||
|
extended_id=True)
|
||||||
|
try:
|
||||||
|
bus.send(m)
|
||||||
|
except BaseException as e:
|
||||||
|
logging.error("Error sending can message {%s}: %s" % (m, e))
|
||||||
|
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
|
bus.shutdown()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Executable
+41
@@ -0,0 +1,41 @@
|
|||||||
|
#! /usr/bin/env python
|
||||||
|
import sys
|
||||||
|
|
||||||
|
msg_id=int(str(sys.argv[1]),0) & 0x1FFFFFFF
|
||||||
|
msg_prio=msg_id>>26
|
||||||
|
msg_type=(msg_id>>24) & 0x03
|
||||||
|
msg_dst=(msg_id>>16) & 0xFF
|
||||||
|
msg_src=(msg_id>>8) & 0xFF
|
||||||
|
msg_cmd=msg_id & 0xFF
|
||||||
|
|
||||||
|
#print('id: {0:b}'.format(msg_id))
|
||||||
|
print('id: {0:#010x} {0:#031b}'.format(msg_id ,msg_id))
|
||||||
|
#print("id:", hex(msg_id), format(40,str(bin(msg_id))))
|
||||||
|
|
||||||
|
print('prio: {0:#03x} {0:#04b}'.format(msg_prio))
|
||||||
|
print('type: {0:#03x} {0:#04b}'.format(msg_type))
|
||||||
|
print('dst: {0:#04x} {0:#010b}'.format(msg_dst))
|
||||||
|
print('src: {0:#04x} {0:#010b}'.format(msg_src))
|
||||||
|
print('cmd: {0:#04x} {0:#010b}'.format(msg_cmd))
|
||||||
|
|
||||||
|
|
||||||
|
nmsg_prio=msg_id>>26
|
||||||
|
nmsg_type=(msg_id>>24) & 0x03
|
||||||
|
nmsg_src=(msg_id>>18) & 0x3F
|
||||||
|
nmsg_dst=(msg_id>>12) & 0x3F
|
||||||
|
nmsg_targ=(msg_id>>6) & 0x3F
|
||||||
|
nmsg_cmd=msg_id & 0x1F
|
||||||
|
|
||||||
|
|
||||||
|
print('New schema')
|
||||||
|
|
||||||
|
#print('id: {0:b}'.format(msg_id))
|
||||||
|
print('id: {0:#010x} {0:#031b}'.format(msg_id))
|
||||||
|
#print("id:", hex(msg_id), format(40,str(bin(msg_id))))
|
||||||
|
|
||||||
|
print('prio: {0:#04x} {0:#04b}'.format(nmsg_prio))
|
||||||
|
print('type: {0:#04x} {0:#04b}'.format(nmsg_type))
|
||||||
|
print('src: {0:#04x} {0:#08b}'.format(nmsg_src))
|
||||||
|
print('dst: {0:#04x} {0:#08b}'.format(nmsg_dst))
|
||||||
|
print('target: {0:#04x} {0:#08b}'.format(nmsg_targ))
|
||||||
|
print('cmd: {0:#04x} {0:#07b}'.format(nmsg_cmd))
|
||||||
Executable
+175
@@ -0,0 +1,175 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from __future__ import absolute_import, print_function
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import argparse
|
||||||
|
import socket
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
import can
|
||||||
|
from can import Bus, BusState, Logger
|
||||||
|
|
||||||
|
import paho.mqtt.client as mqtt
|
||||||
|
|
||||||
|
sub_topic = "light"
|
||||||
|
aliases = {
|
||||||
|
'Esszimmer': 'EZ',
|
||||||
|
'Esszimmer oben': 'EZ',
|
||||||
|
'Küche': 'K',
|
||||||
|
'Wohnzimmer1': 'WZ1',
|
||||||
|
'Wohnzimmer2': 'WZ2',
|
||||||
|
'Wohnzimmer Nord': 'WZ1',
|
||||||
|
'Wohnzimmer Süd': 'WZ2',
|
||||||
|
'Wohnzimmer Tür': 'WZ1',
|
||||||
|
'Wohnzimmer TV': 'WZ2',
|
||||||
|
'Wohnzimmer Fernseher': 'WZ2',
|
||||||
|
'Bad Decke': 'B1',
|
||||||
|
'Bad Spiegel': 'B2',
|
||||||
|
'Bjarne': 'K1',
|
||||||
|
'Inka': 'K2',
|
||||||
|
'Schlafzimmer': 'SCH',
|
||||||
|
'Flur EG': 'FE',
|
||||||
|
'Flur unten': 'FE',
|
||||||
|
'Flur OG': 'FO',
|
||||||
|
'Flur oben': 'FO',
|
||||||
|
'Treppe EG': 'TRE',
|
||||||
|
'Treppe unten': 'TRE',
|
||||||
|
'Treppe OG': 'TRO',
|
||||||
|
'Treppe oben': 'TRO'
|
||||||
|
}
|
||||||
|
light_map = {
|
||||||
|
'EZ': [ 0x03, 0x01 ],
|
||||||
|
'K': [ 0x03, 0x02 ],
|
||||||
|
'WZ1': [ 0x02, 0x01 ],
|
||||||
|
'WZ2': [ 0x02, 0x02 ],
|
||||||
|
'TER': [ 0x03, 0x03 ],
|
||||||
|
'FE': [ 0x03, 0x07 ],
|
||||||
|
'TRE': [ 0x02, 0x03 ],
|
||||||
|
'FO': [ 0x01, 0x03 ],
|
||||||
|
'TRO': [ 0x01, 0x07 ],
|
||||||
|
'KI1': [ 0x01, 0x06 ],
|
||||||
|
'KI2': [ 0x01, 0x04 ],
|
||||||
|
'SCH': [ 0x01, 0x08 ],
|
||||||
|
'B1': [ 0x01, 0x01 ],
|
||||||
|
'B2': [ 0x01, 0x02 ],
|
||||||
|
'ROL_EZ_DOWN': [0x03,0x05],
|
||||||
|
'ROL_EZ_UP': [0x03,0x04],
|
||||||
|
'EG1': [ 0x02, 0x09 ],
|
||||||
|
'EG2': [ 0x03, 0x09 ],
|
||||||
|
'OG': [ 0x01, 0x09 ],
|
||||||
|
'ALL': [ 0xFF, 0x09 ],
|
||||||
|
}
|
||||||
|
cmd_map = {
|
||||||
|
'off': 0,
|
||||||
|
'on': 1,
|
||||||
|
'value': 2,
|
||||||
|
'toggle': 3
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def decon(msg_id):
|
||||||
|
msg_prio=msg_id>>26
|
||||||
|
msg_type=(msg_id>>24) & 0x03
|
||||||
|
msg_dst=(msg_id>>16) & 0xFF
|
||||||
|
msg_src=(msg_id>>8) & 0xFF
|
||||||
|
msg_cmd=msg_id & 0xFF
|
||||||
|
# print("msg_id: ", hex(msg_id), "prio: ", hex(msg_prio),"type: ", hex(msg_type)," dst: ", hex(msg_dst)," src: ", hex(msg_src)," cmd: ",hex(msg_cmd))
|
||||||
|
return [msg_prio, msg_type, msg_dst, msg_src, msg_cmd]
|
||||||
|
|
||||||
|
def con(msg_dst,msg_cmd,msg_prio=3,msg_type=0,msg_src=11, ):
|
||||||
|
msg_id=(msg_prio<<26) + \
|
||||||
|
((msg_type&0x03)<<24) +\
|
||||||
|
((msg_dst&0xFF)<<16) +\
|
||||||
|
((msg_src&0xFF)<<8) +\
|
||||||
|
(msg_cmd&0xFF)
|
||||||
|
print("Constructed ID: "+hex(msg_id))
|
||||||
|
return msg_id
|
||||||
|
|
||||||
|
def on_connect(mcp_mqtt, userdata, flags, rc):
|
||||||
|
print("Connected with result code "+str(rc))
|
||||||
|
|
||||||
|
# Subscribing in on_connect() means that if we lose the connection and
|
||||||
|
# reconnect then subscriptions will be renewed.
|
||||||
|
mcp_mqtt.subscribe(sub_topic+"/+")
|
||||||
|
print("Subscribed to:"+sub_topic+"/+")
|
||||||
|
|
||||||
|
def on_message(mcp_mqtt, userdata, msg):
|
||||||
|
local_bus=userdata
|
||||||
|
print("data Received topic: ", msg.topic)
|
||||||
|
m_decode=str(msg.payload.decode("utf-8","ignore"))
|
||||||
|
print("data Received",m_decode)
|
||||||
|
msg_cmd=2
|
||||||
|
try:
|
||||||
|
value=int(m_decode)
|
||||||
|
except ValueError:
|
||||||
|
msg_cmd=cmd_map[m_decode]
|
||||||
|
|
||||||
|
sub=msg.topic[len(sub_topic)+1:]
|
||||||
|
light=aliases.get(sub,None)
|
||||||
|
if light is None:
|
||||||
|
light=sub
|
||||||
|
|
||||||
|
|
||||||
|
print("substring: "+light)
|
||||||
|
addr = light_map[light]
|
||||||
|
msg_id=con(msg_dst=addr[0],msg_cmd=msg_cmd)
|
||||||
|
msg_data=[addr[1]]
|
||||||
|
print(msg_data)
|
||||||
|
if msg_cmd == 2:
|
||||||
|
msg_data.append(value)
|
||||||
|
print(msg_data)
|
||||||
|
m = can.Message(arbitration_id=msg_id,
|
||||||
|
data=msg_data,
|
||||||
|
extended_id=True)
|
||||||
|
print("going to sent to CAN",m)
|
||||||
|
|
||||||
|
try:
|
||||||
|
local_bus.send(m)
|
||||||
|
except BaseException as e:
|
||||||
|
logging.error("Error sending can message {%s}: %s" % (m, e))
|
||||||
|
print("data sent to CAN",m)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
verbosity = 2
|
||||||
|
|
||||||
|
logging_level_name = ['critical', 'error', 'warning', 'info', 'debug', 'subdebug'][min(5, verbosity)]
|
||||||
|
can.set_logging_level(logging_level_name)
|
||||||
|
|
||||||
|
can_filters = []
|
||||||
|
config = {"can_filters": can_filters, "single_handle": True}
|
||||||
|
config["interface"] = "socketcan"
|
||||||
|
config["bitrate"] = 125000
|
||||||
|
bus = Bus("can1", **config)
|
||||||
|
|
||||||
|
print('Connected to {}: {}'.format(bus.__class__.__name__, bus.channel_info))
|
||||||
|
print('Can Logger (Started on {})\n'.format(datetime.now()))
|
||||||
|
|
||||||
|
mcp_mqtt = mqtt.Client()
|
||||||
|
mcp_mqtt.on_connect = on_connect
|
||||||
|
mcp_mqtt.on_message = on_message
|
||||||
|
mcp_mqtt.user_data_set(bus)
|
||||||
|
mcp_mqtt.connect("mcp", 1883, 60)
|
||||||
|
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
mcp_mqtt.loop_start()
|
||||||
|
msg = bus.recv(1)
|
||||||
|
if msg is not None:
|
||||||
|
de=decon(msg.arbitration_id)
|
||||||
|
m= { "prio": hex(de[0]), "type": hex(de[1]), "dst": hex(de[2]), "src": hex(de[3]), "cmd": hex(de[4]), "action": hex(msg.data[0]) }
|
||||||
|
if de[2]==0 and de[4] == 6:
|
||||||
|
print("received state: ", hex(de[3]), hex(msg.data[0]), hex(msg.data[1]))
|
||||||
|
for key in light_map:
|
||||||
|
address=light_map[key]
|
||||||
|
if address[0] == de[3] and address[1] == msg.data[0]+1:
|
||||||
|
print("light/"+key+" changed to "+str(msg.data[1]))
|
||||||
|
mcp_mqtt.publish("light/"+key+"/state", msg.data[1] , retain=1)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
|
bus.shutdown()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Executable
+55
@@ -0,0 +1,55 @@
|
|||||||
|
#! /usr/bin/env python
|
||||||
|
import sys
|
||||||
|
import json
|
||||||
|
#stuff = json.loads(sys.argv[1])
|
||||||
|
|
||||||
|
|
||||||
|
#data = json.load(sys.stdin)
|
||||||
|
|
||||||
|
|
||||||
|
#print(json.dumps(sys.stdin, sort_keys=True, indent=4))
|
||||||
|
###print str(sys.argv[1])
|
||||||
|
#print(stuff['foo'])
|
||||||
|
|
||||||
|
#print(json.dumps(data, indent=4))
|
||||||
|
|
||||||
|
#msg_id=int(str(sys.argv[1]),0)
|
||||||
|
#msg_prio=msg_id>>26
|
||||||
|
#msg_type=(msg_id>>24) & 0x03
|
||||||
|
#msg_dst=(msg_id>>16) & 0xFF
|
||||||
|
#msg_src=(msg_id>>8) & 0xFF
|
||||||
|
#msg_cmd=msg_id & 0xFF
|
||||||
|
|
||||||
|
#print "id:", hex(msg_id), bin(msg_id)
|
||||||
|
#print "prio:", hex(msg_prio), bin(msg_prio)
|
||||||
|
#print "type:", hex(msg_type), bin(msg_type)
|
||||||
|
#print "dst:", hex(msg_dst), bin(msg_dst)
|
||||||
|
#print "src:", hex(msg_src), bin(msg_src)
|
||||||
|
#print "cmd:", hex(msg_cmd), bin(msg_cmd)
|
||||||
|
import sys
|
||||||
|
import simplejson as json
|
||||||
|
|
||||||
|
|
||||||
|
def main(args):
|
||||||
|
try:
|
||||||
|
inputFile = open(args[1])
|
||||||
|
input = json.load(inputFile)
|
||||||
|
inputFile.close()
|
||||||
|
except IndexError:
|
||||||
|
usage()
|
||||||
|
return False
|
||||||
|
if len(args) < 3:
|
||||||
|
print json.dumps(input, sort_keys = False, indent = 10)
|
||||||
|
else:
|
||||||
|
outputFile = open(args[2], "w")
|
||||||
|
json.dump(input, outputFile, sort_keys = False, indent = 4)
|
||||||
|
outputFile.close()
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def usage():
|
||||||
|
print __doc__
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(not main(sys.argv))
|
||||||
Executable
+130
@@ -0,0 +1,130 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from __future__ import absolute_import, print_function
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import argparse
|
||||||
|
import socket
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
import can
|
||||||
|
from can import Bus, BusState, Logger
|
||||||
|
|
||||||
|
import paho.mqtt.client as mqtt
|
||||||
|
|
||||||
|
sub_topic = "roll"
|
||||||
|
aliases = {
|
||||||
|
'Esszimmer': 'EZ',
|
||||||
|
'Wohnzimmer1': 'WZ1',
|
||||||
|
'Wohnzimmer2': 'WZ2',
|
||||||
|
'Wohnzimmer3': 'WZ3',
|
||||||
|
'Wohnzimmer4': 'WZ4',
|
||||||
|
}
|
||||||
|
coil_map = {
|
||||||
|
'EZ': [ 0x03, 0x04 , 0x03, 0x05 ],
|
||||||
|
'WZ1': [ 0x00, 0x01 , 0x00, 0x01 ],
|
||||||
|
'WZ2': [ 0x00, 0x01 , 0x00, 0x01 ],
|
||||||
|
'WZ3': [ 0x00, 0x01 , 0x00, 0x01 ],
|
||||||
|
'WZ4': [ 0x00, 0x01 , 0x00, 0x01 ],
|
||||||
|
}
|
||||||
|
cmd_map = {
|
||||||
|
'off': 0,
|
||||||
|
'on': 1,
|
||||||
|
'value': 2,
|
||||||
|
'toggle': 3
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def decon(msg_id):
|
||||||
|
msg_prio=msg_id>>26
|
||||||
|
msg_type=(msg_id>>24) & 0x03
|
||||||
|
msg_dst=(msg_id>>16) & 0xFF
|
||||||
|
msg_src=(msg_id>>8) & 0xFF
|
||||||
|
msg_cmd=msg_id & 0xFF
|
||||||
|
print("msg_id: ", hex(msg_id), "prio: ", hex(msg_prio),"type: ", hex(msg_type)," dst: ", hex(msg_dst)," src: ", hex(msg_src)," cmd: ",hex(msg_cmd))
|
||||||
|
return [msg_prio, msg_type, msg_dst, msg_src, msg_cmd]
|
||||||
|
|
||||||
|
def con(msg_dst,msg_cmd,msg_prio=3,msg_type=0,msg_src=11, ):
|
||||||
|
msg_id=(msg_prio<<26) + \
|
||||||
|
((msg_type&0x03)<<24) +\
|
||||||
|
((msg_dst&0xFF)<<16) +\
|
||||||
|
((msg_src&0xFF)<<8) +\
|
||||||
|
(msg_cmd&0xFF)
|
||||||
|
print("Constructed ID: "+hex(msg_id))
|
||||||
|
return msg_id
|
||||||
|
|
||||||
|
def on_connect(mcp_mqtt, userdata, flags, rc):
|
||||||
|
print("Connected with result code "+str(rc))
|
||||||
|
|
||||||
|
# Subscribing in on_connect() means that if we lose the connection and
|
||||||
|
# reconnect then subscriptions will be renewed.
|
||||||
|
mcp_mqtt.subscribe(sub_topic+"/+")
|
||||||
|
print("Subscribed to:"+sub_topic+"/+")
|
||||||
|
|
||||||
|
def on_message(mcp_mqtt, userdata, msg):
|
||||||
|
local_bus=userdata
|
||||||
|
print("data Received topic: ", msg.topic)
|
||||||
|
m_decode=str(msg.payload.decode("utf-8","ignore"))
|
||||||
|
print("data Received",m_decode)
|
||||||
|
msg_cmd=2
|
||||||
|
try:
|
||||||
|
value=int(m_decode)
|
||||||
|
except ValueError:
|
||||||
|
msg_cmd=cmd_map[m_decode]
|
||||||
|
|
||||||
|
sub=msg.topic[len(sub_topic)+1:]
|
||||||
|
roll=aliases.get(sub,None)
|
||||||
|
if roll is None:
|
||||||
|
roll=sub
|
||||||
|
|
||||||
|
print("substring: "+roll)
|
||||||
|
addr = light_map[light]
|
||||||
|
msg_id=con(msg_dst=addr[0],msg_cmd=msg_cmd)
|
||||||
|
msg_data=[addr[1]]
|
||||||
|
print(msg_data)
|
||||||
|
if msg_cmd == 2:
|
||||||
|
msg_data.append(value)
|
||||||
|
print(msg_data)
|
||||||
|
m = can.Message(arbitration_id=msg_id,
|
||||||
|
data=msg_data,
|
||||||
|
extended_id=True)
|
||||||
|
print("going to sent to CAN",m)
|
||||||
|
|
||||||
|
try:
|
||||||
|
local_bus.send(m)
|
||||||
|
except BaseException as e:
|
||||||
|
logging.error("Error sending can message {%s}: %s" % (m, e))
|
||||||
|
print("data sent to CAN",m)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
verbosity = 2
|
||||||
|
|
||||||
|
logging_level_name = ['critical', 'error', 'warning', 'info', 'debug', 'subdebug'][min(5, verbosity)]
|
||||||
|
can.set_logging_level(logging_level_name)
|
||||||
|
|
||||||
|
can_filters = []
|
||||||
|
config = {"can_filters": can_filters, "single_handle": True}
|
||||||
|
config["interface"] = "socketcan"
|
||||||
|
config["bitrate"] = 125000
|
||||||
|
bus = Bus("can1", **config)
|
||||||
|
|
||||||
|
print('Connected to {}: {}'.format(bus.__class__.__name__, bus.channel_info))
|
||||||
|
print('Can Logger (Started on {})\n'.format(datetime.now()))
|
||||||
|
|
||||||
|
mcp_mqtt = mqtt.Client()
|
||||||
|
mcp_mqtt.on_connect = on_connect
|
||||||
|
mcp_mqtt.on_message = on_message
|
||||||
|
mcp_mqtt.user_data_set(bus)
|
||||||
|
mcp_mqtt.connect("mcp", 1883, 60)
|
||||||
|
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
mcp_mqtt.loop_start()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
|
bus.shutdown()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Executable
+141
@@ -0,0 +1,141 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
from __future__ import absolute_import, print_function
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import argparse
|
||||||
|
import socket
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
import can
|
||||||
|
from can import Bus, BusState, Logger
|
||||||
|
|
||||||
|
import paho.mqtt.client as mqtt
|
||||||
|
|
||||||
|
topic = "sunevents"
|
||||||
|
event_map = {
|
||||||
|
'sunrise': "up",
|
||||||
|
'night': "down",
|
||||||
|
}
|
||||||
|
coil_map = {
|
||||||
|
'ROL_EZ_DOWN': [0x03,0x05],
|
||||||
|
'ROL_EZ_UP': [0x03,0x04]
|
||||||
|
}
|
||||||
|
group_map = {
|
||||||
|
'up': ['ROL_EZ_UP'],
|
||||||
|
'down': ['ROL_EZ_DOWN']
|
||||||
|
}
|
||||||
|
cmd_map = {
|
||||||
|
'off': 0,
|
||||||
|
'on': 1,
|
||||||
|
'value': 2,
|
||||||
|
'toggle': 3
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def decon(msg_id):
|
||||||
|
msg_prio=msg_id>>26
|
||||||
|
msg_type=(msg_id>>24) & 0x03
|
||||||
|
msg_dst=(msg_id>>16) & 0xFF
|
||||||
|
msg_src=(msg_id>>8) & 0xFF
|
||||||
|
msg_cmd=msg_id & 0xFF
|
||||||
|
# print("msg_id: ", hex(msg_id), "prio: ", hex(msg_prio),"type: ", hex(msg_type)," dst: ", hex(msg_dst)," src: ", hex(msg_src)," cmd: ",hex(msg_cmd))
|
||||||
|
return [msg_prio, msg_type, msg_dst, msg_src, msg_cmd]
|
||||||
|
|
||||||
|
def con(msg_dst,msg_cmd,msg_prio=3,msg_type=0,msg_src=11, ):
|
||||||
|
msg_id=(msg_prio<<26) + \
|
||||||
|
((msg_type&0x03)<<24) +\
|
||||||
|
((msg_dst&0xFF)<<16) +\
|
||||||
|
((msg_src&0xFF)<<8) +\
|
||||||
|
(msg_cmd&0xFF)
|
||||||
|
print("Constructed ID: "+hex(msg_id))
|
||||||
|
return msg_id
|
||||||
|
|
||||||
|
def on_connect(mcp_mqtt, userdata, flags, rc):
|
||||||
|
print("Connected with result code "+str(rc))
|
||||||
|
|
||||||
|
# Subscribing in on_connect() means that if we lose the connection and
|
||||||
|
# reconnect then subscriptions will be renewed.
|
||||||
|
mcp_mqtt.subscribe(topic)
|
||||||
|
print("Subscribed to:",topic)
|
||||||
|
|
||||||
|
def on_message(mcp_mqtt, userdata, msg):
|
||||||
|
local_bus=userdata
|
||||||
|
print("data Received topic: ", msg.topic)
|
||||||
|
m_decode=str(msg.payload.decode("utf-8","ignore"))
|
||||||
|
print("data Received",m_decode)
|
||||||
|
data=m_decode
|
||||||
|
event=event_map[data]
|
||||||
|
if event is not None:
|
||||||
|
# event=sub
|
||||||
|
for key, value in coil_map.items():
|
||||||
|
msg_id=con(msg_dst=value[0],msg_cmd=0)
|
||||||
|
msg_data=[value[1]]
|
||||||
|
print("turning off: ",key,value[0],value[1])
|
||||||
|
m = can.Message(arbitration_id=msg_id,
|
||||||
|
data=msg_data,
|
||||||
|
extended_id=True)
|
||||||
|
print("going to sent to CAN",m)
|
||||||
|
try:
|
||||||
|
local_bus.send(m)
|
||||||
|
except BaseException as e:
|
||||||
|
logging.error("Error sending can message {%s}: %s" % (m, e))
|
||||||
|
print("data sent to CAN",m)
|
||||||
|
|
||||||
|
print("Group: ",event)
|
||||||
|
for coil in group_map[event]:
|
||||||
|
print("turning on", coil)
|
||||||
|
addr = coil_map[coil]
|
||||||
|
msg_id=con(msg_dst=addr[0],msg_cmd=1)
|
||||||
|
msg_data=[addr[1]]
|
||||||
|
print(msg_data)
|
||||||
|
m = can.Message(arbitration_id=msg_id,
|
||||||
|
data=msg_data,
|
||||||
|
extended_id=True)
|
||||||
|
print("going to sent to CAN",m)
|
||||||
|
|
||||||
|
try:
|
||||||
|
local_bus.send(m)
|
||||||
|
except BaseException as e:
|
||||||
|
logging.error("Error sending can message {%s}: %s" % (m, e))
|
||||||
|
print("data sent to CAN",m)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
verbosity = 2
|
||||||
|
|
||||||
|
logging_level_name = ['critical', 'error', 'warning', 'info', 'debug', 'subdebug'][min(5, verbosity)]
|
||||||
|
can.set_logging_level(logging_level_name)
|
||||||
|
|
||||||
|
can_filters = []
|
||||||
|
config = {"can_filters": can_filters, "single_handle": True}
|
||||||
|
config["interface"] = "socketcan"
|
||||||
|
config["bitrate"] = 125000
|
||||||
|
bus = Bus("can1", **config)
|
||||||
|
|
||||||
|
print('Connected to {}: {}'.format(bus.__class__.__name__, bus.channel_info))
|
||||||
|
print('Can Logger (Started on {})\n'.format(datetime.now()))
|
||||||
|
|
||||||
|
mcp_mqtt = mqtt.Client()
|
||||||
|
mcp_mqtt.on_connect = on_connect
|
||||||
|
mcp_mqtt.on_message = on_message
|
||||||
|
mcp_mqtt.user_data_set(bus)
|
||||||
|
mcp_mqtt.connect("mcp", 1883, 60)
|
||||||
|
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
mcp_mqtt.loop_start()
|
||||||
|
msg = bus.recv(1)
|
||||||
|
if msg is not None:
|
||||||
|
de=decon(msg.arbitration_id)
|
||||||
|
m= { "prio": hex(de[0]), "type": hex(de[1]), "dst": hex(de[2]), "src": hex(de[3]), "cmd": hex(de[4]), "action": hex(msg.data[0]) }
|
||||||
|
# print(m)
|
||||||
|
# mcp_mqtt.publish("can/rx", str(m))
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
|
bus.shutdown()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user