2017年4月15日 星期六

Convert NMEA format data to latitude and longitude for GMap Latlng


Reference...
http://aprs.gids.nl/nmea/

Format...
$GPRMC,hhmmss.ss,A,llll.ll,a,yyyyy.yy,a,x.x,x.x,ddmmyy,x.x,a*hh
1    = UTC of position fix
2    = Data status (V=navigation receiver warning)
3    = Latitude of fix
4    = N or S
5    = Longitude of fix
6    = E or W
7    = Speed over ground in knots
8    = Track made good in degrees True
9    = UT date
10   = Magnetic variation degrees (Easterly var. subtracts from true course)
11   = E or W
12   = Checksum

Formula...
Latitude / Longitude = ddmm.mmmm = dd + (mm.mmmm/60) (* -1 for W and S)

Java code...
String str = "$GPRMC,182807.036,A,3731.9404,N,10601.6986,W,0.078542,40.74,050107,,*20"
if( str.startsWith( "$GPRMC" ) )
{
    String[] tags = str.split(",");
    if( tags[2].equals("A") ) {
        String lotdd = tags[3].substring( 0, tags[3].indexOf(".") - 2 );
        String lotmm = tags[3].substring( tags[3].indexOf(".") -2 );
        float lot = Float.valueOf( lotdd ) + Float.valueOf( lotmm )/60;
        if( tags[4].equals("S") )
            lot = -lot;
        String lngdd = tags[5].substring( 0, tags[5].indexOf(".") - 2 );
        String lngmm = tags[5].substring( tags[5].indexOf(".") -2 );
        float lng = Float.valueOf( lngdd ) + Float.valueOf( lngmm )/60;
        if( tags[6].equals("W") )
            lng = -lng;
        LatLng pos = new LatLng( lot, lng );
    } else {
        // Invalid $GPRMC
    }
}

2017年3月26日 星期日

python 透過 google smtp server 發信的方法

python code‧‧‧

import smtplib
    to = 'where@gmail.com'
    server = "smtp.gmail.com"
    #port = 465 # ssl
    port = 587 # tls
    gmail_user = 'youraccount@gmail.com'
    gmail_pwd = 'yourpassword or application password'
    #smtpserver = smtplib.SMTP_SSL(server, long(port)) # ssl
    smtpserver = smtplib.SMTP(server, long(port)) # tls
    smtpserver.ehlo()
    smtpserver.starttls() # tls
    smtpserver.login(gmail_user, gmail_pwd)
    header = 'To:' + to + '\n' + 'From: ' + gmail_user + '\n' + 'Subject:test \n'
    print header
    msg = header + '\n this is test \n\n'
    smtpserver.sendmail(gmail_user, to, msg)
    print 'done!'
    smtpserver.quit()

*如果你有使用兩階段驗證,必須先到 google 個人設定頁,增加應用程式密碼,smtp 才會驗證通過…
    https://myaccount.google.com/apppasswords

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 的板子。

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

VirtualBox 空間減肥

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