# initialize insmod spi-bcm2708 insmod can insmod can-dev insmod can-raw insmod can-bcm insmod mcp251x # Maerklin Gleisbox (60112 and 60113) uses 250000 # loopback mode for testing ip link set can0 type can bitrate 125000 loopback on ifconfig can0 up
root@raspberrypi ~ # candump any,0:0,#FFFFFFFF
root@raspberrypi ~ # cansend can0 123#deadbeef
cansend can0 181#0200
// Front Left Glass Up 181#0200 // Front Left Glass Down 181#0800 // Front Right Glass Up 181#2000 // Front Right Glass Down 181#8000 // Back Left Glass Up 181#0002 // Back Left Glass Down 181#0008 // Back Right Glass Up 181#0020 // Back Right Glass Down 181#0080 // Central Lock Open 291#09AA020000 // Central Lock Close 291#0955040000 // Update Light status of central lock ( / , , ) 291#0900000000
// // FirstViewController.m // Car Control // // Created by Vitaliy Yurkin on 17.05.15. // Copyright (c) 2015 Vitaliy Yurkin. All rights reserved. // #import "FirstViewController.h" #import "DataConnection.h" #import "CommandConnection.h" @interface FirstViewController () <DataConnectionDelegate> @property (nonatomic, strong) DataConnection *dataConnection; @property (nonatomic, strong) CommandConnection *commandConnection; @property (weak, nonatomic) IBOutlet UILabel *Door_1; @property (weak, nonatomic) IBOutlet UILabel *Door_2; @property (weak, nonatomic) IBOutlet UILabel *Door_3; @property (weak, nonatomic) IBOutlet UILabel *Door_4; @property (weak, nonatomic) IBOutlet UIButton *CentralLock; - (IBAction)lockUnlock:(UIButton *)sender; @end @implementation FirstViewController - (void)viewDidLoad { self.dataConnection = [DataConnection new]; self.dataConnection.delegate = self; [self.dataConnection connectToCanBus]; self.commandConnection = [CommandConnection new]; [self.commandConnection connectToCanBus]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)doorStatusChanged:(char)value { /* 1 - Front Left Door 2 - Front Right Door 4 - Back Left Door 8 - Back Right Door 3 - Front Left&Right Door = 1 + 3 5 - Front& Back left Door = 1 + 4 */ // Front Left Door if (value & 1) { self.Door_1.backgroundColor = [UIColor yellowColor]; self.Door_1.text = @""; NSLog(@"1"); } else { self.Door_1.backgroundColor = [UIColor lightGrayColor]; self.Door_1.text = @""; } // Front Right Door if (value & 2) { self.Door_2.backgroundColor = [UIColor yellowColor]; self.Door_2.text = @""; NSLog(@"2"); } else { self.Door_2.backgroundColor = [UIColor lightGrayColor]; self.Door_2.text = @""; } // Back Left Door if (value & 4) { self.Door_3.backgroundColor = [UIColor yellowColor]; self.Door_3.text = @""; NSLog(@"4"); } else { self.Door_3.backgroundColor = [UIColor lightGrayColor]; self.Door_3.text = @""; } // Back Right Door if (value & 8) { self.Door_4.backgroundColor = [UIColor yellowColor]; self.Door_4.text = @""; NSLog(@"8"); } else { self.Door_4.backgroundColor = [UIColor lightGrayColor]; self.Door_4.text = @""; } } BOOL firstStatusChange = YES; BOOL lastStatus; -(void) centralLockStatusChanged:(BOOL)status { // At first status changes set lastStatus variable if (firstStatusChange) { firstStatusChange = NO; // Invert status, to pass the next test lastStatus = !status; } // Change Lock image only if status changed if (!(lastStatus == status)) { // Check status if (status) { [self.CentralLock setBackgroundImage:[UIImage imageNamed:@"lock_close"] forState:UIControlStateNormal]; } else { [self.CentralLock setBackgroundImage:[UIImage imageNamed:@"lock_open"] forState:UIControlStateNormal]; } lastStatus = status; } } // Front Left Glass - (IBAction)frontLeftUp:(UIButton *)sender { [self.commandConnection sendMessage:@"cansend can0 181#0200"]; } - (IBAction)frontLeftDown:(id)sender { [self.commandConnection sendMessage:@"cansend can0 181#0800"]; } // Front Right Glass - (IBAction)frontRightUp:(UIButton *)sender { [self.commandConnection sendMessage:@"cansend can0 181#2000"]; } - (IBAction)frontRightDown:(id)sender { [self.commandConnection sendMessage:@"cansend can0 181#8000"]; } // Back Left Glass - (IBAction)backLeftUp:(UIButton *)sender { [self.commandConnection sendMessage:@"cansend can0 181#0002"]; } - (IBAction)backLeftDown:(id)sender { [self.commandConnection sendMessage:@"cansend can0 181#0008"]; } // Back Right Glass - (IBAction)backRightUp:(UIButton *)sender { [self.commandConnection sendMessage:@"cansend can0 181#0020"]; } - (IBAction)backtRightDown:(id)sender { [self.commandConnection sendMessage:@"cansend can0 181#0080"]; } - (IBAction)lockUnlock:(UIButton *)sender { // If central lock closed if (lastStatus) { // Open [self.commandConnection sendMessage:@"cansend can0 291#09AA020000"]; int64_t delayInSeconds = 1; // 1 sec dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ [self.commandConnection sendMessage:@"cansend can0 291#0900000000"]; }); } else { // Close [self.commandConnection sendMessage:@"cansend can0 291#0955040000"]; int64_t delayInSeconds = 1; // 1 sec dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ [self.commandConnection sendMessage:@"cansend can0 291#0900000000"]; }); } } @end
wget -q -O - razberry.z-wave.me/install | sudo bash
Source: https://habr.com/ru/post/399043/