Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Lora
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
MONICA
Lora Gateway
Lora
Commits
db608045
Commit
db608045
authored
6 years ago
by
philip.schell
Browse files
Options
Downloads
Patches
Plain Diff
[NF] More porting of lib
parent
2238998b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Lora/lib/LoraConnector.cs
+84
-15
84 additions, 15 deletions
Lora/lib/LoraConnector.cs
with
84 additions
and
15 deletions
Lora/lib/LoraConnector.cs
+
84
−
15
View file @
db608045
...
...
@@ -8,24 +8,77 @@ using Unosquare.RaspberryIO.Gpio;
namespace
Fraunhofer.Fit.Iot.Lora.lib
{
public
class
LoraConnector
{
private
double
_frequency
=
0.0
;
private
int
_packetIndex
=
0
;
private
int
_implictHeaderMode
=
0
;
private
object
_onReceive
=
null
;
enum
Registers
:
Byte
{
REG_VERSION
=
0x42
FIFO
=
0x00
,
OP_MODE
=
0x01
,
FRF_MSB
=
0x06
,
FRF_MID
=
0x07
,
FRF_LSB
=
0x08
,
PA_CONFIG
=
0x09
,
LNA
=
0x0C
,
FIFO_ADDR_PTR
=
0x0D
,
FIFO_TX_BASE_ADDR
=
0x0E
,
FIFO_RX_BASE_ADDR
=
0x0F
,
FIFO_RX_CURRENT_ADDR
=
0x10
,
IRQ_FLAGS
=
0x12
,
RX_NB_BYTES
=
0x13
,
PKT_SNR_VALUE
=
0x19
,
PKT_RSSI_VALUE
=
0x1A
,
MODEM_CONFIG_1
=
0x1D
,
MODEM_CONFIG_2
=
0x1E
,
PREAMBLE_MSB
=
0x20
,
PREAMBLE_LSB
=
0x21
,
PAYLOAD_LENGTH
=
0x22
,
MODEM_CONFIG_3
=
0x26
,
FREQ_ERROR_MSB
=
0x28
,
FREQ_ERROR_MID
=
0x29
,
FREQ_ERROR_LSB
=
0x2A
,
RSSI_WIDEBAND
=
0x2C
,
DETECTION_OPTIMIZE
=
0x31
,
DEDECTION_THRESHOLD
=
0x37
,
SYNC_WORD
=
0x39
,
DIO_MAPPING_1
=
0x40
,
VERSION
=
0x42
};
enum
Modes
:
Byte
{
SLEEP
=
0x00
,
STDBY
=
0x01
,
TX
=
0x03
,
RX_CONTINOUS
=
0x05
,
RX_SINGLE
=
0x06
,
LONG_RANGE_MODE
=
0x80
};
enum
Pa
:
Byte
{
BOOST
=
0x80
};
enum
Irq
:
Byte
{
TX_DONE_MASK
=
0x08
,
PAYLOAD_CRC_ERROR_MASK
=
0x20
,
RX_DONE_MASK
=
0x40
}
public
LoraConnector
()
{
Pi
.
Spi
.
Channel0Frequency
=
SpiChannel
.
MinFrequency
;
//ssPin = 6;
Pi
.
Gpio
.
Pin06
.
PinMode
=
GpioPinDriveMode
.
Output
;
//RST = 0;
Pi
.
Gpio
.
Pin00
.
PinMode
=
GpioPinDriveMode
.
Output
;
Pi
.
Gpio
.
Pin00
.
Write
(
false
);
System
.
Threading
.
Thread
.
Sleep
(
100
);
Pi
.
Gpio
.
Pin00
.
Write
(
true
);
System
.
Threading
.
Thread
.
Sleep
(
100
);
Byte
version
=
ReadRegister
((
Byte
)
Registers
.
REG_VERSION
);
Console
.
WriteLine
(
version
);
this
.
SetupIO
();
this
.
Reset
();
Byte
version
=
ReadRegister
((
Byte
)
Registers
.
VERSION
);
if
(
version
!=
0x12
)
{
throw
new
Exception
(
"Wrong Hardware!"
);
}
this
.
Sleep
();
this
.
SetFrequency
(
freq
);
//set base Addr
this
.
WriteRegister
((
Byte
)
Registers
.
FIFO_TX_BASE_ADDR
,
0
);
this
.
WriteRegister
((
Byte
)
Registers
.
FIFO_RX_BASE_ADDR
,
0
);
//set LNA boost
this
.
WriteRegister
((
Byte
)
Registers
.
LNA
,
(
Byte
)(
ReadRegister
((
Byte
)
Registers
.
LNA
)
|
0x03
));
//set auto AGC
this
.
WriteRegister
((
Byte
)
Registers
.
MODEM_CONFIG_3
,
0x04
);
this
.
SetTxPower
(
17
);
this
.
Ilde
();
}
private
Byte
ReadRegister
(
Byte
address
)
{
return
this
.
SingleTransfer
((
Byte
)(
address
&
0x7F
),
0x00
);
...
...
@@ -33,6 +86,21 @@ namespace Fraunhofer.Fit.Iot.Lora.lib {
private
void
WriteRegister
(
Byte
address
,
Byte
value
)
{
this
.
SingleTransfer
((
Byte
)(
address
|
0x80
),
value
);
}
#
region
Hardware
IO
private
void
Reset
()
{
Pi
.
Gpio
.
Pin00
.
Write
(
false
);
System
.
Threading
.
Thread
.
Sleep
(
100
);
Pi
.
Gpio
.
Pin00
.
Write
(
true
);
System
.
Threading
.
Thread
.
Sleep
(
100
);
}
private
void
SetupIO
()
{
Pi
.
Spi
.
Channel0Frequency
=
SpiChannel
.
MinFrequency
;
//ssPin = 6;
Pi
.
Gpio
.
Pin06
.
PinMode
=
GpioPinDriveMode
.
Output
;
//RST = 0;
Pi
.
Gpio
.
Pin00
.
PinMode
=
GpioPinDriveMode
.
Output
;
}
private
Byte
SingleTransfer
(
Byte
address
,
Byte
value
)
{
Selectreceiver
();
Byte
[]
spibuf
=
Pi
.
Spi
.
Channel0
.
SendReceive
(
new
Byte
[]
{
address
,
0x00
});
...
...
@@ -45,5 +113,6 @@ namespace Fraunhofer.Fit.Iot.Lora.lib {
private
void
Unselectreceiver
()
{
Pi
.
Gpio
.
Pin06
.
Write
(
true
);
}
#
endregion
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment