2017年3月1日 星期三

網頁後台使用 php 執行 python 操作 serial (uart) 權限的設定




uart0.php... (透過 shell_exec 執行 python 碼)
===============================================
$cmd = escapeshellcmd ( '/usr/bin/python uart0.py' );
$output = shell_exec ( $cmd );
echo $output;
===============================================

uart0.py... (console下執行沒問題,但透過 php 執行沒結果)
===============================================
import serial
serialport = serial.Serial("/dev/ttyAMA0", 9600, timeout=0.5)
serialport.write( "TEST" )
response = serialport.readlines(None)
print response
===============================================

解決… (需要設定裝置的權限 ttyAMA0 屬於 dialout 群組)
=1=暫時-reboot後無效==============================
sudo chmod 777 /dev/ttyAMA0
=2=============================================
sudo adduser youruser dialout
usermod -aG dialout youruser
===============================================


2016年10月18日 星期二

AFS ReVersiNG


AFS ReVersiNG Guide


-working with MAZDA CX5、Cadillac ATS


STEP0. Hardware Analyze - connector defination、power line、data line…
STEP1. Use Linbus/Canbus Analyzer
STEP2, Stage by stage mining Linbus data records, in the meantime watch over AFS's action
  • ACC OFF
  • ACC ON
  • ENGINE START
  • TURN ON THE HEADLIGHT
  • GEAR SHIFT TO P/N/D/R/...
  • TURN WHEEL LEFT/RIGHT
  • TURN OFF THE HEADLIGHT
  • STOP ENGINE
  • ACC OFF
STEP3. Find out the valuable changing with wheel turning
STEP4. Figure out which record is writing and which is reading and what is there meaning
STEP5. Is there any initial progress at beginning ?
STEP6. Hardware implement
STEP7. Firmware implement
STEP8. Cut off KD module and replace with reversing one
  • Attention: Do not run to this step until you figure out the ECU's every read / write procedure
STEP9. See what happens :)


2016年4月26日 星期二

Xilinx Virtual Download Cable using Raspberry Pi

based on this project below…( Thanks this great project )
https://github.com/tmbinc/xvcd

just replacement following function calls…

======== gipo.c ========
#include

#define GPIO_TDI 3       /// JTAG TDI pin
#define GPIO_TDO 12   /// JTAG TDO pin
#define GPIO_TCK 13   /// JTAG TCK pin
#define GPIO_TMS 14   /// JTAG TMS pin

void gpio_init(void)
{
if (wiringPiSetup() == -1)
return;
gpio_output(GPIO_TDI, 1);
gpio_output(GPIO_TMS, 1);
gpio_output(GPIO_TCK, 1);
gpio_output(GPIO_TDO, 0);
}

void gpio_close(void)
{
}
================

======== gipo_inline.h ========
static inline void gpio_output(int i, int dir)
{
if (dir)
pinMode (i, OUTPUT);
else
pinMode (i, INPUT);
}

static inline void gpio_set(int i, int val)
{
if (!val)
digitalWrite (i, 0) ; // Off
else
digitalWrite (i, 1) ; // On

}

static inline int gpio_get(int i)
{
return (digitalRead( i )!=0);
}
================

Tested with NetBeans IDE 8.1 + Raspberry Pi 1 & 2 + Xilinx XC3S400AN



2016年4月22日 星期五

NETBEANS 開發 RASPBERRY PI APP

使用 NETBEANS 開發 RASPBERRY PI APP
非常方便,可遠端開發、執行偵錯

請參考此篇…
http://www.raspberry-projects.com/pi/programming-in-c/compilers-and-ides/netbeans-windows/installing-netbeans-for-c-remote-development-on-a-raspberry-pi

主要需增加一個遠端 HOST 的設定

若有使用 WIRING PI 等 I/O 底層服務,則需以 ROOT 身份進行遠端操作
可參考此篇…
http://www.raspberry-projects.com/pi/programming-in-c/compilers-and-ides/netbeans-windows/creating-a-new-project

主要為了打開 ROOT 帳戶
sudo passwd root
sudo nano /etc/ssh/sshd_config
PermitRootLogin and change it to yes (the default "without-password" won't work – change it to "yes"
存檔後 reboot

2016年4月18日 星期一

這些年摸過的小玩意

記錄一下這些年摸過的小玩意…

RASPBERRY PI : 拿來開發較複雜的系統很好,Linux base 的核心基本上可以玩的東西就很多了,而且資源也很豐富。

Intel Galileo : 只稍微摸看看,基本上能玩的跟 PI 應該大同小意。

Arduino DUE : 32bit ARM 作出來的強化版 Arduino,可以開發 ADK( Android Open Accessory Development Kit) 不過現在都走無線的了吧?

Arduino UNO : 好用是無庸置疑的,拿來作快速開發,網路上還有一堆 lib 可以用。

TI MSP430 : Good

ESP2866 : 小型 wifi 嵌入式系統,腳位不多,可以拿來作 iot 之類的東西。

TI CC2541 : 藍牙模組,可以拿來作 iot 之類的東西,開發手機應用產品。

EN28j60 : 8bit 低階 MCU 上網功能,還算堪用,也因此學會了很多網路底層的東西。

STM32F030 : 便宜的 ARM,拿來當強化版的 8bit MCU 用。

Freescale FRDM KL-05 : 還 ok。

Freescale TWR-S12G128 : 還 ok。☆

Arduino W5100  Ethernet Shield : Arduino 要簡單上網就靠它了。

STM32 Demo Board : 拿來學習 ARM 的板子。

ST NUCLEO-F411RE : mbed 開發版。

STM32 Demo Board : 拿來學習 ARM 的板子。

還有其它數不清的小模組板…

2014年9月18日 星期四

Android Bluetooth Serial Port Profile Bluetooth Device Client


透過簡單的函式使用 spp bluetooth 設備…
    bt_init("HC-05");

將底下程式碼 copy 到 activity 中使用…

    // ======== START Bluetooth functions ======== //
    BluetoothAdapter mmBluetoothAdapter = null;
    BluetoothDevice mmDevice = null;
    BluetoothSocket mmSocket = null;
    OutputStream mmOutputStream = null;
    InputStream mmInputStream = null;
    Thread bt_read = null;

    // try to open a Serial Port Profile Bluetooth Device
    public void bt_init(String device_name) {

        mmBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
       
        if (mmBluetoothAdapter == null) {
            Toast.makeText(this, "Bluetooth not found", Toast.LENGTH_SHORT).show();
            return;
        }

        if (!mmBluetoothAdapter.isEnabled()) {
            Intent enableBluetooth = new Intent(
                    BluetoothAdapter.ACTION_REQUEST_ENABLE);
            startActivityForResult(enableBluetooth, 0);
            Toast.makeText(this, "Bluetooth not enabled", Toast.LENGTH_SHORT).show();
            return;
        }

        Set paired = mmBluetoothAdapter.getBondedDevices();
       
        if (paired.size() == 0) {
            Toast.makeText(this, "No paired bluetooth devices", Toast.LENGTH_SHORT).show();
            return;
        }
       
        for (BluetoothDevice device : paired) {
            if (device.getName().equals(device_name)) {
                mmDevice = device;
                break;
            }
        }

        if (mmDevice == null) {
            Toast.makeText(this, "Device not found", Toast.LENGTH_SHORT).show();
            return;
        }

        // Serial Port Profile UUID
        UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
        try {
            mmSocket = mmDevice.createRfcommSocketToServiceRecord(uuid);
            mmSocket.connect();
            mmOutputStream = mmSocket.getOutputStream();
            mmInputStream = mmSocket.getInputStream();
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(this, "Bluetooth connect fail", Toast.LENGTH_SHORT).show();
            return;
        }

        // TODO: read data
        bt_read = new Thread(new Runnable() {
            public void run() {
                while (true) {
                    try {
                        // read a char from bluetooth device
                        if (mmInputStream.available() > 0) {
                            int c = mmInputStream.read();
                            bt_write(c); // ECHO
                        }
                    } catch (IOException ex) {
                        break;
                    }
                }
            }
        });
        bt_read.start();
       
        Toast.makeText(this, "Bluetooth connected", Toast.LENGTH_SHORT).show();
    }

    // TODO: write data
    // write a char to bluetooth device
    void bt_write(int c) {
        try {
            if (mmOutputStream != null)
                mmOutputStream.write(c);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    // ======== END Bluetooth functions ======== //


記得 uses-permission 要增加…
    android.permission.BLUETOOTH
    android.permission.BLUETOOTH_ADMIN


2013年9月22日 星期日

自製 Android 遊戲「香蕉檸檬

自製 Android 遊戲「香蕉檸檬」開發完成,日前正式上架,算是我第一個正式上架的遊戲,朋友們有 Android 手機的可以安裝玩看看哦^^~

雖然是殺時間的小小益智遊戲,但也要手腳明快,頭腦清楚才能得高分唷!!!
目前最高分 300 多萬!!!

*記得用 FB 登入 Swarm,才能進入世界排名~
*Google Play 搜尋 「BANANA X LEMON」就可找到~

https://play.google.com/store/apps/details?id=com.longfellow.bananaxlemon&hl=zh-TW

VirtualBox 空間減肥

sdelete64 -z c: VBoxManage  modifymedium  disk  "/Users/fellow/VirtualBox VMs/Win10/Win10.vdi"  --compact *.vdi 路徑可以在 VirtualBox 儲...