Skip to content

Commit 97d8576

Browse files
committed
2017.02.16. psp_2.0.0
- Initial release (from psp2_20160519)
0 parents  commit 97d8576

File tree

149 files changed

+9046
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+9046
-0
lines changed

README.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
## PHPoC Support Package
2+
PHPoC source codes for basic libraries and examples
3+
4+
## Libraries
5+
* sc_envs.php
6+
* sc_envu.php
7+
* sd_101.php
8+
* sd_104.php
9+
* sd_204.php
10+
* sd_340.php
11+
* sn_dns.php
12+
* sn_esmtp.php
13+
* sn_mysql.php
14+
* sn_smtp.php
15+
* sn_tcp_ac.php
16+
* sn_tcp_ws.php
17+
18+
## Examples
19+
### net
20+
#### 1. php_task
21+
* dns_lookup
22+
* email
23+
* email_msa
24+
* http_get
25+
* mysql_insert
26+
* mysql_update
27+
* tcp0_echo_ac
28+
* tcpn_echo_ac
29+
30+
#### 2. html_text
31+
* setup
32+
33+
### p4s
34+
#### 1. php_task
35+
* hello
36+
* uart_hello
37+
* uio_buzzer
38+
* uio_ob_led
39+
* uio_touch_sensor
40+
* adc_light_sensor
41+
* adc_rotary_angle
42+
* ht_pwm_servo
43+
* ht_ultrasonic
44+
45+
#### 2. html_text
46+
* hello
47+
* uio_buzzer
48+
* uio_ob_led
49+
* uio_touch_sensor
50+
* adc_light_sensor
51+
* adc_rotary_angle
52+
* ht_pwm_servo
53+
* ht_ultrasonic
54+
55+
#### 3. html_image
56+
* hello
57+
* uio_buzzer
58+
* uio_ob_led
59+
* uio_touch_sensor
60+
* adc_light_sensor
61+
* adc_rotary_angle
62+
* ht_pwm_servo
63+
* ht_ultrasonic
64+
65+
#### 4. html5_text
66+
* hello
67+
* uio_touch_sensor
68+
* adc_light_sensor
69+
* adc_rotary_angle
70+
* ht_ultrasonic
71+
72+
#### 5. html5_graphics
73+
* hello
74+
* uio_buzzer
75+
* uio_ob_led
76+
* adc_light_sensor
77+
* adc_rotary_angle
78+
* ht_pwm_servo
79+
80+
### pbh
81+
#### 1. php_task
82+
* 101
83+
* 104
84+
* 204
85+
86+
#### 2. html_text
87+
* 204
88+
89+
## References
90+
* [PSP Library Reference](http://www.phpoc.com/support/manual/psp_library_reference/)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
system("php task0.php");
4+
5+
?>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
if(_SERVER("REQUEST_METHOD"))
4+
exit; // avoid php execution via http request
5+
6+
include_once "/lib/sn_dns.php";
7+
8+
echo "PHPoC example : get ip address by host name\r\n";
9+
10+
dns_setup(0, "");
11+
12+
$host_name = "www.google.com";
13+
$host_addr = dns_lookup($host_name, RR_A);
14+
15+
if($host_addr == $host_name)
16+
echo "$host_name : Not Found\r\n";
17+
else
18+
echo "$host_name : $host_addr\r\n";
19+
20+
?>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
system("php task0.php");
4+
5+
?>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
if(_SERVER("REQUEST_METHOD"))
4+
exit; // avoid php execution via http request
5+
6+
include_once "/lib/sn_dns.php";
7+
include_once "/lib/sn_smtp.php";
8+
9+
echo "PHPoC example : send email\r\n";
10+
11+
//smtp_setup(udp_id, tcp_id, "x.x.x.x");
12+
//smtp_hostname("from_domain.com");
13+
//smtp_account("from_id@from_domain.com", "from_name");
14+
15+
$subject = "email test from PHPoC";
16+
$message = "This is PHPoC test email\r\nGood bye\r\n";
17+
18+
$msg = smtp_send("to_id@to_domain.com", "to_name", $subject, $message);
19+
20+
if($msg == "221")
21+
echo "send email successful\r\n";
22+
else
23+
echo "send email failed\r\n";
24+
25+
?>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
system("php task0.php");
4+
5+
?>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
if(_SERVER("REQUEST_METHOD"))
4+
exit; // avoid php execution via http request
5+
6+
include_once "/lib/sn_dns.php";
7+
include_once "/lib/sn_esmtp.php";
8+
9+
echo "PHPoC example : send email via out-going mail server\r\n";
10+
11+
//esmtp_setup(udp_id, tcp_id, "x.x.x.x");
12+
//esmtp_hostname("from_domain.com");
13+
esmtp_account("from_id@from_domain.com", "from_name");
14+
esmtp_auth("msa_id", "msa_password");
15+
esmtp_msa("smtp.gmail.com", 465);
16+
//esmtp_msa("smtp.naver.com", 465);
17+
//esmtp_msa("smtp.daum.net", 465);
18+
19+
$subject = "msa test";
20+
$message = "Hi PHPoC\r\nThis is PHPoC msa test email\r\nGood bye\r\n";
21+
22+
$msg = esmtp_send("to_id@to_domain.com", "to_name", $subject, $message);
23+
24+
if($msg == "221")
25+
echo "send mail successful\r\n";
26+
else
27+
echo "send mail failed\r\n";
28+
29+
?>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
system("php task0.php");
4+
5+
?>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
if(_SERVER("REQUEST_METHOD"))
4+
exit; // avoid php execution via http request
5+
6+
include_once "/lib/sn_dns.php";
7+
8+
echo "PHPoC example : get web page from www server\r\n";
9+
10+
$host_name = "www.google.com";
11+
$host_addr = dns_lookup($host_name, RR_A);
12+
13+
if($host_addr == $host_name)
14+
exit "$host_name : Not Found\r\n";
15+
16+
$tcp0_pid = pid_open("/mmap/tcp0");
17+
18+
echo "connect to $host_addr:80...";
19+
20+
pid_connect($tcp0_pid, $host_addr, 80);
21+
22+
for(;;)
23+
{
24+
$state = pid_ioctl($tcp0_pid, "get state");
25+
26+
if($state == TCP_CLOSED)
27+
{
28+
pid_close($tcp0_pid);
29+
exit "failed\r\n";
30+
}
31+
32+
if($state == TCP_CONNECTED)
33+
break;
34+
}
35+
36+
echo "connected\r\n";
37+
38+
$http_req = "GET / HTTP/1.1\r\n";
39+
$http_req .= "Host: $host_name\r\n";
40+
$http_req .= "Connection: closed\r\n";
41+
$http_req .= "\r\n\r\n";
42+
43+
pid_send($tcp0_pid, $http_req);
44+
45+
$rbuf = "";
46+
47+
for(;;)
48+
{
49+
if(pid_recv($tcp0_pid, $rbuf) > 0)
50+
{
51+
echo $rbuf;
52+
continue;
53+
}
54+
55+
if(pid_ioctl($tcp0_pid, "get state") == TCP_CLOSED)
56+
break;
57+
}
58+
59+
echo "connection closed\r\n";
60+
61+
pid_close($tcp0_pid);
62+
63+
?>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
system("php task0.php");
4+
5+
?>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
if(_SERVER("REQUEST_METHOD"))
4+
exit; // avoid php execution via http request
5+
6+
include_once "/lib/sn_dns.php";
7+
include_once "/lib/sn_mysql.php";
8+
9+
//Check and print error messages from DB server
10+
function chk_error($result)
11+
{
12+
if($result !== false)
13+
{
14+
$error = mysql_error($result);
15+
if(strlen($error) != 0)
16+
echo "Error: $error\r\n";
17+
}
18+
}
19+
20+
echo "PHPoC example: insert data to MYSQL DB\r\n\r\n";
21+
22+
//Enter your DB Server's hostname or IP address!
23+
$server_addr = "192.168.0.100";
24+
25+
//Enter your account information!
26+
$user_name = "user_id";
27+
$password = "password";
28+
29+
//mysql_setup(0, 0, "", true); // enable IPv6
30+
31+
//Connect to DB Server
32+
if(mysql_connect($server_addr, $user_name, $password))
33+
{
34+
//Create a database named student
35+
$result = mysql_query("CREATE DATABASE student;");
36+
chk_error($result);
37+
$result = mysql_select_db("student");
38+
chk_error($result);
39+
//Create a table named student
40+
$result = mysql_query("CREATE TABLE tbl_student (id INTEGER, name VARCHAR(20));");
41+
chk_error($result);
42+
//Insert a record
43+
$result = mysql_query("INSERT INTO tbl_student (id, name) VALUES (1, 'John');");
44+
chk_error($result);
45+
//Inquiry all record
46+
$result = mysql_query("SELECT * FROM tbl_student;");
47+
chk_error($result);
48+
//Get a result of the inquiry
49+
$result_arr = mysql_fetch_row($result);
50+
//Print the result
51+
printf("%s -> %s\r\n", $result_arr[0], $result_arr[1]);
52+
//Delete the table
53+
$result = mysql_query("DROP TABLE tbl_student;");
54+
chk_error($result);
55+
//Delete the database
56+
$result = mysql_query("DROP DATABASE student;");
57+
chk_error($result);
58+
echo "example has been finished!\r\n";
59+
mysql_close();
60+
}
61+
else
62+
echo "example has been failed\r\n";
63+
64+
?>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
system("php task0.php");
4+
5+
?>

0 commit comments

Comments
 (0)